~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/field.cc

  • Committer: Brian Aker
  • Date: 2008-07-10 19:37:55 UTC
  • mfrom: (51.1.67 remove-dbug)
  • Revision ID: brian@tangent.org-20080710193755-f5g761uieqa3wxmt
Merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
#define BLOB_PACK_LENGTH_TO_MAX_LENGH(arg) \
52
52
((ulong) ((1LL << min(arg, 4) * 8) - 1LL))
53
53
 
54
 
#define ASSERT_COLUMN_MARKED_FOR_READ DBUG_ASSERT(!table || (!table->read_set || bitmap_is_set(table->read_set, field_index)))
55
 
#define ASSERT_COLUMN_MARKED_FOR_WRITE DBUG_ASSERT(!table || (!table->write_set || bitmap_is_set(table->write_set, field_index)))
56
 
 
57
54
/*
58
55
  Rules for merging different types of fields in UNION
59
56
 
683
680
enum_field_types Field::field_type_merge(enum_field_types a,
684
681
                                         enum_field_types b)
685
682
{
686
 
  DBUG_ASSERT(a < FIELDTYPE_TEAR_FROM || a > FIELDTYPE_TEAR_TO);
687
 
  DBUG_ASSERT(b < FIELDTYPE_TEAR_FROM || b > FIELDTYPE_TEAR_TO);
 
683
  assert(a < FIELDTYPE_TEAR_FROM || a > FIELDTYPE_TEAR_TO);
 
684
  assert(b < FIELDTYPE_TEAR_FROM || b > FIELDTYPE_TEAR_TO);
688
685
  return field_types_merge_rules[field_type2index(a)]
689
686
                                [field_type2index(b)];
690
687
}
731
728
    strend      String end
732
729
 
733
730
  RETURN
734
 
    FALSE - If string does not have important data
735
 
    TRUE  - If string has some important data
 
731
    false - If string does not have important data
 
732
    true  - If string has some important data
736
733
*/
737
734
 
738
735
static bool
755
752
 
756
753
Item_result Field::result_merge_type(enum_field_types field_type)
757
754
{
758
 
  DBUG_ASSERT(field_type < FIELDTYPE_TEAR_FROM || field_type
 
755
  assert(field_type < FIELDTYPE_TEAR_FROM || field_type
759
756
              > FIELDTYPE_TEAR_TO);
760
757
  return field_types_result_type[field_type2index(field_type)];
761
758
}
774
771
  @param type  field type
775
772
 
776
773
  @retval
777
 
    TRUE  Type can have a prefixed key
 
774
    true  Type can have a prefixed key
778
775
  @retval
779
 
    FALSE Type can not have a prefixed key
 
776
    false Type can not have a prefixed key
780
777
*/
781
778
 
782
779
bool Field::type_can_have_key_part(enum enum_field_types type)
786
783
  case MYSQL_TYPE_BLOB:
787
784
  case MYSQL_TYPE_VAR_STRING:
788
785
  case MYSQL_TYPE_STRING:
789
 
    return TRUE;
 
786
    return true;
790
787
  default:
791
 
    return FALSE;
 
788
    return false;
792
789
  }
793
790
}
794
791
 
1029
1026
 
1030
1027
String *Field::val_int_as_str(String *val_buffer, my_bool unsigned_val)
1031
1028
{
1032
 
  ASSERT_COLUMN_MARKED_FOR_READ;
1033
1029
  CHARSET_INFO *cs= &my_charset_bin;
1034
1030
  uint length;
1035
1031
  longlong value= val_int();
1055
1051
   key_start(0), part_of_key(0), part_of_key_not_clustered(0),
1056
1052
   part_of_sortkey(0), unireg_check(unireg_check_arg),
1057
1053
   field_length(length_arg), null_bit(null_bit_arg), 
1058
 
   is_created_from_null_item(FALSE)
 
1054
   is_created_from_null_item(false)
1059
1055
{
1060
1056
  flags=null_ptr ? 0: NOT_NULL_FLAG;
1061
1057
  comment.str= (char*) "";
1081
1077
size_t
1082
1078
Field::do_last_null_byte() const
1083
1079
{
1084
 
  DBUG_ASSERT(null_ptr == NULL || null_ptr >= table->record[0]);
 
1080
  assert(null_ptr == NULL || null_ptr >= table->record[0]);
1085
1081
  if (null_ptr)
1086
1082
    return (size_t) (null_ptr - table->record[0]) + 1;
1087
1083
  return LAST_NULL_BYTE_UNDEF;
1172
1168
   the data.
1173
1169
 
1174
1170
   @param low_byte_first
1175
 
   @c TRUE if integers should be stored little-endian, @c FALSE if
 
1171
   @c true if integers should be stored little-endian, @c false if
1176
1172
   native format should be used. Note that for little-endian machines,
1177
1173
   the value of this flag is a moot point since the native format is
1178
1174
   little-endian.
1252
1248
my_decimal *Field::val_decimal(my_decimal *decimal __attribute__((__unused__)))
1253
1249
{
1254
1250
  /* This never have to be called */
1255
 
  DBUG_ASSERT(0);
 
1251
  assert(0);
1256
1252
  return 0;
1257
1253
}
1258
1254
 
1319
1315
    }
1320
1316
    else if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
1321
1317
                                           ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
1322
 
                                           val, TRUE, &i)))
 
1318
                                           val, true, &i)))
1323
1319
    {
1324
1320
      i= ~(longlong) 0;
1325
1321
      *err= 1;
1327
1323
  }
1328
1324
  else if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
1329
1325
                                         ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
1330
 
                                         val, FALSE, &i)))
 
1326
                                         val, false, &i)))
1331
1327
  {
1332
1328
    i= (val->sign() ? LONGLONG_MIN : LONGLONG_MAX);
1333
1329
    *err= 1;
1352
1348
 
1353
1349
int Field_num::store_decimal(const my_decimal *val)
1354
1350
{
1355
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
1356
1351
  int err= 0;
1357
1352
  longlong i= convert_decimal2longlong(val, unsigned_flag, &err);
1358
1353
  return test(err | store(i, unsigned_flag));
1375
1370
 
1376
1371
my_decimal* Field_num::val_decimal(my_decimal *decimal_value)
1377
1372
{
1378
 
  ASSERT_COLUMN_MARKED_FOR_READ;
1379
 
  DBUG_ASSERT(result_type() == INT_RESULT);
 
1373
  assert(result_type() == INT_RESULT);
1380
1374
  longlong nr= val_int();
1381
1375
  int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
1382
1376
  return decimal_value;
1424
1418
 
1425
1419
int Field_str::store_decimal(const my_decimal *d)
1426
1420
{
1427
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
1428
1421
  double val;
1429
1422
  /* TODO: use decimal2string? */
1430
1423
  int err= warn_if_overflow(my_decimal2double(E_DEC_FATAL_ERROR &
1435
1428
 
1436
1429
my_decimal *Field_str::val_decimal(my_decimal *decimal_value)
1437
1430
{
1438
 
  ASSERT_COLUMN_MARKED_FOR_READ;
1439
1431
  longlong nr= val_int();
1440
1432
  int2my_decimal(E_DEC_FATAL_ERROR, nr, 0, decimal_value);
1441
1433
  return decimal_value;
1502
1494
int Field::store_time(MYSQL_TIME *ltime,
1503
1495
                      timestamp_type type_arg __attribute__((__unused__)))
1504
1496
{
1505
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
1506
1497
  char buff[MAX_DATE_STRING_REP_LENGTH];
1507
1498
  uint length= (uint) my_TIME_to_str(ltime, buff);
1508
1499
  return store(buff, length, &my_charset_bin);
1592
1583
{
1593
1584
  precision= my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
1594
1585
  set_if_smaller(precision, DECIMAL_MAX_PRECISION);
1595
 
  DBUG_ASSERT((precision <= DECIMAL_MAX_PRECISION) &&
 
1586
  assert((precision <= DECIMAL_MAX_PRECISION) &&
1596
1587
              (dec <= DECIMAL_MAX_SCALE));
1597
1588
  bin_size= my_decimal_get_binary_size(precision, dec);
1598
1589
}
1609
1600
{
1610
1601
  precision= my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
1611
1602
  set_if_smaller(precision, DECIMAL_MAX_PRECISION);
1612
 
  DBUG_ASSERT((precision <= DECIMAL_MAX_PRECISION) &&
 
1603
  assert((precision <= DECIMAL_MAX_PRECISION) &&
1613
1604
              (dec <= DECIMAL_MAX_SCALE));
1614
1605
  bin_size= my_decimal_get_binary_size(precision, dec);
1615
1606
}
1632
1623
void Field_new_decimal::set_value_on_overflow(my_decimal *decimal_value,
1633
1624
                                              bool sign)
1634
1625
{
1635
 
  DBUG_ENTER("Field_new_decimal::set_value_on_overflow");
1636
1626
  max_my_decimal(decimal_value, precision, decimals());
1637
1627
  if (sign)
1638
1628
  {
1639
1629
    if (unsigned_flag)
1640
1630
      my_decimal_set_zero(decimal_value);
1641
1631
    else
1642
 
      decimal_value->sign(TRUE);
 
1632
      decimal_value->sign(true);
1643
1633
  }
1644
 
  DBUG_VOID_RETURN;
 
1634
  return;
1645
1635
}
1646
1636
 
1647
1637
 
1662
1652
 
1663
1653
bool Field_new_decimal::store_value(const my_decimal *decimal_value)
1664
1654
{
1665
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
1666
1655
  int error= 0;
1667
 
  DBUG_ENTER("Field_new_decimal::store_value");
1668
 
#ifndef DBUG_OFF
1669
 
  {
1670
 
    char dbug_buff[DECIMAL_MAX_STR_LENGTH+1];
1671
 
    DBUG_PRINT("enter", ("value: %s", dbug_decimal_as_string(dbug_buff, decimal_value)));
1672
 
  }
1673
 
#endif
1674
1656
 
1675
1657
  /* check that we do not try to write negative value in unsigned field */
1676
1658
  if (unsigned_flag && decimal_value->sign())
1677
1659
  {
1678
 
    DBUG_PRINT("info", ("unsigned overflow"));
1679
1660
    set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1680
1661
    error= 1;
1681
1662
    decimal_value= &decimal_zero;
1682
1663
  }
1683
 
#ifndef DBUG_OFF
1684
 
  {
1685
 
    char dbug_buff[DECIMAL_MAX_STR_LENGTH+1];
1686
 
    DBUG_PRINT("info", ("saving with precision %d  scale: %d  value %s",
1687
 
                        (int)precision, (int)dec,
1688
 
                        dbug_decimal_as_string(dbug_buff, decimal_value)));
1689
 
  }
1690
 
#endif
1691
1664
 
1692
1665
  if (warn_if_overflow(my_decimal2binary(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW,
1693
1666
                                         decimal_value, ptr, precision, dec)))
1694
1667
  {
1695
1668
    my_decimal buff;
1696
 
    DBUG_PRINT("info", ("overflow"));
1697
1669
    set_value_on_overflow(&buff, decimal_value->sign());
1698
1670
    my_decimal2binary(E_DEC_FATAL_ERROR, &buff, ptr, precision, dec);
1699
1671
    error= 1;
1700
1672
  }
1701
 
  DBUG_EXECUTE("info", print_decimal_buff(decimal_value, (uchar *) ptr,
1702
 
                                          bin_size););
1703
 
  DBUG_RETURN(error);
 
1673
  return(error);
1704
1674
}
1705
1675
 
1706
1676
 
1707
1677
int Field_new_decimal::store(const char *from, uint length,
1708
1678
                             CHARSET_INFO *charset_arg)
1709
1679
{
1710
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
1711
1680
  int err;
1712
1681
  my_decimal decimal_value;
1713
 
  DBUG_ENTER("Field_new_decimal::store(char*)");
1714
1682
 
1715
1683
  if ((err= str2my_decimal(E_DEC_FATAL_ERROR &
1716
1684
                           ~(E_DEC_OVERFLOW | E_DEC_BAD_NUM),
1728
1696
                        "decimal", from_as_str.c_ptr(), field_name,
1729
1697
                        (ulong) table->in_use->row_count);
1730
1698
 
1731
 
    DBUG_RETURN(err);
 
1699
    return(err);
1732
1700
  }
1733
1701
 
1734
1702
  switch (err) {
1756
1724
    }
1757
1725
  }
1758
1726
 
1759
 
#ifndef DBUG_OFF
1760
 
  char dbug_buff[DECIMAL_MAX_STR_LENGTH+1];
1761
 
  DBUG_PRINT("enter", ("value: %s",
1762
 
                       dbug_decimal_as_string(dbug_buff, &decimal_value)));
1763
 
#endif
1764
1727
  store_value(&decimal_value);
1765
 
  DBUG_RETURN(err);
 
1728
  return(err);
1766
1729
}
1767
1730
 
1768
1731
 
1774
1737
 
1775
1738
int Field_new_decimal::store(double nr)
1776
1739
{
1777
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
1778
1740
  my_decimal decimal_value;
1779
1741
  int err;
1780
 
  DBUG_ENTER("Field_new_decimal::store(double)");
1781
1742
 
1782
1743
  err= double2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW, nr,
1783
1744
                         &decimal_value);
1792
1753
    err= 1;
1793
1754
  else if (err && !table->in_use->got_warning)
1794
1755
    err= warn_if_overflow(err);
1795
 
  DBUG_RETURN(err);
 
1756
  return(err);
1796
1757
}
1797
1758
 
1798
1759
 
1799
1760
int Field_new_decimal::store(longlong nr, bool unsigned_val)
1800
1761
{
1801
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
1802
1762
  my_decimal decimal_value;
1803
1763
  int err;
1804
1764
 
1820
1780
 
1821
1781
int Field_new_decimal::store_decimal(const my_decimal *decimal_value)
1822
1782
{
1823
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
1824
1783
  return store_value(decimal_value);
1825
1784
}
1826
1785
 
1835
1794
 
1836
1795
double Field_new_decimal::val_real(void)
1837
1796
{
1838
 
  ASSERT_COLUMN_MARKED_FOR_READ;
1839
1797
  double dbl;
1840
1798
  my_decimal decimal_value;
1841
1799
  my_decimal2double(E_DEC_FATAL_ERROR, val_decimal(&decimal_value), &dbl);
1845
1803
 
1846
1804
longlong Field_new_decimal::val_int(void)
1847
1805
{
1848
 
  ASSERT_COLUMN_MARKED_FOR_READ;
1849
1806
  longlong i;
1850
1807
  my_decimal decimal_value;
1851
1808
  my_decimal2int(E_DEC_FATAL_ERROR, val_decimal(&decimal_value),
1856
1813
 
1857
1814
my_decimal* Field_new_decimal::val_decimal(my_decimal *decimal_value)
1858
1815
{
1859
 
  ASSERT_COLUMN_MARKED_FOR_READ;
1860
 
  DBUG_ENTER("Field_new_decimal::val_decimal");
1861
1816
  binary2my_decimal(E_DEC_FATAL_ERROR, ptr, decimal_value,
1862
1817
                    precision, dec);
1863
 
  DBUG_EXECUTE("info", print_decimal_buff(decimal_value, (uchar *) ptr,
1864
 
                                          bin_size););
1865
 
  DBUG_RETURN(decimal_value);
 
1818
  return(decimal_value);
1866
1819
}
1867
1820
 
1868
1821
 
1869
1822
String *Field_new_decimal::val_str(String *val_buffer,
1870
1823
                                   String *val_ptr __attribute__((unused)))
1871
1824
{
1872
 
  ASSERT_COLUMN_MARKED_FOR_READ;
1873
1825
  my_decimal decimal_value;
1874
1826
  uint fixed_precision= zerofill ? precision : 0;
1875
1827
  my_decimal2string(E_DEC_FATAL_ERROR, val_decimal(&decimal_value),
2041
1993
 
2042
1994
int Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs)
2043
1995
{
2044
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
2045
1996
  int error;
2046
1997
  longlong rnd;
2047
1998
  
2053
2004
 
2054
2005
int Field_tiny::store(double nr)
2055
2006
{
2056
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
2057
2007
  int error= 0;
2058
2008
  nr=rint(nr);
2059
2009
  if (unsigned_flag)
2096
2046
 
2097
2047
int Field_tiny::store(longlong nr, bool unsigned_val)
2098
2048
{
2099
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
2100
2049
  int error= 0;
2101
2050
 
2102
2051
  if (unsigned_flag)
2141
2090
 
2142
2091
double Field_tiny::val_real(void)
2143
2092
{
2144
 
  ASSERT_COLUMN_MARKED_FOR_READ;
2145
2093
  int tmp= unsigned_flag ? (int) ptr[0] :
2146
2094
    (int) ((signed char*) ptr)[0];
2147
2095
  return (double) tmp;
2150
2098
 
2151
2099
longlong Field_tiny::val_int(void)
2152
2100
{
2153
 
  ASSERT_COLUMN_MARKED_FOR_READ;
2154
2101
  int tmp= unsigned_flag ? (int) ptr[0] :
2155
2102
    (int) ((signed char*) ptr)[0];
2156
2103
  return (longlong) tmp;
2160
2107
String *Field_tiny::val_str(String *val_buffer,
2161
2108
                            String *val_ptr __attribute__((unused)))
2162
2109
{
2163
 
  ASSERT_COLUMN_MARKED_FOR_READ;
2164
2110
  CHARSET_INFO *cs= &my_charset_bin;
2165
2111
  uint length;
2166
2112
  uint mlength=max(field_length+1,5*cs->mbmaxlen);
2216
2162
 
2217
2163
int Field_short::store(const char *from,uint len,CHARSET_INFO *cs)
2218
2164
{
2219
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
2220
2165
  int store_tmp;
2221
2166
  int error;
2222
2167
  longlong rnd;
2237
2182
 
2238
2183
int Field_short::store(double nr)
2239
2184
{
2240
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
2241
2185
  int error= 0;
2242
2186
  int16 res;
2243
2187
  nr=rint(nr);
2289
2233
 
2290
2234
int Field_short::store(longlong nr, bool unsigned_val)
2291
2235
{
2292
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
2293
2236
  int error= 0;
2294
2237
  int16 res;
2295
2238
 
2344
2287
 
2345
2288
double Field_short::val_real(void)
2346
2289
{
2347
 
  ASSERT_COLUMN_MARKED_FOR_READ;
2348
2290
  short j;
2349
2291
#ifdef WORDS_BIGENDIAN
2350
2292
  if (table->s->db_low_byte_first)
2357
2299
 
2358
2300
longlong Field_short::val_int(void)
2359
2301
{
2360
 
  ASSERT_COLUMN_MARKED_FOR_READ;
2361
2302
  short j;
2362
2303
#ifdef WORDS_BIGENDIAN
2363
2304
  if (table->s->db_low_byte_first)
2372
2313
String *Field_short::val_str(String *val_buffer,
2373
2314
                             String *val_ptr __attribute__((unused)))
2374
2315
{
2375
 
  ASSERT_COLUMN_MARKED_FOR_READ;
2376
2316
  CHARSET_INFO *cs= &my_charset_bin;
2377
2317
  uint length;
2378
2318
  uint mlength=max(field_length+1,7*cs->mbmaxlen);
2463
2403
 
2464
2404
int Field_long::store(const char *from,uint len,CHARSET_INFO *cs)
2465
2405
{
2466
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
2467
2406
  long store_tmp;
2468
2407
  int error;
2469
2408
  longlong rnd;
2484
2423
 
2485
2424
int Field_long::store(double nr)
2486
2425
{
2487
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
2488
2426
  int error= 0;
2489
2427
  int32 res;
2490
2428
  nr=rint(nr);
2536
2474
 
2537
2475
int Field_long::store(longlong nr, bool unsigned_val)
2538
2476
{
2539
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
2540
2477
  int error= 0;
2541
2478
  int32 res;
2542
2479
 
2589
2526
 
2590
2527
double Field_long::val_real(void)
2591
2528
{
2592
 
  ASSERT_COLUMN_MARKED_FOR_READ;
2593
2529
  int32 j;
2594
2530
#ifdef WORDS_BIGENDIAN
2595
2531
  if (table->s->db_low_byte_first)
2602
2538
 
2603
2539
longlong Field_long::val_int(void)
2604
2540
{
2605
 
  ASSERT_COLUMN_MARKED_FOR_READ;
2606
2541
  int32 j;
2607
2542
  /* See the comment in Field_long::store(long long) */
2608
 
  DBUG_ASSERT(table->in_use == current_thd);
 
2543
  assert(table->in_use == current_thd);
2609
2544
#ifdef WORDS_BIGENDIAN
2610
2545
  if (table->s->db_low_byte_first)
2611
2546
    j=sint4korr(ptr);
2618
2553
String *Field_long::val_str(String *val_buffer,
2619
2554
                            String *val_ptr __attribute__((unused)))
2620
2555
{
2621
 
  ASSERT_COLUMN_MARKED_FOR_READ;
2622
2556
  CHARSET_INFO *cs= &my_charset_bin;
2623
2557
  uint length;
2624
2558
  uint mlength=max(field_length+1,12*cs->mbmaxlen);
2645
2579
 
2646
2580
bool Field_long::send_binary(Protocol *protocol)
2647
2581
{
2648
 
  ASSERT_COLUMN_MARKED_FOR_READ;
2649
2582
  return protocol->store_long(Field_long::val_int());
2650
2583
}
2651
2584
 
2710
2643
 
2711
2644
int Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs)
2712
2645
{
2713
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
2714
2646
  int error= 0;
2715
2647
  char *end;
2716
2648
  uint64_t tmp;
2740
2672
 
2741
2673
int Field_longlong::store(double nr)
2742
2674
{
2743
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
2744
2675
  int error= 0;
2745
2676
  longlong res;
2746
2677
 
2792
2723
 
2793
2724
int Field_longlong::store(longlong nr, bool unsigned_val)
2794
2725
{
2795
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
2796
2726
  int error= 0;
2797
2727
 
2798
2728
  if (nr < 0)                                   // Only possible error
2823
2753
 
2824
2754
double Field_longlong::val_real(void)
2825
2755
{
2826
 
  ASSERT_COLUMN_MARKED_FOR_READ;
2827
2756
  longlong j;
2828
2757
#ifdef WORDS_BIGENDIAN
2829
2758
  if (table->s->db_low_byte_first)
2845
2774
 
2846
2775
longlong Field_longlong::val_int(void)
2847
2776
{
2848
 
  ASSERT_COLUMN_MARKED_FOR_READ;
2849
2777
  longlong j;
2850
2778
#ifdef WORDS_BIGENDIAN
2851
2779
  if (table->s->db_low_byte_first)
2884
2812
 
2885
2813
bool Field_longlong::send_binary(Protocol *protocol)
2886
2814
{
2887
 
  ASSERT_COLUMN_MARKED_FOR_READ;
2888
2815
  return protocol->store_longlong(Field_longlong::val_int(), unsigned_flag);
2889
2816
}
2890
2817
 
2962
2889
Field_real::pack(uchar *to, const uchar *from,
2963
2890
                 uint max_length, bool low_byte_first)
2964
2891
{
2965
 
  DBUG_ENTER("Field_real::pack");
2966
 
  DBUG_ASSERT(max_length >= pack_length());
2967
 
  DBUG_PRINT("debug", ("pack_length(): %u", pack_length()));
 
2892
  assert(max_length >= pack_length());
2968
2893
#ifdef WORDS_BIGENDIAN
2969
2894
  if (low_byte_first != table->s->db_low_byte_first)
2970
2895
  {
2971
2896
    const uchar *dptr= from + pack_length();
2972
2897
    while (dptr-- > from)
2973
2898
      *to++ = *dptr;
2974
 
    DBUG_RETURN(to);
 
2899
    return(to);
2975
2900
  }
2976
2901
  else
2977
2902
#endif
2978
 
    DBUG_RETURN(Field::pack(to, from, max_length, low_byte_first));
 
2903
    return(Field::pack(to, from, max_length, low_byte_first));
2979
2904
}
2980
2905
 
2981
2906
const uchar *
2982
2907
Field_real::unpack(uchar *to, const uchar *from,
2983
2908
                   uint param_data, bool low_byte_first)
2984
2909
{
2985
 
  DBUG_ENTER("Field_real::unpack");
2986
 
  DBUG_PRINT("debug", ("pack_length(): %u", pack_length()));
2987
2910
#ifdef WORDS_BIGENDIAN
2988
2911
  if (low_byte_first != table->s->db_low_byte_first)
2989
2912
  {
2990
2913
    const uchar *dptr= from + pack_length();
2991
2914
    while (dptr-- > from)
2992
2915
      *to++ = *dptr;
2993
 
    DBUG_RETURN(from + pack_length());
 
2916
    return(from + pack_length());
2994
2917
  }
2995
2918
  else
2996
2919
#endif
2997
 
    DBUG_RETURN(Field::unpack(to, from, param_data, low_byte_first));
 
2920
    return(Field::unpack(to, from, param_data, low_byte_first));
2998
2921
}
2999
2922
 
3000
2923
/****************************************************************************
3019
2942
 
3020
2943
int Field_float::store(double nr)
3021
2944
{
3022
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
3023
2945
  int error= truncate(&nr, FLT_MAX);
3024
2946
  float j= (float)nr;
3025
2947
 
3044
2966
 
3045
2967
double Field_float::val_real(void)
3046
2968
{
3047
 
  ASSERT_COLUMN_MARKED_FOR_READ;
3048
2969
  float j;
3049
2970
#ifdef WORDS_BIGENDIAN
3050
2971
  if (table->s->db_low_byte_first)
3075
2996
String *Field_float::val_str(String *val_buffer,
3076
2997
                             String *val_ptr __attribute__((unused)))
3077
2998
{
3078
 
  ASSERT_COLUMN_MARKED_FOR_READ;
3079
2999
  float nr;
3080
3000
#ifdef WORDS_BIGENDIAN
3081
3001
  if (table->s->db_low_byte_first)
3174
3094
 
3175
3095
bool Field_float::send_binary(Protocol *protocol)
3176
3096
{
3177
 
  ASSERT_COLUMN_MARKED_FOR_READ;
3178
3097
  return protocol->store((float) Field_float::val_real(), dec, (String*) 0);
3179
3098
}
3180
3099
 
3233
3152
 
3234
3153
int Field_double::store(double nr)
3235
3154
{
3236
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
3237
3155
  int error= truncate(&nr, DBL_MAX);
3238
3156
 
3239
3157
#ifdef WORDS_BIGENDIAN
3325
3243
 
3326
3244
double Field_double::val_real(void)
3327
3245
{
3328
 
  ASSERT_COLUMN_MARKED_FOR_READ;
3329
3246
  double j;
3330
3247
#ifdef WORDS_BIGENDIAN
3331
3248
  if (table->s->db_low_byte_first)
3340
3257
 
3341
3258
longlong Field_double::val_int(void)
3342
3259
{
3343
 
  ASSERT_COLUMN_MARKED_FOR_READ;
3344
3260
  double j;
3345
3261
  longlong res;
3346
3262
#ifdef WORDS_BIGENDIAN
3380
3296
 
3381
3297
my_decimal *Field_real::val_decimal(my_decimal *decimal_value)
3382
3298
{
3383
 
  ASSERT_COLUMN_MARKED_FOR_READ;
3384
3299
  double2my_decimal(E_DEC_FATAL_ERROR, val_real(), decimal_value);
3385
3300
  return decimal_value;
3386
3301
}
3389
3304
String *Field_double::val_str(String *val_buffer,
3390
3305
                              String *val_ptr __attribute__((unused)))
3391
3306
{
3392
 
  ASSERT_COLUMN_MARKED_FOR_READ;
3393
3307
  double nr;
3394
3308
#ifdef WORDS_BIGENDIAN
3395
3309
  if (table->s->db_low_byte_first)
3424
3338
 
3425
3339
int Field_double::cmp(const uchar *a_ptr, const uchar *b_ptr)
3426
3340
{
3427
 
  ASSERT_COLUMN_MARKED_FOR_READ;
3428
3341
  double a,b;
3429
3342
#ifdef WORDS_BIGENDIAN
3430
3343
  if (table->s->db_low_byte_first)
3595
3508
      function should be called only for first of them (i.e. the one
3596
3509
      having auto-set property).
3597
3510
    */
3598
 
    DBUG_ASSERT(table->timestamp_field == this);
 
3511
    assert(table->timestamp_field == this);
3599
3512
    /* Fall-through */
3600
3513
  case TIMESTAMP_DNUN_FIELD:
3601
3514
    return TIMESTAMP_AUTO_SET_ON_BOTH;
3604
3517
      Normally this function should not be called for TIMESTAMPs without
3605
3518
      auto-set property.
3606
3519
    */
3607
 
    DBUG_ASSERT(0);
 
3520
    assert(0);
3608
3521
    return TIMESTAMP_NO_AUTO_SET;
3609
3522
  }
3610
3523
}
3614
3527
                           uint len,
3615
3528
                           CHARSET_INFO *cs __attribute__((__unused__)))
3616
3529
{
3617
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
3618
3530
  MYSQL_TIME l_time;
3619
3531
  my_time_t tmp= 0;
3620
3532
  int error;
3667
3579
    nr= 0;                                      // Avoid overflow on buff
3668
3580
    error= 1;
3669
3581
  }
3670
 
  error|= Field_timestamp::store((longlong) rint(nr), FALSE);
 
3582
  error|= Field_timestamp::store((longlong) rint(nr), false);
3671
3583
  return error;
3672
3584
}
3673
3585
 
3675
3587
int Field_timestamp::store(longlong nr,
3676
3588
                           bool unsigned_val __attribute__((__unused__)))
3677
3589
{
3678
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
3679
3590
  MYSQL_TIME l_time;
3680
3591
  my_time_t timestamp= 0;
3681
3592
  int error;
3718
3629
 
3719
3630
double Field_timestamp::val_real(void)
3720
3631
{
3721
 
  ASSERT_COLUMN_MARKED_FOR_READ;
3722
3632
  return (double) Field_timestamp::val_int();
3723
3633
}
3724
3634
 
3725
3635
longlong Field_timestamp::val_int(void)
3726
3636
{
3727
 
  ASSERT_COLUMN_MARKED_FOR_READ;
3728
3637
  uint32 temp;
3729
3638
  MYSQL_TIME time_tmp;
3730
3639
  THD  *thd= table ? table->in_use : current_thd;
3750
3659
 
3751
3660
String *Field_timestamp::val_str(String *val_buffer, String *val_ptr)
3752
3661
{
3753
 
  ASSERT_COLUMN_MARKED_FOR_READ;
3754
3662
  uint32 temp, temp2;
3755
3663
  MYSQL_TIME time_tmp;
3756
3664
  THD *thd= table ? table->in_use : current_thd;
3971
3879
            (ltime->minute * 100 + ltime->second);
3972
3880
  if (ltime->neg)
3973
3881
    tmp= -tmp;
3974
 
  return Field_time::store((longlong) tmp, FALSE);
 
3882
  return Field_time::store((longlong) tmp, false);
3975
3883
}
3976
3884
 
3977
3885
 
3978
3886
int Field_time::store(double nr)
3979
3887
{
3980
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
3981
3888
  long tmp;
3982
3889
  int error= 0;
3983
3890
  if (nr > (double)TIME_MAX_VALUE)
4015
3922
 
4016
3923
int Field_time::store(longlong nr, bool unsigned_val)
4017
3924
{
4018
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
4019
3925
  long tmp;
4020
3926
  int error= 0;
4021
3927
  if (nr < (longlong) -TIME_MAX_VALUE && !unsigned_val)
4053
3959
 
4054
3960
double Field_time::val_real(void)
4055
3961
{
4056
 
  ASSERT_COLUMN_MARKED_FOR_READ;
4057
3962
  uint32 j= (uint32) uint3korr(ptr);
4058
3963
  return (double) j;
4059
3964
}
4060
3965
 
4061
3966
longlong Field_time::val_int(void)
4062
3967
{
4063
 
  ASSERT_COLUMN_MARKED_FOR_READ;
4064
3968
  return (longlong) sint3korr(ptr);
4065
3969
}
4066
3970
 
4074
3978
String *Field_time::val_str(String *val_buffer,
4075
3979
                            String *val_ptr __attribute__((unused)))
4076
3980
{
4077
 
  ASSERT_COLUMN_MARKED_FOR_READ;
4078
3981
  MYSQL_TIME ltime;
4079
3982
  val_buffer->alloc(MAX_DATE_STRING_REP_LENGTH);
4080
3983
  long tmp=(long) sint3korr(ptr);
4186
4089
 
4187
4090
int Field_year::store(const char *from, uint len,CHARSET_INFO *cs)
4188
4091
{
4189
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
4190
4092
  char *end;
4191
4093
  int error;
4192
4094
  longlong nr= cs->cset->strntoull10rnd(cs, from, len, 0, &end, &error);
4225
4127
{
4226
4128
  if (nr < 0.0 || nr >= 2155.0)
4227
4129
  {
4228
 
    (void) Field_year::store((longlong) -1, FALSE);
 
4130
    (void) Field_year::store((longlong) -1, false);
4229
4131
    return 1;
4230
4132
  }
4231
 
  return Field_year::store((longlong) nr, FALSE);
 
4133
  return Field_year::store((longlong) nr, false);
4232
4134
}
4233
4135
 
4234
4136
 
4235
4137
int Field_year::store(longlong nr,
4236
4138
                      bool unsigned_val __attribute__((__unused__)))
4237
4139
{
4238
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
4239
4140
  if (nr < 0 || (nr >= 100 && nr <= 1900) || nr > 2155)
4240
4141
  {
4241
4142
    *ptr= 0;
4256
4157
 
4257
4158
bool Field_year::send_binary(Protocol *protocol)
4258
4159
{
4259
 
  ASSERT_COLUMN_MARKED_FOR_READ;
4260
4160
  uint64_t tmp= Field_year::val_int();
4261
4161
  return protocol->store_short(tmp);
4262
4162
}
4270
4170
 
4271
4171
longlong Field_year::val_int(void)
4272
4172
{
4273
 
  ASSERT_COLUMN_MARKED_FOR_READ;
4274
4173
  int tmp= (int) ptr[0];
4275
4174
  if (field_length != 4)
4276
4175
    tmp%=100;                                   // Return last 2 char
4328
4227
                         uint len,
4329
4228
                         CHARSET_INFO *cs __attribute__((__unused__)))
4330
4229
{
4331
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
4332
4230
  long tmp;
4333
4231
  MYSQL_TIME l_time;
4334
4232
  int error;
4372
4270
                         WARN_DATA_TRUNCATED, nr, MYSQL_TIMESTAMP_DATE);
4373
4271
    return 1;
4374
4272
  }
4375
 
  return Field_newdate::store((longlong) rint(nr), FALSE);
 
4273
  return Field_newdate::store((longlong) rint(nr), false);
4376
4274
}
4377
4275
 
4378
4276
 
4379
4277
int Field_newdate::store(longlong nr,
4380
4278
                         bool unsigned_val __attribute__((__unused__)))
4381
4279
{
4382
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
4383
4280
  MYSQL_TIME l_time;
4384
4281
  longlong tmp;
4385
4282
  int error;
4415
4312
 
4416
4313
int Field_newdate::store_time(MYSQL_TIME *ltime,timestamp_type time_type)
4417
4314
{
4418
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
4419
4315
  long tmp;
4420
4316
  int error= 0;
4421
4317
  if (time_type == MYSQL_TIMESTAMP_DATE ||
4467
4363
 
4468
4364
double Field_newdate::val_real(void)
4469
4365
{
4470
 
  ASSERT_COLUMN_MARKED_FOR_READ;
4471
4366
  return (double) Field_newdate::val_int();
4472
4367
}
4473
4368
 
4474
4369
 
4475
4370
longlong Field_newdate::val_int(void)
4476
4371
{
4477
 
  ASSERT_COLUMN_MARKED_FOR_READ;
4478
4372
  ulong j= uint3korr(ptr);
4479
4373
  j= (j % 32L)+(j / 32L % 16L)*100L + (j/(16L*32L))*10000L;
4480
4374
  return (longlong) j;
4484
4378
String *Field_newdate::val_str(String *val_buffer,
4485
4379
                               String *val_ptr __attribute__((unused)))
4486
4380
{
4487
 
  ASSERT_COLUMN_MARKED_FOR_READ;
4488
4381
  val_buffer->alloc(field_length);
4489
4382
  val_buffer->length(field_length);
4490
4383
  uint32 tmp=(uint32) uint3korr(ptr);
4563
4456
                          uint len,
4564
4457
                          CHARSET_INFO *cs __attribute__((__unused__)))
4565
4458
{
4566
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
4567
4459
  MYSQL_TIME time_tmp;
4568
4460
  int error;
4569
4461
  uint64_t tmp= 0;
4609
4501
    nr= 0.0;
4610
4502
    error= 1;
4611
4503
  }
4612
 
  error|= Field_datetime::store((longlong) rint(nr), FALSE);
 
4504
  error|= Field_datetime::store((longlong) rint(nr), false);
4613
4505
  return error;
4614
4506
}
4615
4507
 
4617
4509
int Field_datetime::store(longlong nr,
4618
4510
                          bool unsigned_val __attribute__((__unused__)))
4619
4511
{
4620
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
4621
4512
  MYSQL_TIME not_used;
4622
4513
  int error;
4623
4514
  longlong initial_nr= nr;
4655
4546
 
4656
4547
int Field_datetime::store_time(MYSQL_TIME *ltime,timestamp_type time_type)
4657
4548
{
4658
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
4659
4549
  longlong tmp;
4660
4550
  int error= 0;
4661
4551
  /*
4712
4602
 
4713
4603
longlong Field_datetime::val_int(void)
4714
4604
{
4715
 
  ASSERT_COLUMN_MARKED_FOR_READ;
4716
4605
  longlong j;
4717
4606
#ifdef WORDS_BIGENDIAN
4718
4607
  if (table && table->s->db_low_byte_first)
4727
4616
String *Field_datetime::val_str(String *val_buffer,
4728
4617
                                String *val_ptr __attribute__((unused)))
4729
4618
{
4730
 
  ASSERT_COLUMN_MARKED_FOR_READ;
4731
4619
  val_buffer->alloc(field_length);
4732
4620
  val_buffer->length(field_length);
4733
4621
  uint64_t tmp;
4877
4765
      "Cannot convert character string: 'xxx' for column 't' at row 1"
4878
4766
 
4879
4767
  RETURN
4880
 
    FALSE - If errors didn't happen
4881
 
    TRUE  - If an error happened
 
4768
    false - If errors didn't happen
 
4769
    true  - If an error happened
4882
4770
*/
4883
4771
 
4884
4772
static bool
4893
4781
  
4894
4782
  if (!(pos= well_formed_error_pos) &&
4895
4783
      !(pos= cannot_convert_error_pos))
4896
 
    return FALSE;
 
4784
    return false;
4897
4785
 
4898
4786
  end_orig= end;
4899
4787
  set_if_smaller(end, pos + 6);
4938
4826
                      ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
4939
4827
                      "string", tmp, field->field_name,
4940
4828
                      (ulong) field->table->in_use->row_count);
4941
 
  return TRUE;
 
4829
  return true;
4942
4830
}
4943
4831
 
4944
4832
 
4984
4872
 
4985
4873
int Field_string::store(const char *from,uint length,CHARSET_INFO *cs)
4986
4874
{
4987
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
4988
4875
  uint copy_length;
4989
4876
  const char *well_formed_error_pos;
4990
4877
  const char *cannot_convert_error_pos;
4991
4878
  const char *from_end_pos;
4992
4879
 
4993
4880
  /* See the comment for Field_long::store(long long) */
4994
 
  DBUG_ASSERT(table->in_use == current_thd);
 
4881
  assert(table->in_use == current_thd);
4995
4882
 
4996
4883
  copy_length= well_formed_copy_nchars(field_charset,
4997
4884
                                       (char*) ptr, field_length,
5025
4912
 
5026
4913
int Field_str::store(double nr)
5027
4914
{
5028
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
5029
4915
  char buff[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
5030
4916
  uint local_char_length= field_length / charset()->mbmaxlen;
5031
4917
  size_t length;
5098
4984
 
5099
4985
double Field_string::val_real(void)
5100
4986
{
5101
 
  ASSERT_COLUMN_MARKED_FOR_READ;
5102
4987
  int error;
5103
4988
  char *end;
5104
4989
  CHARSET_INFO *cs= charset();
5124
5009
 
5125
5010
longlong Field_string::val_int(void)
5126
5011
{
5127
 
  ASSERT_COLUMN_MARKED_FOR_READ;
5128
5012
  int error;
5129
5013
  char *end;
5130
5014
  CHARSET_INFO *cs= charset();
5151
5035
String *Field_string::val_str(String *val_buffer __attribute__((unused)),
5152
5036
                              String *val_ptr)
5153
5037
{
5154
 
  ASSERT_COLUMN_MARKED_FOR_READ;
5155
5038
  /* See the comment for Field_long::store(long long) */
5156
 
  DBUG_ASSERT(table->in_use == current_thd);
 
5039
  assert(table->in_use == current_thd);
5157
5040
  uint length;
5158
5041
  if (table->in_use->variables.sql_mode &
5159
5042
      MODE_PAD_CHAR_TO_FULL_LENGTH)
5168
5051
 
5169
5052
my_decimal *Field_string::val_decimal(my_decimal *decimal_value)
5170
5053
{
5171
 
  ASSERT_COLUMN_MARKED_FOR_READ;
5172
5054
  int err= str2my_decimal(E_DEC_FATAL_ERROR, (char*) ptr, field_length,
5173
5055
                          charset(), decimal_value);
5174
5056
  if (!table->in_use->no_errors && err)
5212
5094
 
5213
5095
void Field_string::sort_string(uchar *to,uint length)
5214
5096
{
5215
 
  IF_DBUG(uint tmp=) my_strnxfrm(field_charset,
 
5097
  uint tmp= my_strnxfrm(field_charset,
5216
5098
                                 to, length,
5217
5099
                                 ptr, field_length);
5218
 
  DBUG_ASSERT(tmp == length);
 
5100
  assert(tmp == length);
5219
5101
}
5220
5102
 
5221
5103
 
5491
5373
int Field_varstring::do_save_field_metadata(uchar *metadata_ptr)
5492
5374
{
5493
5375
  char *ptr= (char *)metadata_ptr;
5494
 
  DBUG_ASSERT(field_length <= 65535);
 
5376
  assert(field_length <= 65535);
5495
5377
  int2store(ptr, field_length);
5496
5378
  return 2;
5497
5379
}
5498
5380
 
5499
5381
int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs)
5500
5382
{
5501
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
5502
5383
  uint copy_length;
5503
5384
  const char *well_formed_error_pos;
5504
5385
  const char *cannot_convert_error_pos;
5542
5423
 
5543
5424
double Field_varstring::val_real(void)
5544
5425
{
5545
 
  ASSERT_COLUMN_MARKED_FOR_READ;
5546
5426
  int not_used;
5547
5427
  char *end_not_used;
5548
5428
  uint length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
5553
5433
 
5554
5434
longlong Field_varstring::val_int(void)
5555
5435
{
5556
 
  ASSERT_COLUMN_MARKED_FOR_READ;
5557
5436
  int not_used;
5558
5437
  char *end_not_used;
5559
5438
  uint length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
5564
5443
String *Field_varstring::val_str(String *val_buffer __attribute__((unused)),
5565
5444
                                 String *val_ptr)
5566
5445
{
5567
 
  ASSERT_COLUMN_MARKED_FOR_READ;
5568
5446
  uint length=  length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
5569
5447
  val_ptr->set((const char*) ptr+length_bytes, length, field_charset);
5570
5448
  return val_ptr;
5573
5451
 
5574
5452
my_decimal *Field_varstring::val_decimal(my_decimal *decimal_value)
5575
5453
{
5576
 
  ASSERT_COLUMN_MARKED_FOR_READ;
5577
5454
  uint length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
5578
5455
  str2my_decimal(E_DEC_FATAL_ERROR, (char*) ptr+length_bytes, length,
5579
5456
                 charset(), decimal_value);
5668
5545
  tot_length= my_strnxfrm(field_charset,
5669
5546
                          to, length, ptr + length_bytes,
5670
5547
                          tot_length);
5671
 
  DBUG_ASSERT(tot_length == length);
 
5548
  assert(tot_length == length);
5672
5549
}
5673
5550
 
5674
5551
 
6171
6048
 
6172
6049
int Field_blob::store(const char *from,uint length,CHARSET_INFO *cs)
6173
6050
{
6174
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
6175
6051
  uint copy_length, new_length;
6176
6052
  const char *well_formed_error_pos;
6177
6053
  const char *cannot_convert_error_pos;
6262
6138
 
6263
6139
double Field_blob::val_real(void)
6264
6140
{
6265
 
  ASSERT_COLUMN_MARKED_FOR_READ;
6266
6141
  int not_used;
6267
6142
  char *end_not_used, *blob;
6268
6143
  uint32 length;
6279
6154
 
6280
6155
longlong Field_blob::val_int(void)
6281
6156
{
6282
 
  ASSERT_COLUMN_MARKED_FOR_READ;
6283
6157
  int not_used;
6284
6158
  char *blob;
6285
6159
  memcpy_fixed(&blob,ptr+packlength,sizeof(char*));
6292
6166
String *Field_blob::val_str(String *val_buffer __attribute__((unused)),
6293
6167
                            String *val_ptr)
6294
6168
{
6295
 
  ASSERT_COLUMN_MARKED_FOR_READ;
6296
6169
  char *blob;
6297
6170
  memcpy_fixed(&blob,ptr+packlength,sizeof(char*));
6298
6171
  if (!blob)
6305
6178
 
6306
6179
my_decimal *Field_blob::val_decimal(my_decimal *decimal_value)
6307
6180
{
6308
 
  ASSERT_COLUMN_MARKED_FOR_READ;
6309
6181
  const char *blob;
6310
6182
  size_t length;
6311
6183
  memcpy_fixed(&blob, ptr+packlength, sizeof(const uchar*));
6486
6358
    
6487
6359
    blob_length=my_strnxfrm(field_charset,
6488
6360
                            to, length, blob, blob_length);
6489
 
    DBUG_ASSERT(blob_length == length);
 
6361
    assert(blob_length == length);
6490
6362
  }
6491
6363
}
6492
6364
 
6513
6385
uchar *Field_blob::pack(uchar *to, const uchar *from,
6514
6386
                        uint max_length, bool low_byte_first)
6515
6387
{
6516
 
  DBUG_ENTER("Field_blob::pack");
6517
 
  DBUG_PRINT("enter", ("to: 0x%lx; from: 0x%lx;"
6518
 
                       " max_length: %u; low_byte_first: %d",
6519
 
                       (ulong) to, (ulong) from,
6520
 
                       max_length, low_byte_first));
6521
 
  DBUG_DUMP("record", from, table->s->reclength);
6522
6388
  uchar *save= ptr;
6523
6389
  ptr= (uchar*) from;
6524
6390
  uint32 length=get_length();                   // Length of from string
6539
6405
    memcpy(to+packlength, from,length);
6540
6406
  }
6541
6407
  ptr=save;                                     // Restore org row pointer
6542
 
  DBUG_DUMP("packed", to, packlength + length);
6543
 
  DBUG_RETURN(to+packlength+length);
 
6408
  return(to+packlength+length);
6544
6409
}
6545
6410
 
6546
6411
 
6555
6420
 
6556
6421
   @param   to         Destination of the data
6557
6422
   @param   from       Source of the data
6558
 
   @param   param_data @c TRUE if base types should be stored in little-
6559
 
                       endian format, @c FALSE if native format should
 
6423
   @param   param_data @c true if base types should be stored in little-
 
6424
                       endian format, @c false if native format should
6560
6425
                       be used.
6561
6426
 
6562
6427
   @return  New pointer into memory based on from + length of the data
6566
6431
                                uint param_data,
6567
6432
                                bool low_byte_first)
6568
6433
{
6569
 
  DBUG_ENTER("Field_blob::unpack");
6570
 
  DBUG_PRINT("enter", ("to: 0x%lx; from: 0x%lx;"
6571
 
                       " param_data: %u; low_byte_first: %d",
6572
 
                       (ulong) to, (ulong) from, param_data, low_byte_first));
6573
6434
  uint const master_packlength=
6574
6435
    param_data > 0 ? param_data & 0xFF : packlength;
6575
6436
  uint32 const length= get_length(from, master_packlength, low_byte_first);
6576
 
  DBUG_DUMP("packed", from, length + master_packlength);
6577
6437
  bitmap_set_bit(table->write_set, field_index);
6578
6438
  store(reinterpret_cast<const char*>(from) + master_packlength,
6579
6439
        length, field_charset);
6580
 
  DBUG_DUMP("record", to, table->s->reclength);
6581
 
  DBUG_RETURN(from + master_packlength + length);
 
6440
  return(from + master_packlength + length);
6582
6441
}
6583
6442
 
6584
6443
/* Keys for blobs are like keys on varchars */
6803
6662
 
6804
6663
int Field_enum::store(const char *from,uint length,CHARSET_INFO *cs)
6805
6664
{
6806
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
6807
6665
  int err= 0;
6808
6666
  uint32 not_used;
6809
6667
  char buff[STRING_BUFFER_USUAL_SIZE];
6846
6704
 
6847
6705
int Field_enum::store(double nr)
6848
6706
{
6849
 
  return Field_enum::store((longlong) nr, FALSE);
 
6707
  return Field_enum::store((longlong) nr, false);
6850
6708
}
6851
6709
 
6852
6710
 
6853
6711
int Field_enum::store(longlong nr,
6854
6712
                      bool unsigned_val __attribute__((__unused__)))
6855
6713
{
6856
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
6857
6714
  int error= 0;
6858
6715
  if ((uint64_t) nr > typelib->count || nr == 0)
6859
6716
  {
6877
6734
 
6878
6735
longlong Field_enum::val_int(void)
6879
6736
{
6880
 
  ASSERT_COLUMN_MARKED_FOR_READ;
6881
6737
  switch (packlength) {
6882
6738
  case 1:
6883
6739
    return (longlong) ptr[0];
7022
6878
 
7023
6879
int Field_set::store(const char *from,uint length,CHARSET_INFO *cs)
7024
6880
{
7025
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
7026
6881
  bool got_warning= 0;
7027
6882
  int err= 0;
7028
6883
  char *not_used;
7063
6918
int Field_set::store(longlong nr,
7064
6919
                     bool unsigned_val __attribute__((__unused__)))
7065
6920
{
7066
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
7067
6921
  int error= 0;
7068
6922
  uint64_t max_nr= set_bits(uint64_t, typelib->count);
7069
6923
  if ((uint64_t) nr > max_nr)
7269
7123
  @param fld_charset           Field charset
7270
7124
 
7271
7125
  @retval
7272
 
    FALSE on success
 
7126
    false on success
7273
7127
  @retval
7274
 
    TRUE  on error
 
7128
    true  on error
7275
7129
*/
7276
7130
 
7277
7131
bool Create_field::init(THD *thd, char *fld_name, enum_field_types fld_type,
7286
7140
  uint sign_len, allowed_type_modifier= 0;
7287
7141
  ulong max_field_charlength= MAX_FIELD_CHARLENGTH;
7288
7142
 
7289
 
  DBUG_ENTER("Create_field::init()");
7290
 
 
7291
7143
  field= 0;
7292
7144
  field_name= fld_name;
7293
7145
  def= fld_default_value;
7300
7152
  {
7301
7153
    my_error(ER_TOO_BIG_SCALE, MYF(0), decimals, fld_name,
7302
7154
             NOT_FIXED_DEC-1);
7303
 
    DBUG_RETURN(TRUE);
 
7155
    return(true);
7304
7156
  }
7305
7157
 
7306
7158
  sql_type= fld_type;
7353
7205
    {
7354
7206
      my_error(ER_TOO_BIG_PRECISION, MYF(0), length, fld_name,
7355
7207
               DECIMAL_MAX_PRECISION);
7356
 
      DBUG_RETURN(TRUE);
 
7208
      return(true);
7357
7209
    }
7358
7210
    if (length < decimals)
7359
7211
    {
7360
7212
      my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
7361
 
      DBUG_RETURN(TRUE);
 
7213
      return(true);
7362
7214
    }
7363
7215
    length=
7364
7216
      my_decimal_precision_to_length(length, decimals,
7391
7243
      {
7392
7244
        my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0),
7393
7245
                 fld_name); /* purecov: inspected */
7394
 
        DBUG_RETURN(TRUE);
 
7246
        return(true);
7395
7247
      }
7396
7248
      else
7397
7249
      {
7421
7273
      if (tmp_length > PRECISION_FOR_DOUBLE)
7422
7274
      {
7423
7275
        my_error(ER_WRONG_FIELD_SPEC, MYF(0), fld_name);
7424
 
        DBUG_RETURN(TRUE);
 
7276
        return(true);
7425
7277
      }
7426
7278
      else if (tmp_length > PRECISION_FOR_FLOAT)
7427
7279
      {
7442
7294
        decimals != NOT_FIXED_DEC)
7443
7295
    {
7444
7296
      my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
7445
 
      DBUG_RETURN(TRUE);
 
7297
      return(true);
7446
7298
    }
7447
7299
    break;
7448
7300
  case MYSQL_TYPE_DOUBLE:
7456
7308
        decimals != NOT_FIXED_DEC)
7457
7309
    {
7458
7310
      my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
7459
 
      DBUG_RETURN(TRUE);
 
7311
      return(true);
7460
7312
    }
7461
7313
    break;
7462
7314
  case MYSQL_TYPE_TIMESTAMP:
7555
7407
      break;
7556
7408
   }
7557
7409
  case MYSQL_TYPE_VAR_STRING:
7558
 
    DBUG_ASSERT(0);  /* Impossible. */
 
7410
    assert(0);  /* Impossible. */
7559
7411
    break;
7560
7412
  }
7561
7413
  /* Remember the value of length */
7575
7427
                                                ER_TOO_BIG_DISPLAYWIDTH,
7576
7428
              MYF(0),
7577
7429
              fld_name, max_field_charlength); /* purecov: inspected */
7578
 
    DBUG_RETURN(TRUE);
 
7430
    return(true);
7579
7431
  }
7580
7432
  fld_type_modifier&= AUTO_INCREMENT_FLAG;
7581
7433
  if ((~allowed_type_modifier) & fld_type_modifier)
7582
7434
  {
7583
7435
    my_error(ER_WRONG_FIELD_SPEC, MYF(0), fld_name);
7584
 
    DBUG_RETURN(TRUE);
 
7436
    return(true);
7585
7437
  }
7586
7438
 
7587
 
  DBUG_RETURN(FALSE); /* success */
 
7439
  return(false); /* success */
7588
7440
}
7589
7441
 
7590
7442
 
7878
7730
  case 4:
7879
7731
    return (uint32) 4294967295U;
7880
7732
  default:
7881
 
    DBUG_ASSERT(0); // we should never go here
 
7733
    assert(0); // we should never go here
7882
7734
    return 0;
7883
7735
  }
7884
7736
}