~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/unireg.cc

  • Committer: Brian Aker
  • Date: 2009-02-17 01:24:03 UTC
  • mfrom: (869.1.11 nofrm)
  • Revision ID: brian@tangent.org-20090217012403-0jk7cjdvq0oms0h9
Merge from Stewart.

Show diffs side-by-side

added added

removed removed

Lines of Context:
267
267
  int2store(fileinfo+28,key_info_length);
268
268
 
269
269
 
270
 
  int2store(fileinfo+59,db_file->extra_rec_buf_length());
 
270
  int2store(fileinfo+59, 0); /* was: extra_rec_buf_length */
271
271
 
272
272
  if (pwrite(file, fileinfo, 64, 0L) == 0 ||
273
273
      pwrite(file, keybuff, key_info_length, (ulong) uint2korr(fileinfo+6)) == 0)
408
408
 
409
409
    attribute= table_proto->add_field();
410
410
    attribute->set_name(field_arg->field_name);
 
411
 
411
412
    switch (field_arg->sql_type) {
412
413
    case DRIZZLE_TYPE_TINY:
413
414
      attribute->set_type(drizzle::Table::Field::TINYINT);
480
481
      attribute->set_type(drizzle::Table::Field::BLOB);
481
482
      break;
482
483
    default:
483
 
      assert(1);
 
484
      abort();
 
485
    }
 
486
 
 
487
    if(field_arg->vcol_info)
 
488
    {
 
489
      drizzle::Table::Field::VirtualFieldOptions *field_options;
 
490
 
 
491
      field_options= attribute->mutable_virtual_options();
 
492
 
 
493
      field_options->set_type(attribute->type());
 
494
      attribute->set_type(drizzle::Table::Field::VIRTUAL);
 
495
 
 
496
      field_options->set_expression(field_arg->vcol_info->expr_str.str);
 
497
      field_options->set_physically_stored(field_arg->is_stored);
484
498
    }
485
499
 
486
500
#ifdef NOTDONE
488
502
    constraints->set_is_nullable(field_arg->def->null_value);
489
503
#endif
490
504
 
491
 
    /* Set the comment */
 
505
    switch(field_arg->column_format())
 
506
    {
 
507
    case COLUMN_FORMAT_TYPE_NOT_USED:
 
508
      break;
 
509
    case COLUMN_FORMAT_TYPE_DEFAULT:
 
510
      attribute->set_format(drizzle::Table::Field::DefaultFormat);
 
511
      break;
 
512
    case COLUMN_FORMAT_TYPE_FIXED:
 
513
      attribute->set_format(drizzle::Table::Field::FixedFormat);
 
514
      break;
 
515
    case COLUMN_FORMAT_TYPE_DYNAMIC:
 
516
      attribute->set_format(drizzle::Table::Field::DynamicFormat);
 
517
      break;
 
518
    default:
 
519
      abort();
 
520
    }
 
521
 
492
522
    if (field_arg->comment.length)
493
523
      attribute->set_comment(field_arg->comment.str);
 
524
 
 
525
    if(field_arg->unireg_check == Field::NEXT_NUMBER)
 
526
    {
 
527
      drizzle::Table::Field::NumericFieldOptions *field_options;
 
528
      field_options= attribute->mutable_numeric_options();
 
529
      field_options->set_is_autoincrement(true);
 
530
    }
 
531
 
 
532
    if(field_arg->unireg_check == Field::TIMESTAMP_DN_FIELD
 
533
       || field_arg->unireg_check == Field::TIMESTAMP_DNUN_FIELD)
 
534
    {
 
535
      drizzle::Table::Field::FieldOptions *field_options;
 
536
      field_options= attribute->mutable_options();
 
537
      field_options->set_default_value("NOW()");
 
538
    }
 
539
 
 
540
    if(field_arg->unireg_check == Field::TIMESTAMP_UN_FIELD
 
541
       || field_arg->unireg_check == Field::TIMESTAMP_DNUN_FIELD)
 
542
    {
 
543
      drizzle::Table::Field::FieldOptions *field_options;
 
544
      field_options= attribute->mutable_options();
 
545
      field_options->set_update_value("NOW()");
 
546
    }
 
547
 
 
548
    assert(field_arg->unireg_check == Field::NONE
 
549
           || field_arg->unireg_check == Field::NEXT_NUMBER
 
550
           || field_arg->unireg_check == Field::TIMESTAMP_DN_FIELD
 
551
           || field_arg->unireg_check == Field::TIMESTAMP_UN_FIELD
 
552
           || field_arg->unireg_check == Field::TIMESTAMP_DNUN_FIELD);
 
553
 
 
554
    /* Fuck me. seriously, wtf */
 
555
    ulong data_offset= (create_info->null_bits + 7)/8;
 
556
    attribute->set_recpos(field_arg->offset+1 + (uint)data_offset);
 
557
 
 
558
    /* Because:
 
559
       - flag should never mean flag
 
560
       - unireg_check/unireg_type should exist
 
561
       - and field length should be specified for fixed sized types.
 
562
 
 
563
       NOT.
 
564
 
 
565
       These should all die a horrible death. A freeze-ray is too good for them.
 
566
       A death-ray is way better.
 
567
    */
 
568
    attribute->set_pack_flag(field_arg->pack_flag);
 
569
    attribute->set_field_length(field_arg->length);
 
570
    attribute->set_interval_nr(field_arg->interval_id);
494
571
  }
495
572
 
496
573
  if (create_info->used_fields & HA_CREATE_USED_PACK_KEYS)
872
949
      pos[length + 3]= '\0';
873
950
      pos+= length + 3 + 1;
874
951
    }
875
 
    cfield->row=(uint8_t) row;
876
 
    cfield->col=(uint8_t) (length+1);
877
 
    cfield->sc_length=(uint8_t) cmin(cfield->length,(uint32_t)cols-(length+2));
878
952
  }
879
953
  length=(uint) (pos-start_screen);
880
954
  int2store(start_screen,length);
972
1046
                        uint32_t info_length, uint32_t screens, uint32_t table_options,
973
1047
                        ulong data_offset, handler *file)
974
1048
{
975
 
  uint32_t length,int_count,int_length,no_empty, int_parts;
 
1049
  uint32_t length,int_count,int_length, int_parts;
976
1050
  uint32_t time_stamp_pos,null_fields;
977
1051
  ulong reclength, totlength, n_length, com_length, vcol_info_length;
978
1052
 
985
1059
 
986
1060
  totlength= 0L;
987
1061
  reclength= data_offset;
988
 
  no_empty=int_count=int_parts=int_length=time_stamp_pos=null_fields=
 
1062
  int_count=int_parts=int_length=time_stamp_pos=null_fields=
989
1063
    com_length=vcol_info_length=0;
990
1064
  n_length=2L;
991
1065
 
1032
1106
 
1033
1107
    totlength+= field->length;
1034
1108
    com_length+= field->comment.length;
1035
 
    if (MTYP_TYPENR(field->unireg_check) == Field::NOEMPTY ||
1036
 
        field->unireg_check & MTYP_NOEMPTY_BIT)
1037
 
    {
1038
 
      field->unireg_check= (Field::utype) ((uint) field->unireg_check |
1039
 
                                           MTYP_NOEMPTY_BIT);
1040
 
      no_empty++;
1041
 
    }
1042
1109
    /*
1043
1110
      We mark first TIMESTAMP field with NOW() in DEFAULT or ON UPDATE
1044
1111
      as auto-update field.
1129
1196
  int2store(forminfo+258,create_fields.elements);
1130
1197
  int2store(forminfo+260,info_length);
1131
1198
  int2store(forminfo+262,totlength);
1132
 
  int2store(forminfo+264,no_empty);
 
1199
  int2store(forminfo+264,0); // no_empty
1133
1200
  int2store(forminfo+266,reclength);
1134
1201
  int2store(forminfo+268,n_length);
1135
1202
  int2store(forminfo+270,int_count);
1194
1261
  {
1195
1262
    uint32_t recpos;
1196
1263
    uint32_t cur_vcol_expr_len= 0;
1197
 
    buff[0]= (unsigned char) field->row;
1198
 
    buff[1]= (unsigned char) field->col;
1199
 
    buff[2]= (unsigned char) field->sc_length;
 
1264
    buff[0]= 0; //(unsigned char) field->row;
 
1265
    buff[1]= 0; //(unsigned char) field->col;
 
1266
    buff[2]= 0; //(unsigned char) field->sc_length;
1200
1267
    int2store(buff+3, field->length);
1201
1268
    /* The +1 is here becasue the col offset in .frm file have offset 1 */
1202
1269
    recpos= field->offset+1 + (uint) data_offset;
1448
1515
      regfield->set_notnull();
1449
1516
      regfield->store((int64_t) 1, true);
1450
1517
    }
1451
 
    else if (type == Field::YES)                // Old unireg type
1452
 
      regfield->store(ER(ER_YES),(uint) strlen(ER(ER_YES)),system_charset_info);
1453
 
    else if (type == Field::NO)                 // Old unireg type
1454
 
      regfield->store(ER(ER_NO), (uint) strlen(ER(ER_NO)),system_charset_info);
1455
1518
    else
1456
1519
      regfield->reset();
1457
1520
  }