~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.cc

  • Committer: Brian Aker
  • Date: 2009-02-02 18:19:36 UTC
  • mfrom: (820.1.14 nofrm)
  • Revision ID: brian@tangent.org-20090202181936-l03a2jb3vpndr1k3
Merge from Stewart.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include <drizzled/field/double.h>
36
36
#include <string>
37
37
 
 
38
#include <drizzled/unireg.h>
 
39
#include <drizzled/serialize/table.pb.h>
 
40
 
38
41
using namespace std;
39
42
 
40
43
/* Keyword for parsing virtual column functions */
322
325
 
323
326
  path.reserve(FN_REFLEN);
324
327
  path.append(share->normalized_path.str);
 
328
  string proto_path= path;
 
329
 
325
330
  path.append(reg_ext);
 
331
 
 
332
  proto_path.append(".dfe");
 
333
 
 
334
  drizzle::Table table;
 
335
 
 
336
  if(drizzle_read_table_proto(proto_path.c_str(), &table)==0)
 
337
  {
 
338
    {
 
339
      LEX_STRING engine_name= { (char*)table.engine().name().c_str(),
 
340
                                strlen(table.engine().name().c_str()) };
 
341
      share->db_plugin= ha_resolve_by_name(session, &engine_name);
 
342
    }
 
343
 
 
344
    // share->db_create_options FAIL
 
345
    // share->db_options_in_use FAIL
 
346
    share->mysql_version= DRIZZLE_VERSION_ID; // TODO: remove
 
347
    share->null_field_first= 0;
 
348
 
 
349
    drizzle::Table::TableOptions table_options;
 
350
    
 
351
    if(table.has_options())
 
352
      table_options= table.options();
 
353
 
 
354
    share->avg_row_length= table_options.has_avg_row_length() ?
 
355
      table_options.avg_row_length() : 0;
 
356
 
 
357
    share->page_checksum= table_options.has_page_checksum() ?
 
358
      (table_options.page_checksum()?HA_CHOICE_YES:HA_CHOICE_NO)
 
359
      : HA_CHOICE_UNDEF;
 
360
 
 
361
    share->row_type= table_options.has_row_type() ?
 
362
      (enum row_type) table_options.row_type() : ROW_TYPE_DEFAULT;
 
363
 
 
364
    share->block_size= table_options.has_block_size() ?
 
365
      table_options.block_size() : 0;
 
366
 
 
367
    share->table_charset= get_charset(table_options.has_collation_id()?
 
368
                                      table_options.collation_id() : 0,
 
369
                                      MYF(0));
 
370
 
 
371
    if (!share->table_charset)
 
372
    {
 
373
      /* unknown charset in head[38] or pre-3.23 frm */
 
374
      if (use_mb(default_charset_info))
 
375
      {
 
376
        /* Warn that we may be changing the size of character columns */
 
377
        errmsg_printf(ERRMSG_LVL_WARN,
 
378
                      _("'%s' had no or invalid character set, "
 
379
                        "and default character set is multi-byte, "
 
380
                        "so character column sizes may have changed"),
 
381
                      share->path.str);
 
382
      }
 
383
      share->table_charset= default_charset_info;
 
384
    }
 
385
 
 
386
    share->null_field_first= 1;
 
387
 
 
388
    share->db_record_offset= 1;
 
389
 
 
390
    share->blob_ptr_size= portable_sizeof_char_ptr; // more bonghits.
 
391
 
 
392
    share->db_low_byte_first= true;
 
393
 
 
394
    share->max_rows= table_options.has_max_rows() ?
 
395
      table_options.max_rows() : 0;
 
396
 
 
397
    share->min_rows= table_options.has_min_rows() ?
 
398
      table_options.min_rows() : 0;
 
399
 
 
400
    share->keys= table.indexes_size();
 
401
 
 
402
    share->key_parts= 0;
 
403
    for(int indx= 0; indx < table.indexes_size(); indx++)
 
404
      share->key_parts+= table.indexes(indx).index_part_size();
 
405
 
 
406
    share->keys_for_keyread.init(0);
 
407
    share->keys_in_use.init(share->keys);
 
408
 
 
409
    if(table_options.has_connect_string())
 
410
    {
 
411
      size_t len= table_options.connect_string().length();
 
412
      const char* str= table_options.connect_string().c_str();
 
413
 
 
414
      share->connect_string.length= len;
 
415
      share->connect_string.str= strmake_root(&share->mem_root, str, len);
 
416
    }
 
417
 
 
418
    if(table_options.has_comment())
 
419
    {
 
420
      size_t len= table_options.comment().length();
 
421
      const char* str= table_options.comment().c_str();
 
422
 
 
423
      share->comment.length= len;
 
424
      share->comment.str= strmake_root(&share->mem_root, str, len);
 
425
    }
 
426
 
 
427
    share->key_block_size= table_options.has_key_block_size() ?
 
428
      table_options.key_block_size() : 0;
 
429
 
 
430
//    return 0;
 
431
  }
 
432
 
326
433
  if ((file= open(path.c_str(), O_RDONLY)) < 0)
327
434
  {
328
435
    /*
452
559
  KEY_PART_INFO *key_part;
453
560
  Field  **field_ptr, *reg_field;
454
561
  const char **interval_array;
455
 
  enum legacy_db_type legacy_db_type;
456
562
  my_bitmap_map *bitmaps;
457
563
  unsigned char *buff= 0;
458
564
  unsigned char *field_extra_info= 0;
469
575
  if (my_read(file,forminfo,288,MYF(MY_NABP)))
470
576
    goto err;
471
577
 
472
 
  legacy_db_type= DB_TYPE_FIRST_DYNAMIC;
473
 
  assert(share->db_plugin == NULL);
474
 
  /*
475
 
    if the storage engine is dynamic, no point in resolving it by its
476
 
    dynamically allocated legacy_db_type. We will resolve it later by name.
477
 
  */
478
 
  if (legacy_db_type > DB_TYPE_UNKNOWN &&
479
 
      legacy_db_type < DB_TYPE_FIRST_DYNAMIC)
480
 
    share->db_plugin= ha_lock_engine(NULL,
481
 
                                     ha_checktype(session, legacy_db_type, 0, 0));
482
578
  share->db_create_options= db_create_options= uint2korr(head+30);
483
579
  share->db_options_in_use= share->db_create_options;
484
 
  share->mysql_version= uint4korr(head+51);
485
 
  share->null_field_first= 0;
486
 
  if (!head[32])                                // New frm file in 3.23
487
 
  {
488
 
    share->avg_row_length= uint4korr(head+34);
489
 
    share->transactional= (ha_choice) (head[39] & 3);
490
 
    share->page_checksum= (ha_choice) ((head[39] >> 2) & 3);
491
 
    share->row_type= (row_type) head[40];
492
 
    share->block_size= uint4korr(head+43);
493
 
    share->table_charset= get_charset((uint) head[38],MYF(0));
494
 
    share->null_field_first= 1;
495
 
  }
496
 
  if (!share->table_charset)
497
 
  {
498
 
    /* unknown charset in head[38] or pre-3.23 frm */
499
 
    if (use_mb(default_charset_info))
500
 
    {
501
 
      /* Warn that we may be changing the size of character columns */
502
 
      errmsg_printf(ERRMSG_LVL_WARN, _("'%s' had no or invalid character set, "
503
 
                        "and default character set is multi-byte, "
504
 
                        "so character column sizes may have changed"),
505
 
                        share->path.str);
506
 
    }
507
 
    share->table_charset= default_charset_info;
508
 
  }
509
 
  share->db_record_offset= 1;
510
 
  if (db_create_options & HA_OPTION_LONG_BLOB_PTR)
511
 
    share->blob_ptr_size= portable_sizeof_char_ptr;
512
 
  /* Set temporarily a good value for db_low_byte_first */
513
 
  share->db_low_byte_first= true;
 
580
 
514
581
  error=4;
515
 
  share->max_rows= uint4korr(head+18);
516
 
  share->min_rows= uint4korr(head+22);
517
582
 
518
583
  /* Read keyinformation */
519
584
  key_info_length= (uint) uint2korr(head+28);
622
687
    {
623
688
      goto err;
624
689
    }
625
 
    share->connect_string.length= uint2korr(buff);
626
 
    if (!(share->connect_string.str= strmake_root(&share->mem_root,
627
 
                                                  (char*) next_chunk + 2,
628
 
                                                  share->connect_string.
629
 
                                                  length)))
630
 
    {
631
 
      goto err;
632
 
    }
633
 
    next_chunk+= share->connect_string.length + 2;
 
690
 
 
691
    uint32_t connect_str_length= uint2korr(buff);
 
692
    next_chunk+= connect_str_length + 2;
 
693
 
634
694
    buff_end= buff + n_length;
635
695
    if (next_chunk + 2 < buff_end)
636
696
    {
637
697
      uint32_t str_db_type_length= uint2korr(next_chunk);
638
 
      LEX_STRING name;
639
 
      name.str= (char*) next_chunk + 2;
640
 
      name.length= str_db_type_length;
641
 
 
642
 
      plugin_ref tmp_plugin= ha_resolve_by_name(session, &name);
643
 
      if (tmp_plugin != NULL && !plugin_equals(tmp_plugin, share->db_plugin))
644
 
      {
645
 
        if (legacy_db_type > DB_TYPE_UNKNOWN &&
646
 
            legacy_db_type < DB_TYPE_FIRST_DYNAMIC &&
647
 
            legacy_db_type != ha_legacy_type(
648
 
                plugin_data(tmp_plugin, handlerton *)))
649
 
        {
650
 
          /* bad file, legacy_db_type did not match the name */
651
 
          free(buff);
652
 
          goto err;
653
 
        }
654
 
        /*
655
 
          tmp_plugin is locked with a local lock.
656
 
          we unlock the old value of share->db_plugin before
657
 
          replacing it with a globally locked version of tmp_plugin
658
 
        */
659
 
        plugin_unlock(NULL, share->db_plugin);
660
 
        share->db_plugin= my_plugin_lock(NULL, &tmp_plugin);
661
 
      }
662
 
      else if (!tmp_plugin)
663
 
      {
664
 
        /* purecov: begin inspected */
665
 
        error= 8;
666
 
        my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), name.str);
667
 
        free(buff);
668
 
        goto err;
669
 
        /* purecov: end */
670
 
      }
671
698
      next_chunk+= str_db_type_length + 2;
672
699
    }
673
700
    if (share->mysql_version >= 50110)
683
710
          free(buff);
684
711
          goto err;
685
712
      }
686
 
      share->comment.length = uint2korr(next_chunk);
687
 
      if (! (share->comment.str= strmake_root(&share->mem_root,
688
 
                               (char*)next_chunk + 2, share->comment.length)))
689
 
      {
690
 
          free(buff);
691
 
          goto err;
692
 
      }
693
 
      next_chunk+= 2 + share->comment.length;
 
713
      uint32_t comment_str_length= uint2korr(next_chunk);
 
714
      next_chunk+= 2 + comment_str_length;
694
715
    }
695
716
    assert(next_chunk <= buff_end);
696
717
    if (share->mysql_version >= DRIZZLE_VERSION_TABLESPACE_IN_FRM_CGE)
713
734
      {
714
735
        const uint32_t format_section_header_size= 8;
715
736
        uint32_t format_section_len= uint2korr(next_chunk+0);
716
 
 
717
 
        field_extra_info= next_chunk + format_section_header_size + 1;
 
737
        uint flags=  uint4korr(next_chunk+2);
 
738
 
 
739
        (void)flags;
 
740
 
 
741
        const char *tablespace= (const char*)next_chunk + format_section_header_size;
 
742
        uint tablespace_len= strlen(tablespace);
 
743
 
 
744
        field_extra_info= next_chunk + format_section_header_size + tablespace_len + 1;
718
745
        next_chunk+= format_section_len;
719
746
      }
720
747
    }
724
751
      goto err;
725
752
    }
726
753
  }
727
 
  share->key_block_size= uint2korr(head+62);
728
754
 
729
755
  error=4;
730
756
  extra_rec_buf_length= uint2korr(head+59);
750
776
  vcol_screen_length= uint2korr(forminfo+286);
751
777
  share->vfields= 0;
752
778
  share->stored_fields= share->fields;
753
 
  if (forminfo[46] != (unsigned char)255)
754
 
  {
755
 
    share->comment.length=  (int) (forminfo[46]);
756
 
    share->comment.str= strmake_root(&share->mem_root, (char*) forminfo+47,
757
 
                                     share->comment.length);
758
 
  }
759
779
 
760
780
 
761
781
  if (!(field_ptr = (Field **)