28
28
#include "sql_select.h"
30
30
#include <drizzled/error.h>
31
#include <drizzled/virtual_column_info.h>
32
#include <drizzled/field/str.h>
33
#include <drizzled/field/longstr.h>
34
#include <drizzled/field/num.h>
35
#include <drizzled/field/blob.h>
36
#include <drizzled/field/enum.h>
37
#include <drizzled/field/null.h>
38
#include <drizzled/field/date.h>
39
#include <drizzled/field/fdecimal.h>
40
#include <drizzled/field/real.h>
41
#include <drizzled/field/double.h>
42
#include <drizzled/field/long.h>
43
#include <drizzled/field/int64_t.h>
44
#include <drizzled/field/num.h>
45
#include <drizzled/field/timetype.h>
46
#include <drizzled/field/timestamp.h>
47
#include <drizzled/field/datetime.h>
48
#include <drizzled/field/fstring.h>
49
#include <drizzled/field/varstring.h>
52
33
/*****************************************************************************
559
Detect Item_result by given field type of UNION merge result.
561
@param field_type given field type
564
Item_result (type of internal MySQL expression result)
577
567
Item_result Field::result_merge_type(enum_field_types field_type)
579
569
assert(field_type <= DRIZZLE_TYPE_MAX);
580
570
return field_types_result_type[field_type];
584
bool Field::eq(Field *field)
586
return (ptr == field->ptr && null_ptr == field->null_ptr &&
587
null_bit == field->null_bit);
591
uint32_t Field::pack_length() const
597
uint32_t Field::pack_length_in_rec() const
599
return pack_length();
603
uint32_t Field::pack_length_from_metadata(uint32_t field_metadata)
605
return field_metadata;
609
uint32_t Field::row_pack_length()
615
int Field::save_field_metadata(unsigned char *first_byte)
617
return do_save_field_metadata(first_byte);
621
uint32_t Field::data_length()
623
return pack_length();
627
uint32_t Field::used_length()
629
return pack_length();
633
uint32_t Field::sort_length() const
635
return pack_length();
639
uint32_t Field::max_data_length() const
641
return pack_length();
645
int Field::reset(void)
647
memset(ptr, 0, pack_length());
652
void Field::reset_fields()
656
void Field::set_default()
658
my_ptrdiff_t l_offset= (my_ptrdiff_t) (table->getDefaultValues() - table->record[0]);
659
memcpy(ptr, ptr + l_offset, pack_length());
661
*null_ptr= ((*null_ptr & (unsigned char) ~null_bit) | (null_ptr[l_offset] & null_bit));
665
bool Field::binary() const
671
bool Field::zero_pack() const
677
enum ha_base_keytype Field::key_type() const
679
return HA_KEYTYPE_BINARY;
683
uint32_t Field::key_length() const
685
return pack_length();
689
enum_field_types Field::real_type() const
695
int Field::cmp_max(const unsigned char *a, const unsigned char *b, uint32_t)
701
int Field::cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t)
703
return memcmp(a,b,pack_length());
707
int Field::cmp_offset(uint32_t row_offset)
709
return cmp(ptr,ptr+row_offset);
713
int Field::cmp_binary_offset(uint32_t row_offset)
715
return cmp_binary(ptr, ptr+row_offset);
719
int Field::key_cmp(const unsigned char *a,const unsigned char *b)
725
int Field::key_cmp(const unsigned char *str, uint32_t)
731
uint32_t Field::decimals() const
737
bool Field::is_null(my_ptrdiff_t row_offset)
740
(null_ptr[row_offset] & null_bit ? true : false) :
745
bool Field::is_real_null(my_ptrdiff_t row_offset)
747
return null_ptr ? (null_ptr[row_offset] & null_bit ? true : false) : false;
751
bool Field::is_null_in_record(const unsigned char *record)
755
return test(record[(uint32_t) (null_ptr -table->record[0])] &
760
bool Field::is_null_in_record_with_offset(my_ptrdiff_t offset)
764
return test(null_ptr[offset] & null_bit);
768
void Field::set_null(my_ptrdiff_t row_offset)
771
null_ptr[row_offset]|= null_bit;
775
void Field::set_notnull(my_ptrdiff_t row_offset)
778
null_ptr[row_offset]&= (unsigned char) ~null_bit;
782
bool Field::maybe_null(void)
784
return null_ptr != 0 || table->maybe_null;
788
bool Field::real_maybe_null(void)
790
return null_ptr != 0;
794
size_t Field::last_null_byte() const
796
size_t bytes= do_last_null_byte();
797
assert(bytes <= table->getNullBytes());
802
573
/*****************************************************************************
803
574
Static help functions
804
575
*****************************************************************************/
579
Check whether a field type can be partially indexed by a key.
581
This is a static method, rather than a virtual function, because we need
582
to check the type of a non-Field in mysql_alter_table().
584
@param type field type
587
true Type can have a prefixed key
589
false Type can not have a prefixed key
806
592
bool Field::type_can_have_key_part(enum enum_field_types type)
931
710
/// This is used as a table name when the table structure is not set up
932
711
Field::Field(unsigned char *ptr_arg,uint32_t length_arg,unsigned char *null_ptr_arg,
933
unsigned char null_bit_arg,
934
utype unireg_check_arg, const char *field_name_arg)
712
unsigned char null_bit_arg,
713
utype unireg_check_arg, const char *field_name_arg)
935
714
:ptr(ptr_arg), null_ptr(null_ptr_arg),
936
715
table(0), orig_table(0), table_name(0),
937
716
field_name(field_name_arg),
938
717
key_start(0), part_of_key(0), part_of_key_not_clustered(0),
939
718
part_of_sortkey(0), unireg_check(unireg_check_arg),
940
field_length(length_arg), null_bit(null_bit_arg),
719
field_length(length_arg), null_bit(null_bit_arg),
941
720
is_created_from_null_item(false),
942
721
vcol_info(NULL), is_stored(true)
1149
const unsigned char *Field::unpack(unsigned char* to,
1150
const unsigned char *from)
1152
const unsigned char *result= unpack(to, from, 0U,
1153
table->s->db_low_byte_first);
1158
uint32_t Field::packed_col_length(const unsigned char *, uint32_t length)
1164
int Field::pack_cmp(const unsigned char *a, const unsigned char *b,
1171
int Field::pack_cmp(const unsigned char *b, uint32_t, bool)
1177
915
my_decimal *Field::val_decimal(my_decimal *)
1179
917
/* This never have to be called */
1089
Report "not well formed" or "cannot convert" error
1090
after storing a character string info a field.
1093
check_string_copy_error()
1095
well_formed_error_pos - where not well formed data was first met
1096
cannot_convert_error_pos - where a not-convertable character was first met
1097
end - end of the string
1098
cs - character set of the string
1101
As of version 5.0 both cases return the same error:
1103
"Invalid string value: 'xxx' for column 't' at row 1"
1105
Future versions will possibly introduce a new error message:
1107
"Cannot convert character string: 'xxx' for column 't' at row 1"
1110
false - If errors didn't happen
1111
true - If an error happened
1115
check_string_copy_error(Field_str *field,
1116
const char *well_formed_error_pos,
1117
const char *cannot_convert_error_pos,
1119
const CHARSET_INFO * const cs)
1121
const char *pos, *end_orig;
1124
if (!(pos= well_formed_error_pos) &&
1125
!(pos= cannot_convert_error_pos))
1129
set_if_smaller(end, pos + 6);
1131
for (t= tmp; pos < end; pos++)
1134
If the source string is ASCII compatible (mbminlen==1)
1135
and the source character is in ASCII printable range (0x20..0x7F),
1136
then display the character as is.
1138
Otherwise, if the source string is not ASCII compatible (e.g. UCS2),
1139
or the source character is not in the printable range,
1140
then print the character using HEX notation.
1142
if (((unsigned char) *pos) >= 0x20 &&
1143
((unsigned char) *pos) <= 0x7F &&
1152
*t++= _dig_vec_upper[((unsigned char) *pos) >> 4];
1153
*t++= _dig_vec_upper[((unsigned char) *pos) & 15];
1163
push_warning_printf(field->table->in_use,
1164
field->table->in_use->abort_on_warning ?
1165
DRIZZLE_ERROR::WARN_LEVEL_ERROR :
1166
DRIZZLE_ERROR::WARN_LEVEL_WARN,
1167
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
1168
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
1169
"string", tmp, field->field_name,
1170
(uint32_t) field->table->in_use->row_count);
1350
1174
uint32_t Field::is_equal(Create_field *new_field)
1352
1176
return (new_field->sql_type == real_type());
1880
1704
return new Field_timestamp(ptr,field_length, null_pos, null_bit,
1881
1705
unireg_check, field_name, share,
1882
1706
field_charset);
1883
case DRIZZLE_TYPE_DATE:
1884
return new Field_date(ptr,null_pos,null_bit,
1707
case DRIZZLE_TYPE_NEWDATE:
1708
return new Field_newdate(ptr,null_pos,null_bit,
1885
1709
unireg_check, field_name, field_charset);
1886
1710
case DRIZZLE_TYPE_TIME:
1887
1711
return new Field_time(ptr,null_pos,null_bit,