~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table/instance/base.cc

  • Committer: Mark Atwood
  • Date: 2011-08-21 06:56:57 UTC
  • mfrom: (2385.3.34 rf)
  • Revision ID: me@mark.atwood.name-20110821065657-vk2at03z9u17mf1d
mergeĀ lp:~olafvdspek/drizzle/refactor7

Show diffs side-by-side

added added

removed removed

Lines of Context:
370
370
  table_category=         TABLE_CATEGORY_TEMPORARY;
371
371
  tmp_table=              message::Table::INTERNAL;
372
372
 
373
 
  db.str= const_cast<char *>(private_key_for_cache.vector());
374
 
  db.length= strlen(private_key_for_cache.vector());
 
373
  db= str_ref(private_key_for_cache.vector());
375
374
 
376
 
  table_name.str= const_cast<char *>(private_key_for_cache.vector()) + strlen(private_key_for_cache.vector()) + 1;
377
 
  table_name.length= strlen(table_name.str);
378
 
  path.str= (char *)"";
379
 
  normalized_path.str= path.str;
380
 
  path.length= normalized_path.length= 0;
 
375
  table_name= str_ref(private_key_for_cache.vector() + strlen(private_key_for_cache.vector()) + 1);
 
376
  path= str_ref("");
 
377
  normalized_path= str_ref("");
381
378
 
382
379
  std::string tb_name(identifier.getTableName());
383
380
  boost::to_lower(tb_name);
384
 
  assert(strcmp(tb_name.c_str(), table_name.str) == 0);
385
 
  assert(strcmp(identifier.getSchemaName().c_str(), db.str) == 0);
 
381
  assert(strcmp(tb_name.c_str(), table_name.data()) == 0);
 
382
  assert(strcmp(identifier.getSchemaName().c_str(), db.data()) == 0);
386
383
}
387
384
 
388
 
 
389
385
TableShare::TableShare(const identifier::Table &identifier) : // Just used during createTable()
390
386
  table_category(TABLE_UNKNOWN_CATEGORY),
391
387
  found_next_number_field(NULL),
443
439
  memcpy(&private_normalized_path[0], identifier.getPath().c_str(), identifier.getPath().size());
444
440
 
445
441
  {
446
 
    table_category=         TABLE_CATEGORY_TEMPORARY;
447
 
    tmp_table=              message::Table::INTERNAL;
448
 
    db.str= const_cast<char *>(private_key_for_cache.vector());
449
 
    db.length= strlen(private_key_for_cache.vector());
450
 
    table_name.str= db.str + 1;
451
 
    table_name.length= strlen(table_name.str);
452
 
    path.str= &private_normalized_path[0];
453
 
    normalized_path.str= path.str;
454
 
    path.length= normalized_path.length= private_normalized_path.size();
 
442
    table_category= TABLE_CATEGORY_TEMPORARY;
 
443
    tmp_table= message::Table::INTERNAL;
 
444
    db= str_ref(private_key_for_cache.vector());
 
445
    table_name= str_ref(db.data() + 1);
 
446
    path= private_normalized_path;
 
447
    normalized_path= path;
455
448
  }
456
449
}
457
450
 
519
512
    Let us use the fact that the key is "db/0/table_name/0" + optional
520
513
    part for temporary tables.
521
514
  */
522
 
  db.str= const_cast<char *>(private_key_for_cache.vector());
523
 
  db.length=         strlen(db.str);
524
 
  table_name.str=    db.str + db.length + 1;
525
 
  table_name.length= strlen(table_name.str);
 
515
  db= str_ref(private_key_for_cache.vector());
 
516
  table_name= str_ref(db.data() + db.size() + 1);
526
517
 
527
518
  std::string _path;
528
519
  if (path_arg)
531
522
  }
532
523
  else
533
524
  {
534
 
    _path= identifier::Table::build_table_filename(db.str, table_name.str, false);
 
525
    _path= identifier::Table::build_table_filename(db.data(), table_name.data(), false);
535
526
  }
536
527
 
537
528
  char* path_buff= mem_root.strdup(_path);
538
 
  setPath(path_buff, _path.length());
539
 
  setNormalizedPath(path_buff, _path.length());
 
529
  path= str_ref(path_buff, _path.length());
 
530
  normalized_path= str_ref(path_buff, _path.length());
540
531
 
541
532
  version= g_refresh_version;
542
533
}
543
534
 
544
 
void TableShare::init(const char *new_table_name,
545
 
                      const char *new_path)
 
535
void TableShare::init(const char *new_table_name, const char *new_path)
546
536
{
547
 
 
548
 
  table_category=         TABLE_CATEGORY_TEMPORARY;
549
 
  tmp_table=              message::Table::INTERNAL;
550
 
  db.str= (char *)"";
551
 
  db.length= 0;
552
 
  table_name.str=         (char*) new_table_name;
553
 
  table_name.length=      strlen(new_table_name);
554
 
  path.str=               (char*) new_path;
555
 
  normalized_path.str=    (char*) new_path;
556
 
  path.length= normalized_path.length= strlen(new_path);
 
537
  table_category= TABLE_CATEGORY_TEMPORARY;
 
538
  tmp_table= message::Table::INTERNAL;
 
539
  db= str_ref("");
 
540
  table_name= str_ref(new_table_name);
 
541
  path= str_ref(new_path);
 
542
  normalized_path= str_ref(new_path);
557
543
}
558
544
 
559
545
TableShare::~TableShare() 
571
557
    Let us use the fact that the key is "db/0/table_name/0" + optional
572
558
    part for temporary tables.
573
559
  */
574
 
  db.str= const_cast<char *>(private_key_for_cache.vector());
575
 
  db.length=         strlen(db.str);
576
 
  table_name.str=    db.str + db.length + 1;
577
 
  table_name.length= strlen(table_name.str);
 
560
  db= str_ref(private_key_for_cache.vector());
 
561
  table_name= str_ref(db.data() + db.size() + 1);
578
562
 
579
563
  getTableMessage()->set_name(identifier_arg.getTableName());
580
564
  getTableMessage()->set_schema(identifier_arg.getSchemaName());
635
619
  for (int indx= 0; indx < table.indexes_size(); indx++)
636
620
    key_parts+= table.indexes(indx).index_part_size();
637
621
 
638
 
  key_info= (KeyInfo*) alloc(table.indexes_size() * sizeof(KeyInfo) +key_parts*sizeof(KeyPartInfo));
 
622
  key_info= (KeyInfo*) mem().alloc(table.indexes_size() * sizeof(KeyInfo) +key_parts*sizeof(KeyPartInfo));
639
623
 
640
624
  KeyPartInfo *key_part;
641
625
 
643
627
    (key_info+table.indexes_size());
644
628
 
645
629
 
646
 
  ulong *rec_per_key= (ulong*) alloc(sizeof(ulong*)*key_parts);
 
630
  ulong *rec_per_key= (ulong*) mem().alloc(sizeof(ulong*)*key_parts);
647
631
 
648
632
  KeyInfo* keyinfo= key_info;
649
633
  for (int keynr= 0; keynr < table.indexes_size(); keynr++, keyinfo++)
924
908
 
925
909
    TYPELIB *t= (&intervals[interval_nr]);
926
910
 
927
 
    t->type_names= (const char**)alloc((field_options.field_value_size() + 1) * sizeof(char*));
928
 
 
929
 
    t->type_lengths= (unsigned int*)alloc((field_options.field_value_size() + 1) * sizeof(unsigned int));
 
911
    t->type_names= (const char**)mem().alloc((field_options.field_value_size() + 1) * sizeof(char*));
 
912
    t->type_lengths= (unsigned int*)mem().alloc((field_options.field_value_size() + 1) * sizeof(unsigned int));
930
913
 
931
914
    t->type_names[field_options.field_value_size()]= NULL;
932
915
    t->type_lengths[field_options.field_value_size()]= 0;
1329
1312
  /* Fix key stuff */
1330
1313
  if (key_parts)
1331
1314
  {
1332
 
    uint32_t local_primary_key= 0;
1333
 
    doesKeyNameExist("PRIMARY", local_primary_key);
1334
 
 
 
1315
    uint32_t local_primary_key= doesKeyNameExist("PRIMARY");
1335
1316
    keyinfo= key_info;
1336
1317
    key_part= keyinfo->key_part;
1337
1318
 
1786
1767
  case 1:
1787
1768
    if (db_errno == ENOENT)
1788
1769
    {
1789
 
      identifier::Table identifier(db.str, table_name.str);
 
1770
      identifier::Table identifier(db.data(), table_name.data());
1790
1771
      my_error(ER_TABLE_UNKNOWN, identifier);
1791
1772
    }
1792
1773
    else
1793
1774
    {
1794
 
      snprintf(buff, sizeof(buff), "%s",normalized_path.str);
1795
 
      my_error((db_errno == EMFILE) ? ER_CANT_OPEN_FILE : ER_FILE_NOT_FOUND,
1796
 
               errortype, buff, db_errno);
 
1775
      snprintf(buff, sizeof(buff), "%s",normalized_path.data());
 
1776
      my_error((db_errno == EMFILE) ? ER_CANT_OPEN_FILE : ER_FILE_NOT_FOUND, errortype, buff, db_errno);
1797
1777
    }
1798
1778
    break;
1799
1779
  case 2:
1800
1780
    {
1801
 
      drizzled::error_t err_no;
1802
 
 
1803
 
      err_no= (db_errno == ENOENT) ? ER_FILE_NOT_FOUND : (db_errno == EAGAIN) ?
1804
 
        ER_FILE_USED : ER_CANT_OPEN_FILE;
1805
 
 
1806
 
      my_error(err_no, errortype, normalized_path.str, db_errno);
 
1781
      drizzled::error_t err_no= (db_errno == ENOENT) ? ER_FILE_NOT_FOUND : (db_errno == EAGAIN) ? ER_FILE_USED : ER_CANT_OPEN_FILE;
 
1782
      my_error(err_no, errortype, normalized_path.data(), db_errno);
1807
1783
      break;
1808
1784
    }
1809
1785
  case 5:
1815
1791
        snprintf(tmp, sizeof(tmp), "#%d", pass_errarg);
1816
1792
        csname= tmp;
1817
1793
      }
1818
 
      my_printf_error(ER_UNKNOWN_COLLATION,
1819
 
                      _("Unknown collation '%s' in table '%-.64s' definition"),
1820
 
                      MYF(0), csname, table_name.str);
 
1794
      my_printf_error(ER_UNKNOWN_COLLATION, _("Unknown collation '%s' in table '%-.64s' definition"), MYF(0), csname, table_name.data());
1821
1795
      break;
1822
1796
    }
1823
1797
  case 6:
1824
 
    snprintf(buff, sizeof(buff), "%s", normalized_path.str);
1825
 
    my_printf_error(ER_NOT_FORM_FILE,
1826
 
                    _("Table '%-.64s' was created with a different version "
1827
 
                      "of Drizzle and cannot be read"),
1828
 
                    MYF(0), buff);
 
1798
    snprintf(buff, sizeof(buff), "%s", normalized_path.data());
 
1799
    my_printf_error(ER_NOT_FORM_FILE, _("Table '%-.64s' was created with a different version of Drizzle and cannot be read"), MYF(0), buff);
1829
1800
    break;
1830
1801
  case 8:
1831
1802
    break;
1832
1803
  default:                              /* Better wrong error than none */
1833
1804
  case 4:
1834
 
    snprintf(buff, sizeof(buff), "%s", normalized_path.str);
 
1805
    snprintf(buff, sizeof(buff), "%s", normalized_path.data());
1835
1806
    my_error(ER_NOT_FORM_FILE, errortype, buff, 0);
1836
1807
    break;
1837
1808
  }