~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.cc

Merged from trunk.
Removed test_xml. Moved my_xml to mystrings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
737
737
                     uint8_t dec_arg, bool zero_arg, bool unsigned_arg)
738
738
  :Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
739
739
         unireg_check_arg, field_name_arg),
740
 
  dec(dec_arg),zerofill(zero_arg),unsigned_flag(unsigned_arg)
 
740
  dec(dec_arg),decimal_precision(zero_arg),unsigned_flag(unsigned_arg)
741
741
{
742
 
  if (zerofill)
743
 
    flags|=ZEROFILL_FLAG;
744
742
  if (unsigned_flag)
745
743
    flags|=UNSIGNED_FLAG;
746
744
}
747
745
 
748
746
 
749
 
void Field_num::prepend_zeros(String *value)
750
 
{
751
 
  int diff;
752
 
  if ((diff= (int) (field_length - value->length())) > 0)
753
 
  {
754
 
    bmove_upp((uchar*) value->ptr()+field_length,
755
 
              (uchar*) value->ptr()+value->length(),
756
 
              value->length());
757
 
    bfill((uchar*) value->ptr(),diff,'0');
758
 
    value->length(field_length);
759
 
    (void) value->c_ptr_quick();                // Avoid warnings in purify
760
 
  }
761
 
}
762
 
 
763
747
/**
764
748
  Test if given number is a int.
765
749
 
1191
1175
}
1192
1176
 
1193
1177
 
1194
 
void Field_num::add_zerofill_and_unsigned(String &res) const
 
1178
void Field_num::add_unsigned(String &res) const
1195
1179
{
1196
1180
  if (unsigned_flag)
1197
1181
    res.append(STRING_WITH_LEN(" unsigned"));
1198
 
  if (zerofill)
1199
 
    res.append(STRING_WITH_LEN(" zerofill"));
1200
1182
}
1201
1183
 
1202
1184
 
1458
1440
  tmp->part_of_key.init(0);
1459
1441
  tmp->part_of_sortkey.init(0);
1460
1442
  tmp->unireg_check= Field::NONE;
1461
 
  tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG |
1462
 
                ZEROFILL_FLAG | BINARY_FLAG | ENUM_FLAG | SET_FLAG);
 
1443
  tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | BINARY_FLAG | ENUM_FLAG | SET_FLAG);
1463
1444
  tmp->reset_fields();
1464
1445
  return tmp;
1465
1446
}
1629
1610
                                           (long) *((signed char*) ptr));
1630
1611
  
1631
1612
  val_buffer->length(length);
1632
 
  if (zerofill)
1633
 
    prepend_zeros(val_buffer);
 
1613
 
1634
1614
  return val_buffer;
1635
1615
}
1636
1616
 
1661
1641
  CHARSET_INFO *cs=res.charset();
1662
1642
  res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
1663
1643
                          "tinyint(%d)",(int) field_length));
1664
 
  add_zerofill_and_unsigned(res);
 
1644
  add_unsigned(res);
1665
1645
}
1666
1646
 
1667
1647
 
2174
2154
  Field_num *from_num= (Field_num*) field;
2175
2155
 
2176
2156
  if (unsigned_flag != from_num->unsigned_flag ||
2177
 
      (zerofill && !from_num->zerofill && !zero_pack()) ||
2178
2157
      dec != from_num->dec)
2179
2158
    return 0;
2180
2159
  return 1;
2408
2387
  case DRIZZLE_TYPE_YEAR:
2409
2388
    if (!fld_length || length != 2)
2410
2389
      length= 4; /* Default length */
2411
 
    flags|= ZEROFILL_FLAG | UNSIGNED_FLAG;
 
2390
    flags|= UNSIGNED_FLAG;
2412
2391
    break;
2413
2392
  case DRIZZLE_TYPE_DOUBLE:
2414
2393
    allowed_type_modifier= AUTO_INCREMENT_FLAG;
2439
2418
      length= ((length+1)/2)*2; /* purecov: inspected */
2440
2419
      length= min(length, MAX_DATETIME_COMPRESSED_WIDTH); /* purecov: inspected */
2441
2420
    }
2442
 
    flags|= ZEROFILL_FLAG | UNSIGNED_FLAG;
 
2421
    flags|= UNSIGNED_FLAG;
2443
2422
    if (fld_default_value)
2444
2423
    {
2445
2424
      /* Grammar allows only NOW() value for ON UPDATE clause */
2683
2662
    return new Field_new_decimal(ptr,field_length,null_pos,null_bit,
2684
2663
                                 unireg_check, field_name,
2685
2664
                                 f_decimals(pack_flag),
2686
 
                                 f_is_zerofill(pack_flag) != 0,
 
2665
                                 f_is_decimal_precision(pack_flag) != 0,
2687
2666
                                 f_is_dec(pack_flag) == 0);
2688
2667
  case DRIZZLE_TYPE_DOUBLE:
2689
2668
    return new Field_double(ptr,field_length,null_pos,null_bit,
2690
2669
                            unireg_check, field_name,
2691
2670
                            f_decimals(pack_flag),
2692
 
                            f_is_zerofill(pack_flag) != 0,
 
2671
                            false,
2693
2672
                            f_is_dec(pack_flag)== 0);
2694
2673
  case DRIZZLE_TYPE_TINY:
2695
2674
    return new Field_tiny(ptr,field_length,null_pos,null_bit,
2696
2675
                          unireg_check, field_name,
2697
 
                          f_is_zerofill(pack_flag) != 0,
 
2676
                          false,
2698
2677
                          f_is_dec(pack_flag) == 0);
2699
2678
  case DRIZZLE_TYPE_SHORT:
2700
2679
    return new Field_short(ptr,field_length,null_pos,null_bit,
2701
2680
                           unireg_check, field_name,
2702
 
                           f_is_zerofill(pack_flag) != 0,
 
2681
                           false,
2703
2682
                           f_is_dec(pack_flag) == 0);
2704
2683
  case DRIZZLE_TYPE_LONG:
2705
2684
    return new Field_long(ptr,field_length,null_pos,null_bit,
2706
2685
                           unireg_check, field_name,
2707
 
                           f_is_zerofill(pack_flag) != 0,
 
2686
                           false,
2708
2687
                           f_is_dec(pack_flag) == 0);
2709
2688
  case DRIZZLE_TYPE_LONGLONG:
2710
2689
    return new Field_int64_t(ptr,field_length,null_pos,null_bit,
2711
2690
                              unireg_check, field_name,
2712
 
                              f_is_zerofill(pack_flag) != 0,
 
2691
                              false,
2713
2692
                              f_is_dec(pack_flag) == 0);
2714
2693
  case DRIZZLE_TYPE_TIMESTAMP:
2715
2694
    return new Field_timestamp(ptr,field_length, null_pos, null_bit,