22
#include <drizzled/server_includes.h>
23
23
#include <drizzled/field/str.h>
24
24
#include <drizzled/error.h>
25
#include <drizzled/table.h>
26
#include <drizzled/session.h>
27
#include "drizzled/internal/m_string.h"
34
extern char _dig_vec_upper[];
37
Field_str::Field_str(unsigned char *ptr_arg,
39
unsigned char *null_ptr_arg,
40
unsigned char null_bit_arg,
41
const char *field_name_arg,
42
const CHARSET_INFO * const charset_arg)
43
:Field(ptr_arg, len_arg,
26
Field_str::Field_str(unsigned char *ptr_arg,uint32_t len_arg, unsigned char *null_ptr_arg,
27
unsigned char null_bit_arg, utype unireg_check_arg,
28
const char *field_name_arg, const CHARSET_INFO * const charset_arg)
29
:Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
30
unireg_check_arg, field_name_arg)
49
32
field_charset= charset_arg;
50
33
if (charset_arg->state & MY_CS_BINSORT)
52
35
field_derivation= DERIVATION_IMPLICIT;
56
Check if we lost any important data and send a truncation error/warning
59
Field_str::report_if_important_data()
60
ptr - Truncated rest of string
61
end - End of truncated string
64
0 - None was truncated (or we don't count cut fields)
65
2 - Some bytes was truncated
68
Check if we lost any important data (anything in a binary string,
69
or any non-space in others). If only trailing spaces was lost,
70
send a truncation note, otherwise send a truncation error.
74
Field_str::report_if_important_data(const char *field_ptr, const char *end)
76
if ((field_ptr < end) && getTable()->in_use->count_cuted_fields)
78
set_warning(DRIZZLE_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
86
39
Decimal representation of Field_str.
105
int Field_str::store_decimal(const type::Decimal *d)
58
int Field_str::store_decimal(const my_decimal *d)
107
char buff[DECIMAL_MAX_STR_LENGTH+1];
108
String str(buff, sizeof(buff), &my_charset_bin);
109
class_decimal2string(d, 0, &str);
110
return store(str.ptr(), str.length(), str.charset());
61
/* TODO: use decimal2string? */
62
int err= warn_if_overflow(my_decimal2double(E_DEC_FATAL_ERROR &
63
~E_DEC_OVERFLOW, d, &val));
64
return err | store(val);
113
type::Decimal *Field_str::val_decimal(type::Decimal *decimal_value)
67
my_decimal *Field_str::val_decimal(my_decimal *decimal_value)
115
69
int64_t nr= val_int();
116
int2_class_decimal(E_DEC_FATAL_ERROR, nr, 0, decimal_value);
70
int2my_decimal(E_DEC_FATAL_ERROR, nr, 0, decimal_value);
117
71
return decimal_value;
135
ASSERT_COLUMN_MARKED_FOR_WRITE;
137
length= internal::my_gcvt(nr, internal::MY_GCVT_ARG_DOUBLE, local_char_length, buff, &error);
89
length= my_gcvt(nr, MY_GCVT_ARG_DOUBLE, local_char_length, buff, &error);
140
if (getTable()->getSession()->abortOnWarning())
92
if (table->in_use->abort_on_warning)
142
93
set_warning(DRIZZLE_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
146
95
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
149
97
return store(buff, length, charset());
153
bool check_string_copy_error(Field_str *field,
154
const char *well_formed_error_pos,
155
const char *cannot_convert_error_pos,
157
const CHARSET_INFO * const cs)
159
const char *pos, *end_orig;
162
if (!(pos= well_formed_error_pos) &&
163
!(pos= cannot_convert_error_pos))
167
set_if_smaller(end, pos + 6);
169
for (t= tmp; pos < end; pos++)
172
If the source string is ASCII compatible (mbminlen==1)
173
and the source character is in ASCII printable range (0x20..0x7F),
174
then display the character as is.
176
Otherwise, if the source string is not ASCII compatible (e.g. UCS2),
177
or the source character is not in the printable range,
178
then print the character using HEX notation.
180
if (((unsigned char) *pos) >= 0x20 &&
181
((unsigned char) *pos) <= 0x7F &&
190
*t++= internal::_dig_vec_upper[((unsigned char) *pos) >> 4];
191
*t++= internal::_dig_vec_upper[((unsigned char) *pos) & 15];
201
push_warning_printf(field->getTable()->in_use,
202
field->getTable()->in_use->abortOnWarning() ?
203
DRIZZLE_ERROR::WARN_LEVEL_ERROR :
204
DRIZZLE_ERROR::WARN_LEVEL_WARN,
205
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
206
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
207
"string", tmp, field->field_name,
208
(uint32_t) field->getTable()->in_use->row_count);
212
uint32_t Field_str::max_data_length() const
214
return field_length + (field_length > 255 ? 2 : 1);
217
} /* namespace drizzled */
100
/* If one of the fields is binary and the other one isn't return 1 else 0 */
102
bool Field_str::compare_str_field_flags(Create_field *new_field, uint32_t flag_arg)
104
return (((new_field->flags & (BINCMP_FLAG | BINARY_FLAG)) &&
105
!(flag_arg & (BINCMP_FLAG | BINARY_FLAG))) ||
106
(!(new_field->flags & (BINCMP_FLAG | BINARY_FLAG)) &&
107
(flag_arg & (BINCMP_FLAG | BINARY_FLAG))));
111
uint32_t Field_str::is_equal(Create_field *new_field)
113
if (compare_str_field_flags(new_field, flags))
116
return ((new_field->sql_type == real_type()) &&
117
new_field->charset == field_charset &&
118
new_field->length == max_display_length());