~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

  • Committer: Siddharth Prakash Singh
  • Date: 2010-03-26 19:25:23 UTC
  • mfrom: (1410 drizzle)
  • mto: This revision was merged to the branch mainline in revision 1425.
  • Revision ID: spsneo@spsneo-laptop-20100326192523-ibjlbt1p692vobtj
merging with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
416
416
      Open placeholders have Table::db_stat set to 0, so they should be
417
417
      handled by the first alternative.
418
418
    */
419
 
    assert(!table->open_placeholder);
 
419
    assert(not table->open_placeholder);
420
420
 
421
421
    /* Free memory and reset for next loop */
422
422
    table->cursor->ha_reset();
586
586
}
587
587
 
588
588
 
589
 
void Session::doGetTableNames(CachedDirectory &,
590
 
                              const std::string& db_name,
 
589
void Session::doGetTableNames(const std::string& db_name,
591
590
                              std::set<std::string>& set_of_names)
592
591
{
593
592
  for (Table *table= temporary_tables ; table ; table= table->next)
599
598
  }
600
599
}
601
600
 
 
601
void Session::doGetTableNames(CachedDirectory &,
 
602
                              const std::string &db_name,
 
603
                              std::set<std::string> &set_of_names)
 
604
{
 
605
  doGetTableNames(db_name, set_of_names);
 
606
}
 
607
 
602
608
bool Session::doDoesTableExist(TableIdentifier &identifier)
603
609
{
604
610
  for (Table *table= temporary_tables ; table ; table= table->next)
605
611
  {
606
612
    if (table->s->tmp_table == TEMP_TABLE)
607
613
    {
608
 
      if (not strcmp(identifier.getSchemaName().c_str(), table->s->getSchemaName()))
 
614
      if (not identifier.getSchemaName().compare(table->s->getSchemaName()))
609
615
      {
610
 
        if (not strcmp(identifier.getTableName().c_str(), table->s->table_name.str))
 
616
        if (not identifier.getTableName().compare(table->s->table_name.str))
611
617
        {
612
618
          return true;
613
619
        }
625
631
  {
626
632
    if (table->s->tmp_table == TEMP_TABLE)
627
633
    {
628
 
      if (not strcmp(identifier.getSchemaName().c_str(), table->s->getSchemaName()))
 
634
      if (not identifier.getSchemaName().compare(table->s->getSchemaName()))
629
635
      {
630
 
        if (not strcmp(identifier.getTableName().c_str(), table->s->table_name.str))
 
636
        if (not identifier.getTableName().compare(table->s->table_name.str))
631
637
        {
632
638
          table_proto.CopyFrom(*(table->s->getTableProto()));
633
639
 
644
650
{
645
651
  char  key[MAX_DBKEY_LENGTH];
646
652
  uint  key_length;
647
 
  Table *table;
648
653
 
649
654
  key_length= TableShare::createKey(key, new_db, table_name);
650
655
 
651
 
  for (table= temporary_tables ; table ; table= table->next)
 
656
  for (Table *table= temporary_tables ; table ; table= table->next)
652
657
  {
653
658
    if (table->s->table_cache_key.length == key_length &&
654
 
        !memcmp(table->s->table_cache_key.str, key, key_length))
 
659
        not memcmp(table->s->table_cache_key.str, key, key_length))
 
660
    {
655
661
      return table;
 
662
    }
656
663
  }
657
664
  return NULL;                               // Not a temporary table
658
665
}
662
669
  return find_temporary_table(table_list->db, table_list->table_name);
663
670
}
664
671
 
 
672
Table *Session::find_temporary_table(TableIdentifier &identifier)
 
673
{
 
674
  char  key[MAX_DBKEY_LENGTH];
 
675
  uint  key_length;
 
676
 
 
677
  key_length= TableShare::createKey(key, identifier);
 
678
 
 
679
  for (Table *table= temporary_tables ; table ; table= table->next)
 
680
  {
 
681
    if (table->s->table_cache_key.length == key_length &&
 
682
        not memcmp(table->s->table_cache_key.str, key, key_length))
 
683
 
 
684
      return table;
 
685
  }
 
686
 
 
687
  return NULL;                               // Not a temporary table
 
688
}
 
689
 
665
690
 
666
691
/**
667
692
  Drop a temporary table.
693
718
{
694
719
  Table *table;
695
720
 
696
 
  if (!(table= find_temporary_table(table_list)))
 
721
  if (not (table= find_temporary_table(table_list)))
697
722
    return 1;
698
723
 
699
724
  /* Table might be in use by some outer statement. */
755
780
    list= *prev;
756
781
 
757
782
    if (list->s->table_cache_key.length == key_length &&
758
 
        !memcmp(list->s->table_cache_key.str, key, key_length))
 
783
        not memcmp(list->s->table_cache_key.str, key, key_length))
759
784
    {
760
785
      /* Remove table from open_tables list. */
761
786
      *prev= list->next;
793
818
  table that was locked with LOCK TABLES.
794
819
*/
795
820
 
796
 
void Session::drop_open_table(Table *table, const char *db_name,
797
 
                              const char *table_name)
 
821
void Session::drop_open_table(Table *table, TableIdentifier &identifier)
798
822
{
799
823
  if (table->s->tmp_table)
800
824
  {
808
832
      that something has happened.
809
833
    */
810
834
    unlink_open_table(table);
811
 
    TableIdentifier identifier(db_name, table_name, STANDARD_TABLE);
812
835
    quick_rm_table(*this, identifier);
813
836
    pthread_mutex_unlock(&LOCK_open);
814
837
  }
1041
1064
    *table= 0;
1042
1065
    return false;
1043
1066
  }
1044
 
  if (!(*table= table_cache_insert_placeholder(key, key_length)))
 
1067
  if (not (*table= table_cache_insert_placeholder(key, key_length)))
1045
1068
  {
1046
1069
    pthread_mutex_unlock(&LOCK_open);
1047
1070
    return true;
1503
1526
  the strings are used in a loop even after the share may be freed.
1504
1527
*/
1505
1528
 
 
1529
void Session::close_data_files_and_morph_locks(TableIdentifier &identifier)
 
1530
{
 
1531
  close_data_files_and_morph_locks(identifier.getSchemaName().c_str(), identifier.getTableName().c_str());
 
1532
}
 
1533
 
1506
1534
void Session::close_data_files_and_morph_locks(const char *new_db, const char *new_table_name)
1507
1535
{
1508
1536
  Table *table;
1929
1957
 
1930
1958
  safe_mutex_assert_owner(&LOCK_open);
1931
1959
retry:
1932
 
  if (!(share= TableShare::getShare(session, table_list, cache_key,
1933
 
                                    cache_key_length,
1934
 
                                    table_list->i_s_requested_object,
1935
 
                                    &error)))
 
1960
  if (not (share= TableShare::getShare(session, table_list, cache_key,
 
1961
                                       cache_key_length,
 
1962
                                       table_list->i_s_requested_object,
 
1963
                                       &error)))
1936
1964
    return 1;
1937
1965
 
1938
1966
  while ((error= open_table_from_share(session, share, alias,
2291
2319
  /*
2292
2320
    First open the share, and then open the table from the share we just opened.
2293
2321
  */
2294
 
  if (open_table_def(*this, share) ||
 
2322
  if (open_table_def(*this, identifier, share) ||
2295
2323
      open_table_from_share(this, share, identifier.getTableName().c_str(),
2296
2324
                            (uint32_t) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE |
2297
2325
                                        HA_GET_INDEX),
4422
4450
  for (uint32_t idx=0 ; idx < open_cache.records ; idx++)
4423
4451
  {
4424
4452
    Table *table=(Table*) hash_element(&open_cache,idx);
4425
 
    if (not strcmp(table->s->getSchemaName(), schema_name.c_str()))
 
4453
    if (not schema_name.compare(table->s->getSchemaName()))
4426
4454
    {
4427
4455
      table->s->version= 0L;                    /* Free when thread is ready */
4428
4456
      if (not table->in_use)