~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/unireg.cc

code clean move Item_func_floor, Item_func_length, Item_func_min_max, Item_func_rand, Item_func_round to functions directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
566
566
{
567
567
  uint32_t length,int_count,int_length,no_empty, int_parts;
568
568
  uint32_t time_stamp_pos,null_fields;
569
 
  ulong reclength, totlength, n_length, com_length;
 
569
  ulong reclength, totlength, n_length, com_length, vcol_info_length;
570
570
 
571
571
 
572
572
  if (create_fields.elements > MAX_FIELDS)
578
578
  totlength= 0L;
579
579
  reclength= data_offset;
580
580
  no_empty=int_count=int_parts=int_length=time_stamp_pos=null_fields=
581
 
    com_length=0;
 
581
    com_length=vcol_info_length=0;
582
582
  n_length=2L;
583
583
 
584
584
        /* Check fields */
600
600
               (uint) COLUMN_COMMENT_MAXLEN);
601
601
      return(1);
602
602
    }
 
603
    if (field->vcol_info)
 
604
    {
 
605
      tmp_len= system_charset_info->cset->charpos(system_charset_info,
 
606
                                                  field->vcol_info->expr_str.str,
 
607
                                                  field->vcol_info->expr_str.str +
 
608
                                                  field->vcol_info->expr_str.length,
 
609
                                                  VIRTUAL_COLUMN_EXPRESSION_MAXLEN);
 
610
 
 
611
      if (tmp_len < field->vcol_info->expr_str.length)
 
612
      {
 
613
        my_error(ER_WRONG_STRING_LENGTH, MYF(0),
 
614
                 field->vcol_info->expr_str.str,"VIRTUAL COLUMN EXPRESSION",
 
615
                 (uint) VIRTUAL_COLUMN_EXPRESSION_MAXLEN);
 
616
        return(1);
 
617
      }
 
618
      /*
 
619
        Sum up the length of the expression string and mandatory header bytes
 
620
        to the total length.
 
621
      */
 
622
      vcol_info_length+= field->vcol_info->expr_str.length+(uint)FRM_VCOL_HEADER_SIZE;
 
623
    }
603
624
 
604
625
    totlength+= field->length;
605
626
    com_length+= field->comment.length;
619
640
        !time_stamp_pos)
620
641
      time_stamp_pos= (uint) field->offset+ (uint) data_offset + 1;
621
642
    length=field->pack_length;
622
 
    /* Ensure we don't have any bugs when generating offsets */
623
 
    assert(reclength == field->offset + data_offset);
624
643
    if ((uint) field->offset+ (uint) data_offset+ length > reclength)
625
644
      reclength=(uint) (field->offset+ data_offset + length);
626
645
    n_length+= (ulong) strlen(field->field_name)+1;
687
706
  /* Hack to avoid bugs with small static rows in MySQL */
688
707
  reclength=cmax((ulong)file->min_record_length(table_options),reclength);
689
708
  if (info_length+(ulong) create_fields.elements*FCOMP+288+
690
 
      n_length+int_length+com_length > 65535L || int_count > 255)
 
709
      n_length+int_length+com_length+vcol_info_length > 65535L || 
 
710
      int_count > 255)
691
711
  {
692
712
    my_message(ER_TOO_MANY_FIELDS, ER(ER_TOO_MANY_FIELDS), MYF(0));
693
713
    return(1);
695
715
 
696
716
  memset(forminfo, 0, 288);
697
717
  length=(info_length+create_fields.elements*FCOMP+288+n_length+int_length+
698
 
          com_length);
 
718
          com_length+vcol_info_length);
699
719
  int2store(forminfo,length);
700
720
  forminfo[256] = (uint8_t) screens;
701
721
  int2store(forminfo+258,create_fields.elements);
712
732
  int2store(forminfo+280,22);                   /* Rows needed */
713
733
  int2store(forminfo+282,null_fields);
714
734
  int2store(forminfo+284,com_length);
715
 
  /* Up to forminfo+288 is free to use for additional information */
 
735
  int2store(forminfo+286,vcol_info_length);
 
736
  /* forminfo+288 is free to use for additional information */
716
737
  return(0);
717
738
} /* pack_header */
718
739
 
751
772
                        ulong data_offset)
752
773
{
753
774
  register uint32_t i;
754
 
  uint32_t int_count, comment_length=0;
 
775
  uint32_t int_count, comment_length=0, vcol_info_length=0;
755
776
  unsigned char buff[MAX_FIELD_WIDTH];
756
777
  Create_field *field;
757
778
  
764
785
  while ((field=it++))
765
786
  {
766
787
    uint32_t recpos;
 
788
    uint32_t cur_vcol_expr_len= 0;
767
789
    buff[0]= (unsigned char) field->row;
768
790
    buff[1]= (unsigned char) field->col;
769
791
    buff[2]= (unsigned char) field->sc_length;
779
801
      buff[14]= (unsigned char) field->charset->number;
780
802
    else
781
803
      buff[14]= 0;                              // Numerical
 
804
    if (field->vcol_info)
 
805
    {
 
806
      /* 
 
807
        Use the interval_id place in the .frm file to store the length of
 
808
        virtual field's data.
 
809
      */
 
810
      buff[12]= cur_vcol_expr_len= field->vcol_info->expr_str.length +
 
811
                (uint)FRM_VCOL_HEADER_SIZE;
 
812
      vcol_info_length+= cur_vcol_expr_len+(uint)FRM_VCOL_HEADER_SIZE;
 
813
      buff[13]= (unsigned char) DRIZZLE_TYPE_VIRTUAL;
 
814
    }
782
815
    int2store(buff+15, field->comment.length);
783
816
    comment_length+= field->comment.length;
784
817
    set_if_bigger(int_count,field->interval_id);
873
906
          return(1);
874
907
    }
875
908
  }
 
909
  if (vcol_info_length)
 
910
  {
 
911
    it.rewind();
 
912
    int_count=0;
 
913
    while ((field=it++))
 
914
    {
 
915
      /*
 
916
        Pack each virtual field as follows:
 
917
        byte 1      = 1 (always 1 to allow for future extensions)
 
918
        byte 2      = sql_type
 
919
        byte 3      = flags (as of now, 0 - no flags, 1 - field is physically stored)
 
920
        byte 4-...  = virtual column expression (text data)
 
921
      */
 
922
      if (field->vcol_info && field->vcol_info->expr_str.length)
 
923
      {
 
924
        buff[0]= (unsigned char)1;
 
925
        buff[1]= (unsigned char) field->sql_type;
 
926
        buff[2]= (unsigned char) field->is_stored;
 
927
        if (my_write(file, buff, 3, MYF_RW))
 
928
          return(1);
 
929
        if (my_write(file, 
 
930
                     (unsigned char*) field->vcol_info->expr_str.str, 
 
931
                     field->vcol_info->expr_str.length,
 
932
                     MYF_RW))
 
933
          return(1);
 
934
      }
 
935
    }
 
936
  }
876
937
  return(0);
877
938
}
878
939