1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
|
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
*
* Copyright (C) 2008 MySQL
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
@file
@brief
This file implements classes defined in field.h
*/
#include <drizzled/server_includes.h>
#include "sql_select.h"
#include <errno.h>
#include <drizzled/error.h>
#include <drizzled/virtual_column_info.h>
#include <drizzled/field/str.h>
#include <drizzled/field/longstr.h>
#include <drizzled/field/num.h>
#include <drizzled/field/blob.h>
#include <drizzled/field/enum.h>
#include <drizzled/field/null.h>
#include <drizzled/field/date.h>
#include <drizzled/field/decimal.h>
#include <drizzled/field/real.h>
#include <drizzled/field/double.h>
#include <drizzled/field/long.h>
#include <drizzled/field/int64_t.h>
#include <drizzled/field/num.h>
#include <drizzled/field/timestamp.h>
#include <drizzled/field/datetime.h>
#include <drizzled/field/varstring.h>
/*****************************************************************************
Instansiate templates and static variables
*****************************************************************************/
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
template class List<Create_field>;
template class List_iterator<Create_field>;
#endif
static enum_field_types
field_types_merge_rules [DRIZZLE_TYPE_MAX+1][DRIZZLE_TYPE_MAX+1]=
{
/* DRIZZLE_TYPE_TINY -> */
{
//DRIZZLE_TYPE_TINY
DRIZZLE_TYPE_TINY,
//DRIZZLE_TYPE_LONG
DRIZZLE_TYPE_LONG,
//DRIZZLE_TYPE_DOUBLE
DRIZZLE_TYPE_DOUBLE,
//DRIZZLE_TYPE_NULL
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LE
DRIZZLE_TYPE_VARCHAR,
//DRIZZLE_TYPE_NULL
DRIZZLE_TYPE_ENUM,
//DRIZZLE_TYPE_TIMESTAMP
DRIZZLE_TYPE_VARCHAR,
//DRIZZLE_TYPE_LONGLONG
DRIZZLE_TYPE_VARCHAR,
//DRIZZLE_TYPE_DATETIME
DRIZZLE_TYPE_VARCHAR,
//DRIZZLE_TYPE_DATE
DRIZZLE_TYPE_VARCHAR,
//DRIZZLE_TYPE_VARCHAR
DRIZZLE_TYPE_VARCHAR,
//DRIZZLE_TYPE_VIRTUAL
DRIZZLE_TYPE_VIRTUAL,
//DRIZZLE_TYPE_NEWDECIMAL
DRIZZLE_TYPE_VARCHAR,
//DRIZZLE_TYPE_ENUM
DRIZZLE_TYPE_VARCHAR,
//DRIZZLE_TYPE_BLOB
DRIZZLE_TYPE_BLOB,
},
/* DRIZZLE_TYPE_BLOB -> */
{
//DRIZZLE_TYPE_TINY
DRIZZLE_TYPE_BLOB,
//DRIZZLE_TYPE_LONG
DRIZZLE_TYPE_BLOB,
//DRIZZLE_TYPE_DOUBLE
DRIZZLE_TYPE_BLOB,
//DRIZZLE_TYPE_NULL
DRIZZLE_TYPE_BLOB,
//DRIZZLE_TYPE_TIMESTAMP
DRIZZLE_TYPE_BLOB,
//DRIZZLE_TYPE_LONGLONG
DRIZZLE_TYPE_BLOB,
//DRIZZLE_TYPE_DATETIME
DRIZZLE_TYPE_BLOB,
//DRIZZLE_TYPE_DATE
DRIZZLE_TYPE_BLOB,
//DRIZZLE_TYPE_VARCHAR
DRIZZLE_TYPE_BLOB,
//DRIZZLE_TYPE_VIRTUAL
DRIZZLE_TYPE_VIRTUAL,
//DRIZZLE_TYPE_NEWDECIMAL
DRIZZLE_TYPE_BLOB,
//DRIZZLE_TYPE_ENUM
DRIZZLE_TYPE_BLOB,
//DRIZZLE_TYPE_BLOB
DRIZZLE_TYPE_BLOB,
},
};
/**
Return type of which can carry value of both given types in UNION result.
@param a type for merging
@param b type for merging
@return
type of field
*/
enum_field_types Field::field_type_merge(enum_field_types a,
enum_field_types b)
{
assert(a <= DRIZZLE_TYPE_MAX);
assert(b <= DRIZZLE_TYPE_MAX);
return field_types_merge_rules[a][b];
}
static Item_result field_types_result_type [DRIZZLE_TYPE_MAX+1]=
{
//DRIZZLE_TYPE_TINY
INT_RESULT,
//DRIZZLE_TYPE_LONG
INT_RESULT,
//DRIZZLE_TYPE_DOUBLE
REAL_RESULT,
//DRIZZLE_TYPE_NULL
STRING_RESULT,
//DRIZZLE_TYPE_TIMESTAMP
STRING_RESULT,
//DRIZZLE_TYPE_LONGLONG
INT_RESULT,
//DRIZZLE_TYPE_DATETIME
STRING_RESULT,
//DRIZZLE_TYPE_DATE
STRING_RESULT,
//DRIZZLE_TYPE_VARCHAR
STRING_RESULT,
//DRIZZLE_TYPE_VIRTUAL
STRING_RESULT,
//DRIZZLE_TYPE_NEWDECIMAL
DECIMAL_RESULT,
//DRIZZLE_TYPE_ENUM
STRING_RESULT,
//DRIZZLE_TYPE_BLOB
STRING_RESULT,
};
/*
Test if the given string contains important data:
not spaces for character string,
or any data for binary string.
SYNOPSIS
test_if_important_data()
cs Character set
str String to test
strend String end
RETURN
false - If string does not have important data
true - If string has some important data
*/
bool
test_if_important_data(const CHARSET_INFO * const cs, const char *str,
const char *strend)
{
if (cs != &my_charset_bin)
str+= cs->cset->scan(cs, str, strend, MY_SEQ_SPACES);
return (str < strend);
}
Item_result Field::result_merge_type(enum_field_types field_type)
{
assert(field_type <= DRIZZLE_TYPE_MAX);
return field_types_result_type[field_type];
}
bool Field::eq(Field *field)
{
return (ptr == field->ptr && null_ptr == field->null_ptr &&
null_bit == field->null_bit);
}
uint32_t Field::pack_length() const
{
return field_length;
}
uint32_t Field::pack_length_in_rec() const
{
return pack_length();
}
uint32_t Field::pack_length_from_metadata(uint32_t field_metadata)
{
return field_metadata;
}
uint32_t Field::row_pack_length()
{
return 0;
}
int Field::save_field_metadata(unsigned char *first_byte)
{
return do_save_field_metadata(first_byte);
}
uint32_t Field::data_length()
{
return pack_length();
}
uint32_t Field::used_length()
{
return pack_length();
}
uint32_t Field::sort_length() const
{
return pack_length();
}
uint32_t Field::max_data_length() const
{
return pack_length();
}
int Field::reset(void)
{
memset(ptr, 0, pack_length());
return 0;
}
void Field::reset_fields()
{}
void Field::set_default()
{
my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->getDefaultValues() - table->record[0]);
memcpy(ptr, ptr + l_offset, pack_length());
if (null_ptr)
*null_ptr= ((*null_ptr & (unsigned char) ~null_bit) | (null_ptr[l_offset] & null_bit));
}
bool Field::binary() const
{
return 1;
}
bool Field::zero_pack() const
{
return 1;
}
enum ha_base_keytype Field::key_type() const
{
return HA_KEYTYPE_BINARY;
}
uint32_t Field::key_length() const
{
return pack_length();
}
enum_field_types Field::real_type() const
{
return type();
}
int Field::cmp_max(const unsigned char *a, const unsigned char *b, uint32_t)
{
return cmp(a, b);
}
int Field::cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t)
{
return memcmp(a,b,pack_length());
}
int Field::cmp_offset(uint32_t row_offset)
{
return cmp(ptr,ptr+row_offset);
}
int Field::cmp_binary_offset(uint32_t row_offset)
{
return cmp_binary(ptr, ptr+row_offset);
}
int Field::key_cmp(const unsigned char *a,const unsigned char *b)
{
return cmp(a, b);
}
int Field::key_cmp(const unsigned char *str, uint32_t)
{
return cmp(ptr,str);
}
uint32_t Field::decimals() const
{
return 0;
}
bool Field::is_null(my_ptrdiff_t row_offset)
{
return null_ptr ?
(null_ptr[row_offset] & null_bit ? true : false) :
table->null_row;
}
bool Field::is_real_null(my_ptrdiff_t row_offset)
{
return null_ptr ? (null_ptr[row_offset] & null_bit ? true : false) : false;
}
bool Field::is_null_in_record(const unsigned char *record)
{
if (!null_ptr)
return false;
return test(record[(uint32_t) (null_ptr -table->record[0])] &
null_bit);
}
bool Field::is_null_in_record_with_offset(my_ptrdiff_t with_offset)
{
if (!null_ptr)
return false;
return test(null_ptr[with_offset] & null_bit);
}
void Field::set_null(my_ptrdiff_t row_offset)
{
if (null_ptr)
null_ptr[row_offset]|= null_bit;
}
void Field::set_notnull(my_ptrdiff_t row_offset)
{
if (null_ptr)
null_ptr[row_offset]&= (unsigned char) ~null_bit;
}
bool Field::maybe_null(void)
{
return null_ptr != 0 || table->maybe_null;
}
bool Field::real_maybe_null(void)
{
return null_ptr != 0;
}
size_t Field::last_null_byte() const
{
size_t bytes= do_last_null_byte();
assert(bytes <= table->getNullBytes());
return bytes;
}
/*****************************************************************************
Static help functions
*****************************************************************************/
bool Field::type_can_have_key_part(enum enum_field_types type)
{
switch (type) {
case DRIZZLE_TYPE_VARCHAR:
case DRIZZLE_TYPE_BLOB:
return true;
default:
return false;
}
}
/**
Process decimal library return codes and issue warnings for overflow and
truncation.
@param op_result decimal library return code (E_DEC_* see include/decimal.h)
@retval
E_DEC_OVERFLOW there was overflow
E_DEC_TRUNCATED there was truncation
@retval
0 no error or there was some other error except overflow or truncation
*/
int Field::warn_if_overflow(int op_result)
{
if (op_result == E_DEC_OVERFLOW)
{
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
return E_DEC_OVERFLOW;
}
if (op_result == E_DEC_TRUNCATED)
{
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
return E_DEC_TRUNCATED;
}
return 0;
}
void Field::init(Table *table_arg)
{
orig_table= table= table_arg;
table_name= &table_arg->alias;
}
#ifdef NOT_USED
static bool test_if_real(const char *str,int length, const CHARSET_INFO * const cs)
{
cs= system_charset_info; // QQ move test_if_real into CHARSET_INFO struct
while (length && my_isspace(cs,*str))
{ // Allow start space
length--; str++;
}
if (!length)
return 0;
if (*str == '+' || *str == '-')
{
length--; str++;
if (!length || !(my_isdigit(cs,*str) || *str == '.'))
return 0;
}
while (length && my_isdigit(cs,*str))
{
length--; str++;
}
if (!length)
return 1;
if (*str == '.')
{
length--; str++;
while (length && my_isdigit(cs,*str))
{
length--; str++;
}
}
if (!length)
return 1;
if (*str == 'E' || *str == 'e')
{
if (length < 3 || (str[1] != '+' && str[1] != '-') ||
!my_isdigit(cs,str[2]))
return 0;
length-=3;
str+=3;
while (length && my_isdigit(cs,*str))
{
length--; str++;
}
}
for (; length ; length--, str++)
{ // Allow end space
if (!my_isspace(cs,*str))
return 0;
}
return 1;
}
#endif
/**
Interpret field value as an integer but return the result as a string.
This is used for printing bit_fields as numbers while debugging.
*/
String *Field::val_int_as_str(String *val_buffer, bool unsigned_val)
{
const CHARSET_INFO * const cs= &my_charset_bin;
uint32_t length;
int64_t value= val_int();
if (val_buffer->alloc(MY_INT64_NUM_DECIMAL_DIGITS))
return 0;
length= (uint32_t) (*cs->cset->int64_t10_to_str)(cs, (char*) val_buffer->ptr(),
MY_INT64_NUM_DECIMAL_DIGITS,
unsigned_val ? 10 : -10,
value);
val_buffer->length(length);
return val_buffer;
}
/// This is used as a table name when the table structure is not set up
Field::Field(unsigned char *ptr_arg,uint32_t length_arg,unsigned char *null_ptr_arg,
unsigned char null_bit_arg,
utype unireg_check_arg, const char *field_name_arg)
:ptr(ptr_arg), null_ptr(null_ptr_arg),
table(0), orig_table(0), table_name(0),
field_name(field_name_arg),
key_start(0), part_of_key(0), part_of_key_not_clustered(0),
part_of_sortkey(0), unireg_check(unireg_check_arg),
field_length(length_arg), null_bit(null_bit_arg),
is_created_from_null_item(false),
vcol_info(NULL), is_stored(true)
{
flags=null_ptr ? 0: NOT_NULL_FLAG;
comment.str= (char*) "";
comment.length=0;
field_index= 0;
}
void Field::hash(uint32_t *nr, uint32_t *nr2)
{
if (is_null())
{
*nr^= (*nr << 1) | 1;
}
else
{
uint32_t len= pack_length();
const CHARSET_INFO * const cs= charset();
cs->coll->hash_sort(cs, ptr, len, nr, nr2);
}
}
size_t
Field::do_last_null_byte() const
{
assert(null_ptr == NULL || null_ptr >= table->record[0]);
if (null_ptr)
return (size_t) (null_ptr - table->record[0]) + 1;
return LAST_NULL_BYTE_UNDEF;
}
void Field::copy_from_tmp(int row_offset)
{
memcpy(ptr,ptr+row_offset,pack_length());
if (null_ptr)
{
*null_ptr= (unsigned char) ((null_ptr[0] &
(unsigned char) ~(uint32_t) null_bit) |
(null_ptr[row_offset] &
(unsigned char) null_bit));
}
}
/**
Check to see if field size is compatible with destination.
This method is used in row-based replication to verify that the slave's
field size is less than or equal to the master's field size. The
encoded field metadata (from the master or source) is decoded and compared
to the size of this field (the slave or destination).
@param field_metadata Encoded size in field metadata
@retval 0 if this field's size is < the source field's size
@retval 1 if this field's size is >= the source field's size
*/
int Field::compatible_field_size(uint32_t field_metadata)
{
uint32_t const source_size= pack_length_from_metadata(field_metadata);
uint32_t const destination_size= row_pack_length();
return (source_size <= destination_size);
}
int Field::store(const char *to, uint32_t length,
const CHARSET_INFO * const cs,
enum_check_fields check_level)
{
int res;
enum_check_fields old_check_level= table->in_use->count_cuted_fields;
table->in_use->count_cuted_fields= check_level;
res= store(to, length, cs);
table->in_use->count_cuted_fields= old_check_level;
return res;
}
/**
Pack the field into a format suitable for storage and transfer.
To implement packing functionality, only the virtual function
should be overridden. The other functions are just convenience
functions and hence should not be overridden.
The value of <code>low_byte_first</code> is dependent on how the
packed data is going to be used: for local use, e.g., temporary
store on disk or in memory, use the native format since that is
faster. For data that is going to be transfered to other machines
(e.g., when writing data to the binary log), data should always be
stored in little-endian format.
@note The default method for packing fields just copy the raw bytes
of the record into the destination, but never more than
<code>max_length</code> characters.
@param to
Pointer to memory area where representation of field should be put.
@param from
Pointer to memory area where record representation of field is
stored.
@param max_length
Maximum length of the field, as given in the column definition. For
example, for <code>CHAR(1000)</code>, the <code>max_length</code>
is 1000. This information is sometimes needed to decide how to pack
the data.
@param low_byte_first
@c true if integers should be stored little-endian, @c false if
native format should be used. Note that for little-endian machines,
the value of this flag is a moot point since the native format is
little-endian.
*/
unsigned char *
Field::pack(unsigned char *to, const unsigned char *from, uint32_t max_length,
bool)
{
uint32_t length= pack_length();
set_if_smaller(length, max_length);
memcpy(to, from, length);
return to+length;
}
unsigned char *Field::pack(unsigned char *to, const unsigned char *from)
{
unsigned char *result= this->pack(to, from, UINT32_MAX,
table->s->db_low_byte_first);
return(result);
}
/**
Unpack a field from row data.
This method is used to unpack a field from a master whose size of
the field is less than that of the slave.
The <code>param_data</code> parameter is a two-byte integer (stored
in the least significant 16 bits of the unsigned integer) usually
consisting of two parts: the real type in the most significant byte
and a original pack length in the least significant byte.
The exact layout of the <code>param_data</code> field is given by
the <code>Table_map_log_event::save_field_metadata()</code>.
This is the default method for unpacking a field. It just copies
the memory block in byte order (of original pack length bytes or
length of field, whichever is smaller).
@param to Destination of the data
@param from Source of the data
@param param_data Real type and original pack length of the field
data
@param low_byte_first
If this flag is @c true, all composite entities (e.g., lengths)
should be unpacked in little-endian format; otherwise, the entities
are unpacked in native order.
@return New pointer into memory based on from + length of the data
*/
const unsigned char *
Field::unpack(unsigned char* to, const unsigned char *from, uint32_t param_data,
bool)
{
uint32_t length=pack_length();
int from_type= 0;
/*
If from length is > 255, it has encoded data in the upper bits. Need
to mask it out.
*/
if (param_data > 255)
{
from_type= (param_data & 0xff00) >> 8U; // real_type.
param_data= param_data & 0x00ff; // length.
}
if ((param_data == 0) ||
(length == param_data) ||
(from_type != real_type()))
{
memcpy(to, from, length);
return from+length;
}
uint32_t len= (param_data && (param_data < length)) ?
param_data : length;
memcpy(to, from, param_data > length ? length : len);
return from+len;
}
const unsigned char *Field::unpack(unsigned char* to,
const unsigned char *from)
{
const unsigned char *result= unpack(to, from, 0U,
table->s->db_low_byte_first);
return(result);
}
uint32_t Field::packed_col_length(const unsigned char *, uint32_t length)
{
return length;
}
int Field::pack_cmp(const unsigned char *a, const unsigned char *b,
uint32_t, bool)
{
return cmp(a,b);
}
int Field::pack_cmp(const unsigned char *b, uint32_t, bool)
{
return cmp(ptr,b);
}
my_decimal *Field::val_decimal(my_decimal *)
{
/* This never have to be called */
assert(0);
return 0;
}
void Field::make_field(Send_field *field)
{
if (orig_table && orig_table->s->db.str && *orig_table->s->db.str)
{
field->db_name= orig_table->s->db.str;
field->org_table_name= orig_table->s->table_name.str;
}
else
field->org_table_name= field->db_name= "";
if (orig_table)
{
field->table_name= orig_table->alias;
field->org_col_name= field_name;
}
else
{
field->table_name= "";
field->org_col_name= "";
}
field->col_name= field_name;
field->charsetnr= charset()->number;
field->length=field_length;
field->type=type();
field->flags=table->maybe_null ? (flags & ~NOT_NULL_FLAG) : flags;
field->decimals= 0;
}
/**
Conversion from decimal to int64_t with checking overflow and
setting correct value (min/max) in case of overflow.
@param val value which have to be converted
@param unsigned_flag type of integer in which we convert val
@param err variable to pass error code
@return
value converted from val
*/
int64_t Field::convert_decimal2int64_t(const my_decimal *val, bool, int *err)
{
int64_t i;
if (warn_if_overflow(my_decimal2int(E_DEC_ERROR &
~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED,
val, false, &i)))
{
i= (val->sign() ? INT64_MIN : INT64_MAX);
*err= 1;
}
return i;
}
uint32_t Field::fill_cache_field(CACHE_FIELD *copy)
{
uint32_t store_length;
copy->str=ptr;
copy->length=pack_length();
copy->blob_field=0;
if (flags & BLOB_FLAG)
{
copy->blob_field=(Field_blob*) this;
copy->strip=0;
copy->length-= table->s->blob_ptr_size;
return copy->length;
}
else
{
copy->strip=0;
store_length= 0;
}
return copy->length+ store_length;
}
bool Field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
{
char buff[40];
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
if (!(res=val_str(&tmp)) ||
str_to_datetime_with_warn(res->ptr(), res->length(),
ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
return 1;
return 0;
}
bool Field::get_time(DRIZZLE_TIME *ltime)
{
char buff[40];
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
if (!(res=val_str(&tmp)) ||
str_to_time_with_warn(res->ptr(), res->length(), ltime))
return 1;
return 0;
}
/**
This is called when storing a date in a string.
@note
Needs to be changed if/when we want to support different time formats.
*/
int Field::store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type)
{
char buff[MAX_DATE_STRING_REP_LENGTH];
uint32_t length= (uint32_t) my_TIME_to_str(ltime, buff);
return store(buff, length, &my_charset_bin);
}
bool Field::optimize_range(uint32_t idx, uint32_t part)
{
return test(table->file->index_flags(idx, part, 1) & HA_READ_RANGE);
}
Field *Field::new_field(MEM_ROOT *root, Table *new_table, bool)
{
Field *tmp;
if (!(tmp= (Field*) memdup_root(root,(char*) this,size_of())))
return 0;
if (tmp->table->maybe_null)
tmp->flags&= ~NOT_NULL_FLAG;
tmp->table= new_table;
tmp->key_start.init(0);
tmp->part_of_key.init(0);
tmp->part_of_sortkey.init(0);
tmp->unireg_check= Field::NONE;
tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | BINARY_FLAG | ENUM_FLAG | SET_FLAG);
tmp->reset_fields();
return tmp;
}
Field *Field::new_key_field(MEM_ROOT *root, Table *new_table,
unsigned char *new_ptr, unsigned char *new_null_ptr,
uint32_t new_null_bit)
{
Field *tmp;
if ((tmp= new_field(root, new_table, table == new_table)))
{
tmp->ptr= new_ptr;
tmp->null_ptr= new_null_ptr;
tmp->null_bit= new_null_bit;
}
return tmp;
}
/* This is used to generate a field in Table from TABLE_SHARE */
Field *Field::clone(MEM_ROOT *root, Table *new_table)
{
Field *tmp;
if ((tmp= (Field*) memdup_root(root,(char*) this,size_of())))
{
tmp->init(new_table);
tmp->move_field_offset((my_ptrdiff_t) (new_table->record[0] -
new_table->s->default_values));
}
return tmp;
}
uint32_t Field::is_equal(Create_field *new_field_ptr)
{
return (new_field_ptr->sql_type == real_type());
}
/**
@retval
1 if the fields are equally defined
@retval
0 if the fields are unequally defined
*/
bool Field::eq_def(Field *field)
{
if (real_type() != field->real_type() || charset() != field->charset() ||
pack_length() != field->pack_length())
return 0;
return 1;
}
/**
@return
returns 1 if the fields are equally defined
*/
bool Field_enum::eq_def(Field *field)
{
if (!Field::eq_def(field))
return 0;
TYPELIB *from_lib=((Field_enum*) field)->typelib;
if (typelib->count < from_lib->count)
return 0;
for (uint32_t i=0 ; i < from_lib->count ; i++)
if (my_strnncoll(field_charset,
(const unsigned char*)typelib->type_names[i],
strlen(typelib->type_names[i]),
(const unsigned char*)from_lib->type_names[i],
strlen(from_lib->type_names[i])))
return 0;
return 1;
}
/*****************************************************************************
Handling of field and Create_field
*****************************************************************************/
/**
Convert create_field::length from number of characters to number of bytes.
*/
void Create_field::create_length_to_internal_length(void)
{
switch (sql_type) {
case DRIZZLE_TYPE_BLOB:
case DRIZZLE_TYPE_VARCHAR:
length*= charset->mbmaxlen;
key_length= length;
pack_length= calc_pack_length(sql_type, length);
break;
case DRIZZLE_TYPE_ENUM:
/* Pack_length already calculated in ::init() */
length*= charset->mbmaxlen;
key_length= pack_length;
break;
case DRIZZLE_TYPE_NEWDECIMAL:
key_length= pack_length=
my_decimal_get_binary_size(my_decimal_length_to_precision(length,
decimals,
flags &
UNSIGNED_FLAG),
decimals);
break;
default:
key_length= pack_length= calc_pack_length(sql_type, length);
break;
}
}
/**
Init for a tmp table field. To be extended if need be.
*/
void Create_field::init_for_tmp_table(enum_field_types sql_type_arg,
uint32_t length_arg, uint32_t decimals_arg,
bool maybe_null, bool is_unsigned)
{
field_name= "";
sql_type= sql_type_arg;
char_length= length= length_arg;;
unireg_check= Field::NONE;
interval= 0;
charset= &my_charset_bin;
pack_flag= (FIELDFLAG_NUMBER |
((decimals_arg & FIELDFLAG_MAX_DEC) << FIELDFLAG_DEC_SHIFT) |
(maybe_null ? FIELDFLAG_MAYBE_NULL : 0) |
(is_unsigned ? 0 : FIELDFLAG_DECIMAL));
vcol_info= NULL;
is_stored= true;
}
/**
Initialize field definition for create.
@param session Thread handle
@param fld_name Field name
@param fld_type Field type
@param fld_length Field length
@param fld_decimals Decimal (if any)
@param fld_type_modifier Additional type information
@param fld_default_value Field default value (if any)
@param fld_on_update_value The value of ON UPDATE clause
@param fld_comment Field comment
@param fld_change Field change
@param fld_interval_list Interval list (if any)
@param fld_charset Field charset
@param fld_vcol_info Virtual column data
@retval
false on success
@retval
true on error
*/
bool Create_field::init(Session *, char *fld_name, enum_field_types fld_type,
char *fld_length, char *fld_decimals,
uint32_t fld_type_modifier, Item *fld_default_value,
Item *fld_on_update_value, LEX_STRING *fld_comment,
char *fld_change, List<String> *fld_interval_list,
const CHARSET_INFO * const fld_charset,
uint32_t, enum column_format_type column_format_in,
virtual_column_info *fld_vcol_info)
{
uint32_t sign_len, allowed_type_modifier= 0;
uint32_t max_field_charlength= MAX_FIELD_CHARLENGTH;
field= 0;
field_name= fld_name;
def= fld_default_value;
flags= fld_type_modifier;
flags|= (((uint32_t)column_format_in & COLUMN_FORMAT_MASK) << COLUMN_FORMAT_FLAGS);
unireg_check= (fld_type_modifier & AUTO_INCREMENT_FLAG ?
Field::NEXT_NUMBER : Field::NONE);
decimals= fld_decimals ? (uint32_t)atoi(fld_decimals) : 0;
if (decimals >= NOT_FIXED_DEC)
{
my_error(ER_TOO_BIG_SCALE, MYF(0), decimals, fld_name,
NOT_FIXED_DEC-1);
return(true);
}
sql_type= fld_type;
length= 0;
change= fld_change;
interval= 0;
pack_length= key_length= 0;
charset= fld_charset;
interval_list.empty();
comment= *fld_comment;
vcol_info= fld_vcol_info;
is_stored= true;
/* Initialize data for a virtual field */
if (fld_type == DRIZZLE_TYPE_VIRTUAL)
{
assert(vcol_info && vcol_info->expr_item);
is_stored= vcol_info->get_field_stored();
/*
Perform per item-type checks to determine if the expression is
allowed for a virtual column.
Note that validation of the specific function is done later in
procedures open_table_from_share and fix_fields_vcol_func
*/
switch (vcol_info->expr_item->type()) {
case Item::FUNC_ITEM:
if (((Item_func *)vcol_info->expr_item)->functype() == Item_func::FUNC_SP)
{
my_error(ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED, MYF(0), field_name);
return(true);
}
break;
case Item::COPY_STR_ITEM:
case Item::FIELD_AVG_ITEM:
case Item::PROC_ITEM:
case Item::REF_ITEM:
case Item::FIELD_STD_ITEM:
case Item::FIELD_VARIANCE_ITEM:
case Item::INSERT_VALUE_ITEM:
case Item::SUBSELECT_ITEM:
case Item::CACHE_ITEM:
case Item::TYPE_HOLDER:
case Item::PARAM_ITEM:
my_error(ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED, MYF(0), field_name);
return true;
default:
// Continue with the field creation
break;
}
/*
Make a field created for the real type.
Note that "real" and virtual fields differ from each other
only by Field::vcol_info, which is always 0 for normal columns.
vcol_info is updated for fields later in procedure open_binary_frm.
*/
sql_type= fld_type= vcol_info->get_real_type();
}
/*
Set NO_DEFAULT_VALUE_FLAG if this field doesn't have a default value and
it is NOT NULL, not an AUTO_INCREMENT field and not a TIMESTAMP.
*/
if (!fld_default_value && !(fld_type_modifier & AUTO_INCREMENT_FLAG) &&
(fld_type_modifier & NOT_NULL_FLAG) && fld_type != DRIZZLE_TYPE_TIMESTAMP)
flags|= NO_DEFAULT_VALUE_FLAG;
if (fld_length && !(length= (uint32_t) atoi(fld_length)))
fld_length= 0; /* purecov: inspected */
sign_len= fld_type_modifier & UNSIGNED_FLAG ? 0 : 1;
switch (fld_type) {
case DRIZZLE_TYPE_TINY:
if (!fld_length)
length= MAX_TINYINT_WIDTH+sign_len;
allowed_type_modifier= AUTO_INCREMENT_FLAG;
break;
case DRIZZLE_TYPE_LONG:
if (!fld_length)
length= MAX_INT_WIDTH+sign_len;
allowed_type_modifier= AUTO_INCREMENT_FLAG;
break;
case DRIZZLE_TYPE_LONGLONG:
if (!fld_length)
length= MAX_BIGINT_WIDTH;
allowed_type_modifier= AUTO_INCREMENT_FLAG;
break;
case DRIZZLE_TYPE_NULL:
break;
case DRIZZLE_TYPE_NEWDECIMAL:
my_decimal_trim(&length, &decimals);
if (length > DECIMAL_MAX_PRECISION)
{
my_error(ER_TOO_BIG_PRECISION, MYF(0), length, fld_name,
DECIMAL_MAX_PRECISION);
return(true);
}
if (length < decimals)
{
my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
return(true);
}
length=
my_decimal_precision_to_length(length, decimals,
fld_type_modifier & UNSIGNED_FLAG);
pack_length=
my_decimal_get_binary_size(length, decimals);
break;
case DRIZZLE_TYPE_VARCHAR:
/*
Long VARCHAR's are automaticly converted to blobs in mysql_prepare_table
if they don't have a default value
*/
max_field_charlength= MAX_FIELD_VARCHARLENGTH;
break;
case DRIZZLE_TYPE_BLOB:
if (fld_default_value)
{
/* Allow empty as default value. */
String str,*res;
res= fld_default_value->val_str(&str);
if (res->length())
{
my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0),
fld_name);
return(true);
}
}
flags|= BLOB_FLAG;
break;
case DRIZZLE_TYPE_DOUBLE:
allowed_type_modifier= AUTO_INCREMENT_FLAG;
if (!fld_length && !fld_decimals)
{
length= DBL_DIG+7;
decimals= NOT_FIXED_DEC;
}
if (length < decimals &&
decimals != NOT_FIXED_DEC)
{
my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
return(true);
}
break;
case DRIZZLE_TYPE_TIMESTAMP:
if (!fld_length)
{
/* Compressed date YYYYMMDDHHMMSS */
length= MAX_DATETIME_COMPRESSED_WIDTH;
}
else if (length != MAX_DATETIME_WIDTH)
{
/*
We support only even TIMESTAMP lengths less or equal than 14
and 19 as length of 4.1 compatible representation.
*/
length= ((length+1)/2)*2; /* purecov: inspected */
length= cmin(length, (uint32_t)MAX_DATETIME_COMPRESSED_WIDTH); /* purecov: inspected */
}
flags|= UNSIGNED_FLAG;
if (fld_default_value)
{
/* Grammar allows only NOW() value for ON UPDATE clause */
if (fld_default_value->type() == Item::FUNC_ITEM &&
((Item_func*)fld_default_value)->functype() == Item_func::NOW_FUNC)
{
unireg_check= (fld_on_update_value ? Field::TIMESTAMP_DNUN_FIELD:
Field::TIMESTAMP_DN_FIELD);
/*
We don't need default value any longer moreover it is dangerous.
Everything handled by unireg_check further.
*/
def= 0;
}
else
unireg_check= (fld_on_update_value ? Field::TIMESTAMP_UN_FIELD:
Field::NONE);
}
else
{
/*
If we have default TIMESTAMP NOT NULL column without explicit DEFAULT
or ON UPDATE values then for the sake of compatiblity we should treat
this column as having DEFAULT NOW() ON UPDATE NOW() (when we don't
have another TIMESTAMP column with auto-set option before this one)
or DEFAULT 0 (in other cases).
So here we are setting TIMESTAMP_OLD_FIELD only temporary, and will
replace this value by TIMESTAMP_DNUN_FIELD or NONE later when
information about all TIMESTAMP fields in table will be availiable.
If we have TIMESTAMP NULL column without explicit DEFAULT value
we treat it as having DEFAULT NULL attribute.
*/
unireg_check= (fld_on_update_value ? Field::TIMESTAMP_UN_FIELD :
(flags & NOT_NULL_FLAG ? Field::TIMESTAMP_OLD_FIELD :
Field::NONE));
}
break;
case DRIZZLE_TYPE_DATE:
length= 10;
break;
case DRIZZLE_TYPE_DATETIME:
length= MAX_DATETIME_WIDTH;
break;
case DRIZZLE_TYPE_ENUM:
{
/* Should be safe. */
pack_length= get_enum_pack_length(fld_interval_list->elements);
List_iterator<String> it(*fld_interval_list);
String *tmp;
while ((tmp= it++))
interval_list.push_back(tmp);
length= 1; /* See comment for DRIZZLE_TYPE_SET above. */
break;
}
case DRIZZLE_TYPE_VIRTUAL: // Must not happen
assert(0);
}
/* Remember the value of length */
char_length= length;
if (!(flags & BLOB_FLAG) &&
((length > max_field_charlength &&
fld_type != DRIZZLE_TYPE_ENUM &&
(fld_type != DRIZZLE_TYPE_VARCHAR || fld_default_value)) ||
(!length && fld_type != DRIZZLE_TYPE_VARCHAR)))
{
my_error((fld_type == DRIZZLE_TYPE_VARCHAR) ? ER_TOO_BIG_FIELDLENGTH : ER_TOO_BIG_DISPLAYWIDTH,
MYF(0),
fld_name, max_field_charlength); /* purecov: inspected */
return(true);
}
fld_type_modifier&= AUTO_INCREMENT_FLAG;
if ((~allowed_type_modifier) & fld_type_modifier)
{
my_error(ER_WRONG_FIELD_SPEC, MYF(0), fld_name);
return(true);
}
return(false); /* success */
}
enum_field_types get_blob_type_from_length(uint32_t)
{
enum_field_types type;
type= DRIZZLE_TYPE_BLOB;
return type;
}
/*
Make a field from the .frm file info
*/
uint32_t calc_pack_length(enum_field_types type,uint32_t length)
{
switch (type) {
case DRIZZLE_TYPE_VARCHAR: return (length + (length < 256 ? 1: 2));
case DRIZZLE_TYPE_TINY : return 1;
case DRIZZLE_TYPE_DATE: return 3;
case DRIZZLE_TYPE_TIMESTAMP:
case DRIZZLE_TYPE_LONG : return 4;
case DRIZZLE_TYPE_DOUBLE: return sizeof(double);
case DRIZZLE_TYPE_DATETIME:
case DRIZZLE_TYPE_LONGLONG: return 8; /* Don't crash if no int64_t */
case DRIZZLE_TYPE_NULL : return 0;
case DRIZZLE_TYPE_BLOB: return 4+portable_sizeof_char_ptr;
case DRIZZLE_TYPE_ENUM:
case DRIZZLE_TYPE_NEWDECIMAL:
abort();
default:
return 0;
}
}
uint32_t pack_length_to_packflag(uint32_t type)
{
switch (type) {
case 1: return 1 << FIELDFLAG_PACK_SHIFT;
case 2: assert(1);
case 3: assert(1);
case 4: return f_settype((uint32_t) DRIZZLE_TYPE_LONG);
case 8: return f_settype((uint32_t) DRIZZLE_TYPE_LONGLONG);
}
return 0; // This shouldn't happen
}
Field *make_field(TABLE_SHARE *share, MEM_ROOT *root,
unsigned char *ptr, uint32_t field_length,
unsigned char *null_pos, unsigned char null_bit,
uint32_t pack_flag,
enum_field_types field_type,
const CHARSET_INFO * field_charset,
Field::utype unireg_check,
TYPELIB *interval,
const char *field_name)
{
if(!root)
root= current_mem_root();
if (!f_maybe_null(pack_flag))
{
null_pos=0;
null_bit=0;
}
else
{
null_bit= ((unsigned char) 1) << null_bit;
}
switch (field_type) {
case DRIZZLE_TYPE_DATE:
case DRIZZLE_TYPE_DATETIME:
case DRIZZLE_TYPE_TIMESTAMP:
field_charset= &my_charset_bin;
default: break;
}
if (f_is_alpha(pack_flag))
{
if (!f_is_packed(pack_flag))
{
if (field_type == DRIZZLE_TYPE_VARCHAR)
return new (root) Field_varstring(ptr,field_length,
HA_VARCHAR_PACKLENGTH(field_length),
null_pos,null_bit,
unireg_check, field_name,
share,
field_charset);
return 0; // Error
}
uint32_t pack_length=calc_pack_length((enum_field_types)
f_packtype(pack_flag),
field_length);
if (f_is_blob(pack_flag))
return new (root) Field_blob(ptr,null_pos,null_bit,
unireg_check, field_name, share,
pack_length, field_charset);
if (interval)
{
if (f_is_enum(pack_flag))
{
return new (root) Field_enum(ptr,field_length,null_pos,null_bit,
unireg_check, field_name,
get_enum_pack_length(interval->count),
interval, field_charset);
}
}
}
switch (field_type) {
case DRIZZLE_TYPE_NEWDECIMAL:
return new (root) Field_new_decimal(ptr,field_length,null_pos,null_bit,
unireg_check, field_name,
f_decimals(pack_flag),
f_is_decimal_precision(pack_flag) != 0,
f_is_dec(pack_flag) == 0);
case DRIZZLE_TYPE_DOUBLE:
return new (root) Field_double(ptr,field_length,null_pos,null_bit,
unireg_check, field_name,
f_decimals(pack_flag),
false,
f_is_dec(pack_flag)== 0);
case DRIZZLE_TYPE_TINY:
assert(0);
case DRIZZLE_TYPE_LONG:
return new (root) Field_long(ptr,field_length,null_pos,null_bit,
unireg_check, field_name,
false,
f_is_dec(pack_flag) == 0);
case DRIZZLE_TYPE_LONGLONG:
return new (root) Field_int64_t(ptr,field_length,null_pos,null_bit,
unireg_check, field_name,
false,
f_is_dec(pack_flag) == 0);
case DRIZZLE_TYPE_TIMESTAMP:
return new (root) Field_timestamp(ptr,field_length, null_pos, null_bit,
unireg_check, field_name, share,
field_charset);
case DRIZZLE_TYPE_DATE:
return new (root) Field_date(ptr,null_pos,null_bit,
unireg_check, field_name, field_charset);
case DRIZZLE_TYPE_DATETIME:
return new (root) Field_datetime(ptr,null_pos,null_bit,
unireg_check, field_name, field_charset);
case DRIZZLE_TYPE_NULL:
return new (root) Field_null(ptr, field_length, unireg_check, field_name,
field_charset);
case DRIZZLE_TYPE_VIRTUAL: // Must not happen
assert(0);
default: // Impossible (Wrong version)
break;
}
return 0;
}
/** Create a field suitable for create of table. */
Create_field::Create_field(Field *old_field,Field *orig_field)
{
field= old_field;
field_name=change=old_field->field_name;
length= old_field->field_length;
flags= old_field->flags;
unireg_check=old_field->unireg_check;
pack_length=old_field->pack_length();
key_length= old_field->key_length();
sql_type= old_field->real_type();
charset= old_field->charset(); // May be NULL ptr
comment= old_field->comment;
decimals= old_field->decimals();
vcol_info= old_field->vcol_info;
is_stored= old_field->is_stored;
/* Fix if the original table had 4 byte pointer blobs */
if (flags & BLOB_FLAG)
pack_length= (pack_length- old_field->table->s->blob_ptr_size +
portable_sizeof_char_ptr);
switch (sql_type) {
case DRIZZLE_TYPE_BLOB:
sql_type= DRIZZLE_TYPE_BLOB;
length/= charset->mbmaxlen;
key_length/= charset->mbmaxlen;
break;
/* Change CHAR -> VARCHAR if dynamic record length */
case DRIZZLE_TYPE_ENUM:
case DRIZZLE_TYPE_VARCHAR:
/* This is corrected in create_length_to_internal_length */
length= (length+charset->mbmaxlen-1) / charset->mbmaxlen;
break;
default:
break;
}
if (flags & (ENUM_FLAG | SET_FLAG))
interval= ((Field_enum*) old_field)->typelib;
else
interval=0;
def=0;
char_length= length;
if (!(flags & (NO_DEFAULT_VALUE_FLAG )) &&
old_field->ptr && orig_field &&
(sql_type != DRIZZLE_TYPE_TIMESTAMP || /* set def only if */
old_field->table->timestamp_field != old_field || /* timestamp field */
unireg_check == Field::TIMESTAMP_UN_FIELD)) /* has default val */
{
my_ptrdiff_t diff;
/* Get the value from default_values */
diff= (my_ptrdiff_t) (orig_field->table->s->default_values-
orig_field->table->record[0]);
orig_field->move_field_offset(diff); // Points now at default_values
if (!orig_field->is_real_null())
{
char buff[MAX_FIELD_WIDTH], *pos;
String tmp(buff, sizeof(buff), charset), *res;
res= orig_field->val_str(&tmp);
pos= (char*) sql_strmake(res->ptr(), res->length());
def= new Item_string(pos, res->length(), charset);
}
orig_field->move_field_offset(-diff); // Back to record[0]
}
}
/*****************************************************************************
Warning handling
*****************************************************************************/
/**
Produce warning or note about data saved into field.
@param level - level of message (Note/Warning/Error)
@param code - error code of message to be produced
@param cuted_increment - whenever we should increase cut fields count or not
@note
This function won't produce warning and increase cut fields counter
if count_cuted_fields == CHECK_FIELD_IGNORE for current thread.
if count_cuted_fields == CHECK_FIELD_IGNORE then we ignore notes.
This allows us to avoid notes in optimisation, like convert_constant_item().
@retval
1 if count_cuted_fields == CHECK_FIELD_IGNORE and error level is not NOTE
@retval
0 otherwise
*/
bool
Field::set_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code,
int cuted_increment)
{
/*
If this field was created only for type conversion purposes it
will have table == NULL.
*/
Session *session= table ? table->in_use : current_session;
if (session->count_cuted_fields)
{
session->cuted_fields+= cuted_increment;
push_warning_printf(session, level, code, ER(code), field_name,
session->row_count);
return 0;
}
return level >= DRIZZLE_ERROR::WARN_LEVEL_WARN;
}
/**
Produce warning or note about datetime string data saved into field.
@param level level of message (Note/Warning/Error)
@param code error code of message to be produced
@param str string value which we tried to save
@param str_length length of string which we tried to save
@param ts_type type of datetime value (datetime/date/time)
@param cuted_increment whenever we should increase cut fields count or not
@note
This function will always produce some warning but won't increase cut
fields counter if count_cuted_fields ==FIELD_CHECK_IGNORE for current
thread.
*/
void
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level,
unsigned int code,
const char *str, uint32_t str_length,
enum enum_drizzle_timestamp_type ts_type, int cuted_increment)
{
Session *session= table ? table->in_use : current_session;
if ((session->really_abort_on_warning() &&
level >= DRIZZLE_ERROR::WARN_LEVEL_WARN) ||
set_warning(level, code, cuted_increment))
make_truncated_value_warning(session, level, str, str_length, ts_type,
field_name);
}
/**
Produce warning or note about integer datetime value saved into field.
@param level level of message (Note/Warning/Error)
@param code error code of message to be produced
@param nr numeric value which we tried to save
@param ts_type type of datetime value (datetime/date/time)
@param cuted_increment whenever we should increase cut fields count or not
@note
This function will always produce some warning but won't increase cut
fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
thread.
*/
void
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, uint32_t code,
int64_t nr, enum enum_drizzle_timestamp_type ts_type,
int cuted_increment)
{
Session *session= table ? table->in_use : current_session;
if (session->really_abort_on_warning() ||
set_warning(level, code, cuted_increment))
{
char str_nr[22];
char *str_end= int64_t10_to_str(nr, str_nr, -10);
make_truncated_value_warning(session, level, str_nr, (uint32_t) (str_end - str_nr),
ts_type, field_name);
}
}
/**
Produce warning or note about double datetime data saved into field.
@param level level of message (Note/Warning/Error)
@param code error code of message to be produced
@param nr double value which we tried to save
@param ts_type type of datetime value (datetime/date/time)
@note
This function will always produce some warning but won't increase cut
fields counter if count_cuted_fields == FIELD_CHECK_IGNORE for current
thread.
*/
void
Field::set_datetime_warning(DRIZZLE_ERROR::enum_warning_level level, const uint32_t code,
double nr, enum enum_drizzle_timestamp_type ts_type)
{
Session *session= table ? table->in_use : current_session;
if (session->really_abort_on_warning() ||
set_warning(level, code, 1))
{
/* DBL_DIG is enough to print '-[digits].E+###' */
char str_nr[DBL_DIG + 8];
uint32_t str_len= sprintf(str_nr, "%g", nr);
make_truncated_value_warning(session, level, str_nr, str_len, ts_type,
field_name);
}
}
|