FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
mysql/sql/field.h at t6-dev · sateeshgithub/mysql · GitHub
mysql/sql/field.h at t6-dev · sateeshgithub/mysql · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
sateeshgithub
/
mysql
Public
forked from
twitter-forks/mysql
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
mysql
/
sql
/
field.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
2323 lines (2138 loc) · 84.9 KB
Breadcrumbs
mysql
/
sql
/
field.h
Copy path
File metadata and controls
2323 lines (2138 loc) · 84.9 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
ifndef
FIELD_INCLUDED
#
define
FIELD_INCLUDED
/*
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
Because of the function new_field() all field classes that have static
variables must declare the size_of() member function.
*/
#
ifdef
USE_PRAGMA_INTERFACE
#
pragma
interface
/*
gcc class implementation
*/
#
endif
#
include
"
mysqld.h
"
/*
system_charset_info
*/
#
include
"
table.h
"
/*
TABLE
*/
#
include
"
sql_string.h
"
/*
String
*/
#
include
"
my_decimal.h
"
/*
my_decimal
*/
#
include
"
sql_error.h
"
/*
MYSQL_ERROR
*/
#
define
DATETIME_DEC
6
class
Send_field
;
class
Protocol
;
class
Create_field
;
class
Relay_log_info
;
class
Field
;
enum
enum_check_fields
{
CHECK_FIELD_IGNORE
,
CHECK_FIELD_WARN
,
CHECK_FIELD_ERROR_FOR_NULL
};
enum
Derivation
{
DERIVATION_IGNORABLE
=
6
,
DERIVATION_NUMERIC
=
5
,
DERIVATION_COERCIBLE
=
4
,
DERIVATION_SYSCONST
=
3
,
DERIVATION_IMPLICIT
=
2
,
DERIVATION_NONE
=
1
,
DERIVATION_EXPLICIT
=
0
};
#
define
STORAGE_TYPE_MASK
7
#
define
COLUMN_FORMAT_MASK
7
#
define
COLUMN_FORMAT_SHIFT
3
#
define
my_charset_numeric
my_charset_latin1
#
define
MY_REPERTOIRE_NUMERIC
MY_REPERTOIRE_ASCII
struct
st_cache_field
;
int
field_conv
(Field *to,Field *from);
inline
uint
get_enum_pack_length
(
int
elements)
{
return
elements <
256
?
1
:
2
;
}
inline
uint
get_set_pack_length
(
int
elements)
{
uint len= (elements +
7
) /
8
;
return
len >
4
?
8
: len;
}
class
Field
{
Field
(
const
Item &);
/*
Prevent use of these
*/
void
operator
=(Field &);
public:
static
void
*
operator
new
(
size_t
size)
throw
()
{
return
sql_alloc
(size); }
static
void
operator
delete
(
void
*ptr_arg,
size_t
size) {
TRASH
(ptr_arg, size); }
uchar *ptr;
//
Position to field in record
/*
*
Byte where the @c NULL bit is stored inside a record. If this Field is a
@c NOT @c NULL field, this member is @c NULL.
*/
uchar *null_ptr;
/*
Note that you can use table->in_use as replacement for current_thd member
only inside of val_*() and store() members (e.g. you can't use it in cons)
*/
TABLE
*table;
//
Pointer for table
TABLE
*orig_table;
//
Pointer to original table
const
char
**table_name, *field_name;
LEX_STRING
comment;
/*
Field is part of the following keys
*/
key_map key_start, part_of_key, part_of_key_not_clustered;
key_map part_of_sortkey;
/*
We use three additional unireg types for TIMESTAMP to overcome limitation
of current binary format of .frm file. We'd like to be able to support
NOW() as default and on update value for such fields but unable to hold
this info anywhere except unireg_check field. This issue will be resolved
in more clean way with transition to new text based .frm format.
See also comment for Field_timestamp::Field_timestamp().
*/
enum
utype {
NONE
,
DATE
,
SHIELD
,
NOEMPTY
,
CASEUP
,
PNR
,
BGNR
,
PGNR
,
YES
,
NO
,
REL
,
CHECK
,
EMPTY
,
UNKNOWN_FIELD
,
CASEDN
,
NEXT_NUMBER
,
INTERVAL_FIELD
,
BIT_FIELD
,
TIMESTAMP_OLD_FIELD
,
CAPITALIZE
,
BLOB_FIELD
,
TIMESTAMP_DN_FIELD
,
TIMESTAMP_UN_FIELD
,
TIMESTAMP_DNUN_FIELD
};
enum
geometry_type
{
GEOM_GEOMETRY
=
0
,
GEOM_POINT
=
1
,
GEOM_LINESTRING
=
2
,
GEOM_POLYGON
=
3
,
GEOM_MULTIPOINT
=
4
,
GEOM_MULTILINESTRING
=
5
,
GEOM_MULTIPOLYGON
=
6
,
GEOM_GEOMETRYCOLLECTION
=
7
};
enum
imagetype { itRAW, itMBR};
utype unireg_check;
uint32 field_length;
//
Length of field
uint32 flags;
uint16 field_index;
//
field number in fields array
uchar null_bit;
//
Bit used to test null bit
/*
*
If true, this field was created in create_tmp_field_from_item from a NULL
value. This means that the type of the field is just a guess, and the type
may be freely coerced to another type.
@see create_tmp_field_from_item
@see Item_type_holder::get_real_type
*/
bool
is_created_from_null_item;
Field
(uchar *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,
uchar null_bit_arg, utype unireg_check_arg,
const
char
*field_name_arg);
virtual
~Field
() {}
/*
Store functions returns 1 on overflow and -1 on fatal error
*/
virtual
int
store
(
const
char
*to, uint length,
CHARSET_INFO
*cs)=0;
virtual
int
store
(
double
nr)=0;
virtual
int
store
(longlong nr,
bool
unsigned_val)=0;
virtual
int
store_decimal
(
const
my_decimal *d)=0;
virtual
int
store_time
(
MYSQL_TIME
*ltime, timestamp_type t_type);
int
store
(
const
char
*to, uint length,
CHARSET_INFO
*cs,
enum_check_fields check_level);
virtual
double
val_real
(
void
)=0;
virtual
longlong
val_int
(
void
)=0;
virtual
my_decimal *
val_decimal
(my_decimal *);
inline
String *
val_str
(String *str) {
return
val_str
(str, str); }
/*
val_str(buf1, buf2) gets two buffers and should use them as follows:
if it needs a temp buffer to convert result to string - use buf1
example Field_tiny::val_str()
if the value exists as a string already - use buf2
example Field_string::val_str()
consequently, buf2 may be created as 'String buf;' - no memory
will be allocated for it. buf1 will be allocated to hold a
value if it's too small. Using allocated buffer for buf2 may result in
an unnecessary free (and later, may be an alloc).
This trickery is used to decrease a number of malloc calls.
*/
virtual
String *
val_str
(String*,String *)=0;
String *
val_int_as_str
(String *val_buffer, my_bool unsigned_flag);
/*
str_needs_quotes() returns TRUE if the value returned by val_str() needs
to be quoted when used in constructing an SQL query.
*/
virtual
bool
str_needs_quotes
() {
return
FALSE
; }
virtual
Item_result
result_type
()
const
=0;
virtual
Item_result
cmp_type
()
const
{
return
result_type
(); }
virtual
Item_result
cast_to_int_type
()
const
{
return
result_type
(); }
static
bool
type_can_have_key_part
(enum_field_types);
static
enum_field_types
field_type_merge
(enum_field_types, enum_field_types);
static
Item_result
result_merge_type
(enum_field_types);
virtual
bool
eq
(Field *field)
{
return
(ptr == field->
ptr
&& null_ptr == field->
null_ptr
&&
null_bit == field->
null_bit
&& field->
type
() ==
type
());
}
virtual
bool
eq_def
(Field *field);
/*
pack_length() returns size (in bytes) used to store field data in memory
(i.e. it returns the maximum size of the field in a row of the table,
which is located in RAM).
*/
virtual
uint32
pack_length
()
const
{
return
(uint32) field_length; }
/*
pack_length_in_rec() returns size (in bytes) used to store field data on
storage (i.e. it returns the maximal size of the field in a row of the
table, which is located on disk).
*/
virtual
uint32
pack_length_in_rec
()
const
{
return
pack_length
(); }
virtual
bool
compatible_field_size
(uint metadata, Relay_log_info *rli,
uint16 mflags,
int
*order);
virtual
uint
pack_length_from_metadata
(uint field_metadata)
{
DBUG_ENTER
(
"
Field::pack_length_from_metadata
"
);
DBUG_RETURN
(field_metadata);
}
virtual
uint
row_pack_length
() {
return
0
; }
virtual
int
save_field_metadata
(uchar *first_byte)
{
return
do_save_field_metadata
(first_byte); }
/*
data_length() return the "real size" of the data in memory.
*/
virtual
uint32
data_length
() {
return
pack_length
(); }
virtual
uint32
sort_length
()
const
{
return
pack_length
(); }
/*
*
Get the maximum size of the data in packed format.
@return Maximum data length of the field when packed using the
Field::pack() function.
*/
virtual
uint32
max_data_length
()
const
{
return
pack_length
();
};
virtual
int
reset
(
void
) {
bzero
(ptr,
pack_length
());
return
0
; }
virtual
void
reset_fields
() {}
virtual
void
set_default
()
{
my_ptrdiff_t
l_offset= (
my_ptrdiff_t
) (table->
s
->
default_values
-
table->
record
[
0
]);
memcpy
(ptr, ptr + l_offset,
pack_length
());
if
(null_ptr)
*null_ptr= ((*null_ptr & (uchar) ~null_bit) |
(null_ptr[l_offset] & null_bit));
}
virtual
bool
binary
()
const
{
return
1
; }
virtual
bool
zero_pack
()
const
{
return
1
; }
virtual
enum
ha_base_keytype
key_type
()
const
{
return
HA_KEYTYPE_BINARY
; }
virtual
uint32
key_length
()
const
{
return
pack_length
(); }
virtual
enum_field_types
type
()
const
=0;
virtual
enum_field_types
real_type
()
const
{
return
type
(); }
inline
int
cmp
(
const
uchar *str) {
return
cmp
(ptr,str); }
virtual
int
cmp_max
(
const
uchar *a,
const
uchar *b, uint max_len)
{
return
cmp
(a, b); }
virtual
int
cmp
(
const
uchar *,
const
uchar *)=0;
virtual
int
cmp_binary
(
const
uchar *a,
const
uchar *b, uint32 max_length=~
0L
)
{
return
memcmp
(a,b,
pack_length
()); }
virtual
int
cmp_offset
(uint row_offset)
{
return
cmp
(ptr,ptr+row_offset); }
virtual
int
cmp_binary_offset
(uint row_offset)
{
return
cmp_binary
(ptr, ptr+row_offset); };
virtual
int
key_cmp
(
const
uchar *a,
const
uchar *b)
{
return
cmp
(a, b); }
virtual
int
key_cmp
(
const
uchar *str, uint length)
{
return
cmp
(ptr,str); }
virtual
uint
decimals
()
const
{
return
0
; }
/*
Caller beware: sql_type can change str.Ptr, so check
ptr() to see if it changed if you are using your own buffer
in str and restore it with set() if needed
*/
virtual
void
sql_type
(String &str)
const
=0;
virtual
uint
size_of
()
const
=0;
//
For new field
inline
bool
is_null
(
my_ptrdiff_t
row_offset=
0
)
{
return
null_ptr ? (null_ptr[row_offset] & null_bit ?
1
:
0
) : table->
null_row
; }
inline
bool
is_real_null
(
my_ptrdiff_t
row_offset=
0
)
{
return
null_ptr ? (null_ptr[row_offset] & null_bit ?
1
:
0
) :
0
; }
inline
bool
is_null_in_record
(
const
uchar *record)
{
if
(!null_ptr)
return
0
;
return
test
(record[(uint) (null_ptr -table->
record
[
0
])] &
null_bit);
}
inline
bool
is_null_in_record_with_offset
(
my_ptrdiff_t
offset)
{
if
(!null_ptr)
return
0
;
return
test
(null_ptr[offset] & null_bit);
}
inline
void
set_null
(
my_ptrdiff_t
row_offset=
0
)
{
if
(null_ptr) null_ptr[row_offset]|= null_bit; }
inline
void
set_notnull
(
my_ptrdiff_t
row_offset=
0
)
{
if
(null_ptr) null_ptr[row_offset]&= (uchar) ~null_bit; }
inline
bool
maybe_null
(
void
) {
return
null_ptr !=
0
|| table->
maybe_null
; }
/*
*
Signals that this field is NULL-able.
*/
inline
bool
real_maybe_null
(
void
) {
return
null_ptr !=
0
; }
enum
{
LAST_NULL_BYTE_UNDEF
=
0
};
/*
Find the position of the last null byte for the field.
SYNOPSIS
last_null_byte()
DESCRIPTION
Return a pointer to the last byte of the null bytes where the
field conceptually is placed.
RETURN VALUE
The position of the last null byte relative to the beginning of
the record. If the field does not use any bits of the null
bytes, the value 0 (LAST_NULL_BYTE_UNDEF) is returned.
*/
size_t
last_null_byte
()
const
{
size_t
bytes=
do_last_null_byte
();
DBUG_PRINT
(
"
debug
"
, (
"
last_null_byte() ==> %ld
"
, (
long
) bytes));
DBUG_ASSERT
(bytes <= table->
s
->
null_bytes
);
return
bytes;
}
virtual
void
make_field
(Send_field *);
virtual
void
sort_string
(uchar *buff,uint length)=0;
virtual
bool
optimize_range
(uint idx, uint part);
/*
This should be true for fields which, when compared with constant
items, can be casted to longlong. In this case we will at 'fix_fields'
stage cast the constant items to longlongs and at the execution stage
use field->val_int() for comparison. Used to optimize clauses like
'a_column BETWEEN date_const, date_const'.
*/
virtual
bool
can_be_compared_as_longlong
()
const
{
return
FALSE
; }
virtual
void
free
() {}
virtual
Field *
new_field
(
MEM_ROOT
*root,
TABLE
*new_table,
bool
keep_type);
virtual
Field *
new_key_field
(
MEM_ROOT
*root,
TABLE
*new_table,
uchar *new_ptr, uchar *new_null_ptr,
uint new_null_bit);
Field *
clone
(
MEM_ROOT
*mem_root,
TABLE
*new_table);
inline
void
move_field
(uchar *ptr_arg,uchar *null_ptr_arg,uchar null_bit_arg)
{
ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg;
}
inline
void
move_field
(uchar *ptr_arg) { ptr=ptr_arg; }
virtual
void
move_field_offset
(
my_ptrdiff_t
ptr_diff)
{
ptr=
ADD_TO_PTR
(ptr,ptr_diff, uchar*);
if
(null_ptr)
null_ptr=
ADD_TO_PTR
(null_ptr,ptr_diff,uchar*);
}
virtual
void
get_image
(uchar *buff, uint length,
CHARSET_INFO
*cs)
{
memcpy
(buff,ptr,length); }
virtual
void
set_image
(
const
uchar *buff,uint length,
CHARSET_INFO
*cs)
{
memcpy
(ptr,buff,length); }
/*
Copy a field part into an output buffer.
SYNOPSIS
Field::get_key_image()
buff [out] output buffer
length output buffer size
type itMBR for geometry blobs, otherwise itRAW
DESCRIPTION
This function makes a copy of field part of size equal to or
less than "length" parameter value.
For fields of string types (CHAR, VARCHAR, TEXT) the rest of buffer
is padded by zero byte.
NOTES
For variable length character fields (i.e. UTF-8) the "length"
parameter means a number of output buffer bytes as if all field
characters have maximal possible size (mbmaxlen). In the other words,
"length" parameter is a number of characters multiplied by
field_charset->mbmaxlen.
RETURN
Number of copied bytes (excluding padded zero bytes -- see above).
*/
virtual
uint
get_key_image
(uchar *buff, uint length, imagetype type)
{
get_image
(buff, length, &my_charset_bin);
return
length;
}
virtual
void
set_key_image
(
const
uchar *buff,uint length)
{
set_image
(buff,length, &my_charset_bin); }
inline
longlong
val_int_offset
(uint row_offset)
{
ptr+=row_offset;
longlong tmp=
val_int
();
ptr-=row_offset;
return
tmp;
}
inline
longlong
val_int
(
const
uchar *new_ptr)
{
uchar *old_ptr= ptr;
longlong return_value;
ptr= (uchar*) new_ptr;
return_value=
val_int
();
ptr= old_ptr;
return
return_value;
}
inline
String *
val_str
(String *str,
const
uchar *new_ptr)
{
uchar *old_ptr= ptr;
ptr= (uchar*) new_ptr;
val_str
(str);
ptr= old_ptr;
return
str;
}
virtual
bool
send_binary
(Protocol *protocol);
virtual
uchar *
pack
(uchar *to,
const
uchar *from,
uint max_length,
bool
low_byte_first);
/*
*
@overload Field::pack(uchar*, const uchar*, uint, bool)
*/
uchar *
pack
(uchar *to,
const
uchar *from)
{
DBUG_ENTER
(
"
Field::pack
"
);
uchar *result=
this
->
pack
(to, from,
UINT_MAX
, table->
s
->
db_low_byte_first
);
DBUG_RETURN
(result);
}
virtual
const
uchar *
unpack
(uchar* to,
const
uchar *from,
uint param_data,
bool
low_byte_first);
/*
*
@overload Field::unpack(uchar*, const uchar*, uint, bool)
*/
const
uchar *
unpack
(uchar* to,
const
uchar *from)
{
DBUG_ENTER
(
"
Field::unpack
"
);
const
uchar *result=
unpack
(to, from,
0U
, table->
s
->
db_low_byte_first
);
DBUG_RETURN
(result);
}
virtual
uint
packed_col_length
(
const
uchar *to, uint length)
{
return
length;}
virtual
uint
max_packed_col_length
(uint max_length)
{
return
max_length;}
uint
offset
(uchar *record)
{
return
(uint) (ptr - record);
}
void
copy_from_tmp
(
int
offset);
uint
fill_cache_field
(
struct
st_cache_field
*copy);
virtual
bool
get_date
(
MYSQL_TIME
*ltime,uint fuzzydate);
virtual
bool
get_time
(
MYSQL_TIME
*ltime);
virtual
CHARSET_INFO
*
charset
(
void
)
const
{
return
&my_charset_bin; }
virtual
CHARSET_INFO
*
charset_for_protocol
(
void
)
const
{
return
binary
() ? &my_charset_bin :
charset
(); }
virtual
CHARSET_INFO
*
sort_charset
(
void
)
const
{
return
charset
(); }
virtual
bool
has_charset
(
void
)
const
{
return
FALSE
; }
virtual
void
set_charset
(
CHARSET_INFO
*charset_arg) { }
virtual
enum
Derivation
derivation
(
void
)
const
{
return
DERIVATION_IMPLICIT
; }
virtual
uint
repertoire
(
void
)
const
{
return
MY_REPERTOIRE_UNICODE30
; }
virtual
void
set_derivation
(
enum
Derivation derivation_arg) { }
bool
set_warning
(
MYSQL_ERROR
::enum_warning_level,
unsigned
int
code,
int
cuted_increment);
void
set_datetime_warning
(
MYSQL_ERROR
::enum_warning_level, uint code,
const
char
*str, uint str_len,
timestamp_type ts_type,
int
cuted_increment);
void
set_datetime_warning
(
MYSQL_ERROR
::enum_warning_level, uint code,
longlong nr, timestamp_type ts_type,
int
cuted_increment);
void
set_datetime_warning
(
MYSQL_ERROR
::enum_warning_level,
const
uint code,
double
nr, timestamp_type ts_type);
inline
bool
check_overflow
(
int
op_result)
{
return
(op_result ==
E_DEC_OVERFLOW
);
}
int
warn_if_overflow
(
int
op_result);
void
init
(
TABLE
*table_arg)
{
orig_table= table= table_arg;
table_name= &table_arg->
alias
;
}
/*
maximum possible display length
*/
virtual
uint32
max_display_length
()= 0;
/*
*
Whether a field being created is compatible with a existing one.
Used by the ALTER TABLE code to evaluate whether the new definition
of a table is compatible with the old definition so that it can
determine if data needs to be copied over (table data change).
*/
virtual
uint
is_equal
(Create_field *new_field);
/*
convert decimal to longlong with overflow check
*/
longlong
convert_decimal2longlong
(
const
my_decimal *val,
bool
unsigned_flag,
int
*err);
/*
The max. number of characters
*/
virtual
uint32
char_length
()
{
return
field_length /
charset
()->
mbmaxlen
;
}
virtual
geometry_type
get_geometry_type
()
{
/*
shouldn't get here.
*/
DBUG_ASSERT
(
0
);
return
GEOM_GEOMETRY
;
}
/*
Hash value
*/
virtual
void
hash
(ulong *nr, ulong *nr2);
friend
int
cre_myisam
(
char
* name,
register
TABLE
*form, uint options,
ulonglong auto_increment_value);
friend
class
Copy_field
;
friend
class
Item_avg_field
;
friend
class
Item_std_field
;
friend
class
Item_sum_num
;
friend
class
Item_sum_sum
;
friend
class
Item_sum_str
;
friend
class
Item_sum_count
;
friend
class
Item_sum_avg
;
friend
class
Item_sum_std
;
friend
class
Item_sum_min
;
friend
class
Item_sum_max
;
friend
class
Item_func_group_concat
;
private:
/*
Primitive for implementing last_null_byte().
SYNOPSIS
do_last_null_byte()
DESCRIPTION
Primitive for the implementation of the last_null_byte()
function. This represents the inheritance interface and can be
overridden by subclasses.
*/
virtual
size_t
do_last_null_byte
()
const
;
/*
*
Retrieve the field metadata for fields.
This default implementation returns 0 and saves 0 in the metadata_ptr
value.
@param metadata_ptr First byte of field metadata
@returns 0 no bytes written.
*/
virtual
int
do_save_field_metadata
(uchar *metadata_ptr)
{
return
0
; }
protected:
static
void
handle_int16
(uchar *to,
const
uchar *from,
bool
low_byte_first_from,
bool
low_byte_first_to)
{
int16 val;
#
ifdef
WORDS_BIGENDIAN
if
(low_byte_first_from)
val =
sint2korr
(from);
else
#
endif
shortget
(val, from);
#
ifdef
WORDS_BIGENDIAN
if
(low_byte_first_to)
int2store
(to, val);
else
#
endif
shortstore
(to, val);
}
static
void
handle_int24
(uchar *to,
const
uchar *from,
bool
low_byte_first_from,
bool
low_byte_first_to)
{
int32 val;
#
ifdef
WORDS_BIGENDIAN
if
(low_byte_first_from)
val =
sint3korr
(from);
else
#
endif
val= (from[
0
] <<
16
) + (from[
1
] <<
8
) + from[
2
];
#
ifdef
WORDS_BIGENDIAN
if
(low_byte_first_to)
int2store
(to, val);
else
#
endif
{
to[
0
]=
0xFF
& (val >>
16
);
to[
1
]=
0xFF
& (val >>
8
);
to[
2
]=
0xFF
& val;
}
}
/*
Helper function to pack()/unpack() int32 values
*/
static
void
handle_int32
(uchar *to,
const
uchar *from,
bool
low_byte_first_from,
bool
low_byte_first_to)
{
int32 val;
#
ifdef
WORDS_BIGENDIAN
if
(low_byte_first_from)
val =
sint4korr
(from);
else
#
endif
longget
(val, from);
#
ifdef
WORDS_BIGENDIAN
if
(low_byte_first_to)
int4store
(to, val);
else
#
endif
longstore
(to, val);
}
/*
Helper function to pack()/unpack() int64 values
*/
static
void
handle_int64
(uchar* to,
const
uchar *from,
bool
low_byte_first_from,
bool
low_byte_first_to)
{
int64 val;
#
ifdef
WORDS_BIGENDIAN
if
(low_byte_first_from)
val =
sint8korr
(from);
else
#
endif
longlongget
(val, from);
#
ifdef
WORDS_BIGENDIAN
if
(low_byte_first_to)
int8store
(to, val);
else
#
endif
longlongstore
(to, val);
}
uchar *
pack_int16
(uchar *to,
const
uchar *from,
bool
low_byte_first_to)
{
handle_int16
(to, from, table->
s
->
db_low_byte_first
, low_byte_first_to);
return
to +
sizeof
(int16);
}
const
uchar *
unpack_int16
(uchar* to,
const
uchar *from,
bool
low_byte_first_from)
{
handle_int16
(to, from, low_byte_first_from, table->
s
->
db_low_byte_first
);
return
from +
sizeof
(int16);
}
uchar *
pack_int24
(uchar *to,
const
uchar *from,
bool
low_byte_first_to)
{
handle_int24
(to, from, table->
s
->
db_low_byte_first
, low_byte_first_to);
return
to +
3
;
}
const
uchar *
unpack_int24
(uchar* to,
const
uchar *from,
bool
low_byte_first_from)
{
handle_int24
(to, from, low_byte_first_from, table->
s
->
db_low_byte_first
);
return
from +
3
;
}
uchar *
pack_int32
(uchar *to,
const
uchar *from,
bool
low_byte_first_to)
{
handle_int32
(to, from, table->
s
->
db_low_byte_first
, low_byte_first_to);
return
to +
sizeof
(int32);
}
const
uchar *
unpack_int32
(uchar* to,
const
uchar *from,
bool
low_byte_first_from)
{
handle_int32
(to, from, low_byte_first_from, table->
s
->
db_low_byte_first
);
return
from +
sizeof
(int32);
}
uchar *
pack_int64
(uchar* to,
const
uchar *from,
bool
low_byte_first_to)
{
handle_int64
(to, from, table->
s
->
db_low_byte_first
, low_byte_first_to);
return
to +
sizeof
(int64);
}
const
uchar *
unpack_int64
(uchar* to,
const
uchar *from,
bool
low_byte_first_from)
{
handle_int64
(to, from, low_byte_first_from, table->
s
->
db_low_byte_first
);
return
from +
sizeof
(int64);
}
bool
field_flags_are_binary
()
{
return
(flags & (
BINCMP_FLAG
|
BINARY_FLAG
)) !=
0
;
}
};
class
Field_num
:
public
Field
{
public:
const
uint8 dec;
bool
zerofill,unsigned_flag;
//
Purify cannot handle bit fields
Field_num
(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
uchar null_bit_arg, utype unireg_check_arg,
const
char
*field_name_arg,
uint8 dec_arg,
bool
zero_arg,
bool
unsigned_arg);
Item_result
result_type
()
const
{
return
REAL_RESULT
; }
enum
Derivation
derivation
(
void
)
const
{
return
DERIVATION_NUMERIC
; }
uint
repertoire
(
void
)
const
{
return
MY_REPERTOIRE_NUMERIC
; }
CHARSET_INFO
*
charset
(
void
)
const
{
return
&my_charset_numeric; }
void
prepend_zeros
(String *value);
void
add_zerofill_and_unsigned
(String &res)
const
;
friend
class
Create_field
;
void
make_field
(Send_field *);
uint
decimals
()
const
{
return
(uint) dec; }
uint
size_of
()
const
{
return
sizeof
(*
this
); }
bool
eq_def
(Field *field);
int
store_decimal
(
const
my_decimal *);
my_decimal *
val_decimal
(my_decimal *);
uint
is_equal
(Create_field *new_field);
uint
row_pack_length
() {
return
pack_length
(); }
uint32
pack_length_from_metadata
(uint field_metadata) {
uint32 length=
pack_length
();
DBUG_PRINT
(
"
result
"
, (
"
pack_length_from_metadata(%d): %u
"
,
field_metadata, length));
return
length;
}
int
check_int
(
CHARSET_INFO
*cs,
const
char
*str,
int
length,
const
char
*int_end,
int
error);
bool
get_int
(
CHARSET_INFO
*cs,
const
char
*from, uint len,
longlong *rnd, ulonglong unsigned_max,
longlong signed_min, longlong signed_max);
};
class
Field_str
:
public
Field
{
protected:
CHARSET_INFO
*field_charset;
enum
Derivation field_derivation;
public:
Field_str
(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
uchar null_bit_arg, utype unireg_check_arg,
const
char
*field_name_arg,
CHARSET_INFO
*charset);
Item_result
result_type
()
const
{
return
STRING_RESULT
; }
/*
match_collation_to_optimize_range() is to distinguish in
range optimizer (see opt_range.cc) between real string types:
CHAR, VARCHAR, TEXT
and the other string-alike types with result_type() == STRING_RESULT:
DATE, TIME, DATETIME, TIMESTAMP
We need it to decide whether to test if collation of the operation
matches collation of the field (needed only for real string types).
QQ: shouldn't DATE/TIME types have their own XXX_RESULT types eventually?
*/
virtual
bool
match_collation_to_optimize_range
()
const
=0;
uint
decimals
()
const
{
return
NOT_FIXED_DEC
; }
int
store
(
double
nr);
int
store
(longlong nr,
bool
unsigned_val)=0;
int
store_decimal
(
const
my_decimal *);
int
store
(
const
char
*to,uint length,
CHARSET_INFO
*cs)=0;
uint
size_of
()
const
{
return
sizeof
(*
this
); }
uint
repertoire
(
void
)
const
{
return
my_charset_repertoire
(field_charset);
}
CHARSET_INFO
*
charset
(
void
)
const
{
return
field_charset; }
void
set_charset
(
CHARSET_INFO
*charset_arg) { field_charset= charset_arg; }
enum
Derivation
derivation
(
void
)
const
{
return
field_derivation; }
virtual
void
set_derivation
(
enum
Derivation derivation_arg)
{ field_derivation= derivation_arg; }
bool
binary
()
const
{
return
field_charset == &my_charset_bin; }
uint32
max_display_length
() {
return
field_length; }
friend
class
Create_field
;
my_decimal *
val_decimal
(my_decimal *);
virtual
bool
str_needs_quotes
() {
return
TRUE
; }
uint
is_equal
(Create_field *new_field);
};
/*
base class for Field_string, Field_varstring and Field_blob
*/
class
Field_longstr
:
public
Field_str
{
protected:
int
report_if_important_data
(
const
char
*ptr,
const
char
*end,
bool
count_spaces);
public:
Field_longstr
(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
uchar null_bit_arg, utype unireg_check_arg,
const
char
*field_name_arg,
CHARSET_INFO
*charset_arg)
:Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
field_name_arg, charset_arg)
{}
int
store_decimal
(
const
my_decimal *d);
uint32
max_data_length
()
const
;
};
/*
base class for float and double and decimal (old one)
*/
class
Field_real
:
public
Field_num
{
public:
my_bool not_fixed;
Field_real
(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
uchar null_bit_arg, utype unireg_check_arg,
const
char
*field_name_arg,
uint8 dec_arg,
bool
zero_arg,
bool
unsigned_arg)
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
field_name_arg, dec_arg, zero_arg, unsigned_arg),
not_fixed
(dec_arg >=
NOT_FIXED_DEC
)
{}
int
store_decimal
(
const
my_decimal *);
my_decimal *
val_decimal
(my_decimal *);
int
truncate
(
double
*nr,
double
max_length);
uint32
max_display_length
() {
return
field_length; }
uint
size_of
()
const
{
return
sizeof
(*
this
); }
virtual
const
uchar *
unpack
(uchar* to,
const
uchar *from,
uint param_data,
bool
low_byte_first);
virtual
uchar *
pack
(uchar* to,
const
uchar *from,
uint max_length,
bool
low_byte_first);
};
class
Field_decimal
:
public
Field_real
{
public:
Field_decimal
(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
uchar null_bit_arg,
enum
utype unireg_check_arg,
const
char
*field_name_arg,
uint8 dec_arg,
bool
zero_arg,
bool
unsigned_arg)
:Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
unireg_check_arg, field_name_arg,
dec_arg, zero_arg, unsigned_arg)
{}
enum_field_types
type
()
const
{
return
MYSQL_TYPE_DECIMAL
;}
enum
ha_base_keytype
key_type
()
const
{
return
zerofill ?
HA_KEYTYPE_BINARY
:
HA_KEYTYPE_NUM
; }
int
reset
(
void
);
int
store
(
const
char
*to,uint length,
CHARSET_INFO
*charset);
int
store
(
double
nr);
int
store
(longlong nr,
bool
unsigned_val);
double
val_real
(
void
);
longlong
val_int
(
void
);
String *
val_str
(String*,String *);
int
cmp
(
const
uchar *,
const
uchar *);
void
sort_string
(uchar *buff,uint length);
void
overflow
(
bool
negative);
bool
zero_pack
()
const
{
return
0
; }
void
sql_type
(String &str)
const
;
virtual
const
uchar *
unpack
(uchar* to,
const
uchar *from,
uint param_data,
bool
low_byte_first)
{
return
Field::unpack
(to, from, param_data, low_byte_first);
}
virtual
uchar *
pack
(uchar* to,
const
uchar *from,
uint max_length,
bool
low_byte_first)
{
return
Field::pack
(to, from, max_length, low_byte_first);
}
};
/*
New decimal/numeric field which use fixed point arithmetic
*/
class
Field_new_decimal
:
public
Field_num
{
private:
int
do_save_field_metadata
(uchar *first_byte);
public:
/*
The maximum number of decimal digits can be stored
*/
uint precision;
uint bin_size;
/*
Constructors take max_length of the field as a parameter - not the
precision as the number of decimal digits allowed.
So for example we need to count length from precision handling
CREATE TABLE ( DECIMAL(x,y))
*/
Field_new_decimal
(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
uchar null_bit_arg,
enum
utype unireg_check_arg,
const
char
*field_name_arg,
uint8 dec_arg,
bool
zero_arg,
bool
unsigned_arg);
Field_new_decimal
(uint32 len_arg,
bool
maybe_null_arg,
const
char
*field_name_arg, uint8 dec_arg,
bool
unsigned_arg);
enum_field_types
type
()
const
{
return
MYSQL_TYPE_NEWDECIMAL
;}
enum
ha_base_keytype
key_type
()
const
{
return
HA_KEYTYPE_BINARY
; }
Item_result
result_type
()
const
{
return
DECIMAL_RESULT
; }
int
reset
(
void
);
bool
store_value
(
const
my_decimal *decimal_value);
void
set_value_on_overflow
(my_decimal *decimal_value,
bool
sign);
int
store
(
const
char
*to, uint length,
CHARSET_INFO
*charset);
int
store
(
double
nr);
int
store
(longlong nr,
bool
unsigned_val);
int
store_time
(
MYSQL_TIME
*ltime, timestamp_type t_type);
int
store_decimal
(
const
my_decimal *);
double
val_real
(
void
);
longlong
val_int
(
void
);
my_decimal *
val_decimal
(my_decimal *);
String *
val_str
(String*, String *);
int
cmp
(
const
uchar *,
const
uchar *);
void
sort_string
(uchar *buff, uint length);
bool
zero_pack
()
const
{
return
0
; }
void
sql_type
(String &str)
const
;
uint32
max_display_length
() {
return
field_length; }
uint
size_of
()
const
{
return
sizeof
(*
this
); }
uint32
pack_length
()
const
{
return
(uint32) bin_size; }
uint
pack_length_from_metadata
(uint field_metadata);
uint
row_pack_length
() {
return
pack_length
(); }
bool
compatible_field_size
(uint field_metadata, Relay_log_info *rli,
uint16 mflags,
int
*order_var);
uint
is_equal
(Create_field *new_field);
virtual
const
uchar *
unpack
(uchar* to,
const
uchar *from,
uint param_data,
bool
low_byte_first);
static
Field *
create_from_item
(Item *);
};
class
Field_tiny
:
public
Field_num
{
public:
Field_tiny
(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
uchar null_bit_arg,
enum
utype unireg_check_arg,
const
char
*field_name_arg,
bool
zero_arg,
bool
unsigned_arg)
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
unireg_check_arg, field_name_arg,
0
, zero_arg,unsigned_arg)
{}
enum
Item_result
result_type
()
const
{
return
INT_RESULT
; }
enum_field_types
type
()
const
{
return
MYSQL_TYPE_TINY
;}
enum
ha_base_keytype
key_type
()
const
{
return
unsigned_flag ?
HA_KEYTYPE_BINARY
:
HA_KEYTYPE_INT8
; }
int
store
(
const
char
*to,uint length,
CHARSET_INFO
*charset);
int
store
(
double
nr);
int
store
(longlong nr,
bool
unsigned_val);
int
reset
(
void
) { ptr[
0
]=
0
;
return
0
; }
double
val_real
(
void
);
longlong
val_int
(
void
);
String *
val_str
(String*,String *);
bool
send_binary
(Protocol *protocol);
int
cmp
(
const
uchar *,
const
uchar *);
void
sort_string
(uchar *buff,uint length);
uint32
pack_length
()
const
{
return
1
; }
void
sql_type
(String &str)
const
;
uint32
max_display_length
() {
return
4
; }
virtual
uchar *
pack
(uchar* to,
const
uchar *from,
uint max_length,
bool
low_byte_first)
{
*to= *from;
return
to +
1
;
}
virtual
const
uchar *
unpack
(uchar* to,
const
uchar *from,
uint param_data,
bool
low_byte_first)
{
*to= *from;
return
from +
1
;
}
};
class
Field_short
:
public
Field_num
{
public:
Field_short
(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
uchar null_bit_arg,
enum
utype unireg_check_arg,
const
char
*field_name_arg,
bool
zero_arg,
bool
unsigned_arg)
:Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
unireg_check_arg, field_name_arg,
0
, zero_arg,unsigned_arg)
{}
Field_short
(uint32 len_arg,
bool
maybe_null_arg,
const
char
*field_name_arg,
bool
unsigned_arg)
:Field_num((uchar*)
0
, len_arg, maybe_null_arg ? (uchar*)
"
"
:
0
,
0
,
NONE
, field_name_arg,
0
,
0
, unsigned_arg)
{}
enum
Item_result
result_type
()
const
{
return
INT_RESULT
; }
enum_field_types
type
()
const
{
return
MYSQL_TYPE_SHORT
;}
enum
ha_base_keytype
key_type
()
const
{
return
unsigned_flag ?
HA_KEYTYPE_USHORT_INT
:
HA_KEYTYPE_SHORT_INT
;}
int
store
(
const
char
*to,uint length,
CHARSET_INFO
*charset);
int
store
(
double
nr);
int
store
(longlong nr,
bool
unsigned_val);
int
reset
(
void
) { ptr[
0
]=ptr[
1
]=
0
;
return
0
; }
double
val_real
(
void
);
longlong
val_int
(
void
);
String *
val_str
(String*,String *);
bool
send_binary
(Protocol *protocol);
int
cmp
(
const
uchar *,
const
uchar *);
void
sort_string
(uchar *buff,uint length);
uint32
pack_length
()
const
{
return
2
; }
void
sql_type
(String &str)
const
;
uint32
max_display_length
() {
return
6
; }
virtual
uchar *
pack
(uchar* to,
const
uchar *from,
uint max_length,
bool
low_byte_first)
{
return
pack_int16
(to, from, low_byte_first);
View remainder of file in raw view
Footer
© 2026 GitHub, Inc.
Footer navigation
Terms
Privacy
Security
Status
Community
Docs
Contact
You can’t perform that action at this time.
Back
|
FazBrowse Home
|
New Git URL