~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

  • Committer: pawel
  • Date: 2010-03-29 20:16:08 UTC
  • mto: This revision was merged to the branch mainline in revision 1428.
  • Revision ID: pawel@paw-20100329201608-ndqnc736k47uvy3s
changed function-like defines into functions in some files

Show diffs side-by-side

added added

removed removed

Lines of Context:
156
156
    memset(share, 0, sizeof(*share));
157
157
    share->set_table_cache_key(key_buff, old_share->table_cache_key.str,
158
158
                               old_share->table_cache_key.length);
159
 
    share->tmp_table= message::Table::INTERNAL;       // for intern_close_table()
 
159
    share->tmp_table= INTERNAL_TMP_TABLE;       // for intern_close_table()
160
160
  }
161
161
 
162
162
  table->cursor->close();
491
491
{
492
492
  for (; table; table= table->*link )
493
493
  {
494
 
    if ((table->table == 0 || table->table->s->tmp_table == message::Table::STANDARD) &&
495
 
        strcasecmp(table->db, db_name) == 0 &&
496
 
        strcasecmp(table->table_name, table_name) == 0)
 
494
    if ((table->table == 0 || table->table->s->tmp_table == STANDARD_TABLE) &&
 
495
        strcmp(table->db, db_name) == 0 &&
 
496
        strcmp(table->table_name, table_name) == 0)
497
497
      break;
498
498
  }
499
499
  return table;
555
555
  if (table->table)
556
556
  {
557
557
    /* temporary table is always unique */
558
 
    if (table->table && table->table->s->tmp_table != message::Table::STANDARD)
 
558
    if (table->table && table->table->s->tmp_table != STANDARD_TABLE)
559
559
      return 0;
560
560
    table= table->find_underlying_table(table->table);
561
561
    /*
586
586
}
587
587
 
588
588
 
589
 
void Session::doGetTableNames(SchemaIdentifier &schema_identifier,
 
589
void Session::doGetTableNames(CachedDirectory &,
 
590
                              const std::string& db_name,
590
591
                              std::set<std::string>& set_of_names)
591
592
{
592
593
  for (Table *table= temporary_tables ; table ; table= table->next)
593
594
  {
594
 
    if (schema_identifier.compare(table->s->getSchemaName()))
 
595
    if (not db_name.compare(table->s->getSchemaName()))
595
596
    {
596
597
      set_of_names.insert(table->s->table_name.str);
597
598
    }
598
599
  }
599
600
}
600
601
 
601
 
void Session::doGetTableNames(CachedDirectory &,
602
 
                              SchemaIdentifier &schema_identifier,
603
 
                              std::set<std::string> &set_of_names)
604
 
{
605
 
  doGetTableNames(schema_identifier, set_of_names);
606
 
}
607
 
 
608
 
void Session::doGetTableIdentifiers(SchemaIdentifier &schema_identifier,
609
 
                                    TableIdentifiers &set_of_identifiers)
610
 
{
611
 
  for (Table *table= temporary_tables ; table ; table= table->next)
612
 
  {
613
 
    if (schema_identifier.compare(table->s->getSchemaName()))
614
 
    {
615
 
      set_of_identifiers.push_back(TableIdentifier(table->getShare()->getSchemaName(),
616
 
                                                   table->getShare()->getTableName(),
617
 
                                                   table->getShare()->getPath()));
618
 
    }
619
 
  }
620
 
}
621
 
 
622
 
void Session::doGetTableIdentifiers(CachedDirectory &,
623
 
                                    SchemaIdentifier &schema_identifier,
624
 
                                    TableIdentifiers &set_of_identifiers)
625
 
{
626
 
  doGetTableIdentifiers(schema_identifier, set_of_identifiers);
627
 
}
628
 
 
629
602
bool Session::doDoesTableExist(TableIdentifier &identifier)
630
603
{
631
604
  for (Table *table= temporary_tables ; table ; table= table->next)
632
605
  {
633
 
    if (table->s->tmp_table == message::Table::TEMPORARY)
 
606
    if (table->s->tmp_table == TEMP_TABLE)
634
607
    {
635
 
      if (identifier.compare(table->s->getSchemaName(), table->s->table_name.str))
 
608
      if (not identifier.getSchemaName().compare(table->s->getSchemaName()))
636
609
      {
637
 
        return true;
 
610
        if (not identifier.getTableName().compare(table->s->table_name.str))
 
611
        {
 
612
          return true;
 
613
        }
638
614
      }
639
615
    }
640
616
  }
647
623
{
648
624
  for (Table *table= temporary_tables ; table ; table= table->next)
649
625
  {
650
 
    if (table->s->tmp_table == message::Table::TEMPORARY)
 
626
    if (table->s->tmp_table == TEMP_TABLE)
651
627
    {
652
 
      if (identifier.compare(table->s->getSchemaName(), table->s->table_name.str))
 
628
      if (not identifier.getSchemaName().compare(table->s->getSchemaName()))
653
629
      {
654
 
        table_proto.CopyFrom(*(table->s->getTableProto()));
 
630
        if (not identifier.getTableName().compare(table->s->table_name.str))
 
631
        {
 
632
          table_proto.CopyFrom(*(table->s->getTableProto()));
655
633
 
656
 
        return EEXIST;
 
634
          return EEXIST;
 
635
        }
657
636
      }
658
637
    }
659
638
  }
1020
999
 
1021
1000
  table->s= share;
1022
1001
  share->set_table_cache_key(key_buff, key, key_length);
1023
 
  share->tmp_table= message::Table::INTERNAL;  // for intern_close_table
 
1002
  share->tmp_table= INTERNAL_TMP_TABLE;  // for intern_close_table
1024
1003
  table->in_use= this;
1025
1004
  table->locked_by_name=1;
1026
1005
 
1346
1325
 
1347
1326
    if (table_list->create)
1348
1327
    {
1349
 
      TableIdentifier  lock_table_identifier(table_list->db, table_list->table_name, message::Table::STANDARD);
 
1328
      TableIdentifier  lock_table_identifier(table_list->db, table_list->table_name, STANDARD_TABLE);
1350
1329
 
1351
1330
      if (not plugin::StorageEngine::doesTableExist(*this, lock_table_identifier))
1352
1331
      {
1400
1379
  table->reginfo.lock_type= TL_READ; /* Assume read */
1401
1380
 
1402
1381
reset:
1403
 
  assert(table->s->ref_count > 0 || table->s->tmp_table != message::Table::STANDARD);
 
1382
  assert(table->s->ref_count > 0 || table->s->tmp_table != STANDARD_TABLE);
1404
1383
 
1405
1384
  if (lex->need_correct_ident())
1406
1385
    table->alias_name_used= my_strcasecmp(table_alias_charset,
1541
1520
  the strings are used in a loop even after the share may be freed.
1542
1521
*/
1543
1522
 
1544
 
void Session::close_data_files_and_morph_locks(TableIdentifier &identifier)
1545
 
{
1546
 
  close_data_files_and_morph_locks(identifier.getSchemaName().c_str(), identifier.getTableName().c_str());
1547
 
}
1548
 
 
1549
1523
void Session::close_data_files_and_morph_locks(const char *new_db, const char *new_table_name)
1550
1524
{
1551
1525
  Table *table;
1570
1544
  for (table= open_tables; table ; table=table->next)
1571
1545
  {
1572
1546
    if (!strcmp(table->s->table_name.str, new_table_name) &&
1573
 
        !strcasecmp(table->s->getSchemaName(), new_db))
 
1547
        !strcmp(table->s->getSchemaName(), new_db))
1574
1548
    {
1575
1549
      table->open_placeholder= true;
1576
1550
      close_handle_and_leave_table_as_lock(table);
1886
1860
  {
1887
1861
    next=table->next;
1888
1862
    if (!strcmp(table->s->table_name.str, table_name) &&
1889
 
        !strcasecmp(table->s->getSchemaName(), db))
 
1863
        !strcmp(table->s->getSchemaName(), db))
1890
1864
    {
1891
1865
      mysql_lock_remove(session, table);
1892
1866
 
2150
2124
    {
2151
2125
      if (tables->lock_type == TL_WRITE_DEFAULT)
2152
2126
        tables->table->reginfo.lock_type= update_lock_default;
2153
 
      else if (tables->table->s->tmp_table == message::Table::STANDARD)
 
2127
      else if (tables->table->s->tmp_table == STANDARD_TABLE)
2154
2128
        tables->table->reginfo.lock_type= tables->lock_type;
2155
2129
    }
2156
2130
  }
2314
2288
  uint32_t key_length, path_length;
2315
2289
  TableList table_list;
2316
2290
 
2317
 
  table_list.db=         const_cast<char*>(identifier.getSchemaName().c_str());
2318
 
  table_list.table_name= const_cast<char*>(identifier.getTableName().c_str());
 
2291
  table_list.db=         (char*) identifier.getDBName().c_str();
 
2292
  table_list.table_name= (char*) identifier.getTableName().c_str();
2319
2293
  /* Create the cache_key for temporary tables */
2320
2294
  key_length= table_list.create_table_def_key(cache_key);
2321
2295
  path_length= identifier.getPath().length();
2348
2322
  }
2349
2323
 
2350
2324
  new_tmp_table->reginfo.lock_type= TL_WRITE;    // Simulate locked
2351
 
  share->tmp_table= message::Table::TEMPORARY;
 
2325
  share->tmp_table= TEMP_TABLE;
2352
2326
 
2353
2327
  if (link_in_list)
2354
2328
  {
4105
4079
    assert(tables->is_leaf_for_name_resolution());
4106
4080
 
4107
4081
    if ((table_name && my_strcasecmp(table_alias_charset, table_name, tables->alias)) ||
4108
 
        (db_name && strcasecmp(tables->db,db_name)))
 
4082
        (db_name && strcmp(tables->db,db_name)))
4109
4083
      continue;
4110
4084
 
4111
4085
    /*
4458
4432
and afterwards delete those marked unused.
4459
4433
*/
4460
4434
 
4461
 
void remove_db_from_cache(SchemaIdentifier &schema_identifier)
 
4435
void remove_db_from_cache(const std::string schema_name)
4462
4436
{
4463
4437
  safe_mutex_assert_owner(&LOCK_open);
4464
4438
 
4465
4439
  for (uint32_t idx=0 ; idx < open_cache.records ; idx++)
4466
4440
  {
4467
4441
    Table *table=(Table*) hash_element(&open_cache,idx);
4468
 
    if (not schema_identifier.getPath().compare(table->s->getSchemaName()))
 
4442
    if (not schema_name.compare(table->s->getSchemaName()))
4469
4443
    {
4470
4444
      table->s->version= 0L;                    /* Free when thread is ready */
4471
4445
      if (not table->in_use)