41 #include "sql_join_buffer.h"
47 #define MAX_EXPONENT 1024
52 uchar Field_null::null[1]={1};
53 const char field_separator=
',';
55 #define DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE FLOATING_POINT_BUFFER
56 #define LONGLONG_TO_STRING_CONVERSION_BUFFER_SIZE 128
57 #define DECIMAL_TO_STRING_CONVERSION_BUFFER_SIZE 128
58 #define BLOB_PACK_LENGTH_TO_MAX_LENGH(arg) \
59 ((ulong) ((LL(1) << MY_MIN(arg, 4) * 8) - LL(1)))
68 #define FIELDTYPE_TEAR_FROM (MYSQL_TYPE_BIT + 1)
69 #define FIELDTYPE_TEAR_TO (MYSQL_TYPE_NEWDECIMAL - 1)
70 #define FIELDTYPE_NUM (FIELDTYPE_TEAR_FROM + (255 - FIELDTYPE_TEAR_TO))
73 inline int field_type2index (enum_field_types field_type)
75 field_type= real_type_to_type(field_type);
76 DBUG_ASSERT(field_type < FIELDTYPE_TEAR_FROM ||
77 field_type > FIELDTYPE_TEAR_TO);
78 return (field_type < FIELDTYPE_TEAR_FROM ?
80 ((
int)FIELDTYPE_TEAR_FROM) + (field_type - FIELDTYPE_TEAR_TO) - 1);
84 static enum_field_types field_types_merge_rules [FIELDTYPE_NUM][FIELDTYPE_NUM]=
89 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL,
91 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL,
93 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
95 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
97 MYSQL_TYPE_DECIMAL, MYSQL_TYPE_DECIMAL,
99 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
101 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
103 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
107 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
109 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
111 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
113 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
115 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR
120 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_TINY,
122 MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
124 MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
126 MYSQL_TYPE_TINY, MYSQL_TYPE_VARCHAR,
128 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INT24,
130 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
132 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY,
134 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
138 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
140 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
142 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
144 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
146 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR
151 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_SHORT,
153 MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
155 MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
157 MYSQL_TYPE_SHORT, MYSQL_TYPE_VARCHAR,
159 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INT24,
161 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
163 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_SHORT,
165 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
169 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
171 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
173 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
175 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
177 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR
182 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_LONG,
184 MYSQL_TYPE_LONG, MYSQL_TYPE_LONG,
186 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
188 MYSQL_TYPE_LONG, MYSQL_TYPE_VARCHAR,
190 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_LONG,
192 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
194 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_LONG,
196 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
200 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
202 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
204 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
206 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
208 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR
213 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_FLOAT,
215 MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
217 MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
219 MYSQL_TYPE_FLOAT, MYSQL_TYPE_VARCHAR,
221 MYSQL_TYPE_FLOAT, MYSQL_TYPE_FLOAT,
223 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
225 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_FLOAT,
227 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
231 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_VARCHAR,
233 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
235 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
237 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
239 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR
244 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
246 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
248 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
250 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_VARCHAR,
252 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
254 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
256 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_DOUBLE,
258 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
262 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_VARCHAR,
264 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
266 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
268 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
270 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR
275 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_TINY,
277 MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
279 MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
281 MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP,
283 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_LONGLONG,
285 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_TIME,
287 MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,
289 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
293 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_ENUM,
295 MYSQL_TYPE_SET, MYSQL_TYPE_TINY_BLOB,
297 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
299 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
301 MYSQL_TYPE_STRING, MYSQL_TYPE_GEOMETRY
306 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
308 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
310 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
312 MYSQL_TYPE_TIMESTAMP, MYSQL_TYPE_TIMESTAMP,
314 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
316 MYSQL_TYPE_DATETIME, MYSQL_TYPE_DATETIME,
318 MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
320 MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
324 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
326 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
328 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
330 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
332 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR
337 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_LONGLONG,
339 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_LONGLONG,
341 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
343 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_VARCHAR,
345 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_LONG,
347 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
349 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_LONGLONG,
351 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
355 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
357 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
359 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
361 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
363 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR
368 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_INT24,
370 MYSQL_TYPE_INT24, MYSQL_TYPE_LONG,
372 MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
374 MYSQL_TYPE_INT24, MYSQL_TYPE_VARCHAR,
376 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INT24,
378 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
380 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INT24,
382 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
386 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
388 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
390 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
392 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
394 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR
399 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
401 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
403 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
405 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_DATETIME,
407 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
409 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_DATETIME,
411 MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
413 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
417 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
419 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
421 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
423 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
425 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR
430 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
432 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
434 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
436 MYSQL_TYPE_TIME, MYSQL_TYPE_DATETIME,
438 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
440 MYSQL_TYPE_DATETIME, MYSQL_TYPE_TIME,
442 MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
444 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
448 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
450 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
452 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
454 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
456 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR
461 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
463 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
465 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
467 MYSQL_TYPE_DATETIME, MYSQL_TYPE_DATETIME,
469 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
471 MYSQL_TYPE_DATETIME, MYSQL_TYPE_DATETIME,
473 MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
475 MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
479 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
481 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
483 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
485 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
487 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR
492 MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY,
494 MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
496 MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
498 MYSQL_TYPE_YEAR, MYSQL_TYPE_VARCHAR,
500 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INT24,
502 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
504 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_YEAR,
506 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
510 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
512 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
514 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
516 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
518 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR
523 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
525 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
527 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
529 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_DATETIME,
531 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
533 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_DATETIME,
535 MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
537 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
541 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
543 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
545 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
547 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
549 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR
554 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
556 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
558 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
560 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
562 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
564 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
566 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
568 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
572 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
574 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
576 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
578 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
580 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR
585 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
587 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
589 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
591 MYSQL_TYPE_BIT, MYSQL_TYPE_VARCHAR,
593 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
595 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
597 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
599 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
603 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
605 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
607 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
609 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
611 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR
616 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL,
618 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL,
620 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
622 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
624 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL,
626 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
628 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_NEWDECIMAL,
630 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
634 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
636 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
638 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
640 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
642 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR
647 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
649 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
651 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
653 MYSQL_TYPE_ENUM, MYSQL_TYPE_VARCHAR,
655 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
657 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
659 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
661 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
665 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
667 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
669 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
671 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
673 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR
678 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
680 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
682 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
684 MYSQL_TYPE_SET, MYSQL_TYPE_VARCHAR,
686 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
688 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
690 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
692 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
696 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
698 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
700 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
702 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
704 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR
709 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
711 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
713 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
715 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
717 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
719 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
721 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
723 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
725 MYSQL_TYPE_TINY_BLOB,
727 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
729 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
731 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
733 MYSQL_TYPE_BLOB, MYSQL_TYPE_TINY_BLOB,
735 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB
740 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
742 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
744 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
746 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
748 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
750 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
752 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
754 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
756 MYSQL_TYPE_MEDIUM_BLOB,
758 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
760 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
762 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
764 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
766 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB
771 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
773 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
775 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
777 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
779 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
781 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
783 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
785 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
787 MYSQL_TYPE_LONG_BLOB,
789 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
791 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
793 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
795 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
797 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB
802 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
804 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
806 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
808 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
810 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
812 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
814 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
816 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
820 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
822 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
824 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
826 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
828 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB
833 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
835 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
837 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
839 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
841 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
843 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
845 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
847 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
851 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
853 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
855 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
857 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
859 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR
864 MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
866 MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
868 MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
870 MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
872 MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
874 MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
876 MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
878 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR,
882 MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
884 MYSQL_TYPE_STRING, MYSQL_TYPE_TINY_BLOB,
886 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
888 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
890 MYSQL_TYPE_STRING, MYSQL_TYPE_STRING
895 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
897 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
899 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
901 MYSQL_TYPE_GEOMETRY, MYSQL_TYPE_VARCHAR,
903 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
905 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
907 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
909 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
913 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
915 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
917 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
919 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
921 MYSQL_TYPE_STRING, MYSQL_TYPE_GEOMETRY
939 return field_types_merge_rules[field_type2index(a)]
940 [field_type2index(b)];
944 static Item_result field_types_result_type [FIELDTYPE_NUM]=
947 DECIMAL_RESULT, INT_RESULT,
949 INT_RESULT, INT_RESULT,
951 REAL_RESULT, REAL_RESULT,
953 STRING_RESULT, STRING_RESULT,
955 INT_RESULT, INT_RESULT,
957 STRING_RESULT, STRING_RESULT,
959 STRING_RESULT, INT_RESULT,
961 STRING_RESULT, STRING_RESULT,
965 DECIMAL_RESULT, STRING_RESULT,
967 STRING_RESULT, STRING_RESULT,
969 STRING_RESULT, STRING_RESULT,
971 STRING_RESULT, STRING_RESULT,
973 STRING_RESULT, STRING_RESULT
994 test_if_important_data(
const CHARSET_INFO *cs,
const char *str,
997 if (cs != &my_charset_bin)
998 str+= cs->cset->scan(cs, str, strend, MY_SEQ_SPACES);
999 return (str < strend);
1009 CPP_UNNAMED_NS_START
1033 return field_types_result_type[field_type2index(field_type)];
1053 static void push_numerical_conversion_warning(THD* thd,
const char* str,
1056 const char* typestr,
int error,
1057 const char* field_name=
"UNKNOWN",
1060 char buf[MY_MAX(MY_MAX(DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE,
1061 LONGLONG_TO_STRING_CONVERSION_BUFFER_SIZE),
1062 DECIMAL_TO_STRING_CONVERSION_BUFFER_SIZE)];
1064 String tmp(buf,
sizeof(buf), cs);
1065 tmp.copy(str, length, cs);
1066 push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
1067 error, ER(error), typestr, tmp.c_ptr(),
1068 field_name, row_num);
1091 switch (dec_error) {
1092 case E_DEC_TRUNCATED:
1093 field->
set_warning(Sql_condition::WARN_LEVEL_NOTE, WARN_DATA_TRUNCATED, 1);
1095 case E_DEC_OVERFLOW:
1096 field->
set_warning(Sql_condition::WARN_LEVEL_WARN,
1097 ER_WARN_DATA_OUT_OF_RANGE, 1);
1103 push_warning_printf(field->table->in_use, Sql_condition::WARN_LEVEL_WARN,
1104 ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
1105 ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
1106 "decimal", errmsg.ptr(), field->field_name,
1107 static_cast<ulong
>(da->current_row_for_warning()));
1108 my_decimal_set_zero(dec_value);
1129 case MYSQL_TYPE_VARCHAR:
1130 case MYSQL_TYPE_TINY_BLOB:
1131 case MYSQL_TYPE_MEDIUM_BLOB:
1132 case MYSQL_TYPE_LONG_BLOB:
1133 case MYSQL_TYPE_BLOB:
1134 case MYSQL_TYPE_VAR_STRING:
1135 case MYSQL_TYPE_STRING:
1136 case MYSQL_TYPE_GEOMETRY:
1148 uchar null_bit_arg, utype unireg_check_arg,
1149 const char *field_name_arg,
1150 uint8 dec_arg,
bool zero_arg,
bool unsigned_arg)
1151 :
Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1152 unireg_check_arg, field_name_arg),
1153 dec(dec_arg),zerofill(zero_arg),unsigned_flag(unsigned_arg)
1156 flags|=ZEROFILL_FLAG;
1158 flags|=UNSIGNED_FLAG;
1162 void Field_num::prepend_zeros(
String *value)
1165 if ((diff= (
int) (field_length - value->length())) > 0)
1167 bmove_upp((uchar*) value->ptr()+field_length,
1168 (uchar*) value->ptr()+value->length(),
1170 memset(const_cast<char*>(value->ptr()),
'0', diff);
1171 value->length(field_length);
1172 (void) value->c_ptr_quick();
1193 type_conversion_status
1195 const char *int_end,
int error)
1198 if (str == int_end || error == MY_ERRNO_EDOM)
1201 push_warning_printf(table->in_use, Sql_condition::WARN_LEVEL_WARN,
1202 ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
1203 ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
1204 "integer", err.ptr(), field_name,
1205 (ulong) table->in_use->get_stmt_da()->
1206 current_row_for_warning());
1207 return TYPE_ERR_BAD_VALUE;
1210 if (test_if_important_data(cs, int_end, str + length))
1212 set_warning(Sql_condition::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
1213 return TYPE_WARN_TRUNCATED;
1241 type_conversion_status
1242 Field_num::get_int(
const CHARSET_INFO *cs,
const char *from, uint len,
1243 longlong *rnd, ulonglong unsigned_max,
1244 longlong signed_min, longlong signed_max)
1249 *rnd= (longlong) cs->cset->strntoull10rnd(cs, from, len,
1250 unsigned_flag, &end,
1254 if ((((ulonglong) *rnd > unsigned_max) &&
1255 (*rnd= (longlong) unsigned_max)) ||
1256 error == MY_ERRNO_ERANGE)
1261 if (*rnd < signed_min)
1266 else if (*rnd > signed_max)
1272 if (table->in_use->count_cuted_fields != 0)
1273 return check_int(cs, from, len, end, error);
1278 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1279 return TYPE_WARN_OUT_OF_RANGE;
1291 type_conversion_status
1293 uint8 dec_arg __attribute__((unused)))
1295 longlong nr= TIME_to_ulonglong_round(ltime);
1296 return store(ltime->neg ? -nr : nr, 0);
1312 if (op_result == E_DEC_OVERFLOW)
1314 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1317 if (op_result == E_DEC_TRUNCATED)
1319 set_warning(Sql_condition::WARN_LEVEL_NOTE, WARN_DATA_TRUNCATED, 1);
1334 ASSERT_COLUMN_MARKED_FOR_READ;
1337 longlong value= val_int();
1339 if (val_buffer->alloc(MY_INT64_NUM_DECIMAL_DIGITS))
1341 length= (uint) (*cs->cset->longlong10_to_str)(cs, (
char*) val_buffer->ptr(),
1342 MY_INT64_NUM_DECIMAL_DIGITS,
1343 unsigned_val ? 10 : -10,
1345 val_buffer->length(length);
1351 Field::Field(uchar *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,
1353 utype unireg_check_arg,
const char *field_name_arg)
1354 :ptr(ptr_arg), null_ptr(null_ptr_arg),
1356 field_name(field_name_arg),
1357 unireg_check(unireg_check_arg),
1358 field_length(length_arg), null_bit(null_bit_arg),
1359 is_created_from_null_item(FALSE)
1362 comment.str= (
char*)
"";
1368 void Field::hash(ulong *nr, ulong *nr2)
1372 *nr^= (*nr << 1) | 1;
1376 uint len= pack_length();
1378 cs->coll->hash_sort(cs, ptr, len, nr, nr2);
1383 Field::do_last_null_byte()
const
1387 return null_offset() + 1;
1388 return LAST_NULL_BYTE_UNDEF;
1392 void Field::copy_from_tmp(
int row_offset)
1394 memcpy(ptr,ptr+row_offset,pack_length());
1398 (
null_ptr[row_offset] & (uchar) null_bit));
1403 bool Field::send_binary(
Protocol *protocol)
1405 char buff[MAX_FIELD_WIDTH];
1406 String tmp(buff,
sizeof(buff),charset());
1408 return protocol->
store(tmp.ptr(), tmp.length(), tmp.charset());
1448 uint16 mflags __attribute__((unused)),
1451 uint
const source_size= pack_length_from_metadata(field_metadata);
1452 uint
const destination_size= row_pack_length();
1453 DBUG_PRINT(
"debug", (
"real_type: %d, source_size: %u, destination_size: %u",
1454 real_type(), source_size, destination_size));
1455 *order_var =
compare(source_size, destination_size);
1460 type_conversion_status
1461 Field::store(
const char *
to, uint length,
const CHARSET_INFO *cs,
1462 enum_check_fields check_level)
1464 enum_check_fields old_check_level= table->in_use->count_cuted_fields;
1465 table->in_use->count_cuted_fields= check_level;
1466 const type_conversion_status res= store(to, length, cs);
1467 table->in_use->count_cuted_fields= old_check_level;
1511 bool low_byte_first __attribute__((unused)))
1513 uint32 length= pack_length();
1514 set_if_smaller(length, max_length);
1515 memcpy(to, from, length);
1550 Field::unpack(uchar* to,
const uchar *from, uint param_data,
1551 bool low_byte_first __attribute__((unused)))
1553 uint length=pack_length();
1559 if (param_data > 255)
1561 from_type= (param_data & 0xff00) >> 8
U;
1562 param_data= param_data & 0x00ff;
1565 if ((param_data == 0) ||
1566 (length == param_data) ||
1567 (from_type != real_type()))
1569 memcpy(to, from, length);
1573 uint len= (param_data && (param_data < length)) ?
1574 param_data : length;
1576 memcpy(to, from, param_data > length ? length : len);
1581 void Field_num::add_zerofill_and_unsigned(
String &res)
const
1584 res.append(STRING_WITH_LEN(
" unsigned"));
1586 res.append(STRING_WITH_LEN(
" zerofill"));
1592 if (orig_table && orig_table->s->db.str && *orig_table->s->db.str)
1594 field->db_name= orig_table->s->db.str;
1595 if (orig_table->pos_in_table_list &&
1596 orig_table->pos_in_table_list->schema_table)
1597 field->org_table_name= (orig_table->pos_in_table_list->
1598 schema_table->table_name);
1600 field->org_table_name= orig_table->s->table_name.str;
1603 field->org_table_name= field->db_name=
"";
1604 if (orig_table && orig_table->alias)
1606 field->table_name= orig_table->alias;
1607 field->org_col_name= field_name;
1611 field->table_name=
"";
1612 field->org_col_name=
"";
1614 field->col_name= field_name;
1615 field->charsetnr= charset()->number;
1616 field->length=field_length;
1618 field->flags=table->maybe_null ? (flags & ~NOT_NULL_FLAG) : flags;
1619 field->decimals= decimals();
1638 if (unsigned_flag && val->sign())
1641 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1642 *has_overflow=
true;
1647 int conversion_error= my_decimal2int(E_DEC_ERROR & ~E_DEC_OVERFLOW
1649 val, unsigned_flag, &val_ll);
1653 *has_overflow=
true;
1655 return ULONGLONG_MAX;
1657 return (val->sign() ? LONGLONG_MIN : LONGLONG_MAX);
1678 ASSERT_COLUMN_MARKED_FOR_WRITE;
1679 bool has_overflow=
false;
1681 const type_conversion_status res= store(i, unsigned_flag);
1682 return has_overflow ? TYPE_WARN_OUT_OF_RANGE : res;
1702 ASSERT_COLUMN_MARKED_FOR_READ;
1703 DBUG_ASSERT(result_type() == INT_RESULT);
1704 longlong nr= val_int();
1705 int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
1706 return decimal_value;
1710 bool Field_num::get_date(
MYSQL_TIME *ltime, uint fuzzydate)
1712 DBUG_ASSERT(result_type() == INT_RESULT);
1713 return my_longlong_to_datetime_with_warn(val_int(), ltime, fuzzydate);
1719 DBUG_ASSERT(result_type() == INT_RESULT);
1720 return my_longlong_to_time_with_warn(val_int(), ltime);
1724 Field_str::Field_str(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
1725 uchar null_bit_arg, utype unireg_check_arg,
1726 const char *field_name_arg,
1728 :
Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1729 unireg_check_arg, field_name_arg)
1731 field_charset= charset_arg;
1732 if (charset_arg->state & MY_CS_BINSORT)
1734 field_derivation= DERIVATION_IMPLICIT;
1738 void Field_str::make_field(
Send_field *field)
1740 Field::make_field(field);
1766 ASSERT_COLUMN_MARKED_FOR_WRITE;
1769 int err= my_decimal2double(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW, d, &val);
1771 const type_conversion_status res=
store(val);
1773 return (err != E_DEC_OK) ? decimal_err_to_type_conv_status(err) : res;
1781 copy->
length= pack_length();
1783 if (flags & BLOB_FLAG)
1785 copy->
type= CACHE_BLOB;
1786 copy->
length-= portable_sizeof_char_ptr;
1789 else if (!zero_pack() &&
1790 (type() == MYSQL_TYPE_STRING && copy->
length >= 4 &&
1793 copy->
type= CACHE_STRIPPED;
1796 else if (type() == MYSQL_TYPE_VARCHAR)
1798 copy->
type= pack_length()-row_pack_length() == 1 ? CACHE_VARSTR1:
1807 return copy->
length + store_length;
1811 bool Field::get_date(
MYSQL_TIME *ltime,uint fuzzydate)
1813 char buff[MAX_DATE_STRING_REP_LENGTH];
1814 String tmp(buff,
sizeof(buff),&my_charset_bin),*res;
1815 return !(res= val_str(&tmp)) ||
1816 str_to_datetime_with_warn(res, ltime, fuzzydate);
1822 char buff[MAX_DATE_STRING_REP_LENGTH];
1823 String tmp(buff,
sizeof(buff),&my_charset_bin),*res;
1824 return !(res= val_str(&tmp)) || str_to_time_with_warn(res, ltime);
1831 DBUG_ASSERT(!is_null());
1832 return get_date(<ime, TIME_FUZZY_DATE) ||
1833 datetime_to_timeval(current_thd, <ime, tm, warnings);
1846 ASSERT_COLUMN_MARKED_FOR_WRITE;
1847 char buff[MAX_DATE_STRING_REP_LENGTH];
1848 uint length= (uint) my_TIME_to_str(ltime, buff,
1849 MY_MIN(dec_arg, DATETIME_MAX_DECIMALS));
1851 return store(buff, length, (charset()->state & MY_CS_NONASCII) ?
1852 &my_charset_latin1 : charset());
1856 bool Field::optimize_range(uint idx, uint part)
1858 return test(table->file->index_flags(idx, part, 1) & HA_READ_RANGE);
1863 bool keep_type __attribute__((unused)))
1869 if (tmp->table->maybe_null)
1870 tmp->flags&= ~NOT_NULL_FLAG;
1871 tmp->table= new_table;
1872 tmp->key_start.init(0);
1873 tmp->part_of_key.init(0);
1874 tmp->part_of_sortkey.init(0);
1881 tmp->unireg_check= Field::NONE;
1882 tmp->flags&= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG |
1883 ZEROFILL_FLAG | BINARY_FLAG | ENUM_FLAG | SET_FLAG);
1884 tmp->reset_fields();
1890 uchar *new_ptr, uchar *new_null_ptr,
1894 if ((tmp= new_field(root, new_table, table == new_table)))
1898 tmp->null_bit= new_null_bit;
1905 if (has_insert_default_function())
1911 if (has_update_default_function())
1919 void Field_null::sql_type(
String &res)
const
1921 res.set_ascii(STRING_WITH_LEN(
"null"));
1930 type_conversion_status Field_decimal::reset(
void)
1932 Field_decimal::store(STRING_WITH_LEN(
"0"),&my_charset_bin);
1936 void Field_decimal::overflow(
bool negative)
1938 uint len=field_length;
1939 uchar *to=ptr, filler=
'9';
1941 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1959 uint whole_part=field_length- (dec ? dec+2 : 1);
1961 memset(to,
' ', whole_part);
1968 memset(to, filler, len);
1970 ptr[field_length-dec-1]=
'.';
1975 type_conversion_status Field_decimal::store(
const char *from_arg, uint len,
1978 ASSERT_COLUMN_MARKED_FOR_WRITE;
1979 char buff[STRING_BUFFER_USUAL_SIZE];
1980 String tmp(buff,
sizeof(buff), &my_charset_bin);
1981 const uchar *from= (uchar*) from_arg;
1984 if (cs->mbmaxlen > 1)
1987 tmp.copy((
char*) from, len, cs, &my_charset_bin, &dummy_errors);
1988 from= (uchar*) tmp.ptr();
1992 const uchar *end= from+len;
1995 uint tmp_dec, tmp_uint;
2002 const uchar *pre_zeros_from, *pre_zeros_end;
2004 const uchar *int_digits_from, *int_digits_end;
2006 const uchar *frac_digits_from, *frac_digits_end;
2008 char expo_sign_char=0;
2014 const uchar *UNINIT_VAR(int_digits_tail_from);
2016 uint UNINIT_VAR(int_digits_added_zeros);
2021 const uchar *UNINIT_VAR(frac_digits_head_end);
2023 uint UNINIT_VAR(frac_digits_added_zeros);
2024 uchar *pos,*tmp_left_pos,*tmp_right_pos;
2026 uchar *left_wall,*right_wall;
2032 bool is_cuted_fields_incr=0;
2046 while (from != end && my_isspace(&my_charset_bin,*from))
2050 set_warning(Sql_condition::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
2051 is_cuted_fields_incr=1;
2053 else if (*from ==
'+' || *from ==
'-')
2065 Field_decimal::overflow(1);
2066 return TYPE_WARN_OUT_OF_RANGE;
2072 #ifdef DONT_ALLOW_UNSIGNED_PLUS
2079 pre_zeros_from= from;
2080 for (; from!=end && *from ==
'0'; from++) ;
2081 pre_zeros_end=int_digits_from=from;
2083 for (; from != end && my_isdigit(&my_charset_bin, *from) ; from++) ;
2084 int_digits_end=from;
2085 if (from!=end && *from ==
'.')
2087 frac_digits_from= from;
2089 for (;from!=end && my_isdigit(&my_charset_bin, *from); from++) ;
2090 frac_digits_end=from;
2092 if (from != end && (*from ==
'e' || *from ==
'E'))
2095 if (from != end && (*from ==
'+' || *from ==
'-'))
2096 expo_sign_char= *from++;
2098 expo_sign_char=
'+';
2105 for (;from!=end && my_isdigit(&my_charset_bin, *from); from++)
2107 exponent=10*exponent+(*from-
'0');
2108 if (exponent>MAX_EXPONENT)
2120 if (table->in_use->count_cuted_fields)
2123 for (;from != end && my_isspace(&my_charset_bin, *from); from++) ;
2126 set_warning(Sql_condition::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
2127 is_cuted_fields_incr=1;
2159 if (!expo_sign_char)
2160 tmp_uint=tmp_dec+(uint)(int_digits_end-int_digits_from);
2161 else if (expo_sign_char ==
'-')
2163 tmp_uint=min(exponent,(uint)(int_digits_end-int_digits_from));
2164 frac_digits_added_zeros=exponent-tmp_uint;
2165 int_digits_end -= tmp_uint;
2166 frac_digits_head_end=int_digits_end+tmp_uint;
2167 tmp_uint=tmp_dec+(uint)(int_digits_end-int_digits_from);
2171 tmp_uint=min(exponent,(uint)(frac_digits_end-frac_digits_from));
2172 int_digits_added_zeros=exponent-tmp_uint;
2173 int_digits_tail_from=frac_digits_from;
2174 frac_digits_from=frac_digits_from+tmp_uint;
2180 if (int_digits_from == int_digits_end)
2186 for (; int_digits_tail_from != frac_digits_from &&
2187 *int_digits_tail_from ==
'0'; int_digits_tail_from++) ;
2188 if (int_digits_tail_from == frac_digits_from)
2191 int_digits_added_zeros=0;
2194 tmp_uint= (uint) (tmp_dec+(int_digits_end-int_digits_from)+
2195 (uint)(frac_digits_from-int_digits_tail_from)+
2196 int_digits_added_zeros);
2207 if (field_length < tmp_uint + (
int) (sign_char ==
'-'))
2210 Field_decimal::overflow(sign_char ==
'-');
2211 return TYPE_WARN_OUT_OF_RANGE;
2218 tmp_left_pos=pos=to+(uint)(field_length-tmp_uint);
2221 while (int_digits_from != int_digits_end)
2222 *pos++ = *int_digits_from++ ;
2224 if (expo_sign_char ==
'+')
2226 while (int_digits_tail_from != frac_digits_from)
2227 *pos++= *int_digits_tail_from++;
2228 while (int_digits_added_zeros-- >0)
2246 while (pos > left_wall)
2251 left_wall=to+(sign_char != 0)-1;
2252 if (!expo_sign_char)
2254 for (;pos > left_wall && pre_zeros_from !=pre_zeros_end;
2258 if (pos == tmp_right_pos-1)
2261 if (sign_char && pos != left_wall)
2266 while (pos != left_wall)
2279 pos=to+(uint)(field_length-tmp_dec);
2280 right_wall=to+field_length;
2281 if (pos != right_wall)
2284 if (expo_sign_char ==
'-')
2286 while (frac_digits_added_zeros-- > 0)
2288 if (pos == right_wall)
2290 if (table->in_use->count_cuted_fields && !is_cuted_fields_incr)
2296 while (int_digits_end != frac_digits_head_end)
2298 tmp_char= *int_digits_end++;
2299 if (pos == right_wall)
2301 if (tmp_char !=
'0')
2303 if (!is_cuted_fields_incr)
2305 WARN_DATA_TRUNCATED, 1);
2314 for (;frac_digits_from!=frac_digits_end;)
2316 tmp_char= *frac_digits_from++;
2317 if (pos == right_wall)
2319 if (tmp_char !=
'0')
2321 if (!is_cuted_fields_incr)
2327 set_warning(Sql_condition::WARN_LEVEL_NOTE, WARN_DATA_TRUNCATED, 1);
2336 while (pos != right_wall)
2342 type_conversion_status Field_decimal::store(
double nr)
2344 ASSERT_COLUMN_MARKED_FOR_WRITE;
2345 if (unsigned_flag && nr < 0)
2348 return TYPE_WARN_OUT_OF_RANGE;
2354 return TYPE_WARN_OUT_OF_RANGE;
2360 char buff[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
2362 fyllchar = zerofill ? (char)
'0' : (
char)
' ';
2363 length= my_fcvt(nr, dec, buff, NULL);
2365 if (length > field_length)
2368 return TYPE_WARN_OUT_OF_RANGE;
2373 for (i=field_length-length ; i-- > 0 ;)
2375 memcpy(to,buff,length);
2381 type_conversion_status Field_decimal::store(longlong nr,
bool unsigned_val)
2383 ASSERT_COLUMN_MARKED_FOR_WRITE;
2385 uint length, int_part;
2389 if (nr < 0 && unsigned_flag && !unsigned_val)
2392 return TYPE_WARN_OUT_OF_RANGE;
2394 length= (uint) (longlong10_to_str(nr,buff,unsigned_val ? 10 : -10) - buff);
2395 int_part= field_length- (dec ? dec+1 : 0);
2397 if (length > int_part)
2399 overflow(!unsigned_val && nr < 0L);
2400 return TYPE_WARN_OUT_OF_RANGE;
2403 fyllchar = zerofill ? (char)
'0' : (
char)
' ';
2405 for (uint i=int_part-length ; i-- > 0 ;)
2407 memcpy(to,buff,length);
2411 memset(to + length + 1,
'0', dec);
2417 double Field_decimal::val_real(
void)
2419 ASSERT_COLUMN_MARKED_FOR_READ;
2422 return my_strntod(&my_charset_bin, (
char*) ptr, field_length, &end_not_used,
2426 longlong Field_decimal::val_int(
void)
2428 ASSERT_COLUMN_MARKED_FOR_READ;
2431 return my_strntoull(&my_charset_bin, (
char*) ptr, field_length, 10, NULL,
2433 return my_strntoll(&my_charset_bin, (
char*) ptr, field_length, 10, NULL,
2438 String *Field_decimal::val_str(
String *val_buffer __attribute__((unused)),
2441 ASSERT_COLUMN_MARKED_FOR_READ;
2445 for (str=ptr ; *str ==
' ' ; str++) ;
2446 val_ptr->set_charset(&my_charset_numeric);
2447 tmp_length= (size_t) (str-ptr);
2448 if (field_length < tmp_length)
2451 val_ptr->set_ascii((
const char*) str, field_length-tmp_length);
2465 for (end=a_ptr+field_length;
2467 (*a_ptr == *b_ptr ||
2468 ((my_isspace(&my_charset_bin,*a_ptr) || *a_ptr ==
'+' ||
2470 (my_isspace(&my_charset_bin,*b_ptr) || *b_ptr ==
'+' ||
2484 while (a_ptr != end)
2486 if (*a_ptr++ != *b_ptr++)
2487 return swap ^ (a_ptr[-1] < b_ptr[-1] ? -1 : 1);
2496 for (str=ptr,end=ptr+length;
2498 ((my_isspace(&my_charset_bin,*str) || *str ==
'+' ||
2510 if (my_isdigit(&my_charset_bin,*str))
2511 *to++= (
char) (
'9' - *str++);
2515 else memcpy(to,str,(uint) (end-str));
2519 void Field_decimal::sql_type(
String &res)
const
2522 uint tmp=field_length;
2527 res.length(cs->cset->snprintf(cs,(
char*) res.ptr(),res.alloced_length(),
2528 "decimal(%d,%d)",tmp,dec));
2529 add_zerofill_and_unsigned(res);
2537 Field_new_decimal::Field_new_decimal(uchar *ptr_arg,
2538 uint32 len_arg, uchar *null_ptr_arg,
2540 enum utype unireg_check_arg,
2541 const char *field_name_arg,
2542 uint8 dec_arg,
bool zero_arg,
2544 :
Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
2545 unireg_check_arg, field_name_arg, dec_arg, zero_arg, unsigned_arg)
2547 precision= my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
2550 (dec <= DECIMAL_MAX_SCALE));
2551 bin_size= my_decimal_get_binary_size(precision, dec);
2555 Field_new_decimal::Field_new_decimal(uint32 len_arg,
2556 bool maybe_null_arg,
2561 maybe_null_arg ? (uchar*)
"": 0, 0,
2562 NONE, name, dec_arg, 0, unsigned_arg)
2564 precision= my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
2567 (dec <= DECIMAL_MAX_SCALE));
2568 bin_size= my_decimal_get_binary_size(precision, dec);
2572 Field *Field_new_decimal::create_from_item (
Item *item)
2574 uint8 dec= item->decimals;
2575 uint8 intg= item->decimal_precision() - dec;
2576 uint32 len= item->max_char_length();
2578 DBUG_ASSERT (item->result_type() == DECIMAL_RESULT);
2588 signed int overflow;
2590 dec= min<int>(dec, DECIMAL_MAX_SCALE);
2599 const int required_length=
2600 my_decimal_precision_to_length(intg + dec, dec,
2601 item->unsigned_flag);
2603 overflow= required_length - len;
2606 dec= max(0, dec - overflow);
2609 len= required_length;
2612 dec, item->unsigned_flag);
2616 type_conversion_status Field_new_decimal::reset(
void)
2633 DBUG_ENTER(
"Field_new_decimal::set_value_on_overflow");
2634 max_my_decimal(decimal_value, precision, decimals());
2638 my_decimal_set_zero(decimal_value);
2640 decimal_value->sign(TRUE);
2660 type_conversion_status
2663 ASSERT_COLUMN_MARKED_FOR_WRITE;
2664 type_conversion_status error= TYPE_OK;
2665 DBUG_ENTER(
"Field_new_decimal::store_value");
2669 DBUG_PRINT(
"enter", (
"value: %s", dbug_decimal_as_string(dbug_buff, decimal_value)));
2674 if (unsigned_flag && decimal_value->sign())
2676 DBUG_PRINT(
"info", (
"unsigned overflow"));
2677 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2678 error= TYPE_WARN_OUT_OF_RANGE;
2679 decimal_value= &decimal_zero;
2684 DBUG_PRINT(
"info", (
"saving with precision %d scale: %d value %s",
2685 (
int)precision, (
int)dec,
2686 dbug_decimal_as_string(dbug_buff, decimal_value)));
2690 int err= my_decimal2binary(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW,
2691 decimal_value, ptr, precision, dec);
2695 DBUG_PRINT(
"info", (
"overflow"));
2697 my_decimal2binary(E_DEC_FATAL_ERROR, &buff, ptr, precision, dec);
2699 DBUG_EXECUTE(
"info", print_decimal_buff(decimal_value, (uchar *) ptr,
2701 DBUG_RETURN((err != E_DEC_OK) ? decimal_err_to_type_conv_status(err)
2706 type_conversion_status
2707 Field_new_decimal::store(
const char *from, uint length,
2710 ASSERT_COLUMN_MARKED_FOR_WRITE;
2712 DBUG_ENTER(
"Field_new_decimal::store(char*)");
2714 int err= str2my_decimal(E_DEC_FATAL_ERROR &
2715 ~(E_DEC_OVERFLOW | E_DEC_BAD_NUM),
2716 from, length, charset_arg,
2719 if (err != 0 && table->in_use->abort_on_warning)
2723 push_warning_printf(table->in_use, Sql_condition::WARN_LEVEL_WARN,
2724 ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
2725 ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
2726 "decimal", errmsg.ptr(), field_name,
2727 static_cast<ulong
>(da->current_row_for_warning()));
2728 DBUG_RETURN(decimal_err_to_type_conv_status(err));
2732 set_decimal_warning(
this, err, &decimal_value, from, length, charset_arg);
2736 DBUG_PRINT(
"enter", (
"value: %s",
2737 dbug_decimal_as_string(dbug_buff, &decimal_value)));
2740 type_conversion_status store_stat=
store_value(&decimal_value);
2741 DBUG_RETURN(err != 0 ? decimal_err_to_type_conv_status(err) : store_stat);
2745 type_conversion_status
2749 type_conversion_status stat= TYPE_OK;
2752 if (field->check_overflow(err))
2755 stat= TYPE_WARN_OUT_OF_RANGE;
2757 else if (field->check_truncated(err))
2758 stat= TYPE_NOTE_TRUNCATED;
2760 field->table->in_use->got_warning= 0;
2762 type_conversion_status store_stat= field->
store_value(value);
2763 if (store_stat != TYPE_OK)
2765 else if (err != 0 && !field->table->in_use->got_warning)
2776 type_conversion_status Field_new_decimal::store(
double nr)
2778 ASSERT_COLUMN_MARKED_FOR_WRITE;
2779 DBUG_ENTER(
"Field_new_decimal::store(double)");
2782 int conv_err= double2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW, nr,
2784 DBUG_RETURN(store_internal_with_error_check(
this, conv_err, &decimal_value));
2787 type_conversion_status
2788 Field_new_decimal::store(longlong nr,
bool unsigned_val)
2790 ASSERT_COLUMN_MARKED_FOR_WRITE;
2791 DBUG_ENTER(
"Field_new_decimal::store(double, unsigned_val)");
2793 int conv_err= int2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW,
2794 nr, unsigned_val, &decimal_value);
2795 DBUG_RETURN(store_internal_with_error_check(
this, conv_err, &decimal_value));
2799 type_conversion_status
2802 ASSERT_COLUMN_MARKED_FOR_WRITE;
2807 type_conversion_status
2809 uint8 dec_arg __attribute__((unused)))
2812 return store_value(date2my_decimal(ltime, &decimal_value));
2816 double Field_new_decimal::val_real(
void)
2818 ASSERT_COLUMN_MARKED_FOR_READ;
2821 my_decimal2double(E_DEC_FATAL_ERROR,
val_decimal(&decimal_value), &dbl);
2826 longlong Field_new_decimal::val_int(
void)
2828 ASSERT_COLUMN_MARKED_FOR_READ;
2831 my_decimal2int(E_DEC_FATAL_ERROR,
val_decimal(&decimal_value),
2839 ASSERT_COLUMN_MARKED_FOR_READ;
2840 DBUG_ENTER(
"Field_new_decimal::val_decimal");
2841 binary2my_decimal(E_DEC_FATAL_ERROR, ptr, decimal_value,
2843 DBUG_EXECUTE(
"info", print_decimal_buff(decimal_value, (uchar *) ptr,
2845 DBUG_RETURN(decimal_value);
2850 String *val_ptr __attribute__((unused)))
2852 ASSERT_COLUMN_MARKED_FOR_READ;
2854 uint fixed_precision= zerofill ? precision : 0;
2855 my_decimal2string(E_DEC_FATAL_ERROR,
val_decimal(&decimal_value),
2856 fixed_precision, dec,
'0', val_buffer);
2857 val_buffer->set_charset(&my_charset_numeric);
2862 bool Field_new_decimal::get_date(
MYSQL_TIME *ltime, uint fuzzydate)
2867 set_zero_time(ltime, MYSQL_TIMESTAMP_DATETIME);
2870 return my_decimal_to_datetime_with_warn(decimal_value, ltime, fuzzydate);
2874 bool Field_new_decimal::get_time(
MYSQL_TIME *ltime)
2879 set_zero_time(ltime, MYSQL_TIMESTAMP_TIME);
2882 return my_decimal_to_time_with_warn(decimal_value, ltime);
2886 int Field_new_decimal::cmp(
const uchar *a,
const uchar*b)
2888 return memcmp(a, b, bin_size);
2894 memcpy(buff, ptr, min<uint>(length, bin_size));
2898 void Field_new_decimal::sql_type(
String &str)
const
2901 str.length(cs->cset->snprintf(cs, (
char*) str.ptr(), str.alloced_length(),
2902 "decimal(%d,%d)", precision, (int)dec));
2903 add_zerofill_and_unsigned(str);
2918 int Field_new_decimal::do_save_field_metadata(uchar *metadata_ptr)
2920 *metadata_ptr= precision;
2921 *(metadata_ptr + 1)= decimals();
2940 uint
const source_precision= (field_metadata >> 8
U) & 0x00ff;
2941 uint
const source_decimal= field_metadata & 0x00ff;
2942 uint
const source_size= my_decimal_get_binary_size(source_precision,
2944 return (source_size);
2964 uint16 mflags __attribute__((unused)),
2967 uint
const source_precision= (field_metadata >> 8
U) & 0x00ff;
2968 uint
const source_decimal= field_metadata & 0x00ff;
2969 int order=
compare(source_precision, precision);
2970 *order_var= order != 0 ? order :
compare(source_decimal, dec);
2977 return ((new_field->sql_type == real_type()) &&
2978 ((new_field->flags & UNSIGNED_FLAG) ==
2979 (uint) (flags & UNSIGNED_FLAG)) &&
2980 ((new_field->flags & AUTO_INCREMENT_FLAG) ==
2981 (uint) (flags & AUTO_INCREMENT_FLAG)) &&
2982 (new_field->length == max_display_length()) &&
2983 (new_field->decimals == dec));
3003 bool low_byte_first)
3005 if (param_data == 0)
3008 uint from_precision= (param_data & 0xff00) >> 8
U;
3009 uint from_decimal= param_data & 0x00ff;
3010 uint length=pack_length();
3011 uint from_pack_len= my_decimal_get_binary_size(from_precision, from_decimal);
3012 uint len= (param_data && (from_pack_len < length)) ?
3013 from_pack_len : length;
3014 if ((from_pack_len && (from_pack_len < length)) ||
3015 (from_precision < precision) ||
3016 (from_decimal < decimals()))
3025 dec_val.len= from_precision;
3026 dec_val.buf= dec_buf;
3032 bin2decimal((uchar *)from, &dec_val, from_precision, from_decimal);
3033 decimal2bin(&dec_val, to, precision, decimals());
3036 memcpy(to, from, len);
3044 type_conversion_status
3045 Field_tiny::store(
const char *from,uint len,
const CHARSET_INFO *cs)
3047 ASSERT_COLUMN_MARKED_FOR_WRITE;
3050 const type_conversion_status error= get_int(cs, from, len, &rnd,
3052 ptr[0]= unsigned_flag ? (char) (ulonglong) rnd : (
char) rnd;
3057 type_conversion_status
Field_tiny::store(
double nr)
3059 ASSERT_COLUMN_MARKED_FOR_WRITE;
3060 type_conversion_status error= TYPE_OK;
3067 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3068 error= TYPE_WARN_OUT_OF_RANGE;
3070 else if (nr > 255.0)
3073 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3074 error= TYPE_WARN_OUT_OF_RANGE;
3084 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3085 error= TYPE_WARN_OUT_OF_RANGE;
3087 else if (nr > 127.0)
3090 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3091 error= TYPE_WARN_OUT_OF_RANGE;
3094 *ptr=(char) (
int) nr;
3100 type_conversion_status Field_tiny::store(longlong nr,
bool unsigned_val)
3102 ASSERT_COLUMN_MARKED_FOR_WRITE;
3103 type_conversion_status error= TYPE_OK;
3107 if (nr < 0 && !unsigned_val)
3110 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3111 error= TYPE_WARN_OUT_OF_RANGE;
3113 else if ((ulonglong) nr > (ulonglong) 255)
3116 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3117 error= TYPE_WARN_OUT_OF_RANGE;
3124 if (nr < 0 && unsigned_val)
3129 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3130 error= TYPE_WARN_OUT_OF_RANGE;
3135 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3136 error= TYPE_WARN_OUT_OF_RANGE;
3145 double Field_tiny::val_real(
void)
3147 ASSERT_COLUMN_MARKED_FOR_READ;
3148 int tmp= unsigned_flag ? (int) ptr[0] :
3149 (
int) ((
signed char*) ptr)[0];
3150 return (
double) tmp;
3154 longlong Field_tiny::val_int(
void)
3156 ASSERT_COLUMN_MARKED_FOR_READ;
3157 int tmp= unsigned_flag ? (int) ptr[0] :
3158 (
int) ((
signed char*) ptr)[0];
3159 return (longlong) tmp;
3164 String *val_ptr __attribute__((unused)))
3166 ASSERT_COLUMN_MARKED_FOR_READ;
3169 uint mlength=max(field_length+1,5*cs->mbmaxlen);
3170 val_buffer->alloc(mlength);
3171 char *to=(
char*) val_buffer->ptr();
3174 length= (uint) cs->cset->long10_to_str(cs,to,mlength, 10,
3177 length= (uint) cs->cset->long10_to_str(cs,to,mlength,-10,
3178 (
long) *((
signed char*) ptr));
3180 val_buffer->length(length);
3182 prepend_zeros(val_buffer);
3183 val_buffer->set_charset(cs);
3187 bool Field_tiny::send_binary(
Protocol *protocol)
3189 return protocol->store_tiny((longlong) (int8) ptr[0]);
3192 int Field_tiny::cmp(
const uchar *a_ptr,
const uchar *b_ptr)
3195 a=(
signed char) a_ptr[0]; b= (
signed char) b_ptr[0];
3197 return ((uchar) a < (uchar) b) ? -1 : ((uchar) a > (uchar) b) ? 1 : 0;
3198 return (a < b) ? -1 : (a > b) ? 1 : 0;
3203 DBUG_ASSERT(length >= 1);
3207 to[0] = (char) (ptr[0] ^ (uchar) 128);
3210 void Field_tiny::sql_type(
String &res)
const
3213 res.length(cs->cset->snprintf(cs,(
char*) res.ptr(),res.alloced_length(),
3214 "tinyint(%d)",(int) field_length));
3215 add_zerofill_and_unsigned(res);
3222 type_conversion_status
3223 Field_short::store(
const char *from,uint len,
const CHARSET_INFO *cs)
3225 ASSERT_COLUMN_MARKED_FOR_WRITE;
3229 const type_conversion_status error=
3230 get_int(cs, from, len, &rnd, UINT_MAX16, INT_MIN16, INT_MAX16);
3231 store_tmp= unsigned_flag ? (int) (ulonglong) rnd : (
int) rnd;
3232 #ifdef WORDS_BIGENDIAN
3233 if (table->s->db_low_byte_first)
3235 int2store(ptr, store_tmp);
3239 shortstore(ptr, (
short) store_tmp);
3244 type_conversion_status Field_short::store(
double nr)
3246 ASSERT_COLUMN_MARKED_FOR_WRITE;
3247 type_conversion_status error= TYPE_OK;
3255 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3256 error= TYPE_WARN_OUT_OF_RANGE;
3258 else if (nr > (
double) UINT_MAX16)
3260 res=(int16) UINT_MAX16;
3261 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3262 error= TYPE_WARN_OUT_OF_RANGE;
3265 res=(int16) (uint16) nr;
3269 if (nr < (
double) INT_MIN16)
3272 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3273 error= TYPE_WARN_OUT_OF_RANGE;
3275 else if (nr > (
double) INT_MAX16)
3278 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3279 error= TYPE_WARN_OUT_OF_RANGE;
3282 res=(int16) (
int) nr;
3284 #ifdef WORDS_BIGENDIAN
3285 if (table->s->db_low_byte_first)
3291 shortstore(ptr,res);
3296 type_conversion_status Field_short::store(longlong nr,
bool unsigned_val)
3298 ASSERT_COLUMN_MARKED_FOR_WRITE;
3299 type_conversion_status error= TYPE_OK;
3304 if (nr < 0L && !unsigned_val)
3307 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3308 error= TYPE_WARN_OUT_OF_RANGE;
3310 else if ((ulonglong) nr > (ulonglong) UINT_MAX16)
3312 res=(int16) UINT_MAX16;
3313 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3314 error= TYPE_WARN_OUT_OF_RANGE;
3317 res=(int16) (uint16) nr;
3321 if (nr < 0 && unsigned_val)
3327 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3328 error= TYPE_WARN_OUT_OF_RANGE;
3330 else if (nr > (longlong) INT_MAX16)
3333 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3334 error= TYPE_WARN_OUT_OF_RANGE;
3339 #ifdef WORDS_BIGENDIAN
3340 if (table->s->db_low_byte_first)
3346 shortstore(ptr,res);
3351 double Field_short::val_real(
void)
3353 ASSERT_COLUMN_MARKED_FOR_READ;
3355 #ifdef WORDS_BIGENDIAN
3356 if (table->s->db_low_byte_first)
3361 return unsigned_flag ? (double) (
unsigned short) j : (double) j;
3364 longlong Field_short::val_int(
void)
3366 ASSERT_COLUMN_MARKED_FOR_READ;
3368 #ifdef WORDS_BIGENDIAN
3369 if (table->s->db_low_byte_first)
3374 return unsigned_flag ? (longlong) (
unsigned short) j : (longlong) j;
3379 String *val_ptr __attribute__((unused)))
3381 ASSERT_COLUMN_MARKED_FOR_READ;
3384 uint mlength=max(field_length+1,7*cs->mbmaxlen);
3385 val_buffer->alloc(mlength);
3386 char *to=(
char*) val_buffer->ptr();
3388 #ifdef WORDS_BIGENDIAN
3389 if (table->s->db_low_byte_first)
3396 length=(uint) cs->cset->long10_to_str(cs, to, mlength, 10,
3399 length=(uint) cs->cset->long10_to_str(cs, to, mlength,-10, (
long) j);
3400 val_buffer->length(length);
3402 prepend_zeros(val_buffer);
3403 val_buffer->set_charset(cs);
3408 bool Field_short::send_binary(
Protocol *protocol)
3410 return protocol->store_short(Field_short::val_int());
3414 int Field_short::cmp(
const uchar *a_ptr,
const uchar *b_ptr)
3417 #ifdef WORDS_BIGENDIAN
3418 if (table->s->db_low_byte_first)
3431 return ((
unsigned short) a < (
unsigned short) b) ? -1 :
3432 ((
unsigned short) a > (
unsigned short) b) ? 1 : 0;
3433 return (a < b) ? -1 : (a > b) ? 1 : 0;
3438 DBUG_ASSERT(length >= 2);
3439 #ifdef WORDS_BIGENDIAN
3440 if (!table->s->db_low_byte_first)
3445 to[0] = (char) (ptr[0] ^ 128);
3454 to[0] = (char) (ptr[1] ^ 128);
3459 void Field_short::sql_type(
String &res)
const
3462 res.length(cs->cset->snprintf(cs,(
char*) res.ptr(),res.alloced_length(),
3463 "smallint(%d)",(int) field_length));
3464 add_zerofill_and_unsigned(res);
3472 type_conversion_status Field_medium::store(
const char *from,uint len,
3475 ASSERT_COLUMN_MARKED_FOR_WRITE;
3479 const type_conversion_status error=
3480 get_int(cs, from, len, &rnd, UINT_MAX24, INT_MIN24, INT_MAX24);
3481 store_tmp= unsigned_flag ? (int) (ulonglong) rnd : (
int) rnd;
3482 int3store(ptr, store_tmp);
3489 ASSERT_COLUMN_MARKED_FOR_WRITE;
3490 type_conversion_status error= TYPE_OK;
3497 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3498 error= TYPE_WARN_OUT_OF_RANGE;
3500 else if (nr >= (
double) (
long) (1L << 24))
3502 uint32 tmp=(uint32) (1L << 24)-1L;
3504 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3505 error= TYPE_WARN_OUT_OF_RANGE;
3508 int3store(ptr,(uint32) nr);
3512 if (nr < (
double) INT_MIN24)
3514 long tmp=(long) INT_MIN24;
3516 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3517 error= TYPE_WARN_OUT_OF_RANGE;
3519 else if (nr > (
double) INT_MAX24)
3521 long tmp=(long) INT_MAX24;
3523 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3524 error= TYPE_WARN_OUT_OF_RANGE;
3527 int3store(ptr,(
long) nr);
3533 type_conversion_status Field_medium::store(longlong nr,
bool unsigned_val)
3535 ASSERT_COLUMN_MARKED_FOR_WRITE;
3536 type_conversion_status error= TYPE_OK;
3540 if (nr < 0 && !unsigned_val)
3543 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3544 error= TYPE_WARN_OUT_OF_RANGE;
3546 else if ((ulonglong) nr >= (ulonglong) (
long) (1L << 24))
3548 long tmp= (long) (1L << 24)-1L;
3550 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3551 error= TYPE_WARN_OUT_OF_RANGE;
3554 int3store(ptr,(uint32) nr);
3558 if (nr < 0 && unsigned_val)
3559 nr= (ulonglong) (
long) (1L << 24);
3561 if (nr < (longlong) INT_MIN24)
3563 long tmp= (long) INT_MIN24;
3565 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3566 error= TYPE_WARN_OUT_OF_RANGE;
3568 else if (nr > (longlong) INT_MAX24)
3570 long tmp=(long) INT_MAX24;
3572 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3573 error= TYPE_WARN_OUT_OF_RANGE;
3576 int3store(ptr,(
long) nr);
3582 double Field_medium::val_real(
void)
3584 ASSERT_COLUMN_MARKED_FOR_READ;
3585 long j= unsigned_flag ? (long) uint3korr(ptr) : sint3korr(ptr);
3590 longlong Field_medium::val_int(
void)
3592 ASSERT_COLUMN_MARKED_FOR_READ;
3593 long j= unsigned_flag ? (long) uint3korr(ptr) : sint3korr(ptr);
3594 return (longlong) j;
3599 String *val_ptr __attribute__((unused)))
3601 ASSERT_COLUMN_MARKED_FOR_READ;
3604 uint mlength=max(field_length+1,10*cs->mbmaxlen);
3605 val_buffer->alloc(mlength);
3606 char *to=(
char*) val_buffer->ptr();
3607 long j= unsigned_flag ? (long) uint3korr(ptr) : sint3korr(ptr);
3609 length=(uint) cs->cset->long10_to_str(cs,to,mlength,-10,j);
3610 val_buffer->length(length);
3612 prepend_zeros(val_buffer);
3613 val_buffer->set_charset(cs);
3618 bool Field_medium::send_binary(
Protocol *protocol)
3620 ASSERT_COLUMN_MARKED_FOR_READ;
3621 return protocol->store_long(Field_medium::val_int());
3625 int Field_medium::cmp(
const uchar *a_ptr,
const uchar *b_ptr)
3638 return (a < b) ? -1 : (a > b) ? 1 : 0;
3643 DBUG_ASSERT(length >= 3);
3647 to[0] = (uchar) (ptr[2] ^ 128);
3653 void Field_medium::sql_type(
String &res)
const
3656 res.length(cs->cset->snprintf(cs,(
char*) res.ptr(),res.alloced_length(),
3657 "mediumint(%d)",(int) field_length));
3658 add_zerofill_and_unsigned(res);
3665 type_conversion_status Field_long::store(
const char *from,uint len,
3668 ASSERT_COLUMN_MARKED_FOR_WRITE;
3672 const type_conversion_status error=
3673 get_int(cs, from, len, &rnd, UINT_MAX32, INT_MIN32, INT_MAX32);
3674 store_tmp= unsigned_flag ? (long) (ulonglong) rnd : (
long) rnd;
3675 #ifdef WORDS_BIGENDIAN
3676 if (table->s->db_low_byte_first)
3678 int4store(ptr, store_tmp);
3682 longstore(ptr, store_tmp);
3687 type_conversion_status Field_long::store(
double nr)
3689 ASSERT_COLUMN_MARKED_FOR_WRITE;
3690 type_conversion_status error= TYPE_OK;
3698 error= TYPE_WARN_OUT_OF_RANGE;
3700 else if (nr > (
double) UINT_MAX32)
3703 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3704 error= TYPE_WARN_OUT_OF_RANGE;
3707 res=(int32) (ulong) nr;
3711 if (nr < (
double) INT_MIN32)
3713 res=(int32) INT_MIN32;
3714 error= TYPE_WARN_OUT_OF_RANGE;
3716 else if (nr > (
double) INT_MAX32)
3718 res=(int32) INT_MAX32;
3719 error= TYPE_WARN_OUT_OF_RANGE;
3722 res=(int32) (longlong) nr;
3725 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3727 #ifdef WORDS_BIGENDIAN
3728 if (table->s->db_low_byte_first)
3748 type_conversion_status Field_long::store(longlong nr,
bool unsigned_val)
3750 ASSERT_COLUMN_MARKED_FOR_WRITE;
3751 type_conversion_status error= TYPE_OK;
3756 if (nr < 0 && !unsigned_val)
3759 error= TYPE_WARN_OUT_OF_RANGE;
3761 else if ((ulonglong) nr >= (LL(1) << 32))
3763 res=(int32) (uint32) ~0L;
3764 error= TYPE_WARN_OUT_OF_RANGE;
3767 res=(int32) (uint32) nr;
3771 if (nr < 0 && unsigned_val)
3773 nr= ((longlong) INT_MAX32) + 1;
3774 error= TYPE_WARN_OUT_OF_RANGE;
3776 if (nr < (longlong) INT_MIN32)
3778 res=(int32) INT_MIN32;
3779 error= TYPE_WARN_OUT_OF_RANGE;
3781 else if (nr > (longlong) INT_MAX32)
3783 res=(int32) INT_MAX32;
3784 error= TYPE_WARN_OUT_OF_RANGE;
3790 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3792 #ifdef WORDS_BIGENDIAN
3793 if (table->s->db_low_byte_first)
3804 double Field_long::val_real(
void)
3806 ASSERT_COLUMN_MARKED_FOR_READ;
3808 #ifdef WORDS_BIGENDIAN
3809 if (table->s->db_low_byte_first)
3814 return unsigned_flag ? (double) (uint32) j : (
double) j;
3819 ASSERT_COLUMN_MARKED_FOR_READ;
3822 DBUG_ASSERT(table->in_use == current_thd);
3823 #ifdef WORDS_BIGENDIAN
3824 if (table->s->db_low_byte_first)
3829 return unsigned_flag ? (longlong) (uint32) j : (longlong) j;
3833 String *val_ptr __attribute__((unused)))
3835 ASSERT_COLUMN_MARKED_FOR_READ;
3838 uint mlength=max(field_length+1,12*cs->mbmaxlen);
3839 val_buffer->alloc(mlength);
3840 char *to=(
char*) val_buffer->ptr();
3842 #ifdef WORDS_BIGENDIAN
3843 if (table->s->db_low_byte_first)
3850 length=cs->cset->long10_to_str(cs,to,mlength, 10,(
long) (uint32)j);
3852 length=cs->cset->long10_to_str(cs,to,mlength,-10,(
long) j);
3853 val_buffer->length(length);
3855 prepend_zeros(val_buffer);
3856 val_buffer->set_charset(cs);
3861 bool Field_long::send_binary(
Protocol *protocol)
3863 ASSERT_COLUMN_MARKED_FOR_READ;
3864 return protocol->store_long(Field_long::val_int());
3867 int Field_long::cmp(
const uchar *a_ptr,
const uchar *b_ptr)
3870 #ifdef WORDS_BIGENDIAN
3871 if (table->s->db_low_byte_first)
3883 return ((uint32) a < (uint32) b) ? -1 : ((uint32) a > (uint32) b) ? 1 : 0;
3884 return (a < b) ? -1 : (a > b) ? 1 : 0;
3889 DBUG_ASSERT(length >= 4);
3890 #ifdef WORDS_BIGENDIAN
3891 if (!table->s->db_low_byte_first)
3896 to[0] = (char) (ptr[0] ^ 128);
3907 to[0] = (char) (ptr[3] ^ 128);
3915 void Field_long::sql_type(
String &res)
const
3918 res.length(cs->cset->snprintf(cs,(
char*) res.ptr(),res.alloced_length(),
3919 "int(%d)",(int) field_length));
3920 add_zerofill_and_unsigned(res);
3927 type_conversion_status
3928 Field_longlong::store(
const char *from,uint len,
const CHARSET_INFO *cs)
3930 ASSERT_COLUMN_MARKED_FOR_WRITE;
3932 type_conversion_status error= TYPE_OK;
3936 tmp= cs->cset->strntoull10rnd(cs,from,len,unsigned_flag,&end,&conv_err);
3937 if (conv_err == MY_ERRNO_ERANGE)
3939 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3940 error= TYPE_WARN_OUT_OF_RANGE;
3942 else if (table->in_use->count_cuted_fields &&
3943 check_int(cs, from, len, end, conv_err))
3944 error= TYPE_WARN_OUT_OF_RANGE;
3948 #ifdef WORDS_BIGENDIAN
3949 if (table->s->db_low_byte_first)
3955 longlongstore(ptr,tmp);
3960 type_conversion_status Field_longlong::store(
double nr)
3962 ASSERT_COLUMN_MARKED_FOR_WRITE;
3963 type_conversion_status error= TYPE_OK;
3972 error= TYPE_WARN_OUT_OF_RANGE;
3974 else if (nr >= (
double) ULONGLONG_MAX)
3977 error= TYPE_WARN_OUT_OF_RANGE;
3980 res=(longlong) double2ulonglong(nr);
3984 if (nr <= (
double) LONGLONG_MIN)
3987 if (nr < (
double) LONGLONG_MIN)
3988 error= TYPE_WARN_OUT_OF_RANGE;
3990 else if (nr >= (
double) (ulonglong) LONGLONG_MAX)
3993 if (nr > (
double) LONGLONG_MAX)
3994 error= TYPE_WARN_OUT_OF_RANGE;
4000 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
4002 #ifdef WORDS_BIGENDIAN
4003 if (table->s->db_low_byte_first)
4009 longlongstore(ptr,res);
4014 type_conversion_status Field_longlong::store(longlong nr,
bool unsigned_val)
4016 ASSERT_COLUMN_MARKED_FOR_WRITE;
4017 type_conversion_status error= TYPE_OK;
4025 if (unsigned_flag != unsigned_val)
4027 nr= unsigned_flag ? (ulonglong) 0 : (ulonglong) LONGLONG_MAX;
4029 error= TYPE_WARN_OUT_OF_RANGE;
4033 #ifdef WORDS_BIGENDIAN
4034 if (table->s->db_low_byte_first)
4040 longlongstore(ptr,nr);
4045 double Field_longlong::val_real(
void)
4047 ASSERT_COLUMN_MARKED_FOR_READ;
4049 #ifdef WORDS_BIGENDIAN
4050 if (table->s->db_low_byte_first)
4060 ulonglong tmp= (ulonglong) j;
4061 return ulonglong2double(tmp);
4067 longlong Field_longlong::val_int(
void)
4069 ASSERT_COLUMN_MARKED_FOR_READ;
4071 #ifdef WORDS_BIGENDIAN
4072 if (table->s->db_low_byte_first)
4082 String *val_ptr __attribute__((unused)))
4086 uint mlength=max(field_length+1,22*cs->mbmaxlen);
4087 val_buffer->alloc(mlength);
4088 char *to=(
char*) val_buffer->ptr();
4090 #ifdef WORDS_BIGENDIAN
4091 if (table->s->db_low_byte_first)
4097 length=(uint) (cs->cset->longlong10_to_str)(cs,
to,mlength,
4098 unsigned_flag ? 10 : -10, j);
4099 val_buffer->length(length);
4101 prepend_zeros(val_buffer);
4102 val_buffer->set_charset(cs);
4107 bool Field_longlong::send_binary(
Protocol *protocol)
4109 ASSERT_COLUMN_MARKED_FOR_READ;
4110 return protocol->store_longlong(Field_longlong::val_int(), unsigned_flag);
4114 int Field_longlong::cmp(
const uchar *a_ptr,
const uchar *b_ptr)
4117 #ifdef WORDS_BIGENDIAN
4118 if (table->s->db_low_byte_first)
4126 longlongget(a,a_ptr);
4127 longlongget(b,b_ptr);
4130 return ((ulonglong) a < (ulonglong) b) ? -1 :
4131 ((ulonglong) a > (ulonglong) b) ? 1 : 0;
4132 return (a < b) ? -1 : (a > b) ? 1 : 0;
4138 const int from_length= PACK_LENGTH;
4139 const int to_length= min<int>(from_length, length);
4140 #ifdef WORDS_BIGENDIAN
4141 if (table == NULL || !table->s->db_low_byte_first)
4142 copy_integer<true>(
to, to_length, ptr, from_length, unsigned_flag);
4145 copy_integer<false>(
to, to_length, ptr, from_length, unsigned_flag);
4149 void Field_longlong::sql_type(
String &res)
const
4152 res.length(cs->cset->snprintf(cs,(
char*) res.ptr(),res.alloced_length(),
4153 "bigint(%d)",(int) field_length));
4154 add_zerofill_and_unsigned(res);
4164 uint max_length,
bool low_byte_first)
4166 DBUG_ENTER(
"Field_real::pack");
4167 DBUG_ASSERT(max_length >= pack_length());
4168 #ifdef WORDS_BIGENDIAN
4169 if (low_byte_first != table->s->db_low_byte_first)
4171 const uchar *dptr= from + pack_length();
4172 while (dptr-- > from)
4178 DBUG_RETURN(
Field::pack(to, from, max_length, low_byte_first));
4183 uint param_data,
bool low_byte_first)
4185 DBUG_ENTER(
"Field_real::unpack");
4186 #ifdef WORDS_BIGENDIAN
4187 if (low_byte_first != table->s->db_low_byte_first)
4189 const uchar *dptr= from + pack_length();
4190 while (dptr-- > from)
4192 DBUG_RETURN(from + pack_length());
4196 DBUG_RETURN(
Field::unpack(to, from, param_data, low_byte_first));
4200 type_conversion_status
4202 uint8 dec_arg __attribute__((unused)))
4204 double nr= TIME_to_double(ltime);
4205 return store(ltime->neg ? -nr : nr);
4213 type_conversion_status
4214 Field_float::store(
const char *from,uint len,
const CHARSET_INFO *cs)
4217 type_conversion_status err= TYPE_OK;
4219 double nr= my_strntod(cs,(
char*) from,len,&end,&conv_error);
4220 if (conv_error || (!len || ((uint) (end-from) != len &&
4221 table->in_use->count_cuted_fields)))
4224 (conv_error ? ER_WARN_DATA_OUT_OF_RANGE
4225 : WARN_DATA_TRUNCATED),
4227 err= conv_error ? TYPE_WARN_OUT_OF_RANGE : TYPE_WARN_TRUNCATED;
4229 Field_float::store(nr);
4234 type_conversion_status Field_float::store(
double nr)
4236 ASSERT_COLUMN_MARKED_FOR_WRITE;
4237 const type_conversion_status error=
4238 truncate(&nr, FLT_MAX) ? TYPE_WARN_OUT_OF_RANGE : TYPE_OK;
4242 #ifdef WORDS_BIGENDIAN
4243 if (table->s->db_low_byte_first)
4249 memcpy(ptr, &j,
sizeof(j));
4254 type_conversion_status Field_float::store(longlong nr,
bool unsigned_val)
4256 return Field_float::store(unsigned_val ? ulonglong2double((ulonglong) nr) :
4261 double Field_float::val_real(
void)
4263 ASSERT_COLUMN_MARKED_FOR_READ;
4265 #ifdef WORDS_BIGENDIAN
4266 if (table->s->db_low_byte_first)
4272 memcpy(&j, ptr,
sizeof(j));
4273 return ((
double) j);
4276 longlong Field_float::val_int(
void)
4279 #ifdef WORDS_BIGENDIAN
4280 if (table->s->db_low_byte_first)
4286 memcpy(&j, ptr,
sizeof(j));
4287 return (longlong) rint(j);
4292 String *val_ptr __attribute__((unused)))
4294 ASSERT_COLUMN_MARKED_FOR_READ;
4295 DBUG_ASSERT(!zerofill || field_length <= MAX_FIELD_CHARLENGTH);
4297 #ifdef WORDS_BIGENDIAN
4298 if (table->s->db_low_byte_first)
4304 memcpy(&nr, ptr,
sizeof(nr));
4307 if (val_buffer->alloc(to_length))
4309 my_error(ER_OUT_OF_RESOURCES, MYF(0));
4313 char *to=(
char*) val_buffer->ptr();
4316 if (dec >= NOT_FIXED_DEC)
4317 len= my_gcvt(nr, MY_GCVT_ARG_FLOAT, to_length - 1, to, NULL);
4325 len= my_fcvt(nr, dec, to, NULL);
4327 val_buffer->length((uint) len);
4329 prepend_zeros(val_buffer);
4330 val_buffer->set_charset(&my_charset_numeric);
4335 int Field_float::cmp(
const uchar *a_ptr,
const uchar *b_ptr)
4338 #ifdef WORDS_BIGENDIAN
4339 if (table->s->db_low_byte_first)
4347 memcpy(&a, a_ptr,
sizeof(
float));
4348 memcpy(&b, b_ptr,
sizeof(
float));
4350 return (a < b) ? -1 : (a > b) ? 1 : 0;
4353 #define FLT_EXP_DIG (sizeof(float)*8-FLT_MANT_DIG)
4357 DBUG_ASSERT(length >= 4);
4359 #ifdef WORDS_BIGENDIAN
4360 if (table->s->db_low_byte_first)
4366 memcpy(&nr, ptr, min<uint>(length,
sizeof(
float)));
4369 if (nr == (
float) 0.0)
4372 memset(tmp + 1, 0, min<uint>(length,
sizeof(nr) - 1));
4376 #ifdef WORDS_BIGENDIAN
4377 memcpy(tmp, &nr,
sizeof(nr));
4379 tmp[0]= ptr[3]; tmp[1]=ptr[2]; tmp[2]= ptr[1]; tmp[3]=ptr[0];
4384 for (i=0 ; i <
sizeof(nr); i++)
4385 tmp[i]= (uchar) (tmp[
i] ^ (uchar) 255);
4389 ushort exp_part=(((ushort) tmp[0] << 8) | (ushort) tmp[1] |
4391 exp_part+= (ushort) 1 << (16-1-FLT_EXP_DIG);
4392 tmp[0]= (uchar) (exp_part >> 8);
4393 tmp[1]= (uchar) exp_part;
4399 bool Field_float::send_binary(
Protocol *protocol)
4401 ASSERT_COLUMN_MARKED_FOR_READ;
4402 return protocol->
store((
float) Field_float::val_real(), dec, (
String*) 0);
4415 int Field_float::do_save_field_metadata(uchar *metadata_ptr)
4417 *metadata_ptr= pack_length();
4422 void Field_float::sql_type(
String &res)
const
4424 if (dec == NOT_FIXED_DEC)
4426 res.set_ascii(STRING_WITH_LEN(
"float"));
4431 res.length(cs->cset->snprintf(cs,(
char*) res.ptr(),res.alloced_length(),
4432 "float(%d,%d)",(int) field_length,dec));
4434 add_zerofill_and_unsigned(res);
4442 type_conversion_status
4443 Field_double::store(
const char *from,uint len,
const CHARSET_INFO *cs)
4446 type_conversion_status error= TYPE_OK;
4448 double nr= my_strntod(cs,(
char*) from, len, &end, &conv_error);
4449 if ((conv_error != 0) || (!len || ((uint) (end-from) != len &&
4450 table->in_use->count_cuted_fields)))
4453 (conv_error ? ER_WARN_DATA_OUT_OF_RANGE
4454 : WARN_DATA_TRUNCATED),
4456 error= conv_error ? TYPE_WARN_OUT_OF_RANGE : TYPE_WARN_TRUNCATED;
4458 Field_double::store(nr);
4463 type_conversion_status Field_double::store(
double nr)
4465 ASSERT_COLUMN_MARKED_FOR_WRITE;
4466 const type_conversion_status error=
4467 truncate(&nr, DBL_MAX) ? TYPE_WARN_OUT_OF_RANGE : TYPE_OK;
4469 #ifdef WORDS_BIGENDIAN
4470 if (table->s->db_low_byte_first)
4472 float8store(ptr,nr);
4476 doublestore(ptr,nr);
4481 type_conversion_status Field_double::store(longlong nr,
bool unsigned_val)
4483 return Field_double::store(unsigned_val ? ulonglong2double((ulonglong) nr) :
4493 bool Field_real::truncate(
double *nr,
double max_value)
4499 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
4502 else if (unsigned_flag && *nr < 0)
4505 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
4511 uint order= field_length - dec;
4512 uint step= array_elements(log_10) - 1;
4514 for (; order > step; order-= step)
4515 max_value*= log_10[step];
4516 max_value*= log_10[order];
4517 max_value-= 1.0 / log_10[dec];
4522 double tmp= rint((*nr - floor(*nr)) * log_10[dec]) / log_10[dec];
4523 *nr= floor(*nr) + tmp;
4527 if (*nr < -max_value)
4530 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
4533 else if (*nr > max_value)
4536 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
4547 my_decimal2double(E_DEC_FATAL_ERROR, dm, &dbl);
4551 double Field_double::val_real(
void)
4553 ASSERT_COLUMN_MARKED_FOR_READ;
4555 #ifdef WORDS_BIGENDIAN
4556 if (table->s->db_low_byte_first)
4566 longlong Field_double::val_int(
void)
4568 ASSERT_COLUMN_MARKED_FOR_READ;
4571 #ifdef WORDS_BIGENDIAN
4572 if (table->s->db_low_byte_first)
4580 if (j <= (
double) LONGLONG_MIN)
4582 res= (longlong) LONGLONG_MIN;
4585 if (j >= (
double) (ulonglong) LONGLONG_MAX)
4587 res= (longlong) LONGLONG_MAX;
4590 return (longlong) rint(j);
4594 char buf[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
4595 String tmp(buf,
sizeof(buf), &my_charset_latin1), *str;
4596 str= val_str(&tmp, 0);
4598 push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
4599 ER_TRUNCATED_WRONG_VALUE,
4600 ER(ER_TRUNCATED_WRONG_VALUE),
"INTEGER",
4609 ASSERT_COLUMN_MARKED_FOR_READ;
4610 double2my_decimal(E_DEC_FATAL_ERROR, val_real(), decimal_value);
4611 return decimal_value;
4615 bool Field_real::get_date(
MYSQL_TIME *ltime, uint fuzzydate)
4617 return my_double_to_datetime_with_warn(val_real(), ltime, fuzzydate);
4623 return my_double_to_time_with_warn(val_real(), ltime);
4628 String *val_ptr __attribute__((unused)))
4630 ASSERT_COLUMN_MARKED_FOR_READ;
4631 DBUG_ASSERT(!zerofill || field_length <= MAX_FIELD_CHARLENGTH);
4633 #ifdef WORDS_BIGENDIAN
4634 if (table->s->db_low_byte_first)
4641 uint to_length= DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE;
4642 if (val_buffer->alloc(to_length))
4644 my_error(ER_OUT_OF_RESOURCES, MYF(0));
4648 char *to=(
char*) val_buffer->ptr();
4651 if (dec >= NOT_FIXED_DEC)
4652 len= my_gcvt(nr, MY_GCVT_ARG_DOUBLE, to_length - 1, to, NULL);
4654 len= my_fcvt(nr, dec, to, NULL);
4656 val_buffer->length((uint) len);
4658 prepend_zeros(val_buffer);
4659 val_buffer->set_charset(&my_charset_numeric);
4663 bool Field_double::send_binary(
Protocol *protocol)
4665 return protocol->
store((
double) Field_double::val_real(), dec, (
String*) 0);
4669 int Field_double::cmp(
const uchar *a_ptr,
const uchar *b_ptr)
4672 #ifdef WORDS_BIGENDIAN
4673 if (table->s->db_low_byte_first)
4681 doubleget(a, a_ptr);
4682 doubleget(b, b_ptr);
4684 return (a < b) ? -1 : (a > b) ? 1 : 0;
4688 #define DBL_EXP_DIG (sizeof(double)*8-DBL_MANT_DIG)
4695 #ifdef WORDS_BIGENDIAN
4696 if (table->s->db_low_byte_first)
4706 change_double_for_sort(nr, buff);
4707 memcpy(to, buff, length);
4710 change_double_for_sort(nr, to);
4724 int Field_double::do_save_field_metadata(uchar *metadata_ptr)
4726 *metadata_ptr= pack_length();
4731 void Field_double::sql_type(
String &res)
const
4734 if (dec == NOT_FIXED_DEC)
4736 res.set_ascii(STRING_WITH_LEN(
"double"));
4740 res.length(cs->cset->snprintf(cs,(
char*) res.ptr(),res.alloced_length(),
4741 "double(%d,%d)",(int) field_length,dec));
4743 add_zerofill_and_unsigned(res);
4753 return new_field->sql_type == real_type() &&
4754 new_field->decimals == decimals();
4760 ASSERT_COLUMN_MARKED_FOR_READ;
4761 DBUG_ASSERT(decimals() == 0);
4762 int2my_decimal(E_DEC_FATAL_ERROR, val_int(), 0, decimal_value);
4763 return decimal_value;
4777 int cut_incremented= 0;
4778 timestamp_type ts_type= field_type_to_timestamp_type(type());
4780 if (warnings & MYSQL_TIME_WARN_TRUNCATED)
4782 set_datetime_warning(Sql_condition::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED,
4783 str, ts_type, !cut_incremented);
4786 if (warnings & (MYSQL_TIME_WARN_OUT_OF_RANGE | MYSQL_TIME_WARN_ZERO_DATE |
4787 MYSQL_TIME_WARN_ZERO_IN_DATE))
4789 set_datetime_warning(Sql_condition::WARN_LEVEL_WARN,
4790 ER_WARN_DATA_OUT_OF_RANGE,
4791 str, ts_type, !cut_incremented);
4794 if (warnings & MYSQL_TIME_WARN_INVALID_TIMESTAMP)
4796 set_datetime_warning(Sql_condition::WARN_LEVEL_WARN,
4797 ER_WARN_INVALID_TIMESTAMP,
4798 str, ts_type, !cut_incremented);
4801 if ((warnings & MYSQL_TIME_NOTE_TRUNCATED) &&
4802 !(warnings & MYSQL_TIME_WARN_TRUNCATED))
4804 set_datetime_warning(Sql_condition::WARN_LEVEL_NOTE, WARN_DATA_TRUNCATED,
4805 str, ts_type, !cut_incremented);
4812 ASSERT_COLUMN_MARKED_FOR_WRITE;
4815 type_conversion_status error= convert_number_to_TIME(nr, unsigned_val, 0,
4817 if (error == TYPE_OK || error == TYPE_NOTE_TRUNCATED)
4818 error= store_internal(<ime, &warnings);
4821 DBUG_ASSERT(warnings != 0);
4823 if (warnings & (MYSQL_TIME_WARN_ZERO_DATE |
4824 MYSQL_TIME_WARN_ZERO_IN_DATE) &&
4825 !current_thd->is_strict_mode())
4826 error= TYPE_NOTE_TIME_TRUNCATED;
4834 type_conversion_status
4837 ASSERT_COLUMN_MARKED_FOR_WRITE;
4838 type_conversion_status error;
4840 error= convert_number_to_TIME(lld->quot, 0, lld->rem, <ime, warnings);
4841 if (error == TYPE_OK || error == TYPE_NOTE_TRUNCATED)
4842 error= store_internal_with_round(<ime, warnings);
4843 else if (!*warnings)
4845 DBUG_ASSERT(warnings != 0);
4846 if (((*warnings & MYSQL_TIME_WARN_ZERO_DATE) != 0 ||
4847 (*warnings & MYSQL_TIME_WARN_ZERO_IN_DATE) != 0) &&
4848 !current_thd->is_strict_mode())
4849 error= TYPE_NOTE_TIME_TRUNCATED;
4858 ASSERT_COLUMN_MARKED_FOR_WRITE;
4862 my_decimal2lldiv_t(0, decimal, &lld);
4863 const type_conversion_status error= store_lldiv_t(&lld, &warnings);
4872 ASSERT_COLUMN_MARKED_FOR_WRITE;
4875 double2lldiv_t(nr, &lld);
4876 const type_conversion_status error= store_lldiv_t(&lld, &warnings);
4894 type_conversion_status
4897 ASSERT_COLUMN_MARKED_FOR_WRITE;
4898 type_conversion_status error= TYPE_OK;
4901 if (convert_str_to_TIME(str, len, cs, <ime, &status))
4908 if (status.warnings & (MYSQL_TIME_WARN_ZERO_DATE |
4909 MYSQL_TIME_WARN_ZERO_IN_DATE) &&
4910 !current_thd->is_strict_mode())
4911 error= TYPE_NOTE_TIME_TRUNCATED;
4913 error= TYPE_ERR_BAD_VALUE;
4917 error= time_warning_to_type_conversion_status(status.warnings);
4919 const type_conversion_status tmp_error= store_internal_with_round(<ime,
4923 if (tmp_error > error)
4926 if (status.warnings)
4944 longlong tmp= number_to_datetime(nr, ltime, date_flags(), warnings);
4959 if (get_date_internal(ltime))
4961 DBUG_ASSERT(type() == MYSQL_TYPE_TIMESTAMP);
4962 if (fuzzydate & TIME_NO_ZERO_DATE)
4964 set_zero_time(ltime, MYSQL_TIMESTAMP_DATETIME);
4972 ASSERT_COLUMN_MARKED_FOR_READ;
4974 return get_date_internal(<ime) ?
4975 0 : TIME_to_longlong_datetime_packed(<ime);
4985 ASSERT_COLUMN_MARKED_FOR_READ;
4987 return get_date_internal(<ime) ? 0 : TIME_to_longlong_time_packed(<ime);
4999 my_datetime_number_to_str(
char *pos, longlong tmp)
5001 long part1= (long) (tmp / 1000000LL);
5002 long part2= (long) (tmp - (ulonglong) part1 * 1000000LL);
5004 pos+= MAX_DATETIME_WIDTH;
5006 *pos--= (char) (
'0' + (
char) (part2 % 10));
5008 *pos--= (char) (
'0' + (
char) (part2 % 10));
5009 part3= (int) (part2 / 10);
5011 *pos--= (char) (
'0' + (
char) (part3 % 10));
5013 *pos--= (char) (
'0' + (
char) (part3 % 10));
5016 *pos--= (char) (
'0' + (
char) (part3 % 10));
5018 *pos--= (char) (
'0' + (
char) part3);
5020 *pos--= (char) (
'0' + (
char) (part1 % 10));
5022 *pos--= (char) (
'0' + (
char) (part1 % 10));
5025 *pos--= (char) (
'0' + (
char) (part1 % 10));
5027 *pos--= (char) (
'0' + (
char) (part1 % 10));
5028 part3= (int) (part1 / 10);
5030 *pos--= (char) (
'0' + (
char) (part3 % 10));
5032 *pos--= (char) (
'0' + (
char) (part3 % 10));
5034 *pos--= (char) (
'0' + (
char) (part3 % 10));
5036 *pos= (char) (
'0'+ (
char) part3);
5037 return MAX_DATETIME_WIDTH;
5043 ASSERT_COLUMN_MARKED_FOR_READ;
5045 val_buffer->alloc(field_length + 1);
5046 val_buffer->set_charset(&my_charset_numeric);
5047 if (get_date_internal(<ime))
5049 val_buffer->set_ascii(my_zero_datetime6, field_length);
5057 type_conversion_status
5064 if (nr < 0 || nanoseconds < 0)
5067 *warnings|= MYSQL_TIME_WARN_OUT_OF_RANGE;
5068 return TYPE_WARN_OUT_OF_RANGE;
5071 if (convert_number_to_datetime(nr, unsigned_val, ltime, warnings) == LL(-1))
5072 return TYPE_ERR_BAD_VALUE;
5074 if (ltime->time_type == MYSQL_TIMESTAMP_DATE && nanoseconds)
5076 *warnings|= MYSQL_TIME_WARN_TRUNCATED;
5077 return TYPE_NOTE_TRUNCATED;
5081 if (datetime_add_nanoseconds_with_round(ltime, nanoseconds, warnings))
5084 return TYPE_WARN_OUT_OF_RANGE;
5090 type_conversion_status
5092 uint8 dec_arg __attribute__((unused)))
5094 ASSERT_COLUMN_MARKED_FOR_WRITE;
5095 type_conversion_status error;
5098 switch (ltime->time_type)
5100 case MYSQL_TIMESTAMP_DATETIME:
5101 case MYSQL_TIMESTAMP_DATE:
5102 if (check_date(ltime, non_zero_date(ltime), date_flags(), &warnings))
5104 DBUG_ASSERT(warnings &
5105 (MYSQL_TIME_WARN_OUT_OF_RANGE |
5106 MYSQL_TIME_WARN_ZERO_DATE |
5107 MYSQL_TIME_WARN_ZERO_IN_DATE));
5109 error= time_warning_to_type_conversion_status(warnings);
5113 error= store_internal_with_round(ltime, &warnings);
5115 case MYSQL_TIMESTAMP_TIME:
5118 THD *thd= table ? table->in_use : current_thd;
5120 time_to_datetime(thd, ltime, <ime2);
5121 error= store_internal_with_round(<ime2, &warnings);
5124 case MYSQL_TIMESTAMP_NONE:
5125 case MYSQL_TIMESTAMP_ERROR:
5127 warnings|= MYSQL_TIME_WARN_TRUNCATED;
5129 error= TYPE_WARN_TRUNCATED;
5144 return str_to_datetime(cs, str, len, ltime, date_flags(), status);
5148 bool Field_temporal_with_date::send_binary(
Protocol *protocol)
5151 if (get_date_internal(<ime))
5154 DBUG_ASSERT(type() == MYSQL_TYPE_TIMESTAMP);
5155 set_zero_time(<ime, MYSQL_TIMESTAMP_DATETIME);
5157 return protocol->
store(<ime, 0);
5161 type_conversion_status
5165 if (my_datetime_round(ltime, dec, warnings))
5168 return time_warning_to_type_conversion_status(*warnings);
5171 return store_internal(ltime, warnings);
5184 type_conversion_status error= TYPE_OK;
5191 get_date_internal(<ime);
5192 if (check_date(<ime, non_zero_date(<ime), date_flags(), &warnings))
5193 error= time_warning_to_type_conversion_status(warnings);
5197 ltime.time_type = field_type_to_timestamp_type(type());
5212 ASSERT_COLUMN_MARKED_FOR_WRITE;
5213 if (!my_time_fraction_remainder(tm->tv_usec, decimals()))
5215 store_timestamp_internal(tm);
5219 my_timeval_round(&tm2, decimals());
5220 store_timestamp_internal(&tm2);
5225 Field_temporal_with_date_and_time::convert_TIME_to_timestamp(THD *thd,
5235 if (datetime_with_no_zero_in_date_to_timeval(thd, ltime, tm, warnings))
5237 tm->tv_sec= tm->tv_usec= 0;
5246 if (unireg_check != NONE)
5252 flags|= TIMESTAMP_FLAG;
5253 if (unireg_check != TIMESTAMP_DN_FIELD)
5254 flags|= ON_UPDATE_NOW_FLAG;
5262 double Field_temporal_with_date_and_timef::val_real()
5264 ASSERT_COLUMN_MARKED_FOR_READ;
5266 return get_date_internal(<ime) ? 0 : TIME_to_double_datetime(<ime);
5270 longlong Field_temporal_with_date_and_timef::val_int()
5272 ASSERT_COLUMN_MARKED_FOR_READ;
5274 return get_date_internal(<ime) ?
5275 0 : TIME_to_ulonglong_datetime_round(<ime);
5281 ASSERT_COLUMN_MARKED_FOR_READ;
5283 if (get_date_internal(<ime))
5286 DBUG_ASSERT(
type() == MYSQL_TYPE_TIMESTAMP);
5287 set_zero_time(<ime, MYSQL_TIMESTAMP_DATETIME);
5289 return date2my_decimal(<ime, dec);
5336 uchar *null_ptr_arg, uchar null_bit_arg,
5337 enum utype unireg_check_arg,
5338 const char *field_name_arg)
5340 unireg_check_arg, field_name_arg, 0)
5344 flags|= ZEROFILL_FLAG | UNSIGNED_FLAG;
5349 const char *field_name_arg)
5351 maybe_null_arg ? (uchar *)
"" : 0, 0,
5352 NONE, field_name_arg, 0)
5356 flags|= ZEROFILL_FLAG | UNSIGNED_FLAG;
5363 return (thd->variables.sql_mode & MODE_NO_ZERO_DATE) | MODE_NO_ZERO_IN_DATE;
5367 type_conversion_status
5370 THD *thd=
table ?
table->in_use : current_thd;
5372 convert_TIME_to_timestamp(thd, ltime, &tm, warnings);
5373 const type_conversion_status error=
5374 time_warning_to_type_conversion_status(*warnings);
5387 ASSERT_COLUMN_MARKED_FOR_READ;
5389 THD *thd=
table ?
table->in_use : current_thd;
5390 #ifdef WORDS_BIGENDIAN
5392 temp= uint4korr(ptr);
5398 thd->time_zone()->gmt_sec_to_TIME(ltime, (my_time_t) temp);
5411 #ifdef WORDS_BIGENDIAN
5414 tm->tv_sec= sint4korr(ptr);
5427 #ifdef WORDS_BIGENDIAN
5430 int4store(ptr, tm->tv_sec);
5434 longstore(ptr, (uint32) tm->tv_sec);
5441 DBUG_ASSERT((MY_PACKED_TIME_GET_FRAC_PART(nr) %
5442 (
int) log_10_int[DATETIME_MAX_DECIMALS - decimals()]) == 0);
5444 TIME_from_longlong_datetime_packed(<ime, nr);
5449 longlong Field_timestamp::val_int()
5451 ASSERT_COLUMN_MARKED_FOR_READ;
5457 bool Field_timestamp::get_date(
MYSQL_TIME *ltime, uint fuzzydate)
5464 int Field_timestamp::cmp(
const uchar *a_ptr,
const uchar *b_ptr)
5467 #ifdef WORDS_BIGENDIAN
5479 return ((uint32) a < (uint32) b) ? -1 : ((uint32) a > (uint32) b) ? 1 : 0;
5485 #ifdef WORDS_BIGENDIAN
5504 void Field_timestamp::sql_type(
String &res)
const
5506 res.set_ascii(STRING_WITH_LEN(
"timestamp"));
5517 if (!thd->variables.explicit_defaults_for_timestamp)
5531 uchar *null_ptr_arg, uchar null_bit_arg,
5532 enum utype unireg_check_arg,
5533 const char *field_name_arg,
5536 unireg_check_arg, field_name_arg,
5544 const char *field_name_arg,
5547 maybe_null_arg ? (uchar*)
"": 0, 0,
5548 NONE, field_name_arg, dec_arg)
5550 if (unireg_check != TIMESTAMP_DN_FIELD)
5551 flags|= ON_UPDATE_NOW_FLAG;
5558 return (thd->variables.sql_mode & MODE_NO_ZERO_DATE) | MODE_NO_ZERO_IN_DATE;
5562 type_conversion_status Field_timestampf::reset()
5564 memset(ptr, 0, pack_length());
5571 my_timestamp_to_binary(tm, ptr, dec);
5575 type_conversion_status
5578 THD *thd=
table ?
table->in_use : current_thd;
5580 convert_TIME_to_timestamp(thd, ltime, &tm, warnings);
5581 const type_conversion_status error=
5582 time_warning_to_type_conversion_status(*warnings);
5591 TIME_from_longlong_datetime_packed(<ime, nr);
5596 bool Field_timestampf::get_date(
MYSQL_TIME *ltime, uint fuzzydate)
5603 void Field_timestampf::sql_type(
String &res)
const
5607 res.set_ascii(STRING_WITH_LEN(
"timestamp"));
5611 res.length(cs->cset->snprintf(cs, (
char *) res.ptr(), res.alloced_length(),
5612 "timestamp(%d)", dec));
5619 THD *thd=
table ?
table->in_use : current_thd;
5621 my_timestamp_from_binary(&tm, ptr, dec);
5624 thd->time_zone()->gmt_sec_to_TIME(ltime, tm);
5631 THD *thd=
table ?
table->in_use : current_thd;
5632 thd->time_zone_used= 1;
5633 DBUG_ASSERT(!is_null());
5634 my_timestamp_from_binary(tm, ptr, dec);
5646 if (!thd->variables.explicit_defaults_for_timestamp)
5664 return str_to_time(cs, str, len, ltime, 0, status);
5668 type_conversion_status
5673 if (unsigned_val && nr < 0)
5675 *warnings|= MYSQL_TIME_WARN_OUT_OF_RANGE;
5676 set_max_time(ltime, 0);
5678 return TYPE_WARN_OUT_OF_RANGE;
5680 if (number_to_time(nr, ltime, warnings))
5683 return TYPE_WARN_OUT_OF_RANGE;
5689 if ((ltime->neg|= (nanoseconds < 0)))
5690 nanoseconds= -nanoseconds;
5692 bool round_error= time_add_nanoseconds_with_round(ltime, nanoseconds,
5695 return round_error ? time_warning_to_type_conversion_status(*warnings)
5700 type_conversion_status
5702 uint8 dec_arg __attribute__((unused)))
5705 if (ltime->second >= 60 || ltime->minute >= 60)
5708 MYSQL_TIME_WARN_OUT_OF_RANGE);
5710 return TYPE_WARN_OUT_OF_RANGE;
5717 type_conversion_status
5720 if (my_time_round(ltime, dec))
5721 return TYPE_WARN_OUT_OF_RANGE;
5728 String *val_ptr __attribute__((unused)))
5730 ASSERT_COLUMN_MARKED_FOR_READ;
5732 val_buffer->alloc(MAX_DATE_STRING_REP_LENGTH);
5733 val_buffer->set_charset(&my_charset_numeric);
5734 if (get_time(<ime))
5737 set_zero_time(<ime, MYSQL_TIMESTAMP_TIME);
5752 ASSERT_COLUMN_MARKED_FOR_READ;
5757 set_zero_time(ltime, MYSQL_TIMESTAMP_TIME);
5759 time_to_datetime(
table ?
table->in_use : current_thd, &tm, ltime);
5766 ASSERT_COLUMN_MARKED_FOR_READ;
5768 if (get_time(&time))
5773 time_to_datetime(
table ?
table->in_use : current_thd, &time, &datetime);
5774 return TIME_to_longlong_datetime_packed(&datetime);
5778 bool Field_time_common::send_binary(
Protocol *protocol)
5781 if (get_time(<ime))
5784 set_zero_time(<ime, MYSQL_TIMESTAMP_TIME);
5786 ltime.day= ltime.hour / 24;
5787 ltime.hour-= ltime.day * 24;
5788 return protocol->store_time(<ime, 0);
5799 type_conversion_status
5802 long tmp= ((ltime->month ? 0 : ltime->day * 24L) + ltime->hour) * 10000L +
5803 (ltime->minute * 100 + ltime->second);
5806 int3store(ptr, tmp);
5814 TIME_from_longlong_time_packed(<ime, nr);
5821 ASSERT_COLUMN_MARKED_FOR_READ;
5823 return get_time(<ime) ? 0 : TIME_to_longlong_time_packed(<ime);
5827 longlong Field_time::val_int()
5829 ASSERT_COLUMN_MARKED_FOR_READ;
5830 return (longlong) sint3korr(ptr);
5836 long tmp=(long) sint3korr(ptr);
5837 if ((ltime->neg= tmp < 0))
5839 ltime->year= ltime->month= ltime->day= 0;
5840 TIME_set_hhmmss(ltime, tmp);
5842 ltime->time_type= MYSQL_TIMESTAMP_TIME;
5847 int Field_time::cmp(
const uchar *a_ptr,
const uchar *b_ptr)
5850 a=(int32) sint3korr(a_ptr);
5851 b=(int32) sint3korr(b_ptr);
5852 return (a < b) ? -1 : (a > b) ? 1 : 0;
5858 DBUG_ASSERT(length >= 3);
5859 to[0] = (uchar) (ptr[2] ^ 128);
5865 void Field_time::sql_type(
String &res)
const
5867 res.set_ascii(STRING_WITH_LEN(
"time"));
5878 longlong Field_timef::val_int()
5880 ASSERT_COLUMN_MARKED_FOR_READ;
5882 if (get_time(<ime))
5885 set_zero_time(<ime, MYSQL_TIMESTAMP_TIME);
5887 longlong tmp= (longlong) TIME_to_ulonglong_time_round(<ime);
5888 return ltime.neg ? -tmp : tmp;
5894 ASSERT_COLUMN_MARKED_FOR_READ;
5896 if (get_time(<ime))
5899 set_zero_time(<ime, MYSQL_TIMESTAMP_TIME);
5901 return time2my_decimal(<ime, decimal_value);
5905 double Field_timef::val_real()
5907 ASSERT_COLUMN_MARKED_FOR_READ;
5909 if (get_time(<ime))
5914 double tmp= TIME_to_double_time(<ime);
5915 return ltime.neg ? -tmp : tmp;
5919 void Field_timef::sql_type(
String &res)
const
5923 res.set_ascii(STRING_WITH_LEN(
"time"));
5927 res.length(cs->cset->snprintf(cs, (
char*) res.ptr(), res.alloced_length(),
5932 type_conversion_status Field_timef::reset()
5940 my_time_packed_to_binary(nr, ptr, dec);
5947 ASSERT_COLUMN_MARKED_FOR_READ;
5948 return my_time_packed_from_binary(ptr, dec);
5952 type_conversion_status
5955 type_conversion_status rc=
store_packed(TIME_to_longlong_time_packed(ltime));
5956 if (rc == TYPE_OK && non_zero_date(ltime))
5963 *warnings|= MYSQL_TIME_NOTE_TRUNCATED;
5964 rc= TYPE_NOTE_TIME_TRUNCATED;
5970 bool Field_timef::get_time(
MYSQL_TIME *ltime)
5973 TIME_from_longlong_time_packed(ltime, tmp);
5984 type_conversion_status
5985 Field_year::store(
const char *from, uint len,
const CHARSET_INFO *cs)
5987 ASSERT_COLUMN_MARKED_FOR_WRITE;
5990 type_conversion_status
ret= TYPE_OK;
5991 longlong nr= cs->cset->strntoull10rnd(cs, from, len, 0, &end, &conv_error);
5993 if (nr < 0 || (nr >= 100 && nr <= 1900) || nr > 2155 ||
5994 conv_error == MY_ERRNO_ERANGE)
5997 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
5998 return TYPE_WARN_OUT_OF_RANGE;
6000 else if (conv_error)
6001 ret= TYPE_ERR_BAD_VALUE;
6003 if (
table->in_use->count_cuted_fields)
6005 ret=
check_int(cs, from, len, end, conv_error);
6008 if (ret == TYPE_ERR_BAD_VALUE)
6011 return TYPE_WARN_OUT_OF_RANGE;
6013 ret= TYPE_WARN_OUT_OF_RANGE;
6017 if (nr != 0 || len != 4)
6019 if (nr < YY_PART_YEAR)
6024 *ptr= (char) (uchar) nr;
6029 type_conversion_status Field_year::store(
double nr)
6031 if (nr < 0.0 || nr >= 2155.0)
6033 (void) Field_year::store((longlong) -1, FALSE);
6034 return TYPE_WARN_OUT_OF_RANGE;
6036 return Field_year::store((longlong) nr, FALSE);
6040 type_conversion_status
6042 uint8 dec_arg __attribute__((unused)))
6044 if (ltime->time_type != MYSQL_TIMESTAMP_DATETIME &&
6045 ltime->time_type != MYSQL_TIMESTAMP_DATE)
6048 THD *thd=
table ?
table->in_use : current_thd;
6050 time_to_datetime(thd, ltime, <ime2);
6051 return store(ltime2.year, 0);
6053 return store(ltime->year, 0);
6057 type_conversion_status Field_year::store(longlong nr,
bool unsigned_val)
6059 ASSERT_COLUMN_MARKED_FOR_WRITE;
6060 if (nr < 0 || (nr >= 100 && nr <= 1900) || nr > 2155)
6063 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
6064 return TYPE_WARN_OUT_OF_RANGE;
6066 if (nr != 0 || field_length != 4)
6068 if (nr < YY_PART_YEAR)
6073 *ptr= (char) (uchar) nr;
6078 bool Field_year::send_binary(
Protocol *protocol)
6080 ASSERT_COLUMN_MARKED_FOR_READ;
6081 ulonglong tmp= Field_year::val_int();
6082 return protocol->store_short(tmp);
6086 double Field_year::val_real(
void)
6088 return (
double) Field_year::val_int();
6092 longlong Field_year::val_int(
void)
6094 ASSERT_COLUMN_MARKED_FOR_READ;
6095 DBUG_ASSERT(field_length == 2 || field_length == 4);
6096 int tmp= (int) ptr[0];
6097 if (field_length != 4)
6101 return (longlong) tmp;
6106 String *val_ptr __attribute__((unused)))
6108 DBUG_ASSERT(field_length < 5);
6109 val_buffer->alloc(5);
6110 val_buffer->length(field_length);
6111 char *to=(
char*) val_buffer->ptr();
6112 sprintf(to,field_length == 2 ?
"%02d" :
"%04d",(
int) Field_year::val_int());
6113 val_buffer->set_charset(&my_charset_numeric);
6118 void Field_year::sql_type(
String &res)
const
6121 res.length(cs->cset->snprintf(cs,(
char*)res.ptr(),res.alloced_length(),
6122 "year(%d)",(int) field_length));
6134 return TIME_FUZZY_DATE | thd->datetime_flags();
6138 type_conversion_status
6141 long tmp= ltime->day + ltime->month * 32 + ltime->year * 16 * 32;
6142 int3store(ptr, tmp);
6143 if (non_zero_time(ltime))
6145 *warnings|= MYSQL_TIME_NOTE_TRUNCATED;
6146 return TYPE_NOTE_TIME_TRUNCATED;
6154 uint32 tmp= (uint32) uint3korr(ptr);
6155 ltime->day= tmp & 31;
6156 ltime->month= (tmp >> 5) & 15;
6157 ltime->year= (tmp >> 9);
6158 ltime->time_type= MYSQL_TIMESTAMP_DATE;
6159 ltime->hour= ltime->minute= ltime->second= ltime->
second_part= ltime->neg= 0;
6168 TIME_from_longlong_date_packed(<ime, nr);
6173 bool Field_newdate::send_binary(
Protocol *protocol)
6176 get_date(<ime, 0);
6177 return protocol->store_date(<ime);
6181 longlong Field_newdate::val_int()
6183 ASSERT_COLUMN_MARKED_FOR_READ;
6184 ulong j= uint3korr(ptr);
6185 j= (j % 32L)+(j / 32L % 16L)*100L + (j/(16L*32L))*10000L;
6186 return (longlong) j;
6192 ASSERT_COLUMN_MARKED_FOR_READ;
6200 ASSERT_COLUMN_MARKED_FOR_READ;
6206 String *val_ptr __attribute__((unused)))
6208 ASSERT_COLUMN_MARKED_FOR_READ;
6209 val_buffer->alloc(field_length);
6210 val_buffer->length(field_length);
6211 uint32 tmp=(uint32) uint3korr(ptr);
6213 char *pos=(
char*) val_buffer->ptr()+10;
6217 part=(int) (tmp & 31);
6218 *pos--= (char) (
'0'+part%10);
6219 *pos--= (char) (
'0'+part/10);
6221 part=(int) (tmp >> 5 & 15);
6222 *pos--= (char) (
'0'+part%10);
6223 *pos--= (char) (
'0'+part/10);
6225 part=(int) (tmp >> 9);
6226 *pos--= (char) (
'0'+part%10); part/=10;
6227 *pos--= (char) (
'0'+part%10); part/=10;
6228 *pos--= (char) (
'0'+part%10); part/=10;
6229 *pos= (char) (
'0'+part);
6230 val_buffer->set_charset(&my_charset_numeric);
6235 bool Field_newdate::get_date(
MYSQL_TIME *ltime,uint fuzzydate)
6238 check_fuzzy_date(ltime, fuzzydate);
6242 int Field_newdate::cmp(
const uchar *a_ptr,
const uchar *b_ptr)
6245 a=(uint32) uint3korr(a_ptr);
6246 b=(uint32) uint3korr(b_ptr);
6247 return (a < b) ? -1 : (a > b) ? 1 : 0;
6253 DBUG_ASSERT(length >= 3);
6260 void Field_newdate::sql_type(
String &res)
const
6262 res.set_ascii(STRING_WITH_LEN(
"date"));
6276 return TIME_FUZZY_DATE | thd->datetime_flags();
6283 THD *thd= current_thd;
6284 thd->variables.time_zone->gmt_sec_to_TIME(&mysql_time, *tm);
6285 thd->time_zone_used=
true;
6298 static inline type_conversion_status
6299 datetime_store_internal(
TABLE *
table, ulonglong tmp, uchar *ptr)
6301 #ifdef WORDS_BIGENDIAN
6302 if (table && table->s->db_low_byte_first)
6304 int8store(ptr, tmp);
6308 longlongstore(ptr, tmp);
6320 static inline longlong
6321 datetime_get_internal(
TABLE *table, uchar *ptr)
6324 #ifdef WORDS_BIGENDIAN
6325 if (table && table->s->db_low_byte_first)
6326 tmp= sint8korr(ptr);
6329 longlongget(tmp, ptr);
6336 longlong tmp= datetime_get_internal(table, ptr);
6337 ltime->time_type= MYSQL_TIMESTAMP_DATETIME;
6340 TIME_set_yymmdd(ltime, (uint) (tmp / 1000000LL));
6341 TIME_set_hhmmss(ltime, (uint) (tmp % 1000000LL));
6346 type_conversion_status
6349 ulonglong tmp= TIME_to_ulonglong_datetime(ltime);
6350 return datetime_store_internal(table, tmp, ptr);
6354 type_conversion_status Field_datetime::store(longlong nr,
bool unsigned_val)
6356 ASSERT_COLUMN_MARKED_FOR_WRITE;
6359 type_conversion_status error= TYPE_OK;
6363 error= TYPE_ERR_BAD_VALUE;
6366 error= time_warning_to_type_conversion_status(warnings);
6367 datetime_store_internal(table, tmp, ptr);
6378 TIME_from_longlong_datetime_packed(<ime, nr);
6383 longlong Field_datetime::val_int()
6385 ASSERT_COLUMN_MARKED_FOR_READ;
6386 return datetime_get_internal(table, ptr);
6396 String *val_ptr __attribute__((unused)))
6398 ASSERT_COLUMN_MARKED_FOR_READ;
6399 val_buffer->alloc(field_length + 1);
6400 val_buffer->set_charset(&my_charset_numeric);
6401 val_buffer->length(MAX_DATETIME_WIDTH);
6402 longlong tmp= datetime_get_internal(table, ptr);
6403 val_buffer->length(my_datetime_number_to_str((
char *) val_buffer->ptr(),
6409 bool Field_datetime::get_date(
MYSQL_TIME *ltime, uint fuzzydate)
6412 check_fuzzy_date(ltime, fuzzydate);
6416 int Field_datetime::cmp(
const uchar *a_ptr,
const uchar *b_ptr)
6419 #ifdef WORDS_BIGENDIAN
6420 if (table && table->s->db_low_byte_first)
6428 longlongget(a,a_ptr);
6429 longlongget(b,b_ptr);
6431 return ((ulonglong) a < (ulonglong) b) ? -1 :
6432 ((ulonglong) a > (ulonglong) b) ? 1 : 0;
6437 const int pack_length= PACK_LENGTH;
6438 const int to_length= min<uint>(pack_length, length);
6439 #ifdef WORDS_BIGENDIAN
6440 if (!table || !table->s->db_low_byte_first)
6441 copy_integer<true>(
to, to_length, ptr, pack_length,
true);
6444 copy_integer<false>(
to, to_length, ptr, pack_length,
true);
6448 void Field_datetime::sql_type(
String &res)
const
6450 res.set_ascii(STRING_WITH_LEN(
"datetime"));
6463 return TIME_FUZZY_DATE | thd->datetime_flags();
6470 THD *thd= current_thd;
6471 thd->variables.time_zone->gmt_sec_to_TIME(&mysql_time, *tm);
6472 thd->time_zone_used=
true;
6479 bool Field_datetimef::get_date(
MYSQL_TIME *ltime, uint fuzzydate)
6482 check_fuzzy_date(ltime, fuzzydate);
6486 void Field_datetimef::sql_type(
String &res)
const
6490 res.set_ascii(STRING_WITH_LEN(
"datetime"));
6494 res.length(cs->cset->snprintf(cs, (
char *) res.ptr(), res.alloced_length(),
6495 "datetime(%d)", dec));
6506 type_conversion_status
6514 type_conversion_status Field_datetimef::reset()
6523 return my_datetime_packed_from_binary(ptr, dec);
6529 my_datetime_packed_to_binary(nr, ptr, dec);
6566 type_conversion_status
6568 const char *cannot_convert_error_pos,
6569 const char *from_end_pos,
6576 THD *thd= table->in_use;
6578 if (!(pos= well_formed_error_pos) &&
6579 !(pos= cannot_convert_error_pos))
6580 return report_if_important_data(from_end_pos, end, count_spaces);
6582 convert_to_printable(tmp,
sizeof(tmp), pos, (end - pos), cs, 6);
6584 push_warning_printf(thd,
6585 Sql_condition::WARN_LEVEL_WARN,
6586 ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
6587 ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
6588 "string", tmp, field_name,
6589 thd->get_stmt_da()->current_row_for_warning());
6590 return TYPE_WARN_TRUNCATED;
6614 type_conversion_status
6615 Field_longstr::report_if_important_data(
const char *pstr,
const char *end,
6616 bool count_spaces)
const
6618 if ((pstr < end) && table->in_use->count_cuted_fields)
6620 if (test_if_important_data(field_charset, pstr, end))
6622 if (table->in_use->abort_on_warning)
6623 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_DATA_TOO_LONG, 1);
6625 set_warning(Sql_condition::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
6626 return TYPE_WARN_TRUNCATED;
6628 else if (count_spaces)
6630 set_warning(Sql_condition::WARN_LEVEL_NOTE, WARN_DATA_TRUNCATED, 1);
6631 return TYPE_NOTE_TRUNCATED;
6640 type_conversion_status
6641 Field_string::store(
const char *from,uint length,
const CHARSET_INFO *cs)
6643 ASSERT_COLUMN_MARKED_FOR_WRITE;
6645 const char *well_formed_error_pos;
6646 const char *cannot_convert_error_pos;
6647 const char *from_end_pos;
6650 DBUG_ASSERT(table->in_use == current_thd);
6652 copy_length= well_formed_copy_nchars(field_charset,
6653 (
char*) ptr, field_length,
6655 field_length / field_charset->mbmaxlen,
6656 &well_formed_error_pos,
6657 &cannot_convert_error_pos,
6661 if (copy_length < field_length)
6662 field_charset->cset->fill(field_charset,(
char*) ptr+copy_length,
6663 field_length-copy_length,
6664 field_charset->pad_char);
6667 cannot_convert_error_pos, from_end_pos,
6668 from + length,
false, cs);
6682 ASSERT_COLUMN_MARKED_FOR_WRITE;
6683 char buff[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
6684 uint local_char_length= field_length / charset()->mbmaxlen;
6686 my_bool error= (local_char_length == 0);
6690 length= my_gcvt(nr, MY_GCVT_ARG_DOUBLE, local_char_length, buff, &error);
6694 if (table->in_use->abort_on_warning)
6695 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_DATA_TOO_LONG, 1);
6697 set_warning(Sql_condition::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
6699 return store(buff, length, &my_charset_numeric);
6705 return (new_field->sql_type == real_type());
6711 if (field_flags_are_binary() != new_field->field_flags_are_binary())
6714 return ((new_field->sql_type == real_type()) &&
6715 new_field->charset == field_charset &&
6716 new_field->length == max_display_length());
6720 type_conversion_status Field_string::store(longlong nr,
bool unsigned_val)
6725 l= (cs->cset->longlong10_to_str)(cs,buff,
sizeof(buff),
6726 unsigned_val ? 10 : -10, nr);
6727 return Field_string::store(buff,(uint)l,cs);
6734 String str(buff,
sizeof(buff), &my_charset_numeric);
6735 my_decimal2string(E_DEC_FATAL_ERROR, d, 0, 0, 0, &str);
6736 return store(str.ptr(), str.length(), str.charset());
6741 return field_length + (field_length > 255 ? 2 : 1);
6745 double Field_string::val_real(
void)
6747 ASSERT_COLUMN_MARKED_FOR_READ;
6753 result= my_strntod(cs,(
char*) ptr,field_length,&end,&error);
6754 if (!table->in_use->no_errors &&
6755 (error || (field_length != (uint32)(end - (
char*) ptr) &&
6756 !check_if_only_end_space(cs, end,
6757 (
char*) ptr + field_length))))
6760 push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
6761 ER_TRUNCATED_WRONG_VALUE,
6762 ER(ER_TRUNCATED_WRONG_VALUE),
"DOUBLE",
6769 longlong Field_string::val_int(
void)
6771 ASSERT_COLUMN_MARKED_FOR_READ;
6777 result= my_strntoll(cs, (
char*) ptr,field_length,10,&end,&error);
6778 if (!table->in_use->no_errors &&
6779 (error || (field_length != (uint32)(end - (
char*) ptr) &&
6780 !check_if_only_end_space(cs, end,
6781 (
char*) ptr + field_length))))
6784 push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
6785 ER_TRUNCATED_WRONG_VALUE,
6786 ER(ER_TRUNCATED_WRONG_VALUE),
6787 "INTEGER", err.ptr());
6793 String *Field_string::val_str(
String *val_buffer __attribute__((unused)),
6796 ASSERT_COLUMN_MARKED_FOR_READ;
6798 DBUG_ASSERT(table->in_use == current_thd);
6800 if (table->in_use->variables.sql_mode &
6801 MODE_PAD_CHAR_TO_FULL_LENGTH)
6802 length= my_charpos(field_charset, ptr, ptr + field_length,
6803 field_length / field_charset->mbmaxlen);
6805 length= field_charset->cset->lengthsp(field_charset, (
const char*) ptr,
6807 val_ptr->set((
const char*) ptr, length, field_charset);
6814 ASSERT_COLUMN_MARKED_FOR_READ;
6815 int err= str2my_decimal(E_DEC_FATAL_ERROR, (
char*) ptr, field_length,
6816 charset(), decimal_value);
6817 if (!table->in_use->no_errors && err)
6820 push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
6821 ER_TRUNCATED_WRONG_VALUE,
6822 ER(ER_TRUNCATED_WRONG_VALUE),
6823 "DECIMAL", errmsg.ptr());
6826 return decimal_value;
6834 #ifdef HAVE_REPLICATION
6836 check_field_for_37426(
const void *param_arg)
6839 DBUG_ASSERT(param->field->real_type() == MYSQL_TYPE_STRING);
6840 DBUG_PRINT(
"debug", (
"Field %s - type: %d, size: %d",
6841 param->field->field_name,
6842 param->field->real_type(),
6843 param->field->row_pack_length()));
6844 return param->field->row_pack_length() > 255;
6851 uint16 mflags __attribute__((unused)),
6854 #ifdef HAVE_REPLICATION
6856 if (!is_mts_worker(rli_arg->info_thd) && rpl_master_has_bug(rli_arg, 37426, TRUE,
6857 check_field_for_37426, &check_param))
6864 int Field_string::cmp(
const uchar *a_ptr,
const uchar *b_ptr)
6868 if (field_charset->mbmaxlen != 1)
6870 uint char_len= field_length/field_charset->mbmaxlen;
6871 a_len= my_charpos(field_charset, a_ptr, a_ptr + field_length, char_len);
6872 b_len= my_charpos(field_charset, b_ptr, b_ptr + field_length, char_len);
6875 a_len= b_len= field_length;
6880 return field_charset->coll->strnncollsp(field_charset,
6889 uint tmp __attribute__((unused))=
6890 field_charset->coll->strnxfrm(field_charset,
6891 to, length, char_length(),
6893 MY_STRXFRM_PAD_WITH_SPACE |
6894 MY_STRXFRM_PAD_TO_MAXLEN);
6895 DBUG_ASSERT(tmp == length);
6899 void Field_string::sql_type(
String &res)
const
6901 THD *thd= table->in_use;
6905 length= cs->cset->snprintf(cs,(
char*) res.ptr(),
6906 res.alloced_length(),
"%s(%d)",
6907 ((type() == MYSQL_TYPE_VAR_STRING &&
6908 !thd->variables.new_mode) ?
6909 (has_charset() ?
"varchar" :
"varbinary") :
6910 (has_charset() ?
"char" :
"binary")),
6911 (int) field_length / charset()->mbmaxlen);
6913 if ((thd->variables.sql_mode & (MODE_MYSQL323 | MODE_MYSQL40)) &&
6914 has_charset() && (charset()->state & MY_CS_BINSORT))
6915 res.append(STRING_WITH_LEN(
" binary"));
6921 bool low_byte_first __attribute__((unused)))
6923 uint length= min(field_length,max_length);
6924 uint local_char_length= max_length/field_charset->mbmaxlen;
6925 DBUG_PRINT(
"debug", (
"Packing field '%s' - length: %u ", field_name, length));
6927 if (length > local_char_length)
6928 local_char_length= my_charpos(field_charset, from, from+length,
6930 set_if_smaller(length, local_char_length);
6938 if (field_charset->mbmaxlen == 1)
6940 while (length && from[length-1] == field_charset->pad_char)
6944 length= field_charset->cset->lengthsp(field_charset, (
const char*) from, length);
6947 *to++= (uchar) length;
6948 if (field_length > 255)
6949 *to++= (uchar) (length >> 8);
6952 memcpy(to, from, length);
6980 bool low_byte_first __attribute__((unused)))
6982 uint from_length, length;
6989 from_length= (((param_data >> 4) & 0x300) ^ 0x300) + (param_data & 0x00ff);
6991 from_length= field_length;
6994 (
"param_data: 0x%x, field_length: %u, from_length: %u",
6995 param_data, field_length, from_length));
7000 if (from_length > 255)
7002 length= uint2korr(from);
7006 length= (uint) *from++;
7008 memcpy(to, from, length);
7010 field_charset->cset->fill(field_charset, (
char*) to + length, field_length - length, field_charset->pad_char);
7045 int Field_string::do_save_field_metadata(uchar *metadata_ptr)
7047 DBUG_ASSERT(field_length < 1024);
7048 DBUG_ASSERT((real_type() & 0xF0) == 0xF0);
7049 DBUG_PRINT(
"debug", (
"field_length: %u, real_type: %u",
7050 field_length, real_type()));
7051 *metadata_ptr= (real_type() ^ ((field_length & 0x300) >> 4));
7052 *(metadata_ptr + 1)= field_length & 0xFF;
7057 uint Field_string::packed_col_length(
const uchar *data_ptr, uint length)
7060 return uint2korr(data_ptr)+2;
7061 return (uint) *data_ptr + 1;
7065 uint Field_string::max_packed_col_length(uint max_length)
7067 return (max_length > 255 ? 2 : 1)+max_length;
7071 uint Field_string::get_key_image(uchar *buff, uint length, imagetype type_arg)
7073 uint bytes = my_charpos(field_charset, (
char*) ptr,
7074 (
char*) ptr + field_length,
7075 length / field_charset->mbmaxlen);
7076 memcpy(buff, ptr, bytes);
7078 field_charset->cset->fill(field_charset, (
char*) buff + bytes,
7079 length - bytes, field_charset->pad_char);
7088 if (type() != MYSQL_TYPE_VAR_STRING || keep_type)
7089 field= Field::new_field(root, new_table, keep_type);
7090 else if ((field=
new Field_varstring(field_length, maybe_null(), field_name,
7091 new_table->s, charset())))
7098 field->init(new_table);
7105 field->orig_table= orig_table;
7127 const uint Field_varstring::MAX_SIZE= UINT_MAX16;
7140 int Field_varstring::do_save_field_metadata(uchar *metadata_ptr)
7142 DBUG_ASSERT(field_length <= 65535);
7143 int2store((
char*)metadata_ptr, field_length);
7147 type_conversion_status Field_varstring::store(
const char *from,uint length,
7150 ASSERT_COLUMN_MARKED_FOR_WRITE;
7152 const char *well_formed_error_pos;
7153 const char *cannot_convert_error_pos;
7154 const char *from_end_pos;
7156 copy_length= well_formed_copy_nchars(field_charset,
7157 (
char*) ptr + length_bytes,
7160 field_length / field_charset->mbmaxlen,
7161 &well_formed_error_pos,
7162 &cannot_convert_error_pos,
7165 if (length_bytes == 1)
7166 *ptr= (uchar) copy_length;
7168 int2store(ptr, copy_length);
7171 cannot_convert_error_pos, from_end_pos,
7172 from + length,
true, cs);
7176 type_conversion_status Field_varstring::store(longlong nr,
bool unsigned_val)
7180 length= (uint) (field_charset->cset->longlong10_to_str)(field_charset,
7186 return Field_varstring::store(buff, length, field_charset);
7190 double Field_varstring::val_real(
void)
7192 ASSERT_COLUMN_MARKED_FOR_READ;
7198 uint length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
7199 result= my_strntod(cs, (
char*)ptr+length_bytes, length, &end, &error);
7201 if (!table->in_use->no_errors &&
7202 (error || (length != (uint)(end - (
char*)ptr+length_bytes) &&
7203 !check_if_only_end_space(cs, end, (
char*)ptr+length_bytes+length))))
7205 push_numerical_conversion_warning(current_thd, (
char*)ptr+length_bytes,
7206 length, cs,
"DOUBLE",
7207 ER_TRUNCATED_WRONG_VALUE);
7213 longlong Field_varstring::val_int(
void)
7215 ASSERT_COLUMN_MARKED_FOR_READ;
7220 uint length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
7221 longlong result= my_strntoll(cs, (
char*) ptr+length_bytes, length, 10,
7224 if (!table->in_use->no_errors &&
7225 (error || (length != (uint)(end - (
char*)ptr+length_bytes) &&
7226 !check_if_only_end_space(cs, end, (
char*)ptr+length_bytes+length))))
7228 push_numerical_conversion_warning(current_thd, (
char*)ptr+length_bytes,
7229 length, cs,
"INTEGER",
7230 ER_TRUNCATED_WRONG_VALUE);
7235 String *Field_varstring::val_str(
String *val_buffer __attribute__((unused)),
7238 ASSERT_COLUMN_MARKED_FOR_READ;
7239 uint length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
7240 val_ptr->set((
const char*) ptr+length_bytes, length, field_charset);
7247 ASSERT_COLUMN_MARKED_FOR_READ;
7249 uint length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
7250 int error= str2my_decimal(E_DEC_FATAL_ERROR, (
char*) ptr+length_bytes, length,
7253 if (!table->in_use->no_errors && error)
7255 push_numerical_conversion_warning(current_thd, (
char*)ptr+length_bytes,
7256 length, cs,
"DECIMAL",
7257 ER_TRUNCATED_WRONG_VALUE);
7259 return decimal_value;
7263 int Field_varstring::cmp_max(
const uchar *a_ptr,
const uchar *b_ptr,
7266 uint a_length, b_length;
7269 if (length_bytes == 1)
7271 a_length= (uint) *a_ptr;
7272 b_length= (uint) *b_ptr;
7276 a_length= uint2korr(a_ptr);
7277 b_length= uint2korr(b_ptr);
7279 set_if_smaller(a_length, max_len);
7280 set_if_smaller(b_length, max_len);
7281 diff= field_charset->coll->strnncollsp(field_charset,
7299 uint length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
7300 uint local_char_length= max_key_length / field_charset->mbmaxlen;
7302 local_char_length= my_charpos(field_charset, ptr + length_bytes,
7303 ptr + length_bytes + length, local_char_length);
7304 set_if_smaller(length, local_char_length);
7305 return field_charset->coll->strnncollsp(field_charset,
7310 uint2korr(key_ptr), 0);
7324 return field_charset->coll->strnncollsp(field_charset,
7325 a + HA_KEY_BLOB_LENGTH,
7327 b + HA_KEY_BLOB_LENGTH,
7335 uint tot_length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
7337 if (field_charset == &my_charset_bin)
7340 if (length_bytes == 1)
7341 to[length-1]= tot_length;
7343 mi_int2store(to+length-2, tot_length);
7344 length-= length_bytes;
7347 tot_length= field_charset->coll->strnxfrm(field_charset,
7348 to, length, char_length(),
7349 ptr + length_bytes, tot_length,
7350 MY_STRXFRM_PAD_WITH_SPACE |
7351 MY_STRXFRM_PAD_TO_MAXLEN);
7352 DBUG_ASSERT(tot_length == length);
7356 enum ha_base_keytype Field_varstring::key_type()
const
7358 enum ha_base_keytype res;
7361 res= length_bytes == 1 ? HA_KEYTYPE_VARBINARY1 : HA_KEYTYPE_VARBINARY2;
7363 res= length_bytes == 1 ? HA_KEYTYPE_VARTEXT1 : HA_KEYTYPE_VARTEXT2;
7368 void Field_varstring::sql_type(
String &res)
const
7370 THD *thd= table->in_use;
7374 length= cs->cset->snprintf(cs,(
char*) res.ptr(),
7375 res.alloced_length(),
"%s(%d)",
7376 (has_charset() ?
"varchar" :
"varbinary"),
7377 (
int) field_length / charset()->mbmaxlen);
7379 if ((thd->variables.sql_mode & (MODE_MYSQL323 | MODE_MYSQL40)) &&
7380 has_charset() && (charset()->state & MY_CS_BINSORT))
7381 res.append(STRING_WITH_LEN(
" binary"));
7385 uint32 Field_varstring::data_length()
7387 return length_bytes == 1 ? (uint32) *ptr : uint2korr(ptr);
7397 bool low_byte_first __attribute__((unused)))
7399 uint length= length_bytes == 1 ? (uint) *from : uint2korr(from);
7400 set_if_smaller(max_length, field_length);
7401 if (length > max_length)
7405 *to++= length & 0xFF;
7406 if (max_length > 255)
7407 *to++= (length >> 8) & 0xFF;
7411 memcpy(to, from+length_bytes, length);
7434 bool low_byte_first __attribute__((unused)))
7437 uint l_bytes= (param_data && (param_data < field_length)) ?
7438 (param_data <= 255) ? 1 : 2 : length_bytes;
7443 if (length_bytes == 2)
7448 length= uint2korr(from);
7453 memcpy(to+ length_bytes, from, length);
7458 uint Field_varstring::packed_col_length(
const uchar *data_ptr, uint length)
7461 return uint2korr(data_ptr)+2;
7462 return (uint) *data_ptr + 1;
7466 uint Field_varstring::max_packed_col_length(uint max_length)
7468 return (max_length > 255 ? 2 : 1)+max_length;
7471 uint Field_varstring::get_key_image(uchar *buff, uint length, imagetype
type)
7473 uint f_length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
7474 uint local_char_length= length / field_charset->mbmaxlen;
7475 uchar *pos= ptr+length_bytes;
7476 local_char_length= my_charpos(field_charset, pos, pos + f_length,
7478 set_if_smaller(f_length, local_char_length);
7480 int2store(buff,f_length);
7481 memcpy(buff+HA_KEY_BLOB_LENGTH, pos, f_length);
7482 if (f_length < length)
7488 memset(buff+HA_KEY_BLOB_LENGTH+f_length, 0, (length-f_length));
7490 return HA_KEY_BLOB_LENGTH+f_length;
7494 void Field_varstring::set_key_image(
const uchar *buff,uint length)
7496 length= uint2korr(buff);
7497 (void) Field_varstring::store((
const char*) buff+HA_KEY_BLOB_LENGTH, length,
7502 int Field_varstring::cmp_binary(
const uchar *a_ptr,
const uchar *b_ptr,
7505 uint32 a_length,b_length;
7507 if (length_bytes == 1)
7509 a_length= (uint) *a_ptr;
7510 b_length= (uint) *b_ptr;
7514 a_length= uint2korr(a_ptr);
7515 b_length= uint2korr(b_ptr);
7517 set_if_smaller(a_length, max_length);
7518 set_if_smaller(b_length, max_length);
7519 if (a_length != b_length)
7521 return memcmp(a_ptr+length_bytes, b_ptr+length_bytes, a_length);
7531 res->length_bytes= length_bytes;
7538 uchar *new_ptr, uchar *new_null_ptr,
7549 res->length_bytes= 2;
7557 if (new_field->sql_type == real_type() &&
7558 new_field->charset == field_charset)
7560 if (new_field->length == max_display_length())
7561 return IS_EQUAL_YES;
7562 if (new_field->length > max_display_length() &&
7563 ((new_field->length <= 255 && max_display_length() <= 255) ||
7564 (new_field->length > 255 && max_display_length() > 255)))
7565 return IS_EQUAL_PACK_LENGTH;
7571 void Field_varstring::hash(ulong *nr, ulong *nr2)
7575 *nr^= (*nr << 1) | 1;
7579 uint len= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
7581 cs->coll->hash_sort(cs, ptr + length_bytes, len, nr, nr2);
7592 Field_blob::Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
7593 enum utype unireg_check_arg,
const char *field_name_arg,
7596 :
Field_longstr(ptr_arg, BLOB_PACK_LENGTH_TO_MAX_LENGH(blob_pack_length),
7597 null_ptr_arg, null_bit_arg, unireg_check_arg, field_name_arg,
7599 packlength(blob_pack_length)
7601 DBUG_ASSERT(blob_pack_length <= 4);
7603 share->blob_fields++;
7608 void Field_blob::store_length(uchar *i_ptr,
7611 bool low_byte_first)
7613 switch (i_packlength) {
7615 i_ptr[0]= (uchar) i_number;
7618 #ifdef WORDS_BIGENDIAN
7621 int2store(i_ptr,(
unsigned short) i_number);
7625 shortstore(i_ptr,(
unsigned short) i_number);
7628 int3store(i_ptr,i_number);
7631 #ifdef WORDS_BIGENDIAN
7634 int4store(i_ptr,i_number);
7638 longstore(i_ptr,i_number);
7643 uint32 Field_blob::get_length(
const uchar *pos, uint packlength_arg,
bool low_byte_first)
7645 switch (packlength_arg) {
7647 return (uint32) pos[0];
7651 #ifdef WORDS_BIGENDIAN
7657 return (uint32) tmp;
7660 return (uint32) uint3korr(pos);
7664 #ifdef WORDS_BIGENDIAN
7670 return (uint32) tmp;
7693 *pos= (char) length;
7696 int2store(pos, length);
7699 int3store(pos, length);
7702 int4store(pos, length);
7716 type_conversion_status
7717 Field_blob::store_to_mem(
const char *from, uint length,
7722 DBUG_ASSERT(length > 0);
7729 DBUG_ASSERT(!f_is_hex_escape(flags));
7730 DBUG_ASSERT(field_charset == cs);
7733 if (length > max_length)
7735 int well_formed_error;
7736 length= cs->cset->well_formed_len(cs, from, from + max_length,
7737 length, &well_formed_error);
7743 memset(ptr, 0, Field_blob::pack_length());
7744 return TYPE_ERR_OOM;
7751 type_conversion_status
7752 Field_blob::store_internal(
const char *from, uint length,
7756 char buff[STRING_BUFFER_USUAL_SIZE], *tmp;
7757 String tmpstr(buff,
sizeof(buff), &my_charset_bin);
7759 DBUG_ASSERT(length > 0);
7767 if (from >= value.ptr() && from <= value.ptr()+value.length())
7773 uint32 dummy_offset;
7774 if (!String::needs_conversion(length, cs, field_charset, &dummy_offset))
7779 if (tmpstr.copy(from, length, cs))
7785 if (value.alloc(new_length))
7787 tmp=
const_cast<char*
>(value.ptr());
7789 if (f_is_hex_escape(flags))
7791 uint copy_length= my_copy_with_hex_escaping(field_charset,
7800 const char *well_formed_error_pos;
7801 const char *cannot_convert_error_pos;
7802 const char *from_end_pos;
7808 uint copy_length= well_formed_copy_nchars(field_charset,
7812 &well_formed_error_pos,
7813 &cannot_convert_error_pos,
7818 cannot_convert_error_pos, from_end_pos,
7819 from + length,
true, cs);
7824 memset(ptr, 0, Field_blob::pack_length());
7825 return TYPE_ERR_OOM;
7829 type_conversion_status
7830 Field_blob::store(
const char *from, uint length,
const CHARSET_INFO *cs)
7832 ASSERT_COLUMN_MARKED_FOR_WRITE;
7836 memset(ptr, 0, Field_blob::pack_length());
7841 return store_to_mem(from, length, cs,
7842 table->in_use->variables.group_concat_max_len,
7845 return store_internal(from, length, cs);
7849 type_conversion_status Field_blob::store(
double nr)
7852 value.set_real(nr, NOT_FIXED_DEC, cs);
7853 return Field_blob::store(value.ptr(),(uint) value.length(), cs);
7857 type_conversion_status Field_blob::store(longlong nr,
bool unsigned_val)
7860 value.set_int(nr, unsigned_val, cs);
7861 return Field_blob::store(value.ptr(), (uint) value.length(), cs);
7865 double Field_blob::val_real(
void)
7867 ASSERT_COLUMN_MARKED_FOR_READ;
7869 char *end_not_used, *blob;
7873 memcpy(&blob, ptr+
packlength,
sizeof(
char*));
7876 length= get_length(ptr);
7878 return my_strntod(cs, blob, length, &end_not_used, ¬_used);
7882 longlong Field_blob::val_int(
void)
7884 ASSERT_COLUMN_MARKED_FOR_READ;
7887 memcpy(&blob, ptr+
packlength,
sizeof(
char*));
7890 uint32 length=get_length(ptr);
7891 return my_strntoll(charset(),blob,length,10,NULL,¬_used);
7894 String *Field_blob::val_str(
String *val_buffer __attribute__((unused)),
7897 ASSERT_COLUMN_MARKED_FOR_READ;
7899 memcpy(&blob, ptr+
packlength,
sizeof(
char*));
7901 val_ptr->set(
"",0,charset());
7903 val_ptr->set((
const char*) blob,get_length(ptr),charset());
7910 ASSERT_COLUMN_MARKED_FOR_READ;
7913 memcpy(&blob, ptr+
packlength,
sizeof(
const uchar*));
7920 length= get_length(ptr);
7922 str2my_decimal(E_DEC_FATAL_ERROR, blob, length, charset(),
7924 return decimal_value;
7928 int Field_blob::cmp(
const uchar *a,uint32 a_length,
const uchar *b,
7931 return field_charset->coll->strnncollsp(field_charset,
7932 a, a_length, b, b_length,
7937 int Field_blob::cmp_max(
const uchar *a_ptr,
const uchar *b_ptr,
7940 uchar *blob1,*blob2;
7941 memcpy(&blob1, a_ptr+
packlength,
sizeof(
char*));
7942 memcpy(&blob2, b_ptr+
packlength,
sizeof(
char*));
7943 uint a_len= get_length(a_ptr), b_len= get_length(b_ptr);
7944 set_if_smaller(a_len, max_length);
7945 set_if_smaller(b_len, max_length);
7946 return Field_blob::cmp(blob1,a_len,blob2,b_len);
7950 int Field_blob::cmp_binary(
const uchar *a_ptr,
const uchar *b_ptr,
7955 uint32 a_length,b_length;
7958 a_length=get_length(a_ptr);
7959 if (a_length > max_length)
7960 a_length=max_length;
7961 b_length=get_length(b_ptr);
7962 if (b_length > max_length)
7963 b_length=max_length;
7964 diff=memcmp(a,b,min(a_length,b_length));
7965 return diff ? diff : (int) (a_length - b_length);
7971 uint Field_blob::get_key_image(uchar *buff,uint length, imagetype type_arg)
7973 uint32 blob_length= get_length(ptr);
7977 if (type_arg == itMBR)
7980 Geometry_buffer buffer;
7982 const uint image_length= SIZEOF_STORED_DOUBLE*4;
7984 if (blob_length < SRID_SIZE)
7986 memset(buff, 0, image_length);
7987 return image_length;
7990 gobj= Geometry::construct(&buffer, (
char*) blob, blob_length);
7991 if (!gobj || gobj->get_mbr(&mbr))
7992 memset(buff, 0, image_length);
7995 float8store(buff, mbr.xmin);
7996 float8store(buff+8, mbr.xmax);
7997 float8store(buff+16, mbr.ymin);
7998 float8store(buff+24, mbr.ymax);
8000 return image_length;
8005 uint local_char_length= length / field_charset->mbmaxlen;
8006 local_char_length= my_charpos(field_charset, blob, blob + blob_length,
8008 set_if_smaller(blob_length, local_char_length);
8010 if ((uint32) length > blob_length)
8016 memset(buff+HA_KEY_BLOB_LENGTH+blob_length, 0, (length-blob_length));
8017 length=(uint) blob_length;
8019 int2store(buff,length);
8020 memcpy(buff+HA_KEY_BLOB_LENGTH, blob, length);
8021 return HA_KEY_BLOB_LENGTH+length;
8025 void Field_blob::set_key_image(
const uchar *buff,uint length)
8027 length= uint2korr(buff);
8028 (void) Field_blob::store((
const char*) buff+HA_KEY_BLOB_LENGTH, length,
8033 int Field_blob::key_cmp(
const uchar *key_ptr, uint max_key_length)
8036 uint blob_length=get_length(ptr);
8037 memcpy(&blob1, ptr+
packlength,
sizeof(
char*));
8039 uint local_char_length= max_key_length / cs->mbmaxlen;
8040 local_char_length= my_charpos(cs, blob1, blob1+blob_length,
8042 set_if_smaller(blob_length, local_char_length);
8043 return Field_blob::cmp(blob1, blob_length,
8044 key_ptr+HA_KEY_BLOB_LENGTH,
8045 uint2korr(key_ptr));
8048 int Field_blob::key_cmp(
const uchar *a,
const uchar *b)
8050 return Field_blob::cmp(a+HA_KEY_BLOB_LENGTH, uint2korr(a),
8051 b+HA_KEY_BLOB_LENGTH, uint2korr(b));
8065 int Field_blob::do_save_field_metadata(uchar *metadata_ptr)
8067 DBUG_ENTER(
"Field_blob::do_save_field_metadata");
8069 DBUG_PRINT(
"debug", (
"metadata: %u (pack_length_no_ptr)", *metadata_ptr));
8074 uint32 Field_blob::sort_length()
const
8076 return (uint32) (current_thd->variables.max_sort_length +
8077 (field_charset == &my_charset_bin ? 0 :
packlength));
8084 uint blob_length=get_length();
8087 memset(to, 0, length);
8090 if (field_charset == &my_charset_bin)
8102 *pos= (char) blob_length;
8105 mi_int2store(pos, blob_length);
8108 mi_int3store(pos, blob_length);
8111 mi_int4store(pos, blob_length);
8115 memcpy(&blob, ptr+
packlength,
sizeof(
char*));
8117 blob_length= field_charset->coll->strnxfrm(field_charset,
8120 MY_STRXFRM_PAD_WITH_SPACE |
8121 MY_STRXFRM_PAD_TO_MAXLEN);
8122 DBUG_ASSERT(blob_length == length);
8127 void Field_blob::sql_type(
String &res)
const
8132 default: str=
"tiny"; length=4;
break;
8133 case 2: str=
""; length=0;
break;
8134 case 3: str=
"medium"; length= 6;
break;
8135 case 4: str=
"long"; length=4;
break;
8137 res.set_ascii(str,length);
8138 if (charset() == &my_charset_bin)
8139 res.append(STRING_WITH_LEN(
"blob"));
8142 res.append(STRING_WITH_LEN(
"text"));
8147 uint max_length,
bool low_byte_first)
8151 uint32 length=get_length();
8158 store_length(to,
packlength, min(length, max_length), low_byte_first);
8165 get_ptr((uchar**) &from);
8193 bool low_byte_first)
8195 DBUG_ENTER(
"Field_blob::unpack");
8196 DBUG_PRINT(
"enter", (
"to: 0x%lx; from: 0x%lx;"
8197 " param_data: %u; low_byte_first: %d",
8198 (ulong) to, (ulong) from, param_data, low_byte_first));
8199 uint
const master_packlength=
8200 param_data > 0 ? param_data & 0xFF :
packlength;
8201 uint32
const length= get_length(from, master_packlength, low_byte_first);
8202 DBUG_DUMP(
"packed", from, length + master_packlength);
8203 bitmap_set_bit(table->write_set, field_index);
8204 store(reinterpret_cast<const char*>(from) + master_packlength,
8205 length, field_charset);
8209 DBUG_DUMP(
"field", ptr, pack_length() );
8210 DBUG_DUMP(
"value", vptr, length );
8212 DBUG_RETURN(from + master_packlength + length);
8215 uint Field_blob::packed_col_length(
const uchar *data_ptr, uint length)
8218 return uint2korr(data_ptr)+2;
8219 return (uint) *data_ptr + 1;
8223 uint Field_blob::max_packed_col_length(uint max_length)
8225 return (max_length > 255 ? 2 : 1)+max_length;
8231 if (field_flags_are_binary() != new_field->field_flags_are_binary())
8234 return ((new_field->sql_type == get_blob_type_from_length(
max_data_length()))
8235 && new_field->charset == field_charset &&
8236 new_field->pack_length == pack_length());
8242 void Field_geom::sql_type(
String &res)
const
8248 res.set(STRING_WITH_LEN(
"point"), cs);
8250 case GEOM_LINESTRING:
8251 res.set(STRING_WITH_LEN(
"linestring"), cs);
8254 res.set(STRING_WITH_LEN(
"polygon"), cs);
8256 case GEOM_MULTIPOINT:
8257 res.set(STRING_WITH_LEN(
"multipoint"), cs);
8259 case GEOM_MULTILINESTRING:
8260 res.set(STRING_WITH_LEN(
"multilinestring"), cs);
8262 case GEOM_MULTIPOLYGON:
8263 res.set(STRING_WITH_LEN(
"multipolygon"), cs);
8265 case GEOM_GEOMETRYCOLLECTION:
8266 res.set(STRING_WITH_LEN(
"geometrycollection"), cs);
8269 res.set(STRING_WITH_LEN(
"geometry"), cs);
8274 type_conversion_status Field_geom::store(
double nr)
8276 my_message(ER_CANT_CREATE_GEOMETRY_OBJECT,
8277 ER(ER_CANT_CREATE_GEOMETRY_OBJECT), MYF(0));
8278 return TYPE_ERR_BAD_VALUE;
8282 type_conversion_status Field_geom::store(longlong nr,
bool unsigned_val)
8284 my_message(ER_CANT_CREATE_GEOMETRY_OBJECT,
8285 ER(ER_CANT_CREATE_GEOMETRY_OBJECT), MYF(0));
8286 return TYPE_ERR_BAD_VALUE;
8290 type_conversion_status Field_geom::store_decimal(
const my_decimal *)
8292 my_message(ER_CANT_CREATE_GEOMETRY_OBJECT,
8293 ER(ER_CANT_CREATE_GEOMETRY_OBJECT), MYF(0));
8294 return TYPE_ERR_BAD_VALUE;
8298 type_conversion_status
8299 Field_geom::store_internal(
const char *from, uint length,
8304 DBUG_ASSERT(length > 0);
8307 if (from == Geometry::bad_geometry_data.ptr() ||
8308 length < SRID_SIZE + WKB_HEADER_SIZE + SIZEOF_STORED_DOUBLE * 2 ||
8309 (wkb_type= uint4korr(from + SRID_SIZE + 1)) < (uint32) Geometry::wkb_point ||
8310 wkb_type > (uint32) Geometry::wkb_last)
8312 memset(ptr, 0, Field_blob::pack_length());
8313 my_message(ER_CANT_CREATE_GEOMETRY_OBJECT,
8314 ER(ER_CANT_CREATE_GEOMETRY_OBJECT), MYF(0));
8315 return TYPE_ERR_BAD_VALUE;
8318 if (table->copy_blobs || length <= MAX_FIELD_WIDTH)
8320 value.copy(from, length, cs);
8324 store_ptr_and_length(from, length);
8331 return new_field->field_flags_are_binary() == field_flags_are_binary() &&
8332 new_field->sql_type == real_type() &&
8333 new_field->geom_type == get_geometry_type() &&
8334 new_field->charset == field_charset &&
8335 new_field->pack_length == pack_length();
8347 enum ha_base_keytype Field_enum::key_type()
const
8349 switch (packlength) {
8350 default:
return HA_KEYTYPE_BINARY;
8351 case 2:
return HA_KEYTYPE_USHORT_INT;
8352 case 3:
return HA_KEYTYPE_UINT24;
8353 case 4:
return HA_KEYTYPE_ULONG_INT;
8354 case 8:
return HA_KEYTYPE_ULONGLONG;
8358 void Field_enum::store_type(ulonglong value)
8360 switch (packlength) {
8361 case 1: ptr[0]= (uchar) value;
break;
8363 #ifdef WORDS_BIGENDIAN
8364 if (table->s->db_low_byte_first)
8366 int2store(ptr,(
unsigned short) value);
8370 shortstore(ptr,(
unsigned short) value);
8372 case 3: int3store(ptr,(
long) value);
break;
8374 #ifdef WORDS_BIGENDIAN
8375 if (table->s->db_low_byte_first)
8377 int4store(ptr,value);
8381 longstore(ptr,(
long) value);
8384 #ifdef WORDS_BIGENDIAN
8385 if (table->s->db_low_byte_first)
8387 int8store(ptr,value);
8391 longlongstore(ptr,value);
break;
8402 type_conversion_status
8405 ASSERT_COLUMN_MARKED_FOR_WRITE;
8407 type_conversion_status ret= TYPE_OK;
8409 char buff[STRING_BUFFER_USUAL_SIZE];
8410 String tmpstr(buff,
sizeof(buff), &my_charset_bin);
8413 if (String::needs_conversion(length, cs, field_charset, ¬_used))
8416 tmpstr.copy(from, length, cs, field_charset, &dummy_errors);
8418 length= tmpstr.length();
8422 length= field_charset->cset->lengthsp(field_charset, from, length);
8423 uint tmp=find_type2(typelib, from, length, field_charset);
8430 tmp=(uint) my_strntoul(cs,from,length,10,&end,&err);
8431 if (err || end != from+length || tmp > typelib->count)
8434 set_warning(Sql_condition::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
8435 ret= TYPE_WARN_TRUNCATED;
8437 if (!table->in_use->count_cuted_fields)
8441 set_warning(Sql_condition::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
8443 store_type((ulonglong) tmp);
8456 ASSERT_COLUMN_MARKED_FOR_WRITE;
8457 type_conversion_status error= TYPE_OK;
8458 if ((ulonglong) nr > typelib->count || nr == 0)
8460 set_warning(Sql_condition::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
8461 if (nr != 0 || table->in_use->count_cuted_fields)
8464 error= TYPE_WARN_TRUNCATED;
8467 store_type((ulonglong) (uint) nr);
8472 double Field_enum::val_real(
void)
8474 return (
double) Field_enum::val_int();
8480 ASSERT_COLUMN_MARKED_FOR_READ;
8481 int2my_decimal(E_DEC_FATAL_ERROR, val_int(), 0, decimal_value);
8482 return decimal_value;
8486 longlong Field_enum::val_int(
void)
8488 ASSERT_COLUMN_MARKED_FOR_READ;
8489 switch (packlength) {
8491 return (longlong) ptr[0];
8495 #ifdef WORDS_BIGENDIAN
8496 if (table->s->db_low_byte_first)
8501 return (longlong) tmp;
8504 return (longlong) uint3korr(ptr);
8508 #ifdef WORDS_BIGENDIAN
8509 if (table->s->db_low_byte_first)
8514 return (longlong) tmp;
8519 #ifdef WORDS_BIGENDIAN
8520 if (table->s->db_low_byte_first)
8524 longlongget(tmp,ptr);
8543 int Field_enum::do_save_field_metadata(uchar *metadata_ptr)
8545 *metadata_ptr= real_type();
8546 *(metadata_ptr + 1)= pack_length();
8551 String *Field_enum::val_str(
String *val_buffer __attribute__((unused)),
8554 uint tmp=(uint) Field_enum::val_int();
8555 if (!tmp || tmp > typelib->count)
8556 val_ptr->set(
"", 0, field_charset);
8558 val_ptr->set((
const char*) typelib->type_names[tmp-1],
8559 typelib->type_lengths[tmp-1],
8564 int Field_enum::cmp(
const uchar *a_ptr,
const uchar *b_ptr)
8567 ptr= (uchar*) a_ptr;
8568 ulonglong a=Field_enum::val_int();
8569 ptr= (uchar*) b_ptr;
8570 ulonglong b=Field_enum::val_int();
8572 return (a < b) ? -1 : (a > b) ? 1 : 0;
8577 #ifdef WORDS_BIGENDIAN
8578 if (!table->s->db_low_byte_first)
8579 copy_integer<true>(
to, length, ptr, packlength,
true);
8582 copy_integer<false>(
to, length, ptr, packlength,
true);
8586 void Field_enum::sql_type(
String &res)
const
8589 String enum_item(buffer,
sizeof(buffer), res.charset());
8592 res.append(STRING_WITH_LEN(
"enum("));
8595 uint *len= typelib->type_lengths;
8596 for (
const char **pos= typelib->type_names; *pos; pos++, len++)
8602 enum_item.copy(*pos, *len, charset(), res.charset(), &dummy_errors);
8603 append_unescaped(&res, enum_item.ptr(), enum_item.length());
8615 res->typelib= copy_typelib(root, typelib);
8630 type_conversion_status
8633 ASSERT_COLUMN_MARKED_FOR_WRITE;
8634 bool got_warning= 0;
8636 type_conversion_status ret= TYPE_OK;
8639 uint32 not_used_offset;
8640 char buff[STRING_BUFFER_USUAL_SIZE];
8641 String tmpstr(buff,
sizeof(buff), &my_charset_bin);
8644 if (String::needs_conversion(length, cs, field_charset, ¬_used_offset))
8647 tmpstr.copy(from, length, cs, field_charset, &dummy_errors);
8649 length= tmpstr.length();
8651 ulonglong tmp= find_set(typelib, from, length, field_charset,
8652 ¬_used, ¬_used2, &got_warning);
8653 if (!tmp && length && length < 22)
8657 tmp=my_strntoull(cs,from,length,10,&end,&err);
8658 if (err || end != from+length ||
8659 tmp > (ulonglong) (((longlong) 1 << typelib->count) - (longlong) 1))
8662 set_warning(Sql_condition::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
8663 ret= TYPE_WARN_TRUNCATED;
8666 else if (got_warning)
8667 set_warning(Sql_condition::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
8675 ASSERT_COLUMN_MARKED_FOR_WRITE;
8676 type_conversion_status error= TYPE_OK;
8679 if (
sizeof(ulonglong)*8 <= typelib->count)
8680 max_nr= ULONGLONG_MAX;
8682 max_nr= (ULL(1) << typelib->count) - 1;
8684 if ((ulonglong) nr > max_nr)
8687 set_warning(Sql_condition::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
8688 error= TYPE_WARN_TRUNCATED;
8690 store_type((ulonglong) nr);
8696 String *val_ptr __attribute__((unused)))
8698 ulonglong tmp=(ulonglong) Field_enum::val_int();
8707 *val_buffer= empty_set_string;
8711 val_buffer->set_charset(field_charset);
8712 val_buffer->length(0);
8714 while (tmp && bitnr < (uint) typelib->count)
8718 if (val_buffer->length())
8719 val_buffer->append(&field_separator, 1, &my_charset_latin1);
8720 String str(typelib->type_names[bitnr],
8721 typelib->type_lengths[bitnr],
8723 val_buffer->append(str);
8732 void Field_set::sql_type(
String &res)
const
8735 String set_item(buffer,
sizeof(buffer), res.charset());
8738 res.append(STRING_WITH_LEN(
"set("));
8741 uint *len= typelib->type_lengths;
8742 for (
const char **pos= typelib->type_names; *pos; pos++, len++)
8748 set_item.copy(*pos, *len, charset(), res.charset(), &dummy_errors);
8749 append_unescaped(&res, set_item.ptr(), set_item.length());
8764 if (real_type() != field->real_type() || charset() != field->charset() ||
8765 pack_length() != field->pack_length())
8777 static bool compare_type_names(
const CHARSET_INFO *charset,
8780 for (uint i= 0; i < t1->count; i++)
8781 if (my_strnncoll(charset,
8782 (
const uchar*) t1->type_names[i],
8783 t1->type_lengths[i],
8784 (
const uchar*) t2->type_names[i],
8785 t2->type_lengths[i]))
8805 if (typelib->count != values->count)
8808 return compare_type_names(field_charset, typelib, values);
8823 TYPELIB *values= new_field->interval;
8829 if (new_field->field_flags_are_binary() != field_flags_are_binary() ||
8830 new_field->sql_type != real_type() ||
8831 new_field->charset != field_charset ||
8832 new_field->pack_length != pack_length())
8840 if (typelib->count > values->count)
8844 if (! compare_type_names(field_charset, typelib, new_field->interval))
8847 return IS_EQUAL_YES;
8852 uint max_length,
bool low_byte_first)
8854 DBUG_ENTER(
"Field_enum::pack");
8855 DBUG_PRINT(
"debug", (
"packlength: %d", packlength));
8856 DBUG_DUMP(
"from", from, packlength);
8862 DBUG_RETURN(to + 1);
8863 case 2: DBUG_RETURN(pack_int16(to, from, low_byte_first));
8864 case 3: DBUG_RETURN(pack_int24(to, from, low_byte_first));
8865 case 4: DBUG_RETURN(pack_int32(to, from, low_byte_first));
8866 case 8: DBUG_RETURN(pack_int64(to, from, low_byte_first));
8870 MY_ASSERT_UNREACHABLE();
8875 uint param_data,
bool low_byte_first)
8877 DBUG_ENTER(
"Field_enum::unpack");
8878 DBUG_PRINT(
"debug", (
"packlength: %d", packlength));
8879 DBUG_DUMP(
"from", from, packlength);
8885 DBUG_RETURN(from + 1);
8887 case 2: DBUG_RETURN(unpack_int16(to, from, low_byte_first));
8888 case 3: DBUG_RETURN(unpack_int24(to, from, low_byte_first));
8889 case 4: DBUG_RETURN(unpack_int32(to, from, low_byte_first));
8890 case 8: DBUG_RETURN(unpack_int64(to, from, low_byte_first));
8894 MY_ASSERT_UNREACHABLE();
8909 if (unsigned_flag != from_num->unsigned_flag ||
8910 (zerofill && !from_num->zerofill && !zero_pack()) ||
8911 dec != from_num->dec)
8925 return ((new_field->sql_type == real_type()) &&
8926 ((new_field->flags & UNSIGNED_FLAG) ==
8927 (uint) (flags & UNSIGNED_FLAG)) &&
8928 ((new_field->flags & AUTO_INCREMENT_FLAG) ==
8929 (uint) (flags & AUTO_INCREMENT_FLAG)) &&
8930 (new_field->pack_length == pack_length()));
8963 Field_bit::Field_bit(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
8964 uchar null_bit_arg, uchar *bit_ptr_arg, uchar bit_ofs_arg,
8965 enum utype unireg_check_arg,
const char *field_name_arg)
8966 :
Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
8967 unireg_check_arg, field_name_arg),
8968 bit_ptr(bit_ptr_arg), bit_ofs(bit_ofs_arg), bit_len(len_arg & 7),
8969 bytes_in_rec(len_arg / 8)
8971 DBUG_ENTER(
"Field_bit::Field_bit");
8972 DBUG_PRINT(
"enter", (
"ptr_arg: %p, null_ptr_arg: %p, len_arg: %u, bit_len: %u, bytes_in_rec: %u",
8973 ptr_arg, null_ptr_arg, len_arg, bit_len, bytes_in_rec));
8974 flags|= UNSIGNED_FLAG;
8980 null_bit= bit_ofs_arg;
8985 void Field_bit::hash(ulong *nr, ulong *nr2)
8989 *nr^= (*nr << 1) | 1;
8994 longlong value= Field_bit::val_int();
8996 mi_int8store(tmp,value);
8997 cs->coll->hash_sort(cs, tmp, 8, nr, nr2);
9003 Field_bit::do_last_null_byte()
const
9013 DBUG_PRINT(
"test", (
"bit_ofs: %d, bit_len: %d bit_ptr: 0x%lx",
9014 bit_ofs, bit_len, (
long) bit_ptr));
9018 else if (bit_ofs + bit_len > 8)
9019 result= bit_ptr + 1;
9024 return (
size_t) (result - table->record[0]) + 1;
9025 return LAST_NULL_BYTE_UNDEF;
9031 uchar *new_ptr, uchar *new_null_ptr,
9035 if ((res= (
Field_bit*) Field::new_key_field(root, new_table,
9036 new_ptr, new_null_ptr,
9040 res->bit_ptr= new_ptr;
9051 return (new_field->sql_type == real_type() &&
9052 new_field->length == max_display_length());
9056 type_conversion_status
9057 Field_bit::store(
const char *from, uint length,
const CHARSET_INFO *cs)
9059 ASSERT_COLUMN_MARKED_FOR_WRITE;
9062 for (; length && !*from; from++, length--) ;
9063 delta= bytes_in_rec - length;
9069 (delta == -1 && (uchar) *from > ((1 << bit_len) - 1)) ||
9070 (!bit_len && delta < 0))
9072 set_rec_bits((1 << bit_len) - 1, bit_ptr, bit_ofs, bit_len);
9073 memset(ptr, 0xff, bytes_in_rec);
9074 if (table->in_use->really_abort_on_warning())
9075 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_DATA_TOO_LONG, 1);
9077 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
9078 return TYPE_WARN_OUT_OF_RANGE;
9084 clr_rec_bits(bit_ptr, bit_ofs, bit_len);
9085 memset(ptr, 0, delta);
9086 memcpy(ptr + delta, from, length);
9088 else if (delta == 0)
9091 clr_rec_bits(bit_ptr, bit_ofs, bit_len);
9092 memcpy(ptr, from, length);
9098 set_rec_bits((uchar) *from, bit_ptr, bit_ofs, bit_len);
9101 memcpy(ptr, from, bytes_in_rec);
9107 type_conversion_status Field_bit::store(
double nr)
9109 return Field_bit::store((longlong) nr, FALSE);
9113 type_conversion_status Field_bit::store(longlong nr,
bool unsigned_val)
9117 mi_int8store(buf, nr);
9118 return store(buf, 8, NULL);
9122 type_conversion_status Field_bit::store_decimal(
const my_decimal *val)
9124 bool has_overflow=
false;
9126 type_conversion_status res= store(i, TRUE);
9127 return has_overflow ? TYPE_WARN_OUT_OF_RANGE : res;
9131 double Field_bit::val_real(
void)
9133 return (
double) Field_bit::val_int();
9137 longlong Field_bit::val_int(
void)
9139 ASSERT_COLUMN_MARKED_FOR_READ;
9143 bits= get_rec_bits(bit_ptr, bit_ofs, bit_len);
9144 bits<<= (bytes_in_rec * 8);
9147 switch (bytes_in_rec) {
9148 case 0:
return bits;
9149 case 1:
return bits | (ulonglong) ptr[0];
9150 case 2:
return bits | mi_uint2korr(ptr);
9151 case 3:
return bits | mi_uint3korr(ptr);
9152 case 4:
return bits | mi_uint4korr(ptr);
9153 case 5:
return bits | mi_uint5korr(ptr);
9154 case 6:
return bits | mi_uint6korr(ptr);
9155 case 7:
return bits | mi_uint7korr(ptr);
9156 default:
return mi_uint8korr(ptr + bytes_in_rec -
sizeof(longlong));
9162 String *val_ptr __attribute__((unused)))
9164 ASSERT_COLUMN_MARKED_FOR_READ;
9165 char buff[
sizeof(longlong)];
9166 uint length= min<uint>(pack_length(),
sizeof(longlong));
9167 ulonglong bits= val_int();
9168 mi_int8store(buff,bits);
9170 val_buffer->alloc(length);
9171 memcpy((
char *) val_buffer->ptr(), buff+8-length, length);
9172 val_buffer->length(length);
9173 val_buffer->set_charset(&my_charset_bin);
9180 ASSERT_COLUMN_MARKED_FOR_READ;
9181 int2my_decimal(E_DEC_FATAL_ERROR, val_int(), 1, deciaml_value);
9182 return deciaml_value;
9199 int Field_bit::cmp_max(
const uchar *a,
const uchar *b, uint max_len)
9201 my_ptrdiff_t a_diff= a - ptr;
9202 my_ptrdiff_t b_diff= b - ptr;
9206 uchar bits_a= get_rec_bits(bit_ptr+a_diff, bit_ofs, bit_len);
9207 uchar bits_b= get_rec_bits(bit_ptr+b_diff, bit_ofs, bit_len);
9208 if ((flag= (
int) (bits_a - bits_b)))
9211 return memcmp(a, b, field_length);
9215 int Field_bit::key_cmp(
const uchar *str, uint length)
9220 uchar bits= get_rec_bits(bit_ptr, bit_ofs, bit_len);
9221 if ((flag= (
int) (bits - *str)))
9226 return memcmp(ptr, str, length);
9230 int Field_bit::cmp_offset(uint row_offset)
9235 uchar bits_a= get_rec_bits(bit_ptr, bit_ofs, bit_len);
9236 uchar bits_b= get_rec_bits(bit_ptr + row_offset, bit_ofs, bit_len);
9237 if ((flag= (
int) (bits_a - bits_b)))
9240 return memcmp(ptr, ptr + row_offset, bytes_in_rec);
9244 uint Field_bit::get_key_image(uchar *buff, uint length, imagetype type_arg)
9248 uchar bits= get_rec_bits(bit_ptr, bit_ofs, bit_len);
9252 uint data_length = min(length, bytes_in_rec);
9253 memcpy(buff, ptr, data_length);
9254 return data_length + 1;
9269 int Field_bit::do_save_field_metadata(uchar *metadata_ptr)
9271 DBUG_ENTER(
"Field_bit::do_save_field_metadata");
9272 DBUG_PRINT(
"debug", (
"bit_len: %d, bytes_in_rec: %d",
9273 bit_len, bytes_in_rec));
9279 metadata_ptr[0]= field_length % 8;
9280 metadata_ptr[1]= field_length / 8;
9299 uint
const from_len= (field_metadata >> 8
U) & 0x00ff;
9300 uint
const from_bit_len= field_metadata & 0x00ff;
9301 uint
const source_size= from_len + ((from_bit_len > 0) ? 1 : 0);
9302 return (source_size);
9326 DBUG_ENTER(
"Field_bit::compatible_field_size");
9327 DBUG_ASSERT((field_metadata >> 16) == 0);
9328 uint from_bit_len= 8 * (field_metadata >> 8) + (field_metadata & 0xff);
9329 uint to_bit_len= max_display_length();
9330 DBUG_PRINT(
"debug", (
"from_bit_len: %u, to_bit_len: %u",
9331 from_bit_len, to_bit_len));
9340 if (!(mflags & Table_map_log_event::TM_BIT_LEN_EXACT_F)) {
9341 from_bit_len= (from_bit_len + 7) / 8;
9342 to_bit_len= (to_bit_len + 7) / 8;
9345 *order_var=
compare(from_bit_len, to_bit_len);
9351 void Field_bit::sql_type(
String &res)
const
9354 ulong length= cs->cset->snprintf(cs, (
char*) res.ptr(), res.alloced_length(),
9355 "bit(%d)", (int) field_length);
9356 res.length((uint) length);
9362 bool low_byte_first __attribute__((unused)))
9364 DBUG_ASSERT(max_length > 0);
9387 uchar bits= get_rec_bits(bit_ptr + (from - ptr), bit_ofs, bit_len);
9390 length= min(bytes_in_rec, max_length - (bit_len > 0));
9391 memcpy(to, from, length);
9410 bool low_byte_first __attribute__((unused)))
9412 DBUG_ENTER(
"Field_bit::unpack");
9413 DBUG_PRINT(
"enter", (
"to: %p, from: %p, param_data: 0x%x",
9414 to, from, param_data));
9415 DBUG_PRINT(
"debug", (
"bit_ptr: %p, bit_len: %u, bit_ofs: %u",
9416 bit_ptr, bit_len, bit_ofs));
9417 uint
const from_len= (param_data >> 8
U) & 0x00ff;
9418 uint
const from_bit_len= param_data & 0x00ff;
9419 DBUG_PRINT(
"debug", (
"from_len: %u, from_bit_len: %u",
9420 from_len, from_bit_len));
9425 if (param_data == 0 ||
9426 ((from_bit_len == bit_len) && (from_len == bytes_in_rec)))
9437 set_rec_bits(*from, bit_ptr + (to - ptr), bit_ofs, bit_len);
9440 memcpy(to, from, bytes_in_rec);
9441 DBUG_RETURN(from + bytes_in_rec);
9452 uint new_len= (field_length + 7) / 8;
9453 char *value= (
char *)my_alloca(new_len);
9454 memset(value, 0, new_len);
9455 uint len= from_len + ((from_bit_len > 0) ? 1 : 0);
9456 memcpy(value + (new_len - len), from, len);
9462 if ((from_bit_len > 0) && (from_len > 0))
9463 value[new_len - len]= value[new_len - len] & ((1
U << from_bit_len) - 1);
9464 bitmap_set_bit(table->write_set,field_index);
9465 store(value, new_len, system_charset_info);
9467 DBUG_RETURN(from + len);
9471 void Field_bit::set_default()
9475 my_ptrdiff_t
const offset= table->s->default_values - table->record[0];
9476 uchar bits= get_rec_bits(bit_ptr + offset, bit_ofs, bit_len);
9477 set_rec_bits(bits, bit_ptr, bit_ofs, bit_len);
9479 Field::set_default();
9486 Field_bit_as_char::Field_bit_as_char(uchar *ptr_arg, uint32 len_arg,
9487 uchar *null_ptr_arg, uchar null_bit_arg,
9488 enum utype unireg_check_arg,
9489 const char *field_name_arg)
9490 :
Field_bit(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, 0, 0,
9491 unireg_check_arg, field_name_arg)
9493 flags|= UNSIGNED_FLAG;
9495 bytes_in_rec= (len_arg + 7) / 8;
9499 type_conversion_status Field_bit_as_char::store(
const char *from, uint length,
9502 ASSERT_COLUMN_MARKED_FOR_WRITE;
9504 uchar bits= (uchar) (field_length & 7);
9506 for (; length && !*from; from++, length--) ;
9507 delta= bytes_in_rec - length;
9510 (delta == 0 && bits && (uint) (uchar) *from >= (uint) (1 << bits)))
9512 memset(ptr, 0xff, bytes_in_rec);
9514 *ptr&= ((1 << bits) - 1);
9515 if (table->in_use->really_abort_on_warning())
9516 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_DATA_TOO_LONG, 1);
9518 set_warning(Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
9519 return TYPE_WARN_OUT_OF_RANGE;
9521 memset(ptr, 0, delta);
9522 memcpy(ptr + delta, from, length);
9527 void Field_bit_as_char::sql_type(
String &res)
const
9530 ulong length= cs->cset->snprintf(cs, (
char*) res.ptr(), res.alloced_length(),
9531 "bit(%d)", (int) field_length);
9532 res.length((uint) length);
9547 case MYSQL_TYPE_TINY_BLOB:
9548 case MYSQL_TYPE_MEDIUM_BLOB:
9549 case MYSQL_TYPE_LONG_BLOB:
9550 case MYSQL_TYPE_BLOB:
9551 case MYSQL_TYPE_GEOMETRY:
9552 case MYSQL_TYPE_VAR_STRING:
9553 case MYSQL_TYPE_STRING:
9554 case MYSQL_TYPE_VARCHAR:
9555 length*= charset->mbmaxlen;
9557 pack_length= calc_pack_length(sql_type, length);
9559 case MYSQL_TYPE_ENUM:
9560 case MYSQL_TYPE_SET:
9562 length*= charset->mbmaxlen;
9563 key_length= pack_length;
9565 case MYSQL_TYPE_BIT:
9566 if (f_bit_as_char(pack_flag))
9568 key_length= pack_length= ((length + 7) & ~7) / 8;
9572 pack_length= length / 8;
9574 key_length= pack_length +
test(length & 7);
9577 case MYSQL_TYPE_NEWDECIMAL:
9578 key_length= pack_length=
9579 my_decimal_get_binary_size(my_decimal_length_to_precision(length,
9586 key_length= pack_length= calc_pack_length(sql_type, length);
9596 uint32 length_arg, uint32 decimals_arg,
9597 bool maybe_null,
bool is_unsigned,
9598 uint pack_length_arg)
9600 DBUG_ENTER(
"Create_field::init_for_tmp_table");
9603 sql_type= sql_type_arg;
9604 char_length= length= length_arg;;
9605 unireg_check= Field::NONE;
9607 charset= &my_charset_bin;
9608 geom_type= Field::GEOM_GEOMETRY;
9610 DBUG_PRINT(
"enter", (
"sql_type: %d, length: %u, pack_length: %u",
9611 sql_type_arg, length_arg, pack_length_arg));
9617 switch (sql_type_arg)
9619 case MYSQL_TYPE_VARCHAR:
9620 case MYSQL_TYPE_VAR_STRING:
9621 case MYSQL_TYPE_STRING:
9622 case MYSQL_TYPE_SET:
9626 case MYSQL_TYPE_GEOMETRY:
9627 pack_flag= FIELDFLAG_GEOM;
9630 case MYSQL_TYPE_ENUM:
9631 pack_flag= FIELDFLAG_INTERVAL;
9634 case MYSQL_TYPE_NEWDECIMAL:
9635 DBUG_ASSERT(decimals_arg <= DECIMAL_MAX_SCALE);
9636 case MYSQL_TYPE_DECIMAL:
9637 case MYSQL_TYPE_FLOAT:
9638 case MYSQL_TYPE_DOUBLE:
9639 pack_flag= FIELDFLAG_NUMBER |
9640 (decimals_arg & FIELDFLAG_MAX_DEC) << FIELDFLAG_DEC_SHIFT;
9643 case MYSQL_TYPE_TINY_BLOB:
9644 case MYSQL_TYPE_MEDIUM_BLOB:
9645 case MYSQL_TYPE_LONG_BLOB:
9646 case MYSQL_TYPE_BLOB:
9647 pack_flag= FIELDFLAG_BLOB;
9650 case MYSQL_TYPE_BIT:
9651 pack_flag= FIELDFLAG_NUMBER | FIELDFLAG_TREAT_BIT_AS_CHAR;
9655 pack_flag= FIELDFLAG_NUMBER;
9665 switch (sql_type_arg)
9667 case MYSQL_TYPE_ENUM:
9668 case MYSQL_TYPE_SET:
9669 case MYSQL_TYPE_TINY_BLOB:
9670 case MYSQL_TYPE_MEDIUM_BLOB:
9671 case MYSQL_TYPE_LONG_BLOB:
9672 case MYSQL_TYPE_BLOB:
9673 case MYSQL_TYPE_GEOMETRY:
9676 DBUG_ASSERT(pack_length_arg != ~0
U);
9677 pack_flag|= pack_length_to_packflag(pack_length_arg);
9685 (maybe_null ? FIELDFLAG_MAYBE_NULL : 0) |
9686 (is_unsigned ? 0 : FIELDFLAG_DECIMAL);
9688 DBUG_PRINT(
"debug", (
"pack_flag: %s%s%s%s%s%s, pack_type: %d",
9689 FLAGSTR(pack_flag, FIELDFLAG_BINARY),
9690 FLAGSTR(pack_flag, FIELDFLAG_NUMBER),
9691 FLAGSTR(pack_flag, FIELDFLAG_INTERVAL),
9692 FLAGSTR(pack_flag, FIELDFLAG_GEOM),
9693 FLAGSTR(pack_flag, FIELDFLAG_BLOB),
9694 FLAGSTR(pack_flag, FIELDFLAG_DECIMAL),
9695 f_packtype(pack_flag)));
9726 char *fld_length,
char *fld_decimals,
9727 uint fld_type_modifier,
Item *fld_default_value,
9732 uint sign_len, allowed_type_modifier= 0;
9733 ulong max_field_charlength= MAX_FIELD_CHARLENGTH;
9735 DBUG_ENTER(
"Create_field::init()");
9738 field_name= fld_name;
9739 flags= fld_type_modifier;
9740 charset= fld_charset;
9742 const bool on_update_is_function=
9743 (fld_on_update_value != NULL &&
9744 fld_on_update_value->type() == Item::FUNC_ITEM);
9746 if (fld_default_value != NULL && fld_default_value->type() == Item::FUNC_ITEM)
9750 unireg_check= on_update_is_function ?
9751 Field::TIMESTAMP_DNUN_FIELD :
9752 Field::TIMESTAMP_DN_FIELD;
9757 def= fld_default_value;
9758 if (on_update_is_function)
9760 unireg_check= Field::TIMESTAMP_UN_FIELD;
9763 unireg_check= (fld_type_modifier & AUTO_INCREMENT_FLAG) != 0 ?
9764 Field::NEXT_NUMBER :
9768 decimals= fld_decimals ? (uint)atoi(fld_decimals) : 0;
9769 if (is_temporal_real_type(fld_type))
9771 flags|= BINARY_FLAG;
9772 charset= &my_charset_numeric;
9773 if (decimals > DATETIME_MAX_DECIMALS)
9775 my_error(ER_TOO_BIG_PRECISION, MYF(0),
9776 decimals, fld_name, DATETIME_MAX_DECIMALS);
9780 else if (decimals >= NOT_FIXED_DEC)
9782 my_error(ER_TOO_BIG_SCALE, MYF(0), decimals, fld_name,
9783 static_cast<ulong>(NOT_FIXED_DEC - 1));
9791 pack_length= key_length= 0;
9792 geom_type= (Field::geometry_type) fld_geom_type;
9793 interval_list.empty();
9795 comment= *fld_comment;
9800 if (!fld_default_value &&
9801 (fld_type_modifier & NOT_NULL_FLAG) &&
9802 !(fld_type_modifier & AUTO_INCREMENT_FLAG))
9808 if (thd->variables.explicit_defaults_for_timestamp ||
9809 !is_timestamp_type(fld_type))
9811 flags|= NO_DEFAULT_VALUE_FLAG;
9815 if (fld_length != NULL)
9818 length= strtoul(fld_length, NULL, 10);
9819 if ((errno != 0) || (length > MAX_FIELD_BLOBLENGTH))
9821 my_error(ER_TOO_BIG_DISPLAYWIDTH, MYF(0), fld_name, MAX_FIELD_BLOBLENGTH);
9829 sign_len= fld_type_modifier & UNSIGNED_FLAG ? 0 : 1;
9832 case MYSQL_TYPE_TINY:
9834 length= MAX_TINYINT_WIDTH+sign_len;
9835 allowed_type_modifier= AUTO_INCREMENT_FLAG;
9837 case MYSQL_TYPE_SHORT:
9839 length= MAX_SMALLINT_WIDTH+sign_len;
9840 allowed_type_modifier= AUTO_INCREMENT_FLAG;
9842 case MYSQL_TYPE_INT24:
9844 length= MAX_MEDIUMINT_WIDTH+sign_len;
9845 allowed_type_modifier= AUTO_INCREMENT_FLAG;
9847 case MYSQL_TYPE_LONG:
9849 length= MAX_INT_WIDTH+sign_len;
9850 allowed_type_modifier= AUTO_INCREMENT_FLAG;
9852 case MYSQL_TYPE_LONGLONG:
9854 length= MAX_BIGINT_WIDTH;
9855 allowed_type_modifier= AUTO_INCREMENT_FLAG;
9857 case MYSQL_TYPE_NULL:
9859 case MYSQL_TYPE_NEWDECIMAL:
9860 my_decimal_trim(&length, &decimals);
9863 my_error(ER_TOO_BIG_PRECISION, MYF(0), static_cast<int>(length),
9867 if (length < decimals)
9869 my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
9873 my_decimal_precision_to_length(length, decimals,
9874 fld_type_modifier & UNSIGNED_FLAG);
9876 my_decimal_get_binary_size(length, decimals);
9878 case MYSQL_TYPE_VARCHAR:
9883 max_field_charlength= MAX_FIELD_VARCHARLENGTH;
9885 case MYSQL_TYPE_STRING:
9887 case MYSQL_TYPE_BLOB:
9888 case MYSQL_TYPE_TINY_BLOB:
9889 case MYSQL_TYPE_LONG_BLOB:
9890 case MYSQL_TYPE_MEDIUM_BLOB:
9891 case MYSQL_TYPE_GEOMETRY:
9892 if (fld_default_value)
9896 res= fld_default_value->val_str(&str);
9901 if (res->length() || thd->is_strict_mode())
9903 my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0),
9912 push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
9913 ER_BLOB_CANT_HAVE_DEFAULT,
9914 ER(ER_BLOB_CANT_HAVE_DEFAULT),
9921 case MYSQL_TYPE_YEAR:
9922 if (!fld_length || length != 2)
9924 flags|= ZEROFILL_FLAG | UNSIGNED_FLAG;
9926 case MYSQL_TYPE_FLOAT:
9928 allowed_type_modifier= AUTO_INCREMENT_FLAG;
9929 if (fld_length && !fld_decimals)
9931 uint tmp_length= length;
9932 if (tmp_length > PRECISION_FOR_DOUBLE)
9934 my_error(ER_WRONG_FIELD_SPEC, MYF(0), fld_name);
9937 else if (tmp_length > PRECISION_FOR_FLOAT)
9939 sql_type= MYSQL_TYPE_DOUBLE;
9940 length= MAX_DOUBLE_STR_LENGTH;
9943 length= MAX_FLOAT_STR_LENGTH;
9944 decimals= NOT_FIXED_DEC;
9947 if (!fld_length && !fld_decimals)
9949 length= MAX_FLOAT_STR_LENGTH;
9950 decimals= NOT_FIXED_DEC;
9952 if (length < decimals &&
9953 decimals != NOT_FIXED_DEC)
9955 my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
9959 case MYSQL_TYPE_DOUBLE:
9960 allowed_type_modifier= AUTO_INCREMENT_FLAG;
9961 if (!fld_length && !fld_decimals)
9964 decimals= NOT_FIXED_DEC;
9966 if (length < decimals &&
9967 decimals != NOT_FIXED_DEC)
9969 my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
9973 case MYSQL_TYPE_TIMESTAMP:
9975 flags|= ZEROFILL_FLAG | UNSIGNED_FLAG;
9977 case MYSQL_TYPE_TIMESTAMP2:
9978 if (fld_length == NULL)
9980 length= MAX_DATETIME_WIDTH + (decimals ? (1 + decimals) : 0);
9982 else if (length != MAX_DATETIME_WIDTH)
9989 DBUG_ASSERT(MAX_DATETIME_COMPRESSED_WIDTH < UINT_MAX);
9990 if (length != UINT_MAX)
9991 length= ((length+1)/2)*2;
9992 length= min<ulong>(length, MAX_DATETIME_COMPRESSED_WIDTH);
9999 max_field_charlength= UINT_MAX;
10002 case MYSQL_TYPE_DATE:
10004 sql_type= MYSQL_TYPE_NEWDATE;
10006 case MYSQL_TYPE_NEWDATE:
10007 length= MAX_DATE_WIDTH;
10009 case MYSQL_TYPE_TIME:
10010 case MYSQL_TYPE_TIME2:
10011 length= MAX_TIME_WIDTH + (decimals ? (1 + decimals) : 0);
10013 case MYSQL_TYPE_DATETIME:
10014 case MYSQL_TYPE_DATETIME2:
10015 length= MAX_DATETIME_WIDTH + (decimals ? (1 + decimals) : 0);
10017 case MYSQL_TYPE_SET:
10019 pack_length= get_set_pack_length(fld_interval_list->elements);
10023 while ((tmp= it++))
10024 interval_list.push_back(tmp);
10033 case MYSQL_TYPE_ENUM:
10036 pack_length= get_enum_pack_length(fld_interval_list->elements);
10040 while ((tmp= it++))
10041 interval_list.push_back(tmp);
10045 case MYSQL_TYPE_VAR_STRING:
10048 case MYSQL_TYPE_BIT:
10052 if (length > MAX_BIT_FIELD_LENGTH)
10054 my_error(ER_TOO_BIG_DISPLAYWIDTH, MYF(0), fld_name,
10055 static_cast<ulong>(MAX_BIT_FIELD_LENGTH));
10058 pack_length= (length + 7) / 8;
10061 case MYSQL_TYPE_DECIMAL:
10065 char_length= length;
10067 if (!(flags & BLOB_FLAG) &&
10068 ((length > max_field_charlength && fld_type != MYSQL_TYPE_SET &&
10069 fld_type != MYSQL_TYPE_ENUM &&
10070 (fld_type != MYSQL_TYPE_VARCHAR || fld_default_value)) ||
10072 fld_type != MYSQL_TYPE_STRING &&
10073 fld_type != MYSQL_TYPE_VARCHAR && fld_type != MYSQL_TYPE_GEOMETRY)))
10075 my_error((fld_type == MYSQL_TYPE_VAR_STRING ||
10076 fld_type == MYSQL_TYPE_VARCHAR ||
10077 fld_type == MYSQL_TYPE_STRING) ? ER_TOO_BIG_FIELDLENGTH :
10078 ER_TOO_BIG_DISPLAYWIDTH,
10080 fld_name, max_field_charlength);
10083 fld_type_modifier&= AUTO_INCREMENT_FLAG;
10084 if ((~allowed_type_modifier) & fld_type_modifier)
10086 my_error(ER_WRONG_FIELD_SPEC, MYF(0), fld_name);
10090 DBUG_RETURN(FALSE);
10094 enum_field_types get_blob_type_from_length(ulong length)
10096 enum_field_types
type;
10098 type= MYSQL_TYPE_TINY_BLOB;
10099 else if (length < 65536)
10100 type= MYSQL_TYPE_BLOB;
10101 else if (length < 256L*256L*256L)
10102 type= MYSQL_TYPE_MEDIUM_BLOB;
10104 type= MYSQL_TYPE_LONG_BLOB;
10113 uint32 calc_pack_length(enum_field_types type,uint32 length)
10116 case MYSQL_TYPE_VAR_STRING:
10117 case MYSQL_TYPE_STRING:
10118 case MYSQL_TYPE_DECIMAL:
return (length);
10119 case MYSQL_TYPE_VARCHAR:
return (length + (length < 256 ? 1: 2));
10120 case MYSQL_TYPE_YEAR:
10121 case MYSQL_TYPE_TINY :
return 1;
10122 case MYSQL_TYPE_SHORT :
return 2;
10123 case MYSQL_TYPE_INT24:
10124 case MYSQL_TYPE_NEWDATE:
return 3;
10125 case MYSQL_TYPE_TIME:
return 3;
10126 case MYSQL_TYPE_TIME2:
10127 return length > MAX_TIME_WIDTH ?
10128 my_time_binary_length(length - MAX_TIME_WIDTH - 1) : 3;
10129 case MYSQL_TYPE_TIMESTAMP:
return 4;
10130 case MYSQL_TYPE_TIMESTAMP2:
10131 return length > MAX_DATETIME_WIDTH ?
10132 my_timestamp_binary_length(length - MAX_DATETIME_WIDTH - 1) : 4;
10133 case MYSQL_TYPE_DATE:
10134 case MYSQL_TYPE_LONG :
return 4;
10135 case MYSQL_TYPE_FLOAT :
return sizeof(float);
10136 case MYSQL_TYPE_DOUBLE:
return sizeof(double);
10137 case MYSQL_TYPE_DATETIME:
return 8;
10138 case MYSQL_TYPE_DATETIME2:
10139 return length > MAX_DATETIME_WIDTH ?
10140 my_datetime_binary_length(length - MAX_DATETIME_WIDTH - 1) : 5;
10141 case MYSQL_TYPE_LONGLONG:
return 8;
10142 case MYSQL_TYPE_NULL :
return 0;
10143 case MYSQL_TYPE_TINY_BLOB:
return 1+portable_sizeof_char_ptr;
10144 case MYSQL_TYPE_BLOB:
return 2+portable_sizeof_char_ptr;
10145 case MYSQL_TYPE_MEDIUM_BLOB:
return 3+portable_sizeof_char_ptr;
10146 case MYSQL_TYPE_LONG_BLOB:
return 4+portable_sizeof_char_ptr;
10147 case MYSQL_TYPE_GEOMETRY:
return 4+portable_sizeof_char_ptr;
10148 case MYSQL_TYPE_SET:
10149 case MYSQL_TYPE_ENUM:
10150 case MYSQL_TYPE_NEWDECIMAL:
10152 case MYSQL_TYPE_BIT:
return length / 8;
10159 uint pack_length_to_packflag(uint type)
10162 case 1:
return f_settype((uint) MYSQL_TYPE_TINY);
10163 case 2:
return f_settype((uint) MYSQL_TYPE_SHORT);
10164 case 3:
return f_settype((uint) MYSQL_TYPE_INT24);
10165 case 4:
return f_settype((uint) MYSQL_TYPE_LONG);
10166 case 8:
return f_settype((uint) MYSQL_TYPE_LONGLONG);
10173 uchar *null_pos, uchar null_bit,
10175 enum_field_types field_type,
10177 Field::geometry_type geom_type,
10178 Field::utype unireg_check,
10180 const char *field_name)
10182 uchar *UNINIT_VAR(bit_ptr);
10183 uchar UNINIT_VAR(bit_offset);
10184 if (field_type == MYSQL_TYPE_BIT && !f_bit_as_char(pack_flag))
10187 bit_offset= null_bit;
10188 if (f_maybe_null(pack_flag))
10190 bit_ptr+= (null_bit == 7);
10191 bit_offset= (bit_offset + 1) & 7;
10195 if (!f_maybe_null(pack_flag))
10202 null_bit= ((uchar) 1) << null_bit;
10205 if (is_temporal_real_type(field_type))
10206 field_charset= &my_charset_numeric;
10208 DBUG_PRINT(
"debug", (
"field_type: %d, field_length: %u, interval: %p, pack_flag: %s%s%s%s%s",
10209 field_type, field_length, interval,
10210 FLAGSTR(pack_flag, FIELDFLAG_BINARY),
10211 FLAGSTR(pack_flag, FIELDFLAG_INTERVAL),
10212 FLAGSTR(pack_flag, FIELDFLAG_NUMBER),
10213 FLAGSTR(pack_flag, FIELDFLAG_PACK),
10214 FLAGSTR(pack_flag, FIELDFLAG_BLOB)));
10216 if (f_is_alpha(pack_flag))
10218 if (!f_is_packed(pack_flag))
10220 if (field_type == MYSQL_TYPE_STRING ||
10221 field_type == MYSQL_TYPE_DECIMAL ||
10222 field_type == MYSQL_TYPE_VAR_STRING)
10223 return new Field_string(ptr,field_length,null_pos,null_bit,
10224 unireg_check, field_name,
10226 if (field_type == MYSQL_TYPE_VARCHAR)
10228 HA_VARCHAR_PACKLENGTH(field_length),
10230 unireg_check, field_name,
10236 uint pack_length=calc_pack_length((enum_field_types)
10237 f_packtype(pack_flag),
10240 #ifdef HAVE_SPATIAL
10241 if (f_is_geom(pack_flag))
10242 return new Field_geom(ptr,null_pos,null_bit,
10243 unireg_check, field_name, share,
10244 pack_length, geom_type);
10246 if (f_is_blob(pack_flag))
10247 return new Field_blob(ptr,null_pos,null_bit,
10248 unireg_check, field_name, share,
10249 pack_length, field_charset);
10252 if (f_is_enum(pack_flag))
10253 return new Field_enum(ptr,field_length,null_pos,null_bit,
10254 unireg_check, field_name,
10255 pack_length, interval, field_charset);
10257 return new Field_set(ptr,field_length,null_pos,null_bit,
10258 unireg_check, field_name,
10259 pack_length, interval, field_charset);
10263 switch (field_type) {
10264 case MYSQL_TYPE_DECIMAL:
10265 return new Field_decimal(ptr,field_length,null_pos,null_bit,
10266 unireg_check, field_name,
10267 f_decimals(pack_flag),
10268 f_is_zerofill(pack_flag) != 0,
10269 f_is_dec(pack_flag) == 0);
10270 case MYSQL_TYPE_NEWDECIMAL:
10272 unireg_check, field_name,
10273 f_decimals(pack_flag),
10274 f_is_zerofill(pack_flag) != 0,
10275 f_is_dec(pack_flag) == 0);
10276 case MYSQL_TYPE_FLOAT:
10277 return new Field_float(ptr,field_length,null_pos,null_bit,
10278 unireg_check, field_name,
10279 f_decimals(pack_flag),
10280 f_is_zerofill(pack_flag) != 0,
10281 f_is_dec(pack_flag)== 0);
10282 case MYSQL_TYPE_DOUBLE:
10283 return new Field_double(ptr,field_length,null_pos,null_bit,
10284 unireg_check, field_name,
10285 f_decimals(pack_flag),
10286 f_is_zerofill(pack_flag) != 0,
10287 f_is_dec(pack_flag)== 0);
10288 case MYSQL_TYPE_TINY:
10289 return new Field_tiny(ptr,field_length,null_pos,null_bit,
10290 unireg_check, field_name,
10291 f_is_zerofill(pack_flag) != 0,
10292 f_is_dec(pack_flag) == 0);
10293 case MYSQL_TYPE_SHORT:
10294 return new Field_short(ptr,field_length,null_pos,null_bit,
10295 unireg_check, field_name,
10296 f_is_zerofill(pack_flag) != 0,
10297 f_is_dec(pack_flag) == 0);
10298 case MYSQL_TYPE_INT24:
10299 return new Field_medium(ptr,field_length,null_pos,null_bit,
10300 unireg_check, field_name,
10301 f_is_zerofill(pack_flag) != 0,
10302 f_is_dec(pack_flag) == 0);
10303 case MYSQL_TYPE_LONG:
10304 return new Field_long(ptr,field_length,null_pos,null_bit,
10305 unireg_check, field_name,
10306 f_is_zerofill(pack_flag) != 0,
10307 f_is_dec(pack_flag) == 0);
10308 case MYSQL_TYPE_LONGLONG:
10309 return new Field_longlong(ptr,field_length,null_pos,null_bit,
10310 unireg_check, field_name,
10311 f_is_zerofill(pack_flag) != 0,
10312 f_is_dec(pack_flag) == 0);
10313 case MYSQL_TYPE_TIMESTAMP:
10315 unireg_check, field_name);
10316 case MYSQL_TYPE_TIMESTAMP2:
10318 unireg_check, field_name,
10319 field_length > MAX_DATETIME_WIDTH ?
10320 field_length - 1 - MAX_DATETIME_WIDTH : 0);
10321 case MYSQL_TYPE_YEAR:
10322 return new Field_year(ptr,field_length,null_pos,null_bit,
10323 unireg_check, field_name);
10324 case MYSQL_TYPE_NEWDATE:
10325 return new Field_newdate(ptr, null_pos, null_bit, unireg_check, field_name);
10327 case MYSQL_TYPE_TIME:
10328 return new Field_time(ptr, null_pos, null_bit,
10329 unireg_check, field_name);
10330 case MYSQL_TYPE_TIME2:
10332 unireg_check, field_name,
10333 (field_length > MAX_TIME_WIDTH) ?
10334 field_length - 1 - MAX_TIME_WIDTH : 0);
10335 case MYSQL_TYPE_DATETIME:
10337 unireg_check, field_name);
10338 case MYSQL_TYPE_DATETIME2:
10340 unireg_check, field_name,
10341 (field_length > MAX_DATETIME_WIDTH) ?
10342 field_length - 1 - MAX_DATETIME_WIDTH : 0);
10343 case MYSQL_TYPE_NULL:
10344 return new Field_null(ptr, field_length, unireg_check, field_name,
10346 case MYSQL_TYPE_BIT:
10347 return f_bit_as_char(pack_flag) ?
10349 unireg_check, field_name) :
10350 new
Field_bit(ptr, field_length, null_pos, null_bit, bit_ptr,
10351 bit_offset, unireg_check, field_name);
10380 field_name(old_field->field_name),
10381 change(old_field->field_name),
10382 comment(old_field->comment),
10383 sql_type(old_field->real_type()),
10384 length(old_field->field_length),
10385 decimals(old_field->decimals()),
10387 pack_length(old_field->pack_length()),
10388 key_length(old_field->key_length()),
10389 unireg_check(old_field->unireg_check),
10390 charset(old_field->charset()),
10394 switch (sql_type) {
10395 case MYSQL_TYPE_BLOB:
10396 switch (pack_length - portable_sizeof_char_ptr) {
10397 case 1: sql_type= MYSQL_TYPE_TINY_BLOB;
break;
10398 case 2: sql_type= MYSQL_TYPE_BLOB;
break;
10399 case 3: sql_type= MYSQL_TYPE_MEDIUM_BLOB;
break;
10400 default: sql_type= MYSQL_TYPE_LONG_BLOB;
break;
10402 length/= charset->mbmaxlen;
10403 key_length/= charset->mbmaxlen;
10405 case MYSQL_TYPE_STRING:
10407 if (old_field->type() == MYSQL_TYPE_VAR_STRING)
10408 sql_type= MYSQL_TYPE_VARCHAR;
10411 case MYSQL_TYPE_ENUM:
10412 case MYSQL_TYPE_SET:
10413 case MYSQL_TYPE_VARCHAR:
10414 case MYSQL_TYPE_VAR_STRING:
10416 length= (length+charset->mbmaxlen-1) / charset->mbmaxlen;
10418 #ifdef HAVE_SPATIAL
10419 case MYSQL_TYPE_GEOMETRY:
10420 geom_type= ((Field_geom*)old_field)->geom_type;
10423 case MYSQL_TYPE_YEAR:
10426 push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
10427 ER_INVALID_YEAR_COLUMN_LENGTH,
10428 ER(ER_INVALID_YEAR_COLUMN_LENGTH),
10437 if (flags & (ENUM_FLAG | SET_FLAG))
10438 interval= ((
Field_enum*) old_field)->typelib;
10442 char_length= length;
10455 if (!(flags & (NO_DEFAULT_VALUE_FLAG | BLOB_FLAG)) &&
10456 old_field->ptr != NULL &&
10457 orig_field != NULL)
10459 bool default_now=
false;
10460 if (real_type_with_now_as_default(sql_type))
10463 default_now= orig_field->has_insert_default_function();
10464 bool update_now= orig_field->has_update_default_function();
10466 if (default_now && update_now)
10467 unireg_check= Field::TIMESTAMP_DNUN_FIELD;
10468 else if (default_now)
10469 unireg_check= Field::TIMESTAMP_DN_FIELD;
10470 else if (update_now)
10471 unireg_check= Field::TIMESTAMP_UN_FIELD;
10475 char buff[MAX_FIELD_WIDTH];
10476 String tmp(buff,
sizeof(buff), charset);
10480 diff= (my_ptrdiff_t) (orig_field->table->s->default_values-
10481 orig_field->table->record[0]);
10482 orig_field->move_field_offset(diff);
10483 if (!orig_field->is_real_null())
10485 char buff[MAX_FIELD_WIDTH], *pos;
10486 String tmp(buff,
sizeof(buff), charset), *res;
10487 res= orig_field->val_str(&tmp);
10488 pos= (
char*) sql_strmake(res->ptr(), res->length());
10491 orig_field->move_field_offset(-diff);
10522 return (uint32) 4294967295
U;
10542 return 255 * field_charset->mbmaxlen;
10544 return 65535 * field_charset->mbmaxlen;
10546 return 16777215 * field_charset->mbmaxlen;
10548 return (uint32) 4294967295
U;
10582 int cut_increment)
const
10588 THD *thd= table ? table->in_use : current_thd;
10589 if (thd->count_cuted_fields)
10591 thd->cuted_fields+= cut_increment;
10592 push_warning_printf(thd, level, code, ER(code), field_name,
10593 thd->get_stmt_da()->current_row_for_warning());
10596 return level >= Sql_condition::WARN_LEVEL_WARN;
10617 timestamp_type ts_type,
10620 THD *thd= table ? table->in_use : current_thd;
10621 if (thd->really_abort_on_warning() ||
10623 make_truncated_value_warning(thd, level, val, ts_type, field_name);