~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/db.cc

  • Committer: Brian Aker
  • Date: 2010-12-27 19:18:58 UTC
  • mfrom: (2035 staging)
  • mto: (2035.1.1 clean)
  • mto: This revision was merged to the branch mainline in revision 2037.
  • Revision ID: brian@tangent.org-20101227191858-h11rg8ncrkiklg3f
Manage merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
static long drop_tables_via_filenames(Session *session,
61
61
                                 SchemaIdentifier &schema_identifier,
62
62
                                 TableIdentifier::vector &dropped_tables);
63
 
static void mysql_change_db_impl(Session *session);
64
 
static void mysql_change_db_impl(Session *session, SchemaIdentifier &schema_identifier);
 
63
static void change_db_impl(Session *session);
 
64
static void change_db_impl(Session *session, SchemaIdentifier &schema_identifier);
65
65
 
66
66
/*
67
67
  Create a database
68
68
 
69
69
  SYNOPSIS
70
 
  mysql_create_db()
 
70
  create_db()
71
71
  session               Thread handler
72
72
  db            Name of database to create
73
73
                Function assumes that this is already validated.
84
84
 
85
85
*/
86
86
 
87
 
bool mysql_create_db(Session *session, const message::Schema &schema_message, const bool is_if_not_exists)
 
87
bool create_db(Session *session, const message::Schema &schema_message, const bool is_if_not_exists)
88
88
{
89
89
  TransactionServices &transaction_services= TransactionServices::singleton();
90
90
  bool error= false;
149
149
 
150
150
/* db-name is already validated when we come here */
151
151
 
152
 
bool mysql_alter_db(Session *session, const message::Schema &schema_message)
 
152
bool alter_db(Session *session, const message::Schema &schema_message)
153
153
{
154
154
  TransactionServices &transaction_services= TransactionServices::singleton();
155
155
 
202
202
  Drop all tables in a database and the database itself
203
203
 
204
204
  SYNOPSIS
205
 
    mysql_rm_db()
 
205
    rm_db()
206
206
    session                     Thread handle
207
207
    db                  Database name in the case given by user
208
208
                        It's already validated and set to lower case
215
215
    ERROR Error
216
216
*/
217
217
 
218
 
bool mysql_rm_db(Session *session, SchemaIdentifier &schema_identifier, const bool if_exists)
 
218
bool rm_db(Session *session, SchemaIdentifier &schema_identifier, const bool if_exists)
219
219
{
220
220
  long deleted=0;
221
221
  int error= false;
277
277
      /* After deleting database, remove all cache entries related to schema */
278
278
      table::Cache::singleton().removeSchema(schema_identifier);
279
279
 
280
 
 
281
280
      error= -1;
282
281
      deleted= drop_tables_via_filenames(session, schema_identifier, dropped_tables);
283
282
      if (deleted >= 0)
284
283
      {
285
284
        error= 0;
 
285
        
 
286
        /* We've already verified that the schema does exist, so safe to log it */
 
287
        TransactionServices &transaction_services= TransactionServices::singleton();
 
288
        transaction_services.dropSchema(session, schema_identifier.getSchemaName());
286
289
      }
287
290
    }
288
291
    if (deleted >= 0)
289
292
    {
290
 
      assert(not session->getQueryString()->empty());
291
 
 
292
 
      TransactionServices &transaction_services= TransactionServices::singleton();
293
 
      transaction_services.dropSchema(session, schema_identifier.getSchemaName());
294
293
      session->clear_error();
295
294
      session->server_status|= SERVER_STATUS_DB_DROPPED;
296
295
      session->my_ok((uint32_t) deleted);
342
341
      it to 0.
343
342
    */
344
343
    if (schema_identifier.compare(*session->schema()))
345
 
      mysql_change_db_impl(session);
 
344
      change_db_impl(session);
346
345
  }
347
346
 
348
347
  session->startWaitingGlobalReadLock();
435
434
      {
436
435
        error= plugin::StorageEngine::dropTable(*session, identifier);
437
436
 
 
437
        /* Generate transaction event ONLY when we successfully drop */ 
 
438
        if (error == 0)
 
439
        {
 
440
          transaction_services.dropTable(session, string(db), string(table->getTableName()));
 
441
        }
 
442
 
438
443
        if ((error == ENOENT || error == HA_ERR_NO_SUCH_TABLE))
439
444
        {
440
445
          error= 0;
448
453
        }
449
454
      }
450
455
 
451
 
      if (error == 0 || (foreign_key_error == false))
452
 
      {
453
 
        transaction_services.dropTable(session, string(db), string(table->getTableName()), true);
454
 
      }
455
 
 
456
456
      if (error)
457
457
      {
458
458
        if (wrong_tables.length())
616
616
    @retval true  Error
617
617
*/
618
618
 
619
 
bool mysql_change_db(Session *session, SchemaIdentifier &schema_identifier)
 
619
bool change_db(Session *session, SchemaIdentifier &schema_identifier)
620
620
{
621
621
 
622
622
  if (not plugin::Authorization::isAuthorized(session->user(), schema_identifier))
647
647
    return true;
648
648
  }
649
649
 
650
 
  mysql_change_db_impl(session, schema_identifier);
 
650
  change_db_impl(session, schema_identifier);
651
651
 
652
652
  return false;
653
653
}
663
663
  @param new_db_charset Character set of the new database.
664
664
*/
665
665
 
666
 
static void mysql_change_db_impl(Session *session, SchemaIdentifier &schema_identifier)
 
666
static void change_db_impl(Session *session, SchemaIdentifier &schema_identifier)
667
667
{
668
668
  /* 1. Change current database in Session. */
669
669
 
690
690
  }
691
691
}
692
692
 
693
 
static void mysql_change_db_impl(Session *session)
 
693
static void change_db_impl(Session *session)
694
694
{
695
695
  session->set_db(string());
696
696
}