~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/schema.cc

  • Committer: Lee Bieber
  • Date: 2011-03-23 01:55:35 UTC
  • mfrom: (2245.1.2 build)
  • Revision ID: kalebral@gmail.com-20110323015535-2aatqy8tyiuqtc2z
Merge Olaf - more code refactoring

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
#include <drizzled/pthread_globals.h>
43
43
#include <drizzled/charset.h>
44
44
#include <drizzled/internal/my_sys.h>
45
 
 
 
45
#include <drizzled/catalog/instance.h>
46
46
#include <boost/thread/mutex.hpp>
47
47
 
48
48
#define MAX_DROP_TABLE_Q_LEN      1024
49
49
 
50
50
using namespace std;
51
51
 
52
 
namespace drizzled
53
 
{
54
 
 
55
 
namespace schema
56
 
{
57
 
 
58
 
static void change_db_impl(Session &session);
59
 
static void change_db_impl(Session &session, identifier::Schema &schema_identifier);
 
52
namespace drizzled {
 
53
namespace schema {
60
54
 
61
55
/*
62
56
  Create a database
212
206
    ERROR Error
213
207
*/
214
208
 
215
 
bool drop(Session &session, identifier::Schema &schema_identifier, const bool if_exists)
 
209
bool drop(Session &session, const identifier::Schema &schema_identifier, bool if_exists)
216
210
{
217
211
  bool error= false;
218
212
 
271
265
    it to 0.
272
266
  */
273
267
  if (not error and schema_identifier.compare(*session.schema()))
274
 
    change_db_impl(session);
 
268
    session.set_db("");
275
269
 
276
270
  session.startWaitingGlobalReadLock();
277
271
 
340
334
    @retval true  Error
341
335
*/
342
336
 
343
 
bool change(Session &session, identifier::Schema &schema_identifier)
 
337
bool change(Session &session, const identifier::Schema &schema_identifier)
344
338
{
345
339
 
346
340
  if (not plugin::Authorization::isAuthorized(*session.user(), schema_identifier))
365
359
    return true;
366
360
  }
367
361
 
368
 
  change_db_impl(session, schema_identifier);
 
362
  session.set_db(schema_identifier.getSchemaName());
369
363
 
370
364
  return false;
371
365
}
381
375
  @param new_db_charset Character set of the new database.
382
376
*/
383
377
 
384
 
static void change_db_impl(Session &session, identifier::Schema &schema_identifier)
385
 
{
386
 
  /* 1. Change current database in Session. */
387
 
 
388
 
#if 0
389
 
  if (new_db_name == NULL)
390
 
  {
391
 
    /*
392
 
      Session::set_db() does all the job -- it frees previous database name and
393
 
      sets the new one.
394
 
    */
395
 
 
396
 
    session->set_db(NULL, 0);
397
 
  }
398
 
  else
399
 
#endif
400
 
  {
401
 
    /*
402
 
      Here we already have a copy of database name to be used in Session. So,
403
 
      we just call Session::reset_db(). Since Session::reset_db() does not releases
404
 
      the previous database name, we should do it explicitly.
405
 
    */
406
 
 
407
 
    session.set_db(schema_identifier.getSchemaName());
408
 
  }
409
 
}
410
 
 
411
 
static void change_db_impl(Session &session)
412
 
{
413
 
  session.set_db(string());
414
 
}
415
378
 
416
379
/*
417
380
  Check if database name is valid
425
388
    true ok
426
389
*/
427
390
 
428
 
bool check(Session &session, identifier::Schema &schema_identifier)
 
391
bool check(Session &session, const identifier::Schema &schema_identifier)
429
392
{
430
393
  if (not plugin::Authorization::isAuthorized(*session.user(), schema_identifier))
431
 
  {
432
394
    return false;
433
 
  }
434
 
 
435
395
  return schema_identifier.isValid();
436
396
}
437
397