72
63
static enum_field_types field_types_merge_rules [FIELDTYPE_NUM][FIELDTYPE_NUM]=
74
/* MYSQL_TYPE_DECIMAL -> */
76
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
77
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL,
78
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
79
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL,
82
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
83
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
85
MYSQL_TYPE_NEWDECIMAL,
86
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
87
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
88
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
89
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
90
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
91
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
92
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
93
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
96
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
97
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
101
/* MYSQL_TYPE_TINY -> */
103
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
104
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_TINY,
105
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
106
MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
109
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
110
MYSQL_TYPE_TINY, MYSQL_TYPE_VARCHAR,
111
//MYSQL_TYPE_LONGLONG
113
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
114
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
115
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
116
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY,
117
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
118
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
119
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
120
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
123
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
124
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
128
/* MYSQL_TYPE_SHORT -> */
130
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
131
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_SHORT,
132
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
133
MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
136
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
137
MYSQL_TYPE_SHORT, MYSQL_TYPE_VARCHAR,
138
//MYSQL_TYPE_LONGLONG
140
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
141
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
142
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
143
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_SHORT,
144
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
145
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
146
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
147
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
150
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
151
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
155
/* MYSQL_TYPE_LONG -> */
157
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
158
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_LONG,
159
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
160
MYSQL_TYPE_LONG, MYSQL_TYPE_LONG,
163
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
164
MYSQL_TYPE_LONG, MYSQL_TYPE_VARCHAR,
165
//MYSQL_TYPE_LONGLONG
167
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
168
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
169
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
170
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_LONG,
171
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
172
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
173
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
174
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
177
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
178
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
182
/* MYSQL_TYPE_DOUBLE -> */
184
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
185
MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
186
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
187
MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
190
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
191
MYSQL_TYPE_DOUBLE, MYSQL_TYPE_VARCHAR,
192
//MYSQL_TYPE_LONGLONG
194
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
195
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
196
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
197
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_DOUBLE,
198
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
199
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
200
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
201
MYSQL_TYPE_DOUBLE, MYSQL_TYPE_VARCHAR,
204
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
205
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
209
/* MYSQL_TYPE_NULL -> */
211
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
212
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_TINY,
213
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
214
MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
217
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
218
MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP,
219
//MYSQL_TYPE_LONGLONG
221
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
222
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_TIME,
223
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
224
MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,
225
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
226
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
227
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
228
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_ENUM,
231
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
232
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
236
/* MYSQL_TYPE_TIMESTAMP -> */
238
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
239
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
240
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
241
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
244
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
245
MYSQL_TYPE_TIMESTAMP, MYSQL_TYPE_TIMESTAMP,
246
//MYSQL_TYPE_LONGLONG
248
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
249
MYSQL_TYPE_DATETIME, MYSQL_TYPE_DATETIME,
250
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
251
MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
252
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
253
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
254
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
255
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
258
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
259
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
263
/* MYSQL_TYPE_LONGLONG -> */
265
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
266
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_LONGLONG,
267
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
268
MYSQL_TYPE_LONGLONG, MYSQL_TYPE_LONGLONG,
271
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
272
MYSQL_TYPE_LONGLONG, MYSQL_TYPE_VARCHAR,
273
//MYSQL_TYPE_LONGLONG
275
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
276
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
277
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
278
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_LONGLONG,
279
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
280
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
281
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
282
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
285
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
286
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
290
/* MYSQL_TYPE_DATE -> */
292
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
293
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
294
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
295
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
298
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
299
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_DATETIME,
300
//MYSQL_TYPE_LONGLONG
302
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
303
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_DATETIME,
304
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
305
MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
306
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
307
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
308
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
309
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
312
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
313
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
317
/* MYSQL_TYPE_TIME -> */
319
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
320
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
321
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
322
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
325
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
326
MYSQL_TYPE_TIME, MYSQL_TYPE_DATETIME,
327
//MYSQL_TYPE_LONGLONG
329
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
330
MYSQL_TYPE_DATETIME, MYSQL_TYPE_TIME,
331
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
332
MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
333
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
334
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
335
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
336
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
339
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
340
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
344
/* MYSQL_TYPE_DATETIME -> */
346
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
347
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
348
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
349
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
352
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
353
MYSQL_TYPE_DATETIME, MYSQL_TYPE_DATETIME,
354
//MYSQL_TYPE_LONGLONG
356
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
357
MYSQL_TYPE_DATETIME, MYSQL_TYPE_DATETIME,
358
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
359
MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
360
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
361
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
362
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
363
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
366
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
367
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
371
/* MYSQL_TYPE_YEAR -> */
373
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
374
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_TINY,
375
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
376
MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
379
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
380
MYSQL_TYPE_YEAR, MYSQL_TYPE_VARCHAR,
381
//MYSQL_TYPE_LONGLONG
383
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
384
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
385
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
386
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_YEAR,
387
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
388
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
389
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
390
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
393
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
394
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
398
/* MYSQL_TYPE_NEWDATE -> */
400
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
401
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
402
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
403
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
406
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
407
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_DATETIME,
408
//MYSQL_TYPE_LONGLONG
410
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
411
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_DATETIME,
412
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
413
MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
414
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
415
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
416
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
417
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
420
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
421
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
425
/* MYSQL_TYPE_VARCHAR -> */
427
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
428
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
429
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
430
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
433
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
434
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
435
//MYSQL_TYPE_LONGLONG
437
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
438
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
439
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
440
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
441
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
442
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
443
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
444
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
447
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
448
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
452
/* MYSQL_TYPE_NEWDECIMAL -> */
454
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
455
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL,
456
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
457
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL,
460
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
461
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
462
//MYSQL_TYPE_LONGLONG
463
MYSQL_TYPE_NEWDECIMAL,
464
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
465
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
466
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
467
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_NEWDECIMAL,
468
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
469
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
470
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
471
MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
474
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
475
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
479
/* MYSQL_TYPE_ENUM -> */
481
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
482
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
483
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
484
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
487
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
488
MYSQL_TYPE_ENUM, MYSQL_TYPE_VARCHAR,
489
//MYSQL_TYPE_LONGLONG
491
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
492
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
493
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
494
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
495
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
496
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
497
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
498
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
501
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
502
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
506
/* MYSQL_TYPE_SET -> */
508
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
509
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
510
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
511
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
514
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
515
MYSQL_TYPE_SET, MYSQL_TYPE_VARCHAR,
516
//MYSQL_TYPE_LONGLONG
518
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
519
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
520
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
521
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
522
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
523
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
524
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
525
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
528
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
529
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
533
/* MYSQL_TYPE_BLOB -> */
535
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
536
MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
537
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
538
MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
541
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
542
MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
543
//MYSQL_TYPE_LONGLONG
545
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
546
MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
547
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
548
MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
549
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
550
MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
551
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
552
MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
555
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
556
MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
560
/* MYSQL_TYPE_VAR_STRING -> */
562
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
563
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
564
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
565
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
568
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
569
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
570
//MYSQL_TYPE_LONGLONG
572
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
573
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
574
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
575
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
576
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
577
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
578
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
579
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
582
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
583
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
587
/* MYSQL_TYPE_STRING -> */
589
//MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
590
MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
591
//MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
592
MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
595
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
596
MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
597
//MYSQL_TYPE_LONGLONG
599
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
600
MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
601
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
602
MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
603
//MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
604
MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR,
605
//MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
606
MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
609
//MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
610
MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
65
/* DRIZZLE_TYPE_DECIMAL -> */
67
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
68
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_NEWDECIMAL,
69
//DRIZZLE_TYPE_SHORT DRIZZLE_TYPE_LONG
70
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_NEWDECIMAL,
73
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
74
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_VARCHAR,
75
//DRIZZLE_TYPE_LONGLONG
76
DRIZZLE_TYPE_NEWDECIMAL,
77
//DRIZZLE_TYPE_DATE DRIZZLE_TYPE_TIME
78
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
79
//DRIZZLE_TYPE_DATETIME
81
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
82
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
83
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
84
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_VARCHAR,
87
//DRIZZLE_TYPE_BLOB DRIZZLE_TYPE_VAR_STRING
88
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_VARCHAR,
92
/* DRIZZLE_TYPE_TINY -> */
94
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
95
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_TINY,
96
//DRIZZLE_TYPE_SHORT DRIZZLE_TYPE_LONG
97
DRIZZLE_TYPE_SHORT, DRIZZLE_TYPE_LONG,
100
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
101
DRIZZLE_TYPE_TINY, DRIZZLE_TYPE_VARCHAR,
102
//DRIZZLE_TYPE_LONGLONG
103
DRIZZLE_TYPE_LONGLONG,
104
//DRIZZLE_TYPE_DATE DRIZZLE_TYPE_TIME
105
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
106
//DRIZZLE_TYPE_DATETIME
107
DRIZZLE_TYPE_VARCHAR,
108
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
109
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
110
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
111
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_VARCHAR,
113
DRIZZLE_TYPE_VARCHAR,
114
//DRIZZLE_TYPE_BLOB DRIZZLE_TYPE_VAR_STRING
115
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_VARCHAR,
116
//DRIZZLE_TYPE_STRING
119
/* DRIZZLE_TYPE_SHORT -> */
121
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
122
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_SHORT,
123
//DRIZZLE_TYPE_SHORT DRIZZLE_TYPE_LONG
124
DRIZZLE_TYPE_SHORT, DRIZZLE_TYPE_LONG,
125
//DRIZZLE_TYPE_DOUBLE
127
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
128
DRIZZLE_TYPE_SHORT, DRIZZLE_TYPE_VARCHAR,
129
//DRIZZLE_TYPE_LONGLONG
130
DRIZZLE_TYPE_LONGLONG,
131
//DRIZZLE_TYPE_DATE DRIZZLE_TYPE_TIME
132
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
133
//DRIZZLE_TYPE_DATETIME
134
DRIZZLE_TYPE_VARCHAR,
135
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
136
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
137
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
138
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_VARCHAR,
140
DRIZZLE_TYPE_VARCHAR,
141
//DRIZZLE_TYPE_BLOB DRIZZLE_TYPE_VAR_STRING
142
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_VARCHAR,
143
//DRIZZLE_TYPE_STRING
146
/* DRIZZLE_TYPE_LONG -> */
148
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
149
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_LONG,
150
//DRIZZLE_TYPE_SHORT DRIZZLE_TYPE_LONG
151
DRIZZLE_TYPE_LONG, DRIZZLE_TYPE_LONG,
152
//DRIZZLE_TYPE_DOUBLE
154
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
155
DRIZZLE_TYPE_LONG, DRIZZLE_TYPE_VARCHAR,
156
//DRIZZLE_TYPE_LONGLONG
157
DRIZZLE_TYPE_LONGLONG,
158
//DRIZZLE_TYPE_DATE DRIZZLE_TYPE_TIME
159
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
160
//DRIZZLE_TYPE_DATETIME
161
DRIZZLE_TYPE_VARCHAR,
162
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
163
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
164
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
165
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_VARCHAR,
167
DRIZZLE_TYPE_VARCHAR,
168
//DRIZZLE_TYPE_BLOB DRIZZLE_TYPE_VAR_STRING
169
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_VARCHAR,
170
//DRIZZLE_TYPE_STRING
173
/* DRIZZLE_TYPE_DOUBLE -> */
175
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
176
DRIZZLE_TYPE_DOUBLE, DRIZZLE_TYPE_DOUBLE,
177
//DRIZZLE_TYPE_SHORT DRIZZLE_TYPE_LONG
178
DRIZZLE_TYPE_DOUBLE, DRIZZLE_TYPE_DOUBLE,
179
//DRIZZLE_TYPE_DOUBLE
181
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
182
DRIZZLE_TYPE_DOUBLE, DRIZZLE_TYPE_VARCHAR,
183
//DRIZZLE_TYPE_LONGLONG
185
//DRIZZLE_TYPE_DATE DRIZZLE_TYPE_TIME
186
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
187
//DRIZZLE_TYPE_DATETIME
188
DRIZZLE_TYPE_VARCHAR,
189
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
190
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
191
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
192
DRIZZLE_TYPE_DOUBLE, DRIZZLE_TYPE_VARCHAR,
194
DRIZZLE_TYPE_VARCHAR,
195
//DRIZZLE_TYPE_BLOB DRIZZLE_TYPE_VAR_STRING
196
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_VARCHAR,
197
//DRIZZLE_TYPE_STRING
200
/* DRIZZLE_TYPE_NULL -> */
202
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
203
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_TINY,
204
//DRIZZLE_TYPE_SHORT DRIZZLE_TYPE_LONG
205
DRIZZLE_TYPE_SHORT, DRIZZLE_TYPE_LONG,
206
//DRIZZLE_TYPE_DOUBLE
208
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
209
DRIZZLE_TYPE_NULL, DRIZZLE_TYPE_TIMESTAMP,
210
//DRIZZLE_TYPE_LONGLONG
211
DRIZZLE_TYPE_LONGLONG,
212
//DRIZZLE_TYPE_DATE DRIZZLE_TYPE_TIME
213
DRIZZLE_TYPE_NEWDATE, DRIZZLE_TYPE_TIME,
214
//DRIZZLE_TYPE_DATETIME
215
DRIZZLE_TYPE_DATETIME,
216
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
217
DRIZZLE_TYPE_NEWDATE, DRIZZLE_TYPE_VARCHAR,
218
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
219
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_ENUM,
222
//DRIZZLE_TYPE_BLOB DRIZZLE_TYPE_VAR_STRING
223
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_VARCHAR,
224
//DRIZZLE_TYPE_STRING
227
/* DRIZZLE_TYPE_TIMESTAMP -> */
229
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
230
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
231
//DRIZZLE_TYPE_SHORT DRIZZLE_TYPE_LONG
232
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
233
//DRIZZLE_TYPE_DOUBLE
234
DRIZZLE_TYPE_VARCHAR,
235
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
236
DRIZZLE_TYPE_TIMESTAMP, DRIZZLE_TYPE_TIMESTAMP,
237
//DRIZZLE_TYPE_LONGLONG
238
DRIZZLE_TYPE_VARCHAR,
239
//DRIZZLE_TYPE_DATE DRIZZLE_TYPE_TIME
240
DRIZZLE_TYPE_DATETIME, DRIZZLE_TYPE_DATETIME,
241
//DRIZZLE_TYPE_DATETIME
242
DRIZZLE_TYPE_DATETIME,
243
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
244
DRIZZLE_TYPE_NEWDATE, DRIZZLE_TYPE_VARCHAR,
245
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
246
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
248
DRIZZLE_TYPE_VARCHAR,
249
//DRIZZLE_TYPE_BLOB DRIZZLE_TYPE_VAR_STRING
250
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_VARCHAR,
251
//DRIZZLE_TYPE_STRING
254
/* DRIZZLE_TYPE_LONGLONG -> */
256
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
257
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_LONGLONG,
258
//DRIZZLE_TYPE_SHORT DRIZZLE_TYPE_LONG
259
DRIZZLE_TYPE_LONGLONG, DRIZZLE_TYPE_LONGLONG,
260
//DRIZZLE_TYPE_DOUBLE
262
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
263
DRIZZLE_TYPE_LONGLONG, DRIZZLE_TYPE_VARCHAR,
264
//DRIZZLE_TYPE_LONGLONG
265
DRIZZLE_TYPE_LONGLONG,
266
//DRIZZLE_TYPE_DATE DRIZZLE_TYPE_TIME
267
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
268
//DRIZZLE_TYPE_DATETIME
269
DRIZZLE_TYPE_VARCHAR,
270
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
271
DRIZZLE_TYPE_NEWDATE, DRIZZLE_TYPE_VARCHAR,
272
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
273
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_VARCHAR,
275
DRIZZLE_TYPE_VARCHAR,
276
//DRIZZLE_TYPE_BLOB DRIZZLE_TYPE_VAR_STRING
277
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_VARCHAR,
278
//DRIZZLE_TYPE_STRING
281
/* DRIZZLE_TYPE_DATE -> */
283
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
284
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
285
//DRIZZLE_TYPE_SHORT DRIZZLE_TYPE_LONG
286
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
287
//DRIZZLE_TYPE_DOUBLE
288
DRIZZLE_TYPE_VARCHAR,
289
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
290
DRIZZLE_TYPE_NEWDATE, DRIZZLE_TYPE_DATETIME,
291
//DRIZZLE_TYPE_LONGLONG
292
DRIZZLE_TYPE_VARCHAR,
293
//DRIZZLE_TYPE_DATE DRIZZLE_TYPE_TIME
294
DRIZZLE_TYPE_NEWDATE, DRIZZLE_TYPE_DATETIME,
295
//DRIZZLE_TYPE_DATETIME
296
DRIZZLE_TYPE_DATETIME,
297
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
298
DRIZZLE_TYPE_NEWDATE, DRIZZLE_TYPE_VARCHAR,
299
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
300
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
302
DRIZZLE_TYPE_VARCHAR,
303
//DRIZZLE_TYPE_BLOB DRIZZLE_TYPE_VAR_STRING
304
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_VARCHAR,
305
//DRIZZLE_TYPE_STRING
308
/* DRIZZLE_TYPE_TIME -> */
310
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
311
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
312
//DRIZZLE_TYPE_SHORT DRIZZLE_TYPE_LONG
313
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
314
//DRIZZLE_TYPE_DOUBLE
315
DRIZZLE_TYPE_VARCHAR,
316
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
317
DRIZZLE_TYPE_TIME, DRIZZLE_TYPE_DATETIME,
318
//DRIZZLE_TYPE_LONGLONG
319
DRIZZLE_TYPE_VARCHAR,
320
//DRIZZLE_TYPE_DATE DRIZZLE_TYPE_TIME
321
DRIZZLE_TYPE_DATETIME, DRIZZLE_TYPE_TIME,
322
//DRIZZLE_TYPE_DATETIME
323
DRIZZLE_TYPE_DATETIME,
324
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
325
DRIZZLE_TYPE_NEWDATE, DRIZZLE_TYPE_VARCHAR,
326
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
327
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
329
DRIZZLE_TYPE_VARCHAR,
330
//DRIZZLE_TYPE_BLOB DRIZZLE_TYPE_VAR_STRING
331
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_VARCHAR,
332
//DRIZZLE_TYPE_STRING
335
/* DRIZZLE_TYPE_DATETIME -> */
337
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
338
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
339
//DRIZZLE_TYPE_SHORT DRIZZLE_TYPE_LONG
340
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
341
//DRIZZLE_TYPE_DOUBLE
342
DRIZZLE_TYPE_VARCHAR,
343
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
344
DRIZZLE_TYPE_DATETIME, DRIZZLE_TYPE_DATETIME,
345
//DRIZZLE_TYPE_LONGLONG
346
DRIZZLE_TYPE_VARCHAR,
347
//DRIZZLE_TYPE_DATE DRIZZLE_TYPE_TIME
348
DRIZZLE_TYPE_DATETIME, DRIZZLE_TYPE_DATETIME,
349
//DRIZZLE_TYPE_DATETIME
350
DRIZZLE_TYPE_DATETIME,
351
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
352
DRIZZLE_TYPE_NEWDATE, DRIZZLE_TYPE_VARCHAR,
353
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
354
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
356
DRIZZLE_TYPE_VARCHAR,
357
//DRIZZLE_TYPE_BLOB DRIZZLE_TYPE_VAR_STRING
358
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_VARCHAR,
359
//DRIZZLE_TYPE_STRING
362
/* DRIZZLE_TYPE_NEWDATE -> */
364
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
365
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
366
//DRIZZLE_TYPE_SHORT DRIZZLE_TYPE_LONG
367
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
368
//DRIZZLE_TYPE_DOUBLE
369
DRIZZLE_TYPE_VARCHAR,
370
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
371
DRIZZLE_TYPE_NEWDATE, DRIZZLE_TYPE_DATETIME,
372
//DRIZZLE_TYPE_LONGLONG
373
DRIZZLE_TYPE_VARCHAR,
374
//DRIZZLE_TYPE_DATE DRIZZLE_TYPE_TIME
375
DRIZZLE_TYPE_NEWDATE, DRIZZLE_TYPE_DATETIME,
376
//DRIZZLE_TYPE_DATETIME
377
DRIZZLE_TYPE_DATETIME,
378
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
379
DRIZZLE_TYPE_NEWDATE, DRIZZLE_TYPE_VARCHAR,
380
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
381
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
383
DRIZZLE_TYPE_VARCHAR,
384
//DRIZZLE_TYPE_BLOB DRIZZLE_TYPE_VAR_STRING
385
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_VARCHAR,
386
//DRIZZLE_TYPE_STRING
389
/* DRIZZLE_TYPE_VARCHAR -> */
391
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
392
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
393
//DRIZZLE_TYPE_SHORT DRIZZLE_TYPE_LONG
394
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
395
//DRIZZLE_TYPE_DOUBLE
396
DRIZZLE_TYPE_VARCHAR,
397
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
398
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
399
//DRIZZLE_TYPE_LONGLONG
400
DRIZZLE_TYPE_VARCHAR,
401
//DRIZZLE_TYPE_DATE DRIZZLE_TYPE_TIME
402
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
403
//DRIZZLE_TYPE_DATETIME
404
DRIZZLE_TYPE_VARCHAR,
405
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
406
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
407
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
408
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
410
DRIZZLE_TYPE_VARCHAR,
411
//DRIZZLE_TYPE_BLOB DRIZZLE_TYPE_VAR_STRING
412
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_VARCHAR,
413
//DRIZZLE_TYPE_STRING
416
/* DRIZZLE_TYPE_NEWDECIMAL -> */
418
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
419
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_NEWDECIMAL,
420
//DRIZZLE_TYPE_SHORT DRIZZLE_TYPE_LONG
421
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_NEWDECIMAL,
422
//DRIZZLE_TYPE_DOUBLE
424
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
425
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_VARCHAR,
426
//DRIZZLE_TYPE_LONGLONG
427
DRIZZLE_TYPE_NEWDECIMAL,
428
//DRIZZLE_TYPE_DATE DRIZZLE_TYPE_TIME
429
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
430
//DRIZZLE_TYPE_DATETIME
431
DRIZZLE_TYPE_VARCHAR,
432
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
433
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
434
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
435
DRIZZLE_TYPE_NEWDECIMAL, DRIZZLE_TYPE_VARCHAR,
437
DRIZZLE_TYPE_VARCHAR,
438
//DRIZZLE_TYPE_BLOB DRIZZLE_TYPE_VAR_STRING
439
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_VARCHAR,
440
//DRIZZLE_TYPE_STRING
443
/* DRIZZLE_TYPE_ENUM -> */
445
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
446
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
447
//DRIZZLE_TYPE_SHORT DRIZZLE_TYPE_LONG
448
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
449
//DRIZZLE_TYPE_DOUBLE
450
DRIZZLE_TYPE_VARCHAR,
451
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
452
DRIZZLE_TYPE_ENUM, DRIZZLE_TYPE_VARCHAR,
453
//DRIZZLE_TYPE_LONGLONG
454
DRIZZLE_TYPE_VARCHAR,
455
//DRIZZLE_TYPE_DATE DRIZZLE_TYPE_TIME
456
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
457
//DRIZZLE_TYPE_DATETIME
458
DRIZZLE_TYPE_VARCHAR,
459
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
460
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
461
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
462
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
464
DRIZZLE_TYPE_VARCHAR,
465
//DRIZZLE_TYPE_BLOB DRIZZLE_TYPE_VAR_STRING
466
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_VARCHAR,
467
//DRIZZLE_TYPE_STRING
470
/* DRIZZLE_TYPE_SET -> */
472
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
473
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
474
//DRIZZLE_TYPE_SHORT DRIZZLE_TYPE_LONG
475
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
476
//DRIZZLE_TYPE_DOUBLE
477
DRIZZLE_TYPE_VARCHAR,
478
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
479
DRIZZLE_TYPE_SET, DRIZZLE_TYPE_VARCHAR,
480
//DRIZZLE_TYPE_LONGLONG
481
DRIZZLE_TYPE_VARCHAR,
482
//DRIZZLE_TYPE_DATE DRIZZLE_TYPE_TIME
483
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
484
//DRIZZLE_TYPE_DATETIME
485
DRIZZLE_TYPE_VARCHAR,
486
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
487
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
488
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
489
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
491
DRIZZLE_TYPE_VARCHAR,
492
//DRIZZLE_TYPE_BLOB DRIZZLE_TYPE_VAR_STRING
493
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_VARCHAR,
494
//DRIZZLE_TYPE_STRING
497
/* DRIZZLE_TYPE_BLOB -> */
499
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
500
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_BLOB,
501
//DRIZZLE_TYPE_SHORT DRIZZLE_TYPE_LONG
502
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_BLOB,
503
//DRIZZLE_TYPE_DOUBLE
505
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
506
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_BLOB,
507
//DRIZZLE_TYPE_LONGLONG
509
//DRIZZLE_TYPE_DATE DRIZZLE_TYPE_TIME
510
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_BLOB,
511
//DRIZZLE_TYPE_DATETIME
513
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
514
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_BLOB,
515
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
516
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_BLOB,
519
//DRIZZLE_TYPE_BLOB DRIZZLE_TYPE_VAR_STRING
520
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_BLOB,
521
//DRIZZLE_TYPE_STRING
524
/* DRIZZLE_TYPE_VAR_STRING -> */
526
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
527
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
528
//DRIZZLE_TYPE_SHORT DRIZZLE_TYPE_LONG
529
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
530
//DRIZZLE_TYPE_DOUBLE
531
DRIZZLE_TYPE_VARCHAR,
532
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
533
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
534
//DRIZZLE_TYPE_LONGLONG
535
DRIZZLE_TYPE_VARCHAR,
536
//DRIZZLE_TYPE_DATE DRIZZLE_TYPE_TIME
537
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
538
//DRIZZLE_TYPE_DATETIME
539
DRIZZLE_TYPE_VARCHAR,
540
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
541
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
542
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
543
DRIZZLE_TYPE_VARCHAR, DRIZZLE_TYPE_VARCHAR,
545
DRIZZLE_TYPE_VARCHAR,
546
//DRIZZLE_TYPE_BLOB DRIZZLE_TYPE_VAR_STRING
547
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_VARCHAR,
548
//DRIZZLE_TYPE_STRING
551
/* DRIZZLE_TYPE_STRING -> */
553
//DRIZZLE_TYPE_DECIMAL DRIZZLE_TYPE_TINY
554
DRIZZLE_TYPE_STRING, DRIZZLE_TYPE_STRING,
555
//DRIZZLE_TYPE_SHORT DRIZZLE_TYPE_LONG
556
DRIZZLE_TYPE_STRING, DRIZZLE_TYPE_STRING,
557
//DRIZZLE_TYPE_DOUBLE
559
//DRIZZLE_TYPE_NULL DRIZZLE_TYPE_TIMESTAMP
560
DRIZZLE_TYPE_STRING, DRIZZLE_TYPE_STRING,
561
//DRIZZLE_TYPE_LONGLONG
563
//DRIZZLE_TYPE_DATE DRIZZLE_TYPE_TIME
564
DRIZZLE_TYPE_STRING, DRIZZLE_TYPE_STRING,
565
//DRIZZLE_TYPE_DATETIME
567
//DRIZZLE_TYPE_NEWDATE DRIZZLE_TYPE_VARCHAR
568
DRIZZLE_TYPE_STRING, DRIZZLE_TYPE_VARCHAR,
569
//DRIZZLE_TYPE_NEWDECIMAL DRIZZLE_TYPE_ENUM
570
DRIZZLE_TYPE_STRING, DRIZZLE_TYPE_STRING,
573
//DRIZZLE_TYPE_BLOB DRIZZLE_TYPE_VAR_STRING
574
DRIZZLE_TYPE_BLOB, DRIZZLE_TYPE_VARCHAR,
575
//DRIZZLE_TYPE_STRING
1506
1451
/****************************************************************************
1507
Field_null, a field that always return NULL
1508
****************************************************************************/
1510
void Field_null::sql_type(String &res) const
1512
res.set_ascii(STRING_WITH_LEN("null"));
1516
/****************************************************************************
1517
** Field_new_decimal
1518
****************************************************************************/
1520
Field_new_decimal::Field_new_decimal(uchar *ptr_arg,
1521
uint32 len_arg, uchar *null_ptr_arg,
1523
enum utype unireg_check_arg,
1524
const char *field_name_arg,
1525
uint8 dec_arg,bool zero_arg,
1527
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
1528
unireg_check_arg, field_name_arg, dec_arg, zero_arg, unsigned_arg)
1530
precision= my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
1531
set_if_smaller(precision, DECIMAL_MAX_PRECISION);
1532
assert((precision <= DECIMAL_MAX_PRECISION) &&
1533
(dec <= DECIMAL_MAX_SCALE));
1534
bin_size= my_decimal_get_binary_size(precision, dec);
1538
Field_new_decimal::Field_new_decimal(uint32 len_arg,
1539
bool maybe_null_arg,
1543
:Field_num((uchar*) 0, len_arg,
1544
maybe_null_arg ? (uchar*) "": 0, 0,
1545
NONE, name, dec_arg, 0, unsigned_arg)
1547
precision= my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
1548
set_if_smaller(precision, DECIMAL_MAX_PRECISION);
1549
assert((precision <= DECIMAL_MAX_PRECISION) &&
1550
(dec <= DECIMAL_MAX_SCALE));
1551
bin_size= my_decimal_get_binary_size(precision, dec);
1555
int Field_new_decimal::reset(void)
1557
store_value(&decimal_zero);
1563
Generate max/min decimal value in case of overflow.
1565
@param decimal_value buffer for value
1566
@param sign sign of value which caused overflow
1569
void Field_new_decimal::set_value_on_overflow(my_decimal *decimal_value,
1572
max_my_decimal(decimal_value, precision, decimals());
1576
my_decimal_set_zero(decimal_value);
1578
decimal_value->sign(true);
1585
Store decimal value in the binary buffer.
1587
Checks if decimal_value fits into field size.
1588
If it does, stores the decimal in the buffer using binary format.
1589
Otherwise sets maximal number that can be stored in the field.
1591
@param decimal_value my_decimal
1599
bool Field_new_decimal::store_value(const my_decimal *decimal_value)
1603
/* check that we do not try to write negative value in unsigned field */
1604
if (unsigned_flag && decimal_value->sign())
1606
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1608
decimal_value= &decimal_zero;
1611
if (warn_if_overflow(my_decimal2binary(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW,
1612
decimal_value, ptr, precision, dec)))
1615
set_value_on_overflow(&buff, decimal_value->sign());
1616
my_decimal2binary(E_DEC_FATAL_ERROR, &buff, ptr, precision, dec);
1623
int Field_new_decimal::store(const char *from, uint length,
1624
CHARSET_INFO *charset_arg)
1627
my_decimal decimal_value;
1629
if ((err= str2my_decimal(E_DEC_FATAL_ERROR &
1630
~(E_DEC_OVERFLOW | E_DEC_BAD_NUM),
1631
from, length, charset_arg,
1633
table->in_use->abort_on_warning)
1635
/* Because "from" is not NUL-terminated and we use %s in the ER() */
1637
from_as_str.copy(from, length, &my_charset_bin);
1639
push_warning_printf(table->in_use, MYSQL_ERROR::WARN_LEVEL_ERROR,
1640
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
1641
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
1642
"decimal", from_as_str.c_ptr(), field_name,
1643
(ulong) table->in_use->row_count);
1649
case E_DEC_TRUNCATED:
1650
set_warning(MYSQL_ERROR::WARN_LEVEL_NOTE, WARN_DATA_TRUNCATED, 1);
1652
case E_DEC_OVERFLOW:
1653
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
1654
set_value_on_overflow(&decimal_value, decimal_value.sign());
1658
/* Because "from" is not NUL-terminated and we use %s in the ER() */
1660
from_as_str.copy(from, length, &my_charset_bin);
1662
push_warning_printf(table->in_use, MYSQL_ERROR::WARN_LEVEL_WARN,
1663
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
1664
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
1665
"decimal", from_as_str.c_ptr(), field_name,
1666
(ulong) table->in_use->row_count);
1667
my_decimal_set_zero(&decimal_value);
1673
store_value(&decimal_value);
1680
Fix following when double2my_decimal when double2decimal
1681
will return E_DEC_TRUNCATED always correctly
1684
int Field_new_decimal::store(double nr)
1686
my_decimal decimal_value;
1689
err= double2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW, nr,
1693
if (check_overflow(err))
1694
set_value_on_overflow(&decimal_value, decimal_value.sign());
1695
/* Only issue a warning if store_value doesn't issue an warning */
1696
table->in_use->got_warning= 0;
1698
if (store_value(&decimal_value))
1700
else if (err && !table->in_use->got_warning)
1701
err= warn_if_overflow(err);
1706
int Field_new_decimal::store(int64_t nr, bool unsigned_val)
1708
my_decimal decimal_value;
1711
if ((err= int2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW,
1712
nr, unsigned_val, &decimal_value)))
1714
if (check_overflow(err))
1715
set_value_on_overflow(&decimal_value, decimal_value.sign());
1716
/* Only issue a warning if store_value doesn't issue an warning */
1717
table->in_use->got_warning= 0;
1719
if (store_value(&decimal_value))
1721
else if (err && !table->in_use->got_warning)
1722
err= warn_if_overflow(err);
1727
int Field_new_decimal::store_decimal(const my_decimal *decimal_value)
1729
return store_value(decimal_value);
1733
int Field_new_decimal::store_time(MYSQL_TIME *ltime,
1734
timestamp_type t_type __attribute__((__unused__)))
1736
my_decimal decimal_value;
1737
return store_value(date2my_decimal(ltime, &decimal_value));
1741
double Field_new_decimal::val_real(void)
1744
my_decimal decimal_value;
1745
my_decimal2double(E_DEC_FATAL_ERROR, val_decimal(&decimal_value), &dbl);
1750
int64_t Field_new_decimal::val_int(void)
1753
my_decimal decimal_value;
1754
my_decimal2int(E_DEC_FATAL_ERROR, val_decimal(&decimal_value),
1760
my_decimal* Field_new_decimal::val_decimal(my_decimal *decimal_value)
1762
binary2my_decimal(E_DEC_FATAL_ERROR, ptr, decimal_value,
1764
return(decimal_value);
1768
String *Field_new_decimal::val_str(String *val_buffer,
1769
String *val_ptr __attribute__((unused)))
1771
my_decimal decimal_value;
1772
uint fixed_precision= zerofill ? precision : 0;
1773
my_decimal2string(E_DEC_FATAL_ERROR, val_decimal(&decimal_value),
1774
fixed_precision, dec, '0', val_buffer);
1779
int Field_new_decimal::cmp(const uchar *a,const uchar*b)
1781
return memcmp(a, b, bin_size);
1785
void Field_new_decimal::sort_string(uchar *buff,
1786
uint length __attribute__((unused)))
1788
memcpy(buff, ptr, bin_size);
1792
void Field_new_decimal::sql_type(String &str) const
1794
CHARSET_INFO *cs= str.charset();
1795
str.length(cs->cset->snprintf(cs, (char*) str.ptr(), str.alloced_length(),
1796
"decimal(%d,%d)", precision, (int)dec));
1797
add_zerofill_and_unsigned(str);
1802
Save the field metadata for new decimal fields.
1804
Saves the precision in the first byte and decimals() in the second
1805
byte of the field metadata array at index of *metadata_ptr and
1806
*(metadata_ptr + 1).
1808
@param metadata_ptr First byte of field metadata
1810
@returns number of bytes written to metadata_ptr
1812
int Field_new_decimal::do_save_field_metadata(uchar *metadata_ptr)
1814
*metadata_ptr= precision;
1815
*(metadata_ptr + 1)= decimals();
1821
Returns the number of bytes field uses in row-based replication
1824
This method is used in row-based replication to determine the number
1825
of bytes that the field consumes in the row record format. This is
1826
used to skip fields in the master that do not exist on the slave.
1828
@param field_metadata Encoded size in field metadata
1830
@returns The size of the field based on the field metadata.
1832
uint Field_new_decimal::pack_length_from_metadata(uint field_metadata)
1834
uint const source_precision= (field_metadata >> 8U) & 0x00ff;
1835
uint const source_decimal= field_metadata & 0x00ff;
1836
uint const source_size= my_decimal_get_binary_size(source_precision,
1838
return (source_size);
1843
Check to see if field size is compatible with destination.
1845
This method is used in row-based replication to verify that the slave's
1846
field size is less than or equal to the master's field size. The
1847
encoded field metadata (from the master or source) is decoded and compared
1848
to the size of this field (the slave or destination).
1850
@param field_metadata Encoded size in field metadata
1852
@retval 0 if this field's size is < the source field's size
1853
@retval 1 if this field's size is >= the source field's size
1855
int Field_new_decimal::compatible_field_size(uint field_metadata)
1858
uint const source_precision= (field_metadata >> 8U) & 0x00ff;
1859
uint const source_decimal= field_metadata & 0x00ff;
1860
uint const source_size= my_decimal_get_binary_size(source_precision,
1862
uint const destination_size= row_pack_length();
1863
compatible= (source_size <= destination_size);
1865
compatible= (source_precision <= precision) &&
1866
(source_decimal <= decimals());
1867
return (compatible);
1871
uint Field_new_decimal::is_equal(Create_field *new_field)
1873
return ((new_field->sql_type == real_type()) &&
1874
((new_field->flags & UNSIGNED_FLAG) ==
1875
(uint) (flags & UNSIGNED_FLAG)) &&
1876
((new_field->flags & AUTO_INCREMENT_FLAG) ==
1877
(uint) (flags & AUTO_INCREMENT_FLAG)) &&
1878
(new_field->length == max_display_length()) &&
1879
(new_field->decimals == dec));
1884
Unpack a decimal field from row data.
1886
This method is used to unpack a decimal or numeric field from a master
1887
whose size of the field is less than that of the slave.
1889
@param to Destination of the data
1890
@param from Source of the data
1891
@param param_data Precision (upper) and decimal (lower) values
1893
@return New pointer into memory based on from + length of the data
1896
Field_new_decimal::unpack(uchar* to,
1899
bool low_byte_first)
1901
if (param_data == 0)
1902
return Field::unpack(to, from, param_data, low_byte_first);
1904
uint from_precision= (param_data & 0xff00) >> 8U;
1905
uint from_decimal= param_data & 0x00ff;
1906
uint length=pack_length();
1907
uint from_pack_len= my_decimal_get_binary_size(from_precision, from_decimal);
1908
uint len= (param_data && (from_pack_len < length)) ?
1909
from_pack_len : length;
1910
if ((from_pack_len && (from_pack_len < length)) ||
1911
(from_precision < precision) ||
1912
(from_decimal < decimals()))
1915
If the master's data is smaller than the slave, we need to convert
1916
the binary to decimal then resize the decimal converting it back to
1917
a decimal and write that to the raw data buffer.
1919
decimal_digit_t dec_buf[DECIMAL_MAX_PRECISION];
1921
dec.len= from_precision;
1924
Note: bin2decimal does not change the length of the field. So it is
1925
just the first step the resizing operation. The second step does the
1926
resizing using the precision and decimals from the slave.
1928
bin2decimal((uchar *)from, &dec, from_precision, from_decimal);
1929
decimal2bin(&dec, to, precision, decimals());
1932
memcpy(to, from, len); // Sizes are the same, just copy the data.
1936
/****************************************************************************
1938
1453
****************************************************************************/
2099
1613
CHARSET_INFO *cs=res.charset();
2100
1614
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
2101
1615
"tinyint(%d)",(int) field_length));
2102
add_zerofill_and_unsigned(res);
2105
/****************************************************************************
2106
Field type short int (2 byte)
2107
****************************************************************************/
2109
int Field_short::store(const char *from,uint len,CHARSET_INFO *cs)
2115
error= get_int(cs, from, len, &rnd, UINT16_MAX, INT16_MIN, INT16_MAX);
2116
store_tmp= unsigned_flag ? (int) (uint64_t) rnd : (int) rnd;
2117
#ifdef WORDS_BIGENDIAN
2118
if (table->s->db_low_byte_first)
2120
int2store(ptr, store_tmp);
2124
shortstore(ptr, (short) store_tmp);
2129
int Field_short::store(double nr)
2139
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2142
else if (nr > (double) UINT16_MAX)
2144
res=(int16) UINT16_MAX;
2145
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2149
res=(int16) (uint16) nr;
2153
if (nr < (double) INT16_MIN)
2156
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2159
else if (nr > (double) INT16_MAX)
2162
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2166
res=(int16) (int) nr;
2168
#ifdef WORDS_BIGENDIAN
2169
if (table->s->db_low_byte_first)
2175
shortstore(ptr,res);
2180
int Field_short::store(int64_t nr, bool unsigned_val)
2187
if (nr < 0L && !unsigned_val)
2190
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2193
else if ((uint64_t) nr > (uint64_t) UINT16_MAX)
2195
res=(int16) UINT16_MAX;
2196
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2200
res=(int16) (uint16) nr;
2204
if (nr < 0 && unsigned_val)
2205
nr= UINT16_MAX+1; // Generate overflow
2210
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2213
else if (nr > (int64_t) INT16_MAX)
2216
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2222
#ifdef WORDS_BIGENDIAN
2223
if (table->s->db_low_byte_first)
2229
shortstore(ptr,res);
2234
double Field_short::val_real(void)
2237
#ifdef WORDS_BIGENDIAN
2238
if (table->s->db_low_byte_first)
2243
return unsigned_flag ? (double) (unsigned short) j : (double) j;
2246
int64_t Field_short::val_int(void)
2249
#ifdef WORDS_BIGENDIAN
2250
if (table->s->db_low_byte_first)
2255
return unsigned_flag ? (int64_t) (unsigned short) j : (int64_t) j;
2259
String *Field_short::val_str(String *val_buffer,
2260
String *val_ptr __attribute__((unused)))
2262
CHARSET_INFO *cs= &my_charset_bin;
2264
uint mlength=max(field_length+1,7*cs->mbmaxlen);
2265
val_buffer->alloc(mlength);
2266
char *to=(char*) val_buffer->ptr();
2268
#ifdef WORDS_BIGENDIAN
2269
if (table->s->db_low_byte_first)
2276
length=(uint) cs->cset->long10_to_str(cs, to, mlength, 10,
2279
length=(uint) cs->cset->long10_to_str(cs, to, mlength,-10, (long) j);
2280
val_buffer->length(length);
2282
prepend_zeros(val_buffer);
2287
bool Field_short::send_binary(Protocol *protocol)
2289
return protocol->store_short(Field_short::val_int());
2293
int Field_short::cmp(const uchar *a_ptr, const uchar *b_ptr)
2296
#ifdef WORDS_BIGENDIAN
2297
if (table->s->db_low_byte_first)
2310
return ((unsigned short) a < (unsigned short) b) ? -1 :
2311
((unsigned short) a > (unsigned short) b) ? 1 : 0;
2312
return (a < b) ? -1 : (a > b) ? 1 : 0;
2315
void Field_short::sort_string(uchar *to,uint length __attribute__((unused)))
2317
#ifdef WORDS_BIGENDIAN
2318
if (!table->s->db_low_byte_first)
2323
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
2332
to[0] = (char) (ptr[1] ^ 128); /* Revers signbit */
2337
void Field_short::sql_type(String &res) const
2339
CHARSET_INFO *cs=res.charset();
2340
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
2341
"smallint(%d)",(int) field_length));
2342
add_zerofill_and_unsigned(res);
2346
/****************************************************************************
2348
****************************************************************************/
2350
int Field_long::store(const char *from,uint len,CHARSET_INFO *cs)
2356
error= get_int(cs, from, len, &rnd, UINT32_MAX, INT32_MIN, INT32_MAX);
2357
store_tmp= unsigned_flag ? (long) (uint64_t) rnd : (long) rnd;
2358
#ifdef WORDS_BIGENDIAN
2359
if (table->s->db_low_byte_first)
2361
int4store(ptr, store_tmp);
2365
longstore(ptr, store_tmp);
2370
int Field_long::store(double nr)
2382
else if (nr > (double) UINT32_MAX)
2385
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2389
res=(int32) (ulong) nr;
2393
if (nr < (double) INT32_MIN)
2395
res=(int32) INT32_MIN;
2398
else if (nr > (double) INT32_MAX)
2400
res=(int32) INT32_MAX;
2404
res=(int32) (int64_t) nr;
2407
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2409
#ifdef WORDS_BIGENDIAN
2410
if (table->s->db_low_byte_first)
2421
int Field_long::store(int64_t nr, bool unsigned_val)
2428
if (nr < 0 && !unsigned_val)
2433
else if ((uint64_t) nr >= (1LL << 32))
2435
res=(int32) (uint32) ~0L;
2439
res=(int32) (uint32) nr;
2443
if (nr < 0 && unsigned_val)
2444
nr= ((int64_t) INT32_MAX) + 1; // Generate overflow
2445
if (nr < (int64_t) INT32_MIN)
2447
res=(int32) INT32_MIN;
2450
else if (nr > (int64_t) INT32_MAX)
2452
res=(int32) INT32_MAX;
2459
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2461
#ifdef WORDS_BIGENDIAN
2462
if (table->s->db_low_byte_first)
2473
double Field_long::val_real(void)
2476
#ifdef WORDS_BIGENDIAN
2477
if (table->s->db_low_byte_first)
2482
return unsigned_flag ? (double) (uint32) j : (double) j;
2485
int64_t Field_long::val_int(void)
2488
/* See the comment in Field_long::store(long long) */
2489
assert(table->in_use == current_thd);
2490
#ifdef WORDS_BIGENDIAN
2491
if (table->s->db_low_byte_first)
2496
return unsigned_flag ? (int64_t) (uint32) j : (int64_t) j;
2499
String *Field_long::val_str(String *val_buffer,
2500
String *val_ptr __attribute__((unused)))
2502
CHARSET_INFO *cs= &my_charset_bin;
2504
uint mlength=max(field_length+1,12*cs->mbmaxlen);
2505
val_buffer->alloc(mlength);
2506
char *to=(char*) val_buffer->ptr();
2508
#ifdef WORDS_BIGENDIAN
2509
if (table->s->db_low_byte_first)
2516
length=cs->cset->long10_to_str(cs,to,mlength, 10,(long) (uint32)j);
2518
length=cs->cset->long10_to_str(cs,to,mlength,-10,(long) j);
2519
val_buffer->length(length);
2521
prepend_zeros(val_buffer);
2526
bool Field_long::send_binary(Protocol *protocol)
2528
return protocol->store_long(Field_long::val_int());
2531
int Field_long::cmp(const uchar *a_ptr, const uchar *b_ptr)
2534
#ifdef WORDS_BIGENDIAN
2535
if (table->s->db_low_byte_first)
2547
return ((uint32) a < (uint32) b) ? -1 : ((uint32) a > (uint32) b) ? 1 : 0;
2548
return (a < b) ? -1 : (a > b) ? 1 : 0;
2551
void Field_long::sort_string(uchar *to,uint length __attribute__((unused)))
2553
#ifdef WORDS_BIGENDIAN
2554
if (!table->s->db_low_byte_first)
2559
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
2570
to[0] = (char) (ptr[3] ^ 128); /* Revers signbit */
2578
void Field_long::sql_type(String &res) const
2580
CHARSET_INFO *cs=res.charset();
2581
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
2582
"int(%d)",(int) field_length));
2583
add_zerofill_and_unsigned(res);
2586
/****************************************************************************
2587
Field type int64_t int (8 bytes)
2588
****************************************************************************/
2590
int Field_int64_t::store(const char *from,uint len,CHARSET_INFO *cs)
2596
tmp= cs->cset->strntoull10rnd(cs,from,len,unsigned_flag,&end,&error);
2597
if (error == MY_ERRNO_ERANGE)
2599
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2602
else if (table->in_use->count_cuted_fields &&
2603
check_int(cs, from, len, end, error))
2607
#ifdef WORDS_BIGENDIAN
2608
if (table->s->db_low_byte_first)
2614
int64_tstore(ptr,tmp);
2619
int Field_int64_t::store(double nr)
2632
else if (nr >= (double) UINT64_MAX)
2638
res=(int64_t) (uint64_t) nr;
2642
if (nr <= (double) INT64_MIN)
2645
error= (nr < (double) INT64_MIN);
2647
else if (nr >= (double) (uint64_t) INT64_MAX)
2650
error= (nr > (double) INT64_MAX);
2656
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2658
#ifdef WORDS_BIGENDIAN
2659
if (table->s->db_low_byte_first)
2665
int64_tstore(ptr,res);
2670
int Field_int64_t::store(int64_t nr, bool unsigned_val)
2674
if (nr < 0) // Only possible error
2677
if field is unsigned and value is signed (< 0) or
2678
if field is signed and value is unsigned we have an overflow
2680
if (unsigned_flag != unsigned_val)
2682
nr= unsigned_flag ? (uint64_t) 0 : (uint64_t) INT64_MAX;
2683
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2688
#ifdef WORDS_BIGENDIAN
2689
if (table->s->db_low_byte_first)
2695
int64_tstore(ptr,nr);
2700
double Field_int64_t::val_real(void)
2703
#ifdef WORDS_BIGENDIAN
2704
if (table->s->db_low_byte_first)
2711
/* The following is open coded to avoid a bug in gcc 3.3 */
2714
uint64_t tmp= (uint64_t) j;
2715
return uint64_t2double(tmp);
2721
int64_t Field_int64_t::val_int(void)
2724
#ifdef WORDS_BIGENDIAN
2725
if (table->s->db_low_byte_first)
2734
String *Field_int64_t::val_str(String *val_buffer,
2735
String *val_ptr __attribute__((unused)))
2737
CHARSET_INFO *cs= &my_charset_bin;
2739
uint mlength=max(field_length+1,22*cs->mbmaxlen);
2740
val_buffer->alloc(mlength);
2741
char *to=(char*) val_buffer->ptr();
2743
#ifdef WORDS_BIGENDIAN
2744
if (table->s->db_low_byte_first)
2750
length=(uint) (cs->cset->int64_t10_to_str)(cs,to,mlength,
2751
unsigned_flag ? 10 : -10, j);
2752
val_buffer->length(length);
2754
prepend_zeros(val_buffer);
2759
bool Field_int64_t::send_binary(Protocol *protocol)
2761
return protocol->store_int64_t(Field_int64_t::val_int(), unsigned_flag);
2765
int Field_int64_t::cmp(const uchar *a_ptr, const uchar *b_ptr)
2768
#ifdef WORDS_BIGENDIAN
2769
if (table->s->db_low_byte_first)
2777
int64_tget(a,a_ptr);
2778
int64_tget(b,b_ptr);
2781
return ((uint64_t) a < (uint64_t) b) ? -1 :
2782
((uint64_t) a > (uint64_t) b) ? 1 : 0;
2783
return (a < b) ? -1 : (a > b) ? 1 : 0;
2786
void Field_int64_t::sort_string(uchar *to,uint length __attribute__((unused)))
2788
#ifdef WORDS_BIGENDIAN
2789
if (!table->s->db_low_byte_first)
2794
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
2809
to[0] = (char) (ptr[7] ^ 128); /* Revers signbit */
2821
void Field_int64_t::sql_type(String &res) const
2823
CHARSET_INFO *cs=res.charset();
2824
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
2825
"bigint(%d)",(int) field_length));
2826
add_zerofill_and_unsigned(res);
2831
Floating-point numbers
2835
Field_real::pack(uchar *to, const uchar *from,
2836
uint max_length, bool low_byte_first)
2838
assert(max_length >= pack_length());
2839
#ifdef WORDS_BIGENDIAN
2840
if (low_byte_first != table->s->db_low_byte_first)
2842
const uchar *dptr= from + pack_length();
2843
while (dptr-- > from)
2849
return(Field::pack(to, from, max_length, low_byte_first));
2853
Field_real::unpack(uchar *to, const uchar *from,
2854
uint param_data, bool low_byte_first)
2856
#ifdef WORDS_BIGENDIAN
2857
if (low_byte_first != table->s->db_low_byte_first)
2859
const uchar *dptr= from + pack_length();
2860
while (dptr-- > from)
2862
return(from + pack_length());
2866
return(Field::unpack(to, from, param_data, low_byte_first));
2869
/****************************************************************************
2870
double precision floating point numbers
2871
****************************************************************************/
2873
int Field_double::store(const char *from,uint len,CHARSET_INFO *cs)
2877
double nr= my_strntod(cs,(char*) from, len, &end, &error);
2878
if (error || (!len || (((uint) (end-from) != len) && table->in_use->count_cuted_fields)))
2880
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
2881
(error ? ER_WARN_DATA_OUT_OF_RANGE : WARN_DATA_TRUNCATED), 1);
2882
error= error ? 1 : 2;
2884
Field_double::store(nr);
2889
int Field_double::store(double nr)
2891
int error= truncate(&nr, DBL_MAX);
2893
#ifdef WORDS_BIGENDIAN
2894
if (table->s->db_low_byte_first)
2896
float8store(ptr,nr);
2900
doublestore(ptr,nr);
2905
int Field_double::store(int64_t nr, bool unsigned_val)
2907
return Field_double::store(unsigned_val ? uint64_t2double((uint64_t) nr) :
2912
If a field has fixed length, truncate the double argument pointed to by 'nr'
2914
Also ensure that the argument is within [-max_value; max_value] range.
2917
int Field_real::truncate(double *nr, double max_value)
2926
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2929
else if (unsigned_flag && res < 0)
2932
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2938
uint order= field_length - dec;
2939
uint step= array_elements(log_10) - 1;
2941
for (; order > step; order-= step)
2942
max_value*= log_10[step];
2943
max_value*= log_10[order];
2944
max_value-= 1.0 / log_10[dec];
2946
/* Check for infinity so we don't get NaN in calculations */
2949
double tmp= rint((res - floor(res)) * log_10[dec]) / log_10[dec];
2950
res= floor(res) + tmp;
2954
if (res < -max_value)
2957
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2959
else if (res > max_value)
2962
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
2973
int Field_real::store_decimal(const my_decimal *dm)
2976
my_decimal2double(E_DEC_FATAL_ERROR, dm, &dbl);
2980
double Field_double::val_real(void)
2983
#ifdef WORDS_BIGENDIAN
2984
if (table->s->db_low_byte_first)
2994
int64_t Field_double::val_int(void)
2998
#ifdef WORDS_BIGENDIAN
2999
if (table->s->db_low_byte_first)
3006
/* Check whether we fit into int64_t range */
3007
if (j <= (double) INT64_MIN)
3009
res= (int64_t) INT64_MIN;
3012
if (j >= (double) (uint64_t) INT64_MAX)
3014
res= (int64_t) INT64_MAX;
3017
return (int64_t) rint(j);
3021
char buf[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
3022
String tmp(buf, sizeof(buf), &my_charset_latin1), *str;
3023
str= val_str(&tmp, 0);
3024
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3025
ER_TRUNCATED_WRONG_VALUE,
3026
ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER",
3033
my_decimal *Field_real::val_decimal(my_decimal *decimal_value)
3035
double2my_decimal(E_DEC_FATAL_ERROR, val_real(), decimal_value);
3036
return decimal_value;
3040
String *Field_double::val_str(String *val_buffer,
3041
String *val_ptr __attribute__((unused)))
3044
#ifdef WORDS_BIGENDIAN
3045
if (table->s->db_low_byte_first)
3053
uint to_length=max(field_length, DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE);
3054
val_buffer->alloc(to_length);
3055
char *to=(char*) val_buffer->ptr();
3058
if (dec >= NOT_FIXED_DEC)
3059
len= my_gcvt(nr, MY_GCVT_ARG_DOUBLE, to_length - 1, to, NULL);
3061
len= my_fcvt(nr, dec, to, NULL);
3063
val_buffer->length((uint) len);
3065
prepend_zeros(val_buffer);
3069
bool Field_double::send_binary(Protocol *protocol)
3071
return protocol->store((double) Field_double::val_real(), dec, (String*) 0);
3075
int Field_double::cmp(const uchar *a_ptr, const uchar *b_ptr)
3078
#ifdef WORDS_BIGENDIAN
3079
if (table->s->db_low_byte_first)
3087
doubleget(a, a_ptr);
3088
doubleget(b, b_ptr);
3090
return (a < b) ? -1 : (a > b) ? 1 : 0;
3094
#define DBL_EXP_DIG (sizeof(double)*8-DBL_MANT_DIG)
3096
/* The following should work for IEEE */
3098
void Field_double::sort_string(uchar *to,uint length __attribute__((unused)))
3101
#ifdef WORDS_BIGENDIAN
3102
if (table->s->db_low_byte_first)
3109
change_double_for_sort(nr, to);
3114
Save the field metadata for double fields.
3116
Saves the pack length in the first byte of the field metadata array
3117
at index of *metadata_ptr.
3119
@param metadata_ptr First byte of field metadata
3121
@returns number of bytes written to metadata_ptr
3123
int Field_double::do_save_field_metadata(uchar *metadata_ptr)
3125
*metadata_ptr= pack_length();
3130
void Field_double::sql_type(String &res) const
3132
CHARSET_INFO *cs=res.charset();
3133
if (dec == NOT_FIXED_DEC)
3135
res.set_ascii(STRING_WITH_LEN("double"));
3139
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
3140
"double(%d,%d)",(int) field_length,dec));
3142
add_zerofill_and_unsigned(res);
3147
TIMESTAMP type holds datetime values in range from 1970-01-01 00:00:01 UTC to
3148
2038-01-01 00:00:00 UTC stored as number of seconds since Unix
3151
Up to one of timestamps columns in the table can be automatically
3152
set on row update and/or have NOW() as default value.
3153
TABLE::timestamp_field points to Field object for such timestamp with
3154
auto-set-on-update. TABLE::time_stamp holds offset in record + 1 for this
3155
field, and is used by handler code which performs updates required.
3157
Actually SQL-99 says that we should allow niladic functions (like NOW())
3158
as defaults for any field. Current limitations (only NOW() and only
3159
for one TIMESTAMP field) are because of restricted binary .frm format
3160
and should go away in the future.
3162
Also because of this limitation of binary .frm format we use 5 different
3163
unireg_check values with TIMESTAMP field to distinguish various cases of
3164
DEFAULT or ON UPDATE values. These values are:
3166
TIMESTAMP_OLD_FIELD - old timestamp, if there was not any fields with
3167
auto-set-on-update (or now() as default) in this table before, then this
3168
field has NOW() as default and is updated when row changes, else it is
3169
field which has 0 as default value and is not automatically updated.
3170
TIMESTAMP_DN_FIELD - field with NOW() as default but not set on update
3171
automatically (TIMESTAMP DEFAULT NOW())
3172
TIMESTAMP_UN_FIELD - field which is set on update automatically but has not
3173
NOW() as default (but it may has 0 or some other const timestamp as
3174
default) (TIMESTAMP ON UPDATE NOW()).
3175
TIMESTAMP_DNUN_FIELD - field which has now() as default and is auto-set on
3176
update. (TIMESTAMP DEFAULT NOW() ON UPDATE NOW())
3177
NONE - field which is not auto-set on update with some other than NOW()
3178
default value (TIMESTAMP DEFAULT 0).
3180
Note that TIMESTAMP_OLD_FIELDs are never created explicitly now, they are
3181
left only for preserving ability to read old tables. Such fields replaced
3182
with their newer analogs in CREATE TABLE and in SHOW CREATE TABLE. This is
3183
because we want to prefer NONE unireg_check before TIMESTAMP_OLD_FIELD for
3184
"TIMESTAMP DEFAULT 'Const'" field. (Old timestamps allowed such
3185
specification too but ignored default value for first timestamp, which of
3186
course is non-standard.) In most cases user won't notice any change, only
3187
exception is different behavior of old/new timestamps during ALTER TABLE.
3190
Field_timestamp::Field_timestamp(uchar *ptr_arg,
3191
uint32 len_arg __attribute__((__unused__)),
3192
uchar *null_ptr_arg, uchar null_bit_arg,
3193
enum utype unireg_check_arg,
3194
const char *field_name_arg,
3197
:Field_str(ptr_arg, MAX_DATETIME_WIDTH, null_ptr_arg, null_bit_arg,
3198
unireg_check_arg, field_name_arg, cs)
3200
/* For 4.0 MYD and 4.0 InnoDB compatibility */
3201
flags|= ZEROFILL_FLAG | UNSIGNED_FLAG;
3202
if (!share->timestamp_field && unireg_check != NONE)
3204
/* This timestamp has auto-update */
3205
share->timestamp_field= this;
3206
flags|= TIMESTAMP_FLAG;
3207
if (unireg_check != TIMESTAMP_DN_FIELD)
3208
flags|= ON_UPDATE_NOW_FLAG;
3213
Field_timestamp::Field_timestamp(bool maybe_null_arg,
3214
const char *field_name_arg,
3216
:Field_str((uchar*) 0, MAX_DATETIME_WIDTH,
3217
maybe_null_arg ? (uchar*) "": 0, 0,
3218
NONE, field_name_arg, cs)
3220
/* For 4.0 MYD and 4.0 InnoDB compatibility */
3221
flags|= ZEROFILL_FLAG | UNSIGNED_FLAG;
3222
if (unireg_check != TIMESTAMP_DN_FIELD)
3223
flags|= ON_UPDATE_NOW_FLAG;
3228
Get auto-set type for TIMESTAMP field.
3230
Returns value indicating during which operations this TIMESTAMP field
3231
should be auto-set to current timestamp.
3233
timestamp_auto_set_type Field_timestamp::get_auto_set_type() const
3235
switch (unireg_check)
3237
case TIMESTAMP_DN_FIELD:
3238
return TIMESTAMP_AUTO_SET_ON_INSERT;
3239
case TIMESTAMP_UN_FIELD:
3240
return TIMESTAMP_AUTO_SET_ON_UPDATE;
3241
case TIMESTAMP_OLD_FIELD:
3243
Although we can have several such columns in legacy tables this
3244
function should be called only for first of them (i.e. the one
3245
having auto-set property).
3247
assert(table->timestamp_field == this);
3249
case TIMESTAMP_DNUN_FIELD:
3250
return TIMESTAMP_AUTO_SET_ON_BOTH;
3253
Normally this function should not be called for TIMESTAMPs without
3257
return TIMESTAMP_NO_AUTO_SET;
3262
int Field_timestamp::store(const char *from,
3264
CHARSET_INFO *cs __attribute__((__unused__)))
3269
bool have_smth_to_conv;
3270
bool in_dst_time_gap;
3271
THD *thd= table ? table->in_use : current_thd;
3273
/* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */
3274
have_smth_to_conv= (str_to_datetime(from, len, &l_time, 1, &error) >
3275
MYSQL_TIMESTAMP_ERROR);
3277
if (error || !have_smth_to_conv)
3280
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED,
3281
from, len, MYSQL_TIMESTAMP_DATETIME, 1);
3284
/* Only convert a correct date (not a zero date) */
3285
if (have_smth_to_conv && l_time.month)
3287
if (!(tmp= TIME_to_timestamp(thd, &l_time, &in_dst_time_gap)))
3289
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3290
ER_WARN_DATA_OUT_OF_RANGE,
3291
from, len, MYSQL_TIMESTAMP_DATETIME, !error);
3294
else if (in_dst_time_gap)
3296
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3297
ER_WARN_INVALID_TIMESTAMP,
3298
from, len, MYSQL_TIMESTAMP_DATETIME, !error);
3302
store_timestamp(tmp);
3307
int Field_timestamp::store(double nr)
3310
if (nr < 0 || nr > 99991231235959.0)
3312
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3313
ER_WARN_DATA_OUT_OF_RANGE,
3314
nr, MYSQL_TIMESTAMP_DATETIME);
3315
nr= 0; // Avoid overflow on buff
3318
error|= Field_timestamp::store((int64_t) rint(nr), false);
3323
int Field_timestamp::store(int64_t nr,
3324
bool unsigned_val __attribute__((__unused__)))
3327
my_time_t timestamp= 0;
3329
bool in_dst_time_gap;
3330
THD *thd= table ? table->in_use : current_thd;
3332
/* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */
3333
int64_t tmp= number_to_datetime(nr, &l_time, (thd->variables.sql_mode &
3334
MODE_NO_ZERO_DATE) |
3335
MODE_NO_ZERO_IN_DATE, &error);
3343
if (!(timestamp= TIME_to_timestamp(thd, &l_time, &in_dst_time_gap)))
3345
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3346
ER_WARN_DATA_OUT_OF_RANGE,
3347
nr, MYSQL_TIMESTAMP_DATETIME, 1);
3350
if (in_dst_time_gap)
3352
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3353
ER_WARN_INVALID_TIMESTAMP,
3354
nr, MYSQL_TIMESTAMP_DATETIME, 1);
3358
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3359
WARN_DATA_TRUNCATED,
3360
nr, MYSQL_TIMESTAMP_DATETIME, 1);
3362
store_timestamp(timestamp);
3366
double Field_timestamp::val_real(void)
3368
return (double) Field_timestamp::val_int();
3371
int64_t Field_timestamp::val_int(void)
3374
MYSQL_TIME time_tmp;
3375
THD *thd= table ? table->in_use : current_thd;
3377
thd->time_zone_used= 1;
3378
#ifdef WORDS_BIGENDIAN
3379
if (table && table->s->db_low_byte_first)
3380
temp=uint4korr(ptr);
3385
if (temp == 0L) // No time
3386
return(0); /* purecov: inspected */
3388
thd->variables.time_zone->gmt_sec_to_TIME(&time_tmp, (my_time_t)temp);
3390
return time_tmp.year * 10000000000LL + time_tmp.month * 100000000LL +
3391
time_tmp.day * 1000000L + time_tmp.hour * 10000L +
3392
time_tmp.minute * 100 + time_tmp.second;
3396
String *Field_timestamp::val_str(String *val_buffer, String *val_ptr)
3399
MYSQL_TIME time_tmp;
3400
THD *thd= table ? table->in_use : current_thd;
3403
val_buffer->alloc(field_length+1);
3404
to= (char*) val_buffer->ptr();
3405
val_buffer->length(field_length);
3407
thd->time_zone_used= 1;
3408
#ifdef WORDS_BIGENDIAN
3409
if (table && table->s->db_low_byte_first)
3410
temp=uint4korr(ptr);
3416
{ /* Zero time is "000000" */
3417
val_ptr->set(STRING_WITH_LEN("0000-00-00 00:00:00"), &my_charset_bin);
3420
val_buffer->set_charset(&my_charset_bin); // Safety
3422
thd->variables.time_zone->gmt_sec_to_TIME(&time_tmp,(my_time_t)temp);
3424
temp= time_tmp.year % 100;
3425
if (temp < YY_PART_YEAR - 1)
3435
temp2=temp/10; temp=temp-temp2*10;
3436
*to++= (char) ('0'+(char) (temp2));
3437
*to++= (char) ('0'+(char) (temp));
3439
temp=time_tmp.month;
3440
temp2=temp/10; temp=temp-temp2*10;
3441
*to++= (char) ('0'+(char) (temp2));
3442
*to++= (char) ('0'+(char) (temp));
3445
temp2=temp/10; temp=temp-temp2*10;
3446
*to++= (char) ('0'+(char) (temp2));
3447
*to++= (char) ('0'+(char) (temp));
3450
temp2=temp/10; temp=temp-temp2*10;
3451
*to++= (char) ('0'+(char) (temp2));
3452
*to++= (char) ('0'+(char) (temp));
3454
temp=time_tmp.minute;
3455
temp2=temp/10; temp=temp-temp2*10;
3456
*to++= (char) ('0'+(char) (temp2));
3457
*to++= (char) ('0'+(char) (temp));
3459
temp=time_tmp.second;
3460
temp2=temp/10; temp=temp-temp2*10;
3461
*to++= (char) ('0'+(char) (temp2));
3462
*to++= (char) ('0'+(char) (temp));
3468
bool Field_timestamp::get_date(MYSQL_TIME *ltime, uint fuzzydate)
3471
THD *thd= table ? table->in_use : current_thd;
3472
thd->time_zone_used= 1;
3473
#ifdef WORDS_BIGENDIAN
3474
if (table && table->s->db_low_byte_first)
3475
temp=uint4korr(ptr);
3480
{ /* Zero time is "000000" */
3481
if (fuzzydate & TIME_NO_ZERO_DATE)
3483
bzero((char*) ltime,sizeof(*ltime));
3487
thd->variables.time_zone->gmt_sec_to_TIME(ltime, (my_time_t)temp);
3492
bool Field_timestamp::get_time(MYSQL_TIME *ltime)
3494
return Field_timestamp::get_date(ltime,0);
3498
bool Field_timestamp::send_binary(Protocol *protocol)
3501
Field_timestamp::get_date(&tm, 0);
3502
return protocol->store(&tm);
3506
int Field_timestamp::cmp(const uchar *a_ptr, const uchar *b_ptr)
3509
#ifdef WORDS_BIGENDIAN
3510
if (table && table->s->db_low_byte_first)
3521
return ((uint32) a < (uint32) b) ? -1 : ((uint32) a > (uint32) b) ? 1 : 0;
3525
void Field_timestamp::sort_string(uchar *to,uint length __attribute__((unused)))
3527
#ifdef WORDS_BIGENDIAN
3528
if (!table || !table->s->db_low_byte_first)
3546
void Field_timestamp::sql_type(String &res) const
3548
res.set_ascii(STRING_WITH_LEN("timestamp"));
3552
void Field_timestamp::set_time()
3554
THD *thd= table ? table->in_use : current_thd;
3555
long tmp= (long) thd->query_start();
3557
store_timestamp(tmp);
3560
/****************************************************************************
3562
** In string context: HH:MM:SS
3563
** In number context: HHMMSS
3564
** Stored as a 3 byte unsigned int
3565
****************************************************************************/
3567
int Field_time::store(const char *from,
3569
CHARSET_INFO *cs __attribute__((__unused__)))
3576
if (str_to_time(from, len, <ime, &warning))
3580
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED,
3581
from, len, MYSQL_TIMESTAMP_TIME, 1);
3585
if (warning & MYSQL_TIME_WARN_TRUNCATED)
3587
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3588
WARN_DATA_TRUNCATED,
3589
from, len, MYSQL_TIMESTAMP_TIME, 1);
3592
if (warning & MYSQL_TIME_WARN_OUT_OF_RANGE)
3594
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3595
ER_WARN_DATA_OUT_OF_RANGE,
3596
from, len, MYSQL_TIMESTAMP_TIME, !error);
3601
tmp=(ltime.day*24L+ltime.hour)*10000L+(ltime.minute*100+ltime.second);
3611
int Field_time::store_time(MYSQL_TIME *ltime,
3612
timestamp_type time_type __attribute__((__unused__)))
3614
long tmp= ((ltime->month ? 0 : ltime->day * 24L) + ltime->hour) * 10000L +
3615
(ltime->minute * 100 + ltime->second);
3618
return Field_time::store((int64_t) tmp, false);
3622
int Field_time::store(double nr)
3626
if (nr > (double)TIME_MAX_VALUE)
3628
tmp= TIME_MAX_VALUE;
3629
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3630
ER_WARN_DATA_OUT_OF_RANGE, nr, MYSQL_TIMESTAMP_TIME);
3633
else if (nr < (double)-TIME_MAX_VALUE)
3635
tmp= -TIME_MAX_VALUE;
3636
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3637
ER_WARN_DATA_OUT_OF_RANGE, nr, MYSQL_TIMESTAMP_TIME);
3642
tmp=(long) floor(fabs(nr)); // Remove fractions
3645
if (tmp % 100 > 59 || tmp/100 % 100 > 59)
3648
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3649
ER_WARN_DATA_OUT_OF_RANGE, nr,
3650
MYSQL_TIMESTAMP_TIME);
3659
int Field_time::store(int64_t nr, bool unsigned_val)
3663
if (nr < (int64_t) -TIME_MAX_VALUE && !unsigned_val)
3665
tmp= -TIME_MAX_VALUE;
3666
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3667
ER_WARN_DATA_OUT_OF_RANGE, nr,
3668
MYSQL_TIMESTAMP_TIME, 1);
3671
else if (nr > (int64_t) TIME_MAX_VALUE || (nr < 0 && unsigned_val))
3673
tmp= TIME_MAX_VALUE;
3674
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3675
ER_WARN_DATA_OUT_OF_RANGE, nr,
3676
MYSQL_TIMESTAMP_TIME, 1);
3682
if (tmp % 100 > 59 || tmp/100 % 100 > 59)
3685
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
3686
ER_WARN_DATA_OUT_OF_RANGE, nr,
3687
MYSQL_TIMESTAMP_TIME, 1);
3696
double Field_time::val_real(void)
3698
uint32 j= (uint32) uint3korr(ptr);
3702
int64_t Field_time::val_int(void)
3704
return (int64_t) sint3korr(ptr);
3710
This function is multi-byte safe as the result string is always of type
3714
String *Field_time::val_str(String *val_buffer,
3715
String *val_ptr __attribute__((unused)))
3718
val_buffer->alloc(MAX_DATE_STRING_REP_LENGTH);
3719
long tmp=(long) sint3korr(ptr);
3726
ltime.day= (uint) 0;
3727
ltime.hour= (uint) (tmp/10000);
3728
ltime.minute= (uint) (tmp/100 % 100);
3729
ltime.second= (uint) (tmp % 100);
3730
make_time((DATE_TIME_FORMAT*) 0, <ime, val_buffer);
3737
Normally we would not consider 'time' as a valid date, but we allow
3738
get_date() here to be able to do things like
3739
DATE_FORMAT(time, "%l.%i %p")
3742
bool Field_time::get_date(MYSQL_TIME *ltime, uint fuzzydate)
3745
THD *thd= table ? table->in_use : current_thd;
3746
if (!(fuzzydate & TIME_FUZZY_DATE))
3748
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3749
ER_WARN_DATA_OUT_OF_RANGE,
3750
ER(ER_WARN_DATA_OUT_OF_RANGE), field_name,
3754
tmp=(long) sint3korr(ptr);
3761
ltime->hour=tmp/10000;
3762
tmp-=ltime->hour*10000;
3763
ltime->minute= tmp/100;
3764
ltime->second= tmp % 100;
3765
ltime->year= ltime->month= ltime->day= ltime->second_part= 0;
3770
bool Field_time::get_time(MYSQL_TIME *ltime)
3772
long tmp=(long) sint3korr(ptr);
3780
ltime->hour= (int) (tmp/10000);
3781
tmp-=ltime->hour*10000;
3782
ltime->minute= (int) tmp/100;
3783
ltime->second= (int) tmp % 100;
3784
ltime->second_part=0;
3785
ltime->time_type= MYSQL_TIMESTAMP_TIME;
3790
bool Field_time::send_binary(Protocol *protocol)
3793
Field_time::get_time(&tm);
3794
tm.day= tm.hour/24; // Move hours to days
3795
tm.hour-= tm.day*24;
3796
return protocol->store_time(&tm);
3800
int Field_time::cmp(const uchar *a_ptr, const uchar *b_ptr)
3803
a=(int32) sint3korr(a_ptr);
3804
b=(int32) sint3korr(b_ptr);
3805
return (a < b) ? -1 : (a > b) ? 1 : 0;
3808
void Field_time::sort_string(uchar *to,uint length __attribute__((unused)))
3810
to[0] = (uchar) (ptr[2] ^ 128);
3815
void Field_time::sql_type(String &res) const
3817
res.set_ascii(STRING_WITH_LEN("time"));
3820
/****************************************************************************
3822
** Save in a byte the year 0, 1901->2155
3823
** Can handle 2 byte or 4 byte years!
3824
****************************************************************************/
3826
int Field_year::store(const char *from, uint len,CHARSET_INFO *cs)
3830
int64_t nr= cs->cset->strntoull10rnd(cs, from, len, 0, &end, &error);
3832
if (nr < 0 || (nr >= 100 && nr <= 1900) || nr > 2155 ||
3833
error == MY_ERRNO_ERANGE)
3836
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3839
if (table->in_use->count_cuted_fields &&
3840
(error= check_int(cs, from, len, end, error)))
3842
if (error == 1) /* empty or incorrect string */
3850
if (nr != 0 || len != 4)
3852
if (nr < YY_PART_YEAR)
3853
nr+=100; // 2000 - 2069
3857
*ptr= (char) (uchar) nr;
3862
int Field_year::store(double nr)
3864
if (nr < 0.0 || nr >= 2155.0)
3866
(void) Field_year::store((int64_t) -1, false);
3869
return Field_year::store((int64_t) nr, false);
3873
int Field_year::store(int64_t nr,
3874
bool unsigned_val __attribute__((__unused__)))
3876
if (nr < 0 || (nr >= 100 && nr <= 1900) || nr > 2155)
3879
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
3882
if (nr != 0 || field_length != 4) // 0000 -> 0; 00 -> 2000
3884
if (nr < YY_PART_YEAR)
3885
nr+=100; // 2000 - 2069
3889
*ptr= (char) (uchar) nr;
3894
bool Field_year::send_binary(Protocol *protocol)
3896
uint64_t tmp= Field_year::val_int();
3897
return protocol->store_short(tmp);
3901
double Field_year::val_real(void)
3903
return (double) Field_year::val_int();
3907
int64_t Field_year::val_int(void)
3909
int tmp= (int) ptr[0];
3910
if (field_length != 4)
3911
tmp%=100; // Return last 2 char
3914
return (int64_t) tmp;
3918
String *Field_year::val_str(String *val_buffer,
3919
String *val_ptr __attribute__((unused)))
3921
val_buffer->alloc(5);
3922
val_buffer->length(field_length);
3923
char *to=(char*) val_buffer->ptr();
3924
sprintf(to,field_length == 2 ? "%02d" : "%04d",(int) Field_year::val_int());
3929
void Field_year::sql_type(String &res) const
3931
CHARSET_INFO *cs=res.charset();
3932
res.length(cs->cset->snprintf(cs,(char*)res.ptr(),res.alloced_length(),
3933
"year(%d)",(int) field_length));
3937
/****************************************************************************
3938
** The new date type
3939
** This is identical to the old date type, but stored on 3 bytes instead of 4
3940
** In number context: YYYYMMDD
3941
****************************************************************************/
3944
Store string into a date field
3947
Field_newdate::store()
3949
len Length of date field
3950
cs Character set (not used)
3954
1 Value was cut during conversion
3956
3 Datetime value that was cut (warning level NOTE)
3957
This is used by opt_range.cc:get_mm_leaf(). Note that there is a
3958
nearly-identical class Field_date doesn't ever return 3 from its
3962
int Field_newdate::store(const char *from,
3964
CHARSET_INFO *cs __attribute__((__unused__)))
3969
THD *thd= table ? table->in_use : current_thd;
3970
enum enum_mysql_timestamp_type ret;
3971
if ((ret= str_to_datetime(from, len, &l_time,
3973
(thd->variables.sql_mode &
3974
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE |
3975
MODE_INVALID_DATES))),
3976
&error)) <= MYSQL_TIMESTAMP_ERROR)
3983
tmp= l_time.day + l_time.month*32 + l_time.year*16*32;
3984
if (!error && (ret != MYSQL_TIMESTAMP_DATE) &&
3985
(l_time.hour || l_time.minute || l_time.second || l_time.second_part))
3986
error= 3; // Datetime was cut (note)
3990
set_datetime_warning(error == 3 ? MYSQL_ERROR::WARN_LEVEL_NOTE :
3991
MYSQL_ERROR::WARN_LEVEL_WARN,
3992
WARN_DATA_TRUNCATED,
3993
from, len, MYSQL_TIMESTAMP_DATE, 1);
3995
int3store(ptr, tmp);
4000
int Field_newdate::store(double nr)
4002
if (nr < 0.0 || nr > 99991231235959.0)
4004
int3store(ptr,(int32) 0);
4005
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
4006
WARN_DATA_TRUNCATED, nr, MYSQL_TIMESTAMP_DATE);
4009
return Field_newdate::store((int64_t) rint(nr), false);
4013
int Field_newdate::store(int64_t nr,
4014
bool unsigned_val __attribute__((__unused__)))
4019
THD *thd= table ? table->in_use : current_thd;
4020
if (number_to_datetime(nr, &l_time,
4022
(thd->variables.sql_mode &
4023
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE |
4024
MODE_INVALID_DATES))),
4031
tmp= l_time.day + l_time.month*32 + l_time.year*16*32;
4033
if (!error && l_time.time_type != MYSQL_TIMESTAMP_DATE &&
4034
(l_time.hour || l_time.minute || l_time.second || l_time.second_part))
4038
set_datetime_warning(error == 3 ? MYSQL_ERROR::WARN_LEVEL_NOTE :
4039
MYSQL_ERROR::WARN_LEVEL_WARN,
4041
ER_WARN_DATA_OUT_OF_RANGE : WARN_DATA_TRUNCATED,
4042
nr,MYSQL_TIMESTAMP_DATE, 1);
4049
int Field_newdate::store_time(MYSQL_TIME *ltime,timestamp_type time_type)
4053
if (time_type == MYSQL_TIMESTAMP_DATE ||
4054
time_type == MYSQL_TIMESTAMP_DATETIME)
4056
tmp=ltime->year*16*32+ltime->month*32+ltime->day;
4057
if (check_date(ltime, tmp != 0,
4059
(current_thd->variables.sql_mode &
4060
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE |
4061
MODE_INVALID_DATES))), &error))
4063
char buff[MAX_DATE_STRING_REP_LENGTH];
4064
String str(buff, sizeof(buff), &my_charset_latin1);
4065
make_date((DATE_TIME_FORMAT *) 0, ltime, &str);
4066
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED,
4067
str.ptr(), str.length(), MYSQL_TIMESTAMP_DATE, 1);
4069
if (!error && ltime->time_type != MYSQL_TIMESTAMP_DATE &&
4070
(ltime->hour || ltime->minute || ltime->second || ltime->second_part))
4072
char buff[MAX_DATE_STRING_REP_LENGTH];
4073
String str(buff, sizeof(buff), &my_charset_latin1);
4074
make_datetime((DATE_TIME_FORMAT *) 0, ltime, &str);
4075
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_NOTE,
4076
WARN_DATA_TRUNCATED,
4077
str.ptr(), str.length(), MYSQL_TIMESTAMP_DATE, 1);
4085
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
4092
bool Field_newdate::send_binary(Protocol *protocol)
4095
Field_newdate::get_date(&tm,0);
4096
return protocol->store_date(&tm);
4100
double Field_newdate::val_real(void)
4102
return (double) Field_newdate::val_int();
4106
int64_t Field_newdate::val_int(void)
4108
ulong j= uint3korr(ptr);
4109
j= (j % 32L)+(j / 32L % 16L)*100L + (j/(16L*32L))*10000L;
4114
String *Field_newdate::val_str(String *val_buffer,
4115
String *val_ptr __attribute__((unused)))
4117
val_buffer->alloc(field_length);
4118
val_buffer->length(field_length);
4119
uint32 tmp=(uint32) uint3korr(ptr);
4121
char *pos=(char*) val_buffer->ptr()+10;
4123
/* Open coded to get more speed */
4124
*pos--=0; // End NULL
4125
part=(int) (tmp & 31);
4126
*pos--= (char) ('0'+part%10);
4127
*pos--= (char) ('0'+part/10);
4129
part=(int) (tmp >> 5 & 15);
4130
*pos--= (char) ('0'+part%10);
4131
*pos--= (char) ('0'+part/10);
4133
part=(int) (tmp >> 9);
4134
*pos--= (char) ('0'+part%10); part/=10;
4135
*pos--= (char) ('0'+part%10); part/=10;
4136
*pos--= (char) ('0'+part%10); part/=10;
4137
*pos= (char) ('0'+part);
4142
bool Field_newdate::get_date(MYSQL_TIME *ltime,uint fuzzydate)
4144
uint32 tmp=(uint32) uint3korr(ptr);
4145
ltime->day= tmp & 31;
4146
ltime->month= (tmp >> 5) & 15;
4147
ltime->year= (tmp >> 9);
4148
ltime->time_type= MYSQL_TIMESTAMP_DATE;
4149
ltime->hour= ltime->minute= ltime->second= ltime->second_part= ltime->neg= 0;
4150
return ((!(fuzzydate & TIME_FUZZY_DATE) && (!ltime->month || !ltime->day)) ?
4155
bool Field_newdate::get_time(MYSQL_TIME *ltime)
4157
return Field_newdate::get_date(ltime,0);
4161
int Field_newdate::cmp(const uchar *a_ptr, const uchar *b_ptr)
4164
a=(uint32) uint3korr(a_ptr);
4165
b=(uint32) uint3korr(b_ptr);
4166
return (a < b) ? -1 : (a > b) ? 1 : 0;
4170
void Field_newdate::sort_string(uchar *to,uint length __attribute__((unused)))
4178
void Field_newdate::sql_type(String &res) const
4180
res.set_ascii(STRING_WITH_LEN("date"));
4184
/****************************************************************************
4186
** In string context: YYYY-MM-DD HH:MM:DD
4187
** In number context: YYYYMMDDHHMMDD
4188
** Stored as a 8 byte unsigned int. Should sometimes be change to a 6 byte int.
4189
****************************************************************************/
4191
int Field_datetime::store(const char *from,
4193
CHARSET_INFO *cs __attribute__((__unused__)))
4195
MYSQL_TIME time_tmp;
4198
enum enum_mysql_timestamp_type func_res;
4199
THD *thd= table ? table->in_use : current_thd;
4201
func_res= str_to_datetime(from, len, &time_tmp,
4203
(thd->variables.sql_mode &
4204
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE |
4205
MODE_INVALID_DATES))),
4207
if ((int) func_res > (int) MYSQL_TIMESTAMP_ERROR)
4208
tmp= TIME_to_uint64_t_datetime(&time_tmp);
4210
error= 1; // Fix if invalid zero date
4213
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
4214
ER_WARN_DATA_OUT_OF_RANGE,
4215
from, len, MYSQL_TIMESTAMP_DATETIME, 1);
4217
#ifdef WORDS_BIGENDIAN
4218
if (table && table->s->db_low_byte_first)
4224
int64_tstore(ptr,tmp);
4229
int Field_datetime::store(double nr)
4232
if (nr < 0.0 || nr > 99991231235959.0)
4234
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
4235
ER_WARN_DATA_OUT_OF_RANGE,
4236
nr, MYSQL_TIMESTAMP_DATETIME);
4240
error|= Field_datetime::store((int64_t) rint(nr), false);
4245
int Field_datetime::store(int64_t nr,
4246
bool unsigned_val __attribute__((__unused__)))
4248
MYSQL_TIME not_used;
4250
int64_t initial_nr= nr;
4251
THD *thd= table ? table->in_use : current_thd;
4253
nr= number_to_datetime(nr, ¬_used, (TIME_FUZZY_DATE |
4254
(thd->variables.sql_mode &
4255
(MODE_NO_ZERO_IN_DATE |
4257
MODE_INVALID_DATES))), &error);
4266
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
4267
error == 2 ? ER_WARN_DATA_OUT_OF_RANGE :
4268
WARN_DATA_TRUNCATED, initial_nr,
4269
MYSQL_TIMESTAMP_DATETIME, 1);
4271
#ifdef WORDS_BIGENDIAN
4272
if (table && table->s->db_low_byte_first)
4278
int64_tstore(ptr,nr);
4283
int Field_datetime::store_time(MYSQL_TIME *ltime,timestamp_type time_type)
4288
We don't perform range checking here since values stored in TIME
4289
structure always fit into DATETIME range.
4291
if (time_type == MYSQL_TIMESTAMP_DATE ||
4292
time_type == MYSQL_TIMESTAMP_DATETIME)
4294
tmp=((ltime->year*10000L+ltime->month*100+ltime->day)*1000000LL+
4295
(ltime->hour*10000L+ltime->minute*100+ltime->second));
4296
if (check_date(ltime, tmp != 0,
4298
(current_thd->variables.sql_mode &
4299
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE |
4300
MODE_INVALID_DATES))), &error))
4302
char buff[MAX_DATE_STRING_REP_LENGTH];
4303
String str(buff, sizeof(buff), &my_charset_latin1);
4304
make_datetime((DATE_TIME_FORMAT *) 0, ltime, &str);
4305
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED,
4306
str.ptr(), str.length(), MYSQL_TIMESTAMP_DATETIME,1);
4313
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
4315
#ifdef WORDS_BIGENDIAN
4316
if (table && table->s->db_low_byte_first)
4322
int64_tstore(ptr,tmp);
4326
bool Field_datetime::send_binary(Protocol *protocol)
4329
Field_datetime::get_date(&tm, TIME_FUZZY_DATE);
4330
return protocol->store(&tm);
4334
double Field_datetime::val_real(void)
4336
return (double) Field_datetime::val_int();
4339
int64_t Field_datetime::val_int(void)
4342
#ifdef WORDS_BIGENDIAN
4343
if (table && table->s->db_low_byte_first)
4352
String *Field_datetime::val_str(String *val_buffer,
4353
String *val_ptr __attribute__((unused)))
4355
val_buffer->alloc(field_length);
4356
val_buffer->length(field_length);
4362
#ifdef WORDS_BIGENDIAN
4363
if (table && table->s->db_low_byte_first)
4367
int64_tget(tmp,ptr);
4370
Avoid problem with slow int64_t arithmetic and sprintf
4373
part1=(long) (tmp/1000000LL);
4374
part2=(long) (tmp - (uint64_t) part1*1000000LL);
4376
pos=(char*) val_buffer->ptr() + MAX_DATETIME_WIDTH;
4378
*pos--= (char) ('0'+(char) (part2%10)); part2/=10;
4379
*pos--= (char) ('0'+(char) (part2%10)); part3= (int) (part2 / 10);
4381
*pos--= (char) ('0'+(char) (part3%10)); part3/=10;
4382
*pos--= (char) ('0'+(char) (part3%10)); part3/=10;
4384
*pos--= (char) ('0'+(char) (part3%10)); part3/=10;
4385
*pos--= (char) ('0'+(char) part3);
4387
*pos--= (char) ('0'+(char) (part1%10)); part1/=10;
4388
*pos--= (char) ('0'+(char) (part1%10)); part1/=10;
4390
*pos--= (char) ('0'+(char) (part1%10)); part1/=10;
4391
*pos--= (char) ('0'+(char) (part1%10)); part3= (int) (part1/10);
4393
*pos--= (char) ('0'+(char) (part3%10)); part3/=10;
4394
*pos--= (char) ('0'+(char) (part3%10)); part3/=10;
4395
*pos--= (char) ('0'+(char) (part3%10)); part3/=10;
4396
*pos=(char) ('0'+(char) part3);
4400
bool Field_datetime::get_date(MYSQL_TIME *ltime, uint fuzzydate)
4402
int64_t tmp=Field_datetime::val_int();
4404
part1=(uint32) (tmp/1000000LL);
4405
part2=(uint32) (tmp - (uint64_t) part1*1000000LL);
4407
ltime->time_type= MYSQL_TIMESTAMP_DATETIME;
4409
ltime->second_part= 0;
4410
ltime->second= (int) (part2%100);
4411
ltime->minute= (int) (part2/100%100);
4412
ltime->hour= (int) (part2/10000);
4413
ltime->day= (int) (part1%100);
4414
ltime->month= (int) (part1/100%100);
4415
ltime->year= (int) (part1/10000);
4416
return (!(fuzzydate & TIME_FUZZY_DATE) && (!ltime->month || !ltime->day)) ? 1 : 0;
4419
bool Field_datetime::get_time(MYSQL_TIME *ltime)
4421
return Field_datetime::get_date(ltime,0);
4424
int Field_datetime::cmp(const uchar *a_ptr, const uchar *b_ptr)
4427
#ifdef WORDS_BIGENDIAN
4428
if (table && table->s->db_low_byte_first)
4436
int64_tget(a,a_ptr);
4437
int64_tget(b,b_ptr);
4439
return ((uint64_t) a < (uint64_t) b) ? -1 :
4440
((uint64_t) a > (uint64_t) b) ? 1 : 0;
4443
void Field_datetime::sort_string(uchar *to,uint length __attribute__((unused)))
4445
#ifdef WORDS_BIGENDIAN
4446
if (!table || !table->s->db_low_byte_first)
4472
void Field_datetime::sql_type(String &res) const
4474
res.set_ascii(STRING_WITH_LEN("datetime"));
4477
/****************************************************************************
4479
** A string may be varchar or binary
4480
****************************************************************************/
4483
1621
Report "not well formed" or "cannot convert" error
4712
1805
return store(str.ptr(), str.length(), str.charset());
4715
uint32 Field_longstr::max_data_length() const
1808
uint32_t Field_longstr::max_data_length() const
4717
1810
return field_length + (field_length > 255 ? 2 : 1);
4721
double Field_string::val_real(void)
4725
CHARSET_INFO *cs= charset();
4728
result= my_strntod(cs,(char*) ptr,field_length,&end,&error);
4729
if (!table->in_use->no_errors &&
4730
(error || (field_length != (uint32)(end - (char*) ptr) &&
4731
!check_if_only_end_space(cs, end,
4732
(char*) ptr + field_length))))
4734
char buf[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
4735
String tmp(buf, sizeof(buf), cs);
4736
tmp.copy((char*) ptr, field_length, cs);
4737
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
4738
ER_TRUNCATED_WRONG_VALUE,
4739
ER(ER_TRUNCATED_WRONG_VALUE),
4740
"DOUBLE", tmp.c_ptr());
4746
int64_t Field_string::val_int(void)
4750
CHARSET_INFO *cs= charset();
4753
result= my_strntoll(cs, (char*) ptr,field_length,10,&end,&error);
4754
if (!table->in_use->no_errors &&
4755
(error || (field_length != (uint32)(end - (char*) ptr) &&
4756
!check_if_only_end_space(cs, end,
4757
(char*) ptr + field_length))))
4759
char buf[LONGLONG_TO_STRING_CONVERSION_BUFFER_SIZE];
4760
String tmp(buf, sizeof(buf), cs);
4761
tmp.copy((char*) ptr, field_length, cs);
4762
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
4763
ER_TRUNCATED_WRONG_VALUE,
4764
ER(ER_TRUNCATED_WRONG_VALUE),
4765
"INTEGER", tmp.c_ptr());
4771
String *Field_string::val_str(String *val_buffer __attribute__((unused)),
4774
/* See the comment for Field_long::store(long long) */
4775
assert(table->in_use == current_thd);
4777
if (table->in_use->variables.sql_mode &
4778
MODE_PAD_CHAR_TO_FULL_LENGTH)
4779
length= my_charpos(field_charset, ptr, ptr + field_length, field_length);
4781
length= field_charset->cset->lengthsp(field_charset, (const char*) ptr,
4783
val_ptr->set((const char*) ptr, length, field_charset);
4788
my_decimal *Field_string::val_decimal(my_decimal *decimal_value)
4790
int err= str2my_decimal(E_DEC_FATAL_ERROR, (char*) ptr, field_length,
4791
charset(), decimal_value);
4792
if (!table->in_use->no_errors && err)
4794
char buf[DECIMAL_TO_STRING_CONVERSION_BUFFER_SIZE];
4795
CHARSET_INFO *cs= charset();
4796
String tmp(buf, sizeof(buf), cs);
4797
tmp.copy((char*) ptr, field_length, cs);
4798
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
4799
ER_TRUNCATED_WRONG_VALUE,
4800
ER(ER_TRUNCATED_WRONG_VALUE),
4801
"DECIMAL", tmp.c_ptr());
4804
return decimal_value;
4808
int Field_string::cmp(const uchar *a_ptr, const uchar *b_ptr)
4812
if (field_charset->mbmaxlen != 1)
4814
uint char_len= field_length/field_charset->mbmaxlen;
4815
a_len= my_charpos(field_charset, a_ptr, a_ptr + field_length, char_len);
4816
b_len= my_charpos(field_charset, b_ptr, b_ptr + field_length, char_len);
4819
a_len= b_len= field_length;
4821
We have to remove end space to be able to compare multi-byte-characters
4822
like in latin_de 'ae' and 0xe4
4824
return field_charset->coll->strnncollsp(field_charset,
4831
void Field_string::sort_string(uchar *to,uint length)
4833
uint tmp= my_strnxfrm(field_charset,
4836
assert(tmp == length);
4840
void Field_string::sql_type(String &res) const
4842
THD *thd= table->in_use;
4843
CHARSET_INFO *cs=res.charset();
4846
length= cs->cset->snprintf(cs,(char*) res.ptr(),
4847
res.alloced_length(), "%s(%d)",
4848
((type() == MYSQL_TYPE_VAR_STRING &&
4849
!thd->variables.new_mode) ?
4850
(has_charset() ? "varchar" : "varbinary") :
4851
(has_charset() ? "char" : "binary")),
4852
(int) field_length / charset()->mbmaxlen);
4854
if ((thd->variables.sql_mode & (MODE_MYSQL323 | MODE_MYSQL40)) &&
4855
has_charset() && (charset()->state & MY_CS_BINSORT))
4856
res.append(STRING_WITH_LEN(" binary"));
4860
uchar *Field_string::pack(uchar *to, const uchar *from,
4862
bool low_byte_first __attribute__((unused)))
4864
uint length= min(field_length,max_length);
4865
uint local_char_length= max_length/field_charset->mbmaxlen;
4866
if (length > local_char_length)
4867
local_char_length= my_charpos(field_charset, from, from+length,
4869
set_if_smaller(length, local_char_length);
4870
while (length && from[length-1] == field_charset->pad_char)
4873
// Length always stored little-endian
4874
*to++= (uchar) length;
4875
if (field_length > 255)
4876
*to++= (uchar) (length >> 8);
4878
// Store the actual bytes of the string
4879
memcpy(to, from, length);
4885
Unpack a string field from row data.
4887
This method is used to unpack a string field from a master whose size
4888
of the field is less than that of the slave. Note that there can be a
4889
variety of field types represented with this class. Certain types like
4890
ENUM or SET are processed differently. Hence, the upper byte of the
4891
@c param_data argument contains the result of field->real_type() from
4894
@param to Destination of the data
4895
@param from Source of the data
4896
@param param_data Real type (upper) and length (lower) values
4898
@return New pointer into memory based on from + length of the data
4901
Field_string::unpack(uchar *to,
4904
bool low_byte_first __attribute__((unused)))
4907
param_data ? min(param_data & 0x00ff, field_length) : field_length;
4910
if (from_length > 255)
4912
length= uint2korr(from);
4916
length= (uint) *from++;
4918
memcpy(to, from, length);
4919
// Pad the string with the pad character of the fields charset
4920
bfill(to + length, field_length - length, field_charset->pad_char);
4926
Save the field metadata for string fields.
4928
Saves the real type in the first byte and the field length in the
4929
second byte of the field metadata array at index of *metadata_ptr and
4930
*(metadata_ptr + 1).
4932
@param metadata_ptr First byte of field metadata
4934
@returns number of bytes written to metadata_ptr
4936
int Field_string::do_save_field_metadata(uchar *metadata_ptr)
4938
*metadata_ptr= real_type();
4939
*(metadata_ptr + 1)= field_length;
4945
Compare two packed keys
4952
insert_or_update 1 if this is an insert or update
4960
int Field_string::pack_cmp(const uchar *a, const uchar *b, uint length,
4961
my_bool insert_or_update)
4963
uint a_length, b_length;
4966
a_length= uint2korr(a);
4967
b_length= uint2korr(b);
4973
a_length= (uint) *a++;
4974
b_length= (uint) *b++;
4976
return field_charset->coll->strnncollsp(field_charset,
4984
Compare a packed key against row.
4986
@param key Original key
4987
@param length Key length. (May be less than field length)
4988
@param insert_or_update 1 if this is an insert or update
4998
int Field_string::pack_cmp(const uchar *key, uint length,
4999
my_bool insert_or_update)
5001
uint row_length, local_key_length;
5005
local_key_length= uint2korr(key);
5009
local_key_length= (uint) *key++;
5011
/* Only use 'length' of key, not field_length */
5013
while (end > ptr && end[-1] == ' ')
5015
row_length= (uint) (end - ptr);
5017
return field_charset->coll->strnncollsp(field_charset,
5019
key, local_key_length,
5024
uint Field_string::packed_col_length(const uchar *data_ptr, uint length)
5027
return uint2korr(data_ptr)+2;
5028
return (uint) *data_ptr + 1;
5032
uint Field_string::max_packed_col_length(uint max_length)
5034
return (max_length > 255 ? 2 : 1)+max_length;
5038
uint Field_string::get_key_image(uchar *buff,
5040
imagetype type_arg __attribute__((__unused__)))
5042
uint bytes = my_charpos(field_charset, (char*) ptr,
5043
(char*) ptr + field_length,
5044
length / field_charset->mbmaxlen);
5045
memcpy(buff, ptr, bytes);
5047
field_charset->cset->fill(field_charset, (char*) buff + bytes,
5048
length - bytes, field_charset->pad_char);
5053
Field *Field_string::new_field(MEM_ROOT *root, struct st_table *new_table,
5057
if (type() != MYSQL_TYPE_VAR_STRING || keep_type)
5058
field= Field::new_field(root, new_table, keep_type);
5059
else if ((field= new Field_varstring(field_length, maybe_null(), field_name,
5060
new_table->s, charset())))
5063
Old VARCHAR field which should be modified to a VARCHAR on copy
5064
This is done to ensure that ALTER TABLE will convert old VARCHAR fields
5065
to now VARCHAR fields.
5067
field->init(new_table);
5069
Normally orig_table is different from table only if field was created
5070
via ::new_field. Here we alter the type of field, so ::new_field is
5071
not applicable. But we still need to preserve the original field
5072
metadata for the client-server protocol.
5074
field->orig_table= orig_table;
5080
/****************************************************************************
5082
Data in field->ptr is stored as:
5083
1 or 2 bytes length-prefix-header (from Field_varstring::length_bytes)
5087
When VARCHAR is stored in a key (for handler::index_read() etc) it's always
5088
stored with a 2 byte prefix. (Just like blob keys).
5090
Normally length_bytes is calculated as (field_length < 256 : 1 ? 2)
5091
The exception is if there is a prefix key field that is part of a long
5092
VARCHAR, in which case field_length for this may be 1 but the length_bytes
5094
****************************************************************************/
5096
const uint Field_varstring::MAX_SIZE= UINT16_MAX;
5099
Save the field metadata for varstring fields.
5101
Saves the field length in the first byte. Note: may consume
5102
2 bytes. Caller must ensure second byte is contiguous with
5103
first byte (e.g. array index 0,1).
5105
@param metadata_ptr First byte of field metadata
5107
@returns number of bytes written to metadata_ptr
5109
int Field_varstring::do_save_field_metadata(uchar *metadata_ptr)
5111
char *ptr= (char *)metadata_ptr;
5112
assert(field_length <= 65535);
5113
int2store(ptr, field_length);
5117
int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs)
5120
const char *well_formed_error_pos;
5121
const char *cannot_convert_error_pos;
5122
const char *from_end_pos;
5124
copy_length= well_formed_copy_nchars(field_charset,
5125
(char*) ptr + length_bytes,
5128
field_length / field_charset->mbmaxlen,
5129
&well_formed_error_pos,
5130
&cannot_convert_error_pos,
5133
if (length_bytes == 1)
5134
*ptr= (uchar) copy_length;
5136
int2store(ptr, copy_length);
5138
if (check_string_copy_error(this, well_formed_error_pos,
5139
cannot_convert_error_pos, from + length, cs))
5142
return report_if_important_data(from_end_pos, from + length);
5146
int Field_varstring::store(int64_t nr, bool unsigned_val)
5150
length= (uint) (field_charset->cset->int64_t10_to_str)(field_charset,
5156
return Field_varstring::store(buff, length, field_charset);
5160
double Field_varstring::val_real(void)
5164
uint length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
5165
return my_strntod(field_charset, (char*) ptr+length_bytes, length,
5166
&end_not_used, ¬_used);
5170
int64_t Field_varstring::val_int(void)
5174
uint length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
5175
return my_strntoll(field_charset, (char*) ptr+length_bytes, length, 10,
5176
&end_not_used, ¬_used);
5179
String *Field_varstring::val_str(String *val_buffer __attribute__((unused)),
5182
uint length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
5183
val_ptr->set((const char*) ptr+length_bytes, length, field_charset);
5188
my_decimal *Field_varstring::val_decimal(my_decimal *decimal_value)
5190
uint length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
5191
str2my_decimal(E_DEC_FATAL_ERROR, (char*) ptr+length_bytes, length,
5192
charset(), decimal_value);
5193
return decimal_value;
5197
int Field_varstring::cmp_max(const uchar *a_ptr, const uchar *b_ptr,
5200
uint a_length, b_length;
5203
if (length_bytes == 1)
5205
a_length= (uint) *a_ptr;
5206
b_length= (uint) *b_ptr;
5210
a_length= uint2korr(a_ptr);
5211
b_length= uint2korr(b_ptr);
5213
set_if_smaller(a_length, max_len);
5214
set_if_smaller(b_length, max_len);
5215
diff= field_charset->coll->strnncollsp(field_charset,
5228
varstring and blob keys are ALWAYS stored with a 2 byte length prefix
5231
int Field_varstring::key_cmp(const uchar *key_ptr, uint max_key_length)
5233
uint length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
5234
uint local_char_length= max_key_length / field_charset->mbmaxlen;
5236
local_char_length= my_charpos(field_charset, ptr + length_bytes,
5237
ptr + length_bytes + length, local_char_length);
5238
set_if_smaller(length, local_char_length);
5239
return field_charset->coll->strnncollsp(field_charset,
5244
uint2korr(key_ptr), 0);
5249
Compare to key segments (always 2 byte length prefix).
5252
This is used only to compare key segments created for index_read().
5253
(keys are created and compared in key.cc)
5256
int Field_varstring::key_cmp(const uchar *a,const uchar *b)
5258
return field_charset->coll->strnncollsp(field_charset,
5259
a + HA_KEY_BLOB_LENGTH,
5261
b + HA_KEY_BLOB_LENGTH,
5267
void Field_varstring::sort_string(uchar *to,uint length)
5269
uint tot_length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
5271
if (field_charset == &my_charset_bin)
5273
/* Store length last in high-byte order to sort longer strings first */
5274
if (length_bytes == 1)
5275
to[length-1]= tot_length;
5277
mi_int2store(to+length-2, tot_length);
5278
length-= length_bytes;
5281
tot_length= my_strnxfrm(field_charset,
5282
to, length, ptr + length_bytes,
5284
assert(tot_length == length);
5288
enum ha_base_keytype Field_varstring::key_type() const
5290
enum ha_base_keytype res;
5293
res= length_bytes == 1 ? HA_KEYTYPE_VARBINARY1 : HA_KEYTYPE_VARBINARY2;
5295
res= length_bytes == 1 ? HA_KEYTYPE_VARTEXT1 : HA_KEYTYPE_VARTEXT2;
5300
void Field_varstring::sql_type(String &res) const
5302
THD *thd= table->in_use;
5303
CHARSET_INFO *cs=res.charset();
5306
length= cs->cset->snprintf(cs,(char*) res.ptr(),
5307
res.alloced_length(), "%s(%d)",
5308
(has_charset() ? "varchar" : "varbinary"),
5309
(int) field_length / charset()->mbmaxlen);
5311
if ((thd->variables.sql_mode & (MODE_MYSQL323 | MODE_MYSQL40)) &&
5312
has_charset() && (charset()->state & MY_CS_BINSORT))
5313
res.append(STRING_WITH_LEN(" binary"));
5317
uint32 Field_varstring::data_length()
5319
return length_bytes == 1 ? (uint32) *ptr : uint2korr(ptr);
5322
uint32 Field_varstring::used_length()
5324
return length_bytes == 1 ? 1 + (uint32) (uchar) *ptr : 2 + uint2korr(ptr);
5328
Functions to create a packed row.
5329
Here the number of length bytes are depending on the given max_length
5332
uchar *Field_varstring::pack(uchar *to, const uchar *from,
5334
bool low_byte_first __attribute__((unused)))
5336
uint length= length_bytes == 1 ? (uint) *from : uint2korr(from);
5337
set_if_smaller(max_length, field_length);
5338
if (length > max_length)
5341
/* Length always stored little-endian */
5342
*to++= length & 0xFF;
5343
if (max_length > 255)
5344
*to++= (length >> 8) & 0xFF;
5346
/* Store bytes of string */
5348
memcpy(to, from+length_bytes, length);
5354
Field_varstring::pack_key(uchar *to, const uchar *key, uint max_length,
5355
bool low_byte_first __attribute__((unused)))
5357
uint length= length_bytes == 1 ? (uint) *key : uint2korr(key);
5358
uint local_char_length= ((field_charset->mbmaxlen > 1) ?
5359
max_length/field_charset->mbmaxlen : max_length);
5361
if (length > local_char_length)
5363
local_char_length= my_charpos(field_charset, key, key+length,
5365
set_if_smaller(length, local_char_length);
5367
*to++= (char) (length & 255);
5368
if (max_length > 255)
5369
*to++= (char) (length >> 8);
5371
memcpy(to, key, length);
5377
Unpack a key into a record buffer.
5379
A VARCHAR key has a maximum size of 64K-1.
5380
In its packed form, the length field is one or two bytes long,
5381
depending on 'max_length'.
5383
@param to Pointer into the record buffer.
5384
@param key Pointer to the packed key.
5385
@param max_length Key length limit from key description.
5388
Pointer to end of 'key' (To the next key part if multi-segment key)
5392
Field_varstring::unpack_key(uchar *to __attribute__((__unused__)),
5393
const uchar *key, uint max_length,
5394
bool low_byte_first __attribute__((unused)))
5396
/* get length of the blob key */
5397
uint32 length= *key++;
5398
if (max_length > 255)
5399
length+= (*key++) << 8;
5401
/* put the length into the record buffer */
5402
if (length_bytes == 1)
5403
*ptr= (uchar) length;
5405
int2store(ptr, length);
5406
memcpy(ptr + length_bytes, key, length);
5407
return key + length;
5411
Create a packed key that will be used for storage in the index tree.
5413
@param to Store packed key segment here
5414
@param from Key segment (as given to index_read())
5415
@param max_length Max length of key
5422
Field_varstring::pack_key_from_key_image(uchar *to, const uchar *from, uint max_length,
5423
bool low_byte_first __attribute__((unused)))
5425
/* Key length is always stored as 2 bytes */
5426
uint length= uint2korr(from);
5427
if (length > max_length)
5429
*to++= (char) (length & 255);
5430
if (max_length > 255)
5431
*to++= (char) (length >> 8);
5433
memcpy(to, from+HA_KEY_BLOB_LENGTH, length);
5439
Unpack a varstring field from row data.
5441
This method is used to unpack a varstring field from a master
5442
whose size of the field is less than that of the slave.
5445
The string length is always packed little-endian.
5447
@param to Destination of the data
5448
@param from Source of the data
5449
@param param_data Length bytes from the master's field data
5451
@return New pointer into memory based on from + length of the data
5454
Field_varstring::unpack(uchar *to, const uchar *from,
5456
bool low_byte_first __attribute__((unused)))
5459
uint l_bytes= (param_data && (param_data < field_length)) ?
5460
(param_data <= 255) ? 1 : 2 : length_bytes;
5465
if (length_bytes == 2)
5468
else /* l_bytes == 2 */
5470
length= uint2korr(from);
5475
memcpy(to+ length_bytes, from, length);
5480
int Field_varstring::pack_cmp(const uchar *a, const uchar *b,
5481
uint key_length_arg,
5482
my_bool insert_or_update)
5484
uint a_length, b_length;
5485
if (key_length_arg > 255)
5487
a_length=uint2korr(a); a+= 2;
5488
b_length=uint2korr(b); b+= 2;
5492
a_length= (uint) *a++;
5493
b_length= (uint) *b++;
5495
return field_charset->coll->strnncollsp(field_charset,
5502
int Field_varstring::pack_cmp(const uchar *b, uint key_length_arg,
5503
my_bool insert_or_update)
5505
uchar *a= ptr+ length_bytes;
5506
uint a_length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
5508
uint local_char_length= ((field_charset->mbmaxlen > 1) ?
5509
key_length_arg / field_charset->mbmaxlen :
5512
if (key_length_arg > 255)
5514
b_length=uint2korr(b); b+= HA_KEY_BLOB_LENGTH;
5517
b_length= (uint) *b++;
5519
if (a_length > local_char_length)
5521
local_char_length= my_charpos(field_charset, a, a+a_length,
5523
set_if_smaller(a_length, local_char_length);
5526
return field_charset->coll->strnncollsp(field_charset,
5533
uint Field_varstring::packed_col_length(const uchar *data_ptr, uint length)
5536
return uint2korr(data_ptr)+2;
5537
return (uint) *data_ptr + 1;
5541
uint Field_varstring::max_packed_col_length(uint max_length)
5543
return (max_length > 255 ? 2 : 1)+max_length;
5546
uint Field_varstring::get_key_image(uchar *buff,
5548
imagetype type __attribute__((__unused__)))
5550
uint f_length= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
5551
uint local_char_length= length / field_charset->mbmaxlen;
5552
uchar *pos= ptr+length_bytes;
5553
local_char_length= my_charpos(field_charset, pos, pos + f_length,
5555
set_if_smaller(f_length, local_char_length);
5556
/* Key is always stored with 2 bytes */
5557
int2store(buff,f_length);
5558
memcpy(buff+HA_KEY_BLOB_LENGTH, pos, f_length);
5559
if (f_length < length)
5562
Must clear this as we do a memcmp in opt_range.cc to detect
5565
bzero(buff+HA_KEY_BLOB_LENGTH+f_length, (length-f_length));
5567
return HA_KEY_BLOB_LENGTH+f_length;
5571
void Field_varstring::set_key_image(const uchar *buff,uint length)
5573
length= uint2korr(buff); // Real length is here
5574
(void) Field_varstring::store((const char*) buff+HA_KEY_BLOB_LENGTH, length,
5579
int Field_varstring::cmp_binary(const uchar *a_ptr, const uchar *b_ptr,
5582
uint32 a_length,b_length;
5584
if (length_bytes == 1)
5586
a_length= (uint) *a_ptr;
5587
b_length= (uint) *b_ptr;
5591
a_length= uint2korr(a_ptr);
5592
b_length= uint2korr(b_ptr);
5594
set_if_smaller(a_length, max_length);
5595
set_if_smaller(b_length, max_length);
5596
if (a_length != b_length)
5598
return memcmp(a_ptr+length_bytes, b_ptr+length_bytes, a_length);
5602
Field *Field_varstring::new_field(MEM_ROOT *root, struct st_table *new_table,
5605
Field_varstring *res= (Field_varstring*) Field::new_field(root, new_table,
5608
res->length_bytes= length_bytes;
5613
Field *Field_varstring::new_key_field(MEM_ROOT *root,
5614
struct st_table *new_table,
5615
uchar *new_ptr, uchar *new_null_ptr,
5618
Field_varstring *res;
5619
if ((res= (Field_varstring*) Field::new_key_field(root,
5625
/* Keys length prefixes are always packed with 2 bytes */
5626
res->length_bytes= 2;
5632
uint Field_varstring::is_equal(Create_field *new_field)
5634
if (new_field->sql_type == real_type() &&
5635
new_field->charset == field_charset)
5637
if (new_field->length == max_display_length())
5638
return IS_EQUAL_YES;
5639
if (new_field->length > max_display_length() &&
5640
((new_field->length <= 255 && max_display_length() <= 255) ||
5641
(new_field->length > 255 && max_display_length() > 255)))
5642
return IS_EQUAL_PACK_LENGTH; // VARCHAR, longer variable length
5648
void Field_varstring::hash(ulong *nr, ulong *nr2)
5652
*nr^= (*nr << 1) | 1;
5656
uint len= length_bytes == 1 ? (uint) *ptr : uint2korr(ptr);
5657
CHARSET_INFO *cs= charset();
5658
cs->coll->hash_sort(cs, ptr + length_bytes, len, nr, nr2);
5663
/****************************************************************************
5665
** A blob is saved as a length and a pointer. The length is stored in the
5666
** packlength slot and may be from 1-4.
5667
****************************************************************************/
5669
Field_blob::Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
5670
enum utype unireg_check_arg, const char *field_name_arg,
5671
TABLE_SHARE *share, uint blob_pack_length,
5673
:Field_longstr(ptr_arg, BLOB_PACK_LENGTH_TO_MAX_LENGH(blob_pack_length),
5674
null_ptr_arg, null_bit_arg, unireg_check_arg, field_name_arg,
5676
packlength(blob_pack_length)
5679
share->blob_fields++;
5680
/* TODO: why do not fill table->s->blob_field array here? */
5684
void Field_blob::store_length(uchar *i_ptr,
5687
bool low_byte_first __attribute__((__unused__)))
5689
switch (i_packlength) {
5691
i_ptr[0]= (uchar) i_number;
5694
#ifdef WORDS_BIGENDIAN
5697
int2store(i_ptr,(unsigned short) i_number);
5701
shortstore(i_ptr,(unsigned short) i_number);
5704
int3store(i_ptr,i_number);
5707
#ifdef WORDS_BIGENDIAN
5710
int4store(i_ptr,i_number);
5714
longstore(i_ptr,i_number);
5719
uint32 Field_blob::get_length(const uchar *pos,
5720
uint packlength_arg,
5721
bool low_byte_first __attribute__((__unused__)))
5723
switch (packlength_arg) {
5725
return (uint32) pos[0];
5729
#ifdef WORDS_BIGENDIAN
5735
return (uint32) tmp;
5738
return (uint32) uint3korr(pos);
5742
#ifdef WORDS_BIGENDIAN
5748
return (uint32) tmp;
5751
return 0; // Impossible
5756
Put a blob length field into a record buffer.
5758
Depending on the maximum length of a blob, its length field is
5759
put into 1 to 4 bytes. This is a property of the blob object,
5760
described by 'packlength'.
5762
@param pos Pointer into the record buffer.
5763
@param length The length value to put.
5766
void Field_blob::put_length(uchar *pos, uint32 length)
5768
switch (packlength) {
5770
*pos= (char) length;
5773
int2store(pos, length);
5776
int3store(pos, length);
5779
int4store(pos, length);
5785
int Field_blob::store(const char *from,uint length,CHARSET_INFO *cs)
5787
uint copy_length, new_length;
5788
const char *well_formed_error_pos;
5789
const char *cannot_convert_error_pos;
5790
const char *from_end_pos, *tmp;
5791
char buff[STRING_BUFFER_USUAL_SIZE];
5792
String tmpstr(buff,sizeof(buff), &my_charset_bin);
5796
bzero(ptr,Field_blob::pack_length());
5800
if (from == value.ptr())
5802
uint32 dummy_offset;
5803
if (!String::needs_conversion(length, cs, field_charset, &dummy_offset))
5805
Field_blob::store_length(length);
5806
bmove(ptr+packlength,(char*) &from,sizeof(char*));
5809
if (tmpstr.copy(from, length, cs))
5814
new_length= min(max_data_length(), field_charset->mbmaxlen * length);
5815
if (value.alloc(new_length))
5819
if (f_is_hex_escape(flags))
5821
copy_length= my_copy_with_hex_escaping(field_charset,
5822
(char*) value.ptr(), new_length,
5824
Field_blob::store_length(copy_length);
5826
bmove(ptr + packlength, (uchar*) &tmp, sizeof(char*));
5830
"length" is OK as "nchars" argument to well_formed_copy_nchars as this
5831
is never used to limit the length of the data. The cut of long data
5832
is done with the new_length value.
5834
copy_length= well_formed_copy_nchars(field_charset,
5835
(char*) value.ptr(), new_length,
5838
&well_formed_error_pos,
5839
&cannot_convert_error_pos,
5842
Field_blob::store_length(copy_length);
5844
bmove(ptr+packlength,(uchar*) &tmp,sizeof(char*));
5846
if (check_string_copy_error(this, well_formed_error_pos,
5847
cannot_convert_error_pos, from + length, cs))
5850
return report_if_important_data(from_end_pos, from + length);
5853
/* Fatal OOM error */
5854
bzero(ptr,Field_blob::pack_length());
5859
int Field_blob::store(double nr)
5861
CHARSET_INFO *cs=charset();
5862
value.set_real(nr, NOT_FIXED_DEC, cs);
5863
return Field_blob::store(value.ptr(),(uint) value.length(), cs);
5867
int Field_blob::store(int64_t nr, bool unsigned_val)
5869
CHARSET_INFO *cs=charset();
5870
value.set_int(nr, unsigned_val, cs);
5871
return Field_blob::store(value.ptr(), (uint) value.length(), cs);
5875
double Field_blob::val_real(void)
5878
char *end_not_used, *blob;
5882
memcpy_fixed(&blob,ptr+packlength,sizeof(char*));
5885
length= get_length(ptr);
5887
return my_strntod(cs, blob, length, &end_not_used, ¬_used);
5891
int64_t Field_blob::val_int(void)
5895
memcpy_fixed(&blob,ptr+packlength,sizeof(char*));
5898
uint32 length=get_length(ptr);
5899
return my_strntoll(charset(),blob,length,10,NULL,¬_used);
5902
String *Field_blob::val_str(String *val_buffer __attribute__((unused)),
5906
memcpy_fixed(&blob,ptr+packlength,sizeof(char*));
5908
val_ptr->set("",0,charset()); // A bit safer than ->length(0)
5910
val_ptr->set((const char*) blob,get_length(ptr),charset());
5915
my_decimal *Field_blob::val_decimal(my_decimal *decimal_value)
5919
memcpy_fixed(&blob, ptr+packlength, sizeof(const uchar*));
5926
length= get_length(ptr);
5928
str2my_decimal(E_DEC_FATAL_ERROR, blob, length, charset(),
5930
return decimal_value;
5934
int Field_blob::cmp(const uchar *a,uint32 a_length, const uchar *b,
5937
return field_charset->coll->strnncollsp(field_charset,
5938
a, a_length, b, b_length,
5943
int Field_blob::cmp_max(const uchar *a_ptr, const uchar *b_ptr,
5946
uchar *blob1,*blob2;
5947
memcpy_fixed(&blob1,a_ptr+packlength,sizeof(char*));
5948
memcpy_fixed(&blob2,b_ptr+packlength,sizeof(char*));
5949
uint a_len= get_length(a_ptr), b_len= get_length(b_ptr);
5950
set_if_smaller(a_len, max_length);
5951
set_if_smaller(b_len, max_length);
5952
return Field_blob::cmp(blob1,a_len,blob2,b_len);
5956
int Field_blob::cmp_binary(const uchar *a_ptr, const uchar *b_ptr,
5961
uint32 a_length,b_length;
5962
memcpy_fixed(&a,a_ptr+packlength,sizeof(char*));
5963
memcpy_fixed(&b,b_ptr+packlength,sizeof(char*));
5964
a_length=get_length(a_ptr);
5965
if (a_length > max_length)
5966
a_length=max_length;
5967
b_length=get_length(b_ptr);
5968
if (b_length > max_length)
5969
b_length=max_length;
5970
diff=memcmp(a,b,min(a_length,b_length));
5971
return diff ? diff : (int) (a_length - b_length);
5975
/* The following is used only when comparing a key */
5977
uint Field_blob::get_key_image(uchar *buff,
5979
imagetype type_arg __attribute__((__unused__)))
5981
uint32 blob_length= get_length(ptr);
5985
uint local_char_length= length / field_charset->mbmaxlen;
5986
local_char_length= my_charpos(field_charset, blob, blob + blob_length,
5988
set_if_smaller(blob_length, local_char_length);
5990
if ((uint32) length > blob_length)
5993
Must clear this as we do a memcmp in opt_range.cc to detect
5996
bzero(buff+HA_KEY_BLOB_LENGTH+blob_length, (length-blob_length));
5997
length=(uint) blob_length;
5999
int2store(buff,length);
6000
memcpy(buff+HA_KEY_BLOB_LENGTH, blob, length);
6001
return HA_KEY_BLOB_LENGTH+length;
6005
void Field_blob::set_key_image(const uchar *buff,uint length)
6007
length= uint2korr(buff);
6008
(void) Field_blob::store((const char*) buff+HA_KEY_BLOB_LENGTH, length,
6013
int Field_blob::key_cmp(const uchar *key_ptr, uint max_key_length)
6016
uint blob_length=get_length(ptr);
6017
memcpy_fixed(&blob1,ptr+packlength,sizeof(char*));
6018
CHARSET_INFO *cs= charset();
6019
uint local_char_length= max_key_length / cs->mbmaxlen;
6020
local_char_length= my_charpos(cs, blob1, blob1+blob_length,
6022
set_if_smaller(blob_length, local_char_length);
6023
return Field_blob::cmp(blob1, blob_length,
6024
key_ptr+HA_KEY_BLOB_LENGTH,
6025
uint2korr(key_ptr));
6028
int Field_blob::key_cmp(const uchar *a,const uchar *b)
6030
return Field_blob::cmp(a+HA_KEY_BLOB_LENGTH, uint2korr(a),
6031
b+HA_KEY_BLOB_LENGTH, uint2korr(b));
6036
Save the field metadata for blob fields.
6038
Saves the pack length in the first byte of the field metadata array
6039
at index of *metadata_ptr.
6041
@param metadata_ptr First byte of field metadata
6043
@returns number of bytes written to metadata_ptr
6045
int Field_blob::do_save_field_metadata(uchar *metadata_ptr)
6047
*metadata_ptr= pack_length_no_ptr();
6052
uint32 Field_blob::sort_length() const
6054
return (uint32) (current_thd->variables.max_sort_length +
6055
(field_charset == &my_charset_bin ? 0 : packlength));
6059
void Field_blob::sort_string(uchar *to,uint length)
6062
uint blob_length=get_length();
6068
if (field_charset == &my_charset_bin)
6073
Store length of blob last in blob to shorter blobs before longer blobs
6075
length-= packlength;
6078
switch (packlength) {
6080
*pos= (char) blob_length;
6083
mi_int2store(pos, blob_length);
6086
mi_int3store(pos, blob_length);
6089
mi_int4store(pos, blob_length);
6093
memcpy_fixed(&blob,ptr+packlength,sizeof(char*));
6095
blob_length=my_strnxfrm(field_charset,
6096
to, length, blob, blob_length);
6097
assert(blob_length == length);
6102
void Field_blob::sql_type(String &res) const
6106
switch (packlength) {
6107
default: str="tiny"; length=4; break;
6108
case 2: str=""; length=0; break;
6109
case 3: str="medium"; length= 6; break;
6110
case 4: str="long"; length=4; break;
6112
res.set_ascii(str,length);
6113
if (charset() == &my_charset_bin)
6114
res.append(STRING_WITH_LEN("blob"));
6117
res.append(STRING_WITH_LEN("text"));
6121
uchar *Field_blob::pack(uchar *to, const uchar *from,
6122
uint max_length, bool low_byte_first)
6126
uint32 length=get_length(); // Length of from string
6129
Store max length, which will occupy packlength bytes. If the max
6130
length given is smaller than the actual length of the blob, we
6131
just store the initial bytes of the blob.
6133
store_length(to, packlength, min(length, max_length), low_byte_first);
6136
Store the actual blob data, which will occupy 'length' bytes.
6140
get_ptr((uchar**) &from);
6141
memcpy(to+packlength, from,length);
6143
ptr=save; // Restore org row pointer
6144
return(to+packlength+length);
6149
Unpack a blob field from row data.
6151
This method is used to unpack a blob field from a master whose size of
6152
the field is less than that of the slave. Note: This method is included
6153
to satisfy inheritance rules, but is not needed for blob fields. It
6154
simply is used as a pass-through to the original unpack() method for
6157
@param to Destination of the data
6158
@param from Source of the data
6159
@param param_data @c true if base types should be stored in little-
6160
endian format, @c false if native format should
6163
@return New pointer into memory based on from + length of the data
6165
const uchar *Field_blob::unpack(uchar *to __attribute__((__unused__)),
6168
bool low_byte_first)
6170
uint const master_packlength=
6171
param_data > 0 ? param_data & 0xFF : packlength;
6172
uint32 const length= get_length(from, master_packlength, low_byte_first);
6173
bitmap_set_bit(table->write_set, field_index);
6174
store(reinterpret_cast<const char*>(from) + master_packlength,
6175
length, field_charset);
6176
return(from + master_packlength + length);
6179
/* Keys for blobs are like keys on varchars */
6181
int Field_blob::pack_cmp(const uchar *a, const uchar *b, uint key_length_arg,
6182
my_bool insert_or_update)
6184
uint a_length, b_length;
6185
if (key_length_arg > 255)
6187
a_length=uint2korr(a); a+=2;
6188
b_length=uint2korr(b); b+=2;
6192
a_length= (uint) *a++;
6193
b_length= (uint) *b++;
6195
return field_charset->coll->strnncollsp(field_charset,
6202
int Field_blob::pack_cmp(const uchar *b, uint key_length_arg,
6203
my_bool insert_or_update)
6206
uint a_length, b_length;
6207
memcpy_fixed(&a,ptr+packlength,sizeof(char*));
6209
return key_length_arg > 0 ? -1 : 0;
6211
a_length= get_length(ptr);
6212
if (key_length_arg > 255)
6214
b_length= uint2korr(b); b+=2;
6217
b_length= (uint) *b++;
6218
return field_charset->coll->strnncollsp(field_charset,
6224
/** Create a packed key that will be used for storage from a MySQL row. */
6227
Field_blob::pack_key(uchar *to, const uchar *from, uint max_length,
6228
bool low_byte_first __attribute__((unused)))
6232
uint32 length=get_length(); // Length of from string
6233
uint local_char_length= ((field_charset->mbmaxlen > 1) ?
6234
max_length/field_charset->mbmaxlen : max_length);
6236
get_ptr((uchar**) &from);
6237
if (length > local_char_length)
6238
local_char_length= my_charpos(field_charset, from, from+length,
6240
set_if_smaller(length, local_char_length);
6241
*to++= (uchar) length;
6242
if (max_length > 255) // 2 byte length
6243
*to++= (uchar) (length >> 8);
6244
memcpy(to, from, length);
6245
ptr=save; // Restore org row pointer
6251
Unpack a blob key into a record buffer.
6253
A blob key has a maximum size of 64K-1.
6254
In its packed form, the length field is one or two bytes long,
6255
depending on 'max_length'.
6256
Depending on the maximum length of a blob, its length field is
6257
put into 1 to 4 bytes. This is a property of the blob object,
6258
described by 'packlength'.
6259
Blobs are internally stored apart from the record buffer, which
6260
contains a pointer to the blob buffer.
6263
@param to Pointer into the record buffer.
6264
@param from Pointer to the packed key.
6265
@param max_length Key length limit from key description.
6268
Pointer into 'from' past the last byte copied from packed key.
6272
Field_blob::unpack_key(uchar *to, const uchar *from, uint max_length,
6273
bool low_byte_first __attribute__((unused)))
6275
/* get length of the blob key */
6276
uint32 length= *from++;
6277
if (max_length > 255)
6278
length+= *from++ << 8;
6280
/* put the length into the record buffer */
6281
put_length(to, length);
6283
/* put the address of the blob buffer or NULL */
6285
memcpy_fixed(to + packlength, &from, sizeof(from));
6287
bzero(to + packlength, sizeof(from));
6289
/* point to first byte of next field in 'from' */
6290
return from + length;
6294
/** Create a packed key that will be used for storage from a MySQL key. */
6297
Field_blob::pack_key_from_key_image(uchar *to, const uchar *from, uint max_length,
6298
bool low_byte_first __attribute__((unused)))
6300
uint length=uint2korr(from);
6301
if (length > max_length)
6303
*to++= (char) (length & 255);
6304
if (max_length > 255)
6305
*to++= (char) (length >> 8);
6307
memcpy(to, from+HA_KEY_BLOB_LENGTH, length);
6312
uint Field_blob::packed_col_length(const uchar *data_ptr, uint length)
6315
return uint2korr(data_ptr)+2;
6316
return (uint) *data_ptr + 1;
6320
uint Field_blob::max_packed_col_length(uint max_length)
6322
return (max_length > 255 ? 2 : 1)+max_length;
6326
uint Field_blob::is_equal(Create_field *new_field)
6328
if (compare_str_field_flags(new_field, flags))
6331
return ((new_field->sql_type == get_blob_type_from_length(max_data_length()))
6332
&& new_field->charset == field_charset &&
6333
((Field_blob *)new_field->field)->max_data_length() ==
6338
1814
/****************************************************************************
6340
1816
** This is a string which only can have a selection of different values.