~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.cc

  • Committer: Brian Aker
  • Date: 2009-05-22 18:50:00 UTC
  • mfrom: (1034.1.3 merge)
  • Revision ID: brian@gaz-20090522185000-wvehph10pogb92jt
Merge Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
217
217
  Item *default_item= NULL;
218
218
  int error= 0;
219
219
 
220
 
  if(default_null)
 
220
  if (default_null)
221
221
  {
222
222
    return new Item_null();
223
223
  }
251
251
    break;
252
252
  case DRIZZLE_TYPE_VARCHAR:
253
253
  case DRIZZLE_TYPE_BLOB: /* Blob is here due to TINYTEXT. Feel the hate. */
254
 
    if(charset==&my_charset_bin)
 
254
    if (charset==&my_charset_bin)
255
255
    {
256
256
      default_item= new Item_string(default_bin_value->c_str(),
257
257
                                    default_bin_value->length(),
289
289
 
290
290
  drizzled::message::Table::TableOptions table_options;
291
291
 
292
 
  if(table.has_options())
 
292
  if (table.has_options())
293
293
    table_options= table.options();
294
294
 
295
295
  uint32_t db_create_options= HA_OPTION_LONG_BLOB_PTR;
296
296
 
297
 
  if(table_options.has_pack_keys())
 
297
  if (table_options.has_pack_keys())
298
298
  {
299
 
    if(table_options.pack_keys())
 
299
    if (table_options.pack_keys())
300
300
      db_create_options|= HA_OPTION_PACK_KEYS;
301
301
    else
302
302
      db_create_options|= HA_OPTION_NO_PACK_KEYS;
303
303
  }
304
304
 
305
 
  if(table_options.pack_record())
 
305
  if (table_options.pack_record())
306
306
    db_create_options|= HA_OPTION_PACK_RECORD;
307
307
 
308
 
  if(table_options.has_checksum())
 
308
  if (table_options.has_checksum())
309
309
  {
310
 
    if(table_options.checksum())
 
310
    if (table_options.checksum())
311
311
      db_create_options|= HA_OPTION_CHECKSUM;
312
312
    else
313
313
      db_create_options|= HA_OPTION_NO_CHECKSUM;
314
314
  }
315
315
 
316
 
  if(table_options.has_delay_key_write())
 
316
  if (table_options.has_delay_key_write())
317
317
  {
318
 
    if(table_options.delay_key_write())
 
318
    if (table_options.delay_key_write())
319
319
      db_create_options|= HA_OPTION_DELAY_KEY_WRITE;
320
320
    else
321
321
      db_create_options|= HA_OPTION_NO_DELAY_KEY_WRITE;
410
410
    keyinfo->table= 0;
411
411
    keyinfo->flags= 0;
412
412
 
413
 
    if(indx.is_unique())
 
413
    if (indx.is_unique())
414
414
      keyinfo->flags|= HA_NOSAME;
415
415
 
416
 
    if(indx.has_options())
 
416
    if (indx.has_options())
417
417
    {
418
418
      drizzled::message::Table::Index::IndexOptions indx_options= indx.options();
419
 
      if(indx_options.pack_key())
 
419
      if (indx_options.pack_key())
420
420
        keyinfo->flags|= HA_PACK_KEY;
421
421
 
422
 
      if(indx_options.var_length_key())
 
422
      if (indx_options.var_length_key())
423
423
        keyinfo->flags|= HA_VAR_LENGTH_PART;
424
424
 
425
 
      if(indx_options.null_part_key())
 
425
      if (indx_options.null_part_key())
426
426
        keyinfo->flags|= HA_NULL_PART_KEY;
427
427
 
428
 
      if(indx_options.binary_pack_key())
 
428
      if (indx_options.binary_pack_key())
429
429
        keyinfo->flags|= HA_BINARY_PACK_KEY;
430
430
 
431
 
      if(indx_options.has_partial_segments())
 
431
      if (indx_options.has_partial_segments())
432
432
        keyinfo->flags|= HA_KEY_HAS_PART_KEY_SEG;
433
433
 
434
 
      if(indx_options.auto_generated_key())
 
434
      if (indx_options.auto_generated_key())
435
435
        keyinfo->flags|= HA_GENERATED_KEY;
436
436
 
437
 
      if(indx_options.has_key_block_size())
 
437
      if (indx_options.has_key_block_size())
438
438
      {
439
439
        keyinfo->flags|= HA_USES_BLOCK_SIZE;
440
440
        keyinfo->block_size= indx_options.key_block_size();
492
492
      /* key_part->key_type= */ /* I *THINK* this may be okay.... */
493
493
      /* key_part->type ???? */
494
494
      key_part->key_part_flag= 0;
495
 
      if(part.has_in_reverse_order())
 
495
      if (part.has_in_reverse_order())
496
496
        key_part->key_part_flag= part.in_reverse_order()? HA_REVERSE_SORT : 0;
497
497
 
498
498
      key_part->length= part.compare_length();
504
504
 
505
505
    }
506
506
 
507
 
    if(!indx.has_comment())
 
507
    if (!indx.has_comment())
508
508
    {
509
509
      keyinfo->comment.length= 0;
510
510
      keyinfo->comment.str= NULL;
529
529
  share->keys_for_keyread.reset();
530
530
  set_prefix(share->keys_in_use, share->keys);
531
531
 
532
 
  if(table_options.has_connect_string())
 
532
  if (table_options.has_connect_string())
533
533
  {
534
534
    size_t len= table_options.connect_string().length();
535
535
    const char* str= table_options.connect_string().c_str();
538
538
    share->connect_string.str= strmake_root(&share->mem_root, str, len);
539
539
  }
540
540
 
541
 
  if(table_options.has_comment())
 
541
  if (table_options.has_comment())
542
542
  {
543
543
    size_t len= table_options.comment().length();
544
544
    const char* str= table_options.comment().c_str();
572
572
  for (unsigned int fieldnr=0; fieldnr < share->fields; fieldnr++)
573
573
  {
574
574
    drizzled::message::Table::Field pfield= table.field(fieldnr);
575
 
    if(pfield.has_constraints() && pfield.constraints().is_nullable())
 
575
    if (pfield.has_constraints() && pfield.constraints().is_nullable())
576
576
      null_fields++;
577
577
 
578
578
    enum_field_types drizzle_field_type=
640
640
  share->null_fields= null_fields;
641
641
 
642
642
  ulong null_bits= null_fields;
643
 
  if(!table_options.pack_record())
 
643
  if (!table_options.pack_record())
644
644
    null_bits++;
645
645
  ulong data_offset= (null_bits + 7)/8;
646
646
 
663
663
 
664
664
  int null_count= 0;
665
665
 
666
 
  if(!table_options.pack_record())
 
666
  if (!table_options.pack_record())
667
667
  {
668
668
    null_count++; // one bit for delete mark.
669
669
    *record|= 1;
671
671
 
672
672
  share->default_values= record;
673
673
 
674
 
  if(interval_count)
 
674
  if (interval_count)
675
675
  {
676
676
    share->intervals= (TYPELIB*)alloc_root(&share->mem_root,
677
677
                                           interval_count*sizeof(TYPELIB));
708
708
    share->fieldnames.type_lengths[fieldnr]= pfield.name().length();
709
709
 
710
710
    /* enum typelibs */
711
 
    if(pfield.type() != drizzled::message::Table::Field::ENUM)
 
711
    if (pfield.type() != drizzled::message::Table::Field::ENUM)
712
712
      continue;
713
713
 
714
714
    drizzled::message::Table::Field::SetFieldOptions field_options=
757
757
 
758
758
  bool use_hash= share->fields >= MAX_FIELDS_BEFORE_HASH;
759
759
 
760
 
  if(use_hash)
 
760
  if (use_hash)
761
761
    use_hash= !hash_init(&share->name_hash,
762
762
                         system_charset_info,
763
763
                         share->fields, 0, 0,
789
789
 
790
790
    Field::utype unireg_type= Field::NONE;
791
791
 
792
 
    if(pfield.has_numeric_options()
 
792
    if (pfield.has_numeric_options()
793
793
       && pfield.numeric_options().is_autoincrement())
794
794
    {
795
795
      unireg_type= Field::NEXT_NUMBER;
796
796
    }
797
797
 
798
 
    if(pfield.has_options()
 
798
    if (pfield.has_options()
799
799
       && pfield.options().has_default_value()
800
800
       && pfield.options().default_value().compare("NOW()")==0)
801
801
    {
802
 
      if(pfield.options().has_update_value()
 
802
      if (pfield.options().has_update_value()
803
803
         && pfield.options().update_value().compare("NOW()")==0)
804
804
      {
805
805
        unireg_type= Field::TIMESTAMP_DNUN_FIELD;
819
819
    }
820
820
 
821
821
    LEX_STRING comment;
822
 
    if(!pfield.has_comment())
 
822
    if (!pfield.has_comment())
823
823
    {
824
824
      comment.str= (char*)"";
825
825
      comment.length= 0;
839
839
 
840
840
    const CHARSET_INFO *charset= &my_charset_bin;
841
841
 
842
 
    if(field_type==DRIZZLE_TYPE_BLOB
 
842
    if (field_type==DRIZZLE_TYPE_BLOB
843
843
       || field_type==DRIZZLE_TYPE_VARCHAR)
844
844
    {
845
845
      drizzled::message::Table::Field::StringFieldOptions field_options=
853
853
 
854
854
    }
855
855
 
856
 
    if(field_type==DRIZZLE_TYPE_ENUM)
 
856
    if (field_type==DRIZZLE_TYPE_ENUM)
857
857
    {
858
858
      drizzled::message::Table::Field::SetFieldOptions field_options=
859
859
        pfield.set_options();
868
868
 
869
869
    Item *default_value= NULL;
870
870
 
871
 
    if(pfield.options().has_default_value()
 
871
    if (pfield.options().has_default_value()
872
872
       || pfield.options().has_default_null()
873
873
       || pfield.options().has_default_bin_value())
874
874
    {
906
906
 
907
907
    f->init(&temp_table); /* blob default values need table obj */
908
908
 
909
 
    if(!(f->flags & NOT_NULL_FLAG))
 
909
    if (!(f->flags & NOT_NULL_FLAG))
910
910
    {
911
911
      *f->null_ptr|= f->null_bit;
912
912
      if (!(null_bit_pos= (null_bit_pos + 1) & 7))
914
914
      null_count++;
915
915
    }
916
916
 
917
 
    if(default_value)
 
917
    if (default_value)
918
918
    {
919
919
      enum_check_fields old_count_cuted_fields= session->count_cuted_fields;
920
920
      session->count_cuted_fields= CHECK_FIELD_WARN;
927
927
        goto err;
928
928
      }
929
929
    }
930
 
    else if(f->real_type() == DRIZZLE_TYPE_ENUM &&
 
930
    else if (f->real_type() == DRIZZLE_TYPE_ENUM &&
931
931
            (f->flags & NOT_NULL_FLAG))
932
932
    {
933
933
      f->set_notnull();
942
942
 
943
943
    f->field_index= fieldnr;
944
944
    f->comment= comment;
945
 
    if(!default_value
 
945
    if (!default_value
946
946
       && !(f->unireg_check==Field::NEXT_NUMBER)
947
947
       && (f->flags & NOT_NULL_FLAG)
948
948
       && (f->real_type() != DRIZZLE_TYPE_TIMESTAMP))
949
949
      f->flags|= NO_DEFAULT_VALUE_FLAG;
950
950
 
951
 
    if(f->unireg_check == Field::NEXT_NUMBER)
 
951
    if (f->unireg_check == Field::NEXT_NUMBER)
952
952
      share->found_next_number_field= &(share->field[fieldnr]);
953
953
 
954
 
    if(share->timestamp_field == f)
 
954
    if (share->timestamp_field == f)
955
955
      share->timestamp_field_offset= fieldnr;
956
956
 
957
957
    if (use_hash) /* supposedly this never fails... but comments lie */
992
992
  free(field_offsets);
993
993
  free(field_pack_length);
994
994
 
995
 
  if(!(handler_file= get_new_handler(share, session->mem_root,
 
995
  if (!(handler_file= get_new_handler(share, session->mem_root,
996
996
                                     share->db_type())))
997
997
    abort(); // FIXME
998
998
 
1188
1188
  bitmap_init(&share->all_set, bitmaps, share->fields, false);
1189
1189
  bitmap_set_all(&share->all_set);
1190
1190
 
1191
 
  if(handler_file)
 
1191
  if (handler_file)
1192
1192
    delete handler_file;
1193
1193
  return (0);
1194
1194
 
1197
1197
  share->open_errno= my_errno;
1198
1198
  share->errarg= 0;
1199
1199
  hash_free(&share->name_hash);
1200
 
  if(handler_file)
 
1200
  if (handler_file)
1201
1201
    delete handler_file;
1202
1202
  open_table_error(share, error, share->open_errno, 0);
1203
1203
  return error;
1243
1243
 
1244
1244
  drizzled::message::Table table;
1245
1245
 
1246
 
  if((error= drizzle_read_table_proto(proto_path.c_str(), &table)))
 
1246
  if ((error= drizzle_read_table_proto(proto_path.c_str(), &table)))
1247
1247
  {
1248
 
    if(error>0)
 
1248
    if (error>0)
1249
1249
    {
1250
1250
      my_errno= error;
1251
1251
      error= 1;
1252
1252
    }
1253
1253
    else
1254
1254
    {
1255
 
      if(!table.IsInitialized())
 
1255
      if (!table.IsInitialized())
1256
1256
      {
1257
1257
        error= 4;
1258
1258
      }