61
54
nearly-identical class Field_date doesn't ever return 3 from its
64
58
int Field_date::store(const char *from,
66
const CHARSET_INFO * const )
69
* Try to create a DateTime from the supplied string. Throw an error
70
* if unable to create a valid DateTime. A DateTime is used so that
71
* automatic conversion from the higher-storage DateTime can be used
72
* and matches on datetime format strings can occur.
74
ASSERT_COLUMN_MARKED_FOR_WRITE;
76
if (! temporal.from_string(from, (size_t) len))
78
my_error(ER_INVALID_DATE_VALUE, MYF(ME_FATALERROR), from);
81
/* Create the stored integer format. @TODO This should go away. Should be up to engine... */
82
uint32_t int_value= (temporal.years() * 10000) + (temporal.months() * 100) + temporal.days();
83
int4store(ptr, int_value);
87
int Field_date::store(double from)
89
ASSERT_COLUMN_MARKED_FOR_WRITE;
90
if (from < 0.0 || from > 99991231235959.0)
92
/* Convert the double to a string using stringstream */
95
ss.precision(18); /* 18 places should be fine for error display of double input. */
96
ss << from; ss >> tmp;
98
my_error(ER_INVALID_DATE_VALUE, MYF(ME_FATALERROR), tmp.c_str());
101
return Field_date::store((int64_t) rint(from), false);
104
int Field_date::store(int64_t from, bool)
107
* Try to create a DateTime from the supplied integer. Throw an error
108
* if unable to create a valid DateTime.
110
ASSERT_COLUMN_MARKED_FOR_WRITE;
112
if (! temporal.from_int64_t(from))
114
/* Convert the integer to a string using boost::lexical_cast */
115
std::string tmp(boost::lexical_cast<std::string>(from));
117
my_error(ER_INVALID_DATE_VALUE, MYF(ME_FATALERROR), tmp.c_str());
121
/* Create the stored integer format. @TODO This should go away. Should be up to engine... */
122
uint32_t int_value= (temporal.years() * 10000) + (temporal.months() * 100) + temporal.days();
123
int4store(ptr, int_value);
128
int Field_date::store_time(type::Time <ime,
129
type::timestamp_t time_type)
60
const CHARSET_INFO * const cs __attribute__((unused)))
65
Session *session= table ? table->in_use : current_session;
66
enum enum_drizzle_timestamp_type ret;
67
if ((ret= str_to_datetime(from, len, &l_time,
69
(session->variables.sql_mode &
70
(MODE_NO_ZERO_DATE | MODE_INVALID_DATES))),
71
&error)) <= DRIZZLE_TIMESTAMP_ERROR)
78
tmp= l_time.day + l_time.month*32 + l_time.year*16*32;
79
if (!error && (ret != DRIZZLE_TIMESTAMP_DATE) &&
80
(l_time.hour || l_time.minute || l_time.second || l_time.second_part))
81
error= 3; // Datetime was cut (note)
85
set_datetime_warning(error == 3 ? DRIZZLE_ERROR::WARN_LEVEL_NOTE :
86
DRIZZLE_ERROR::WARN_LEVEL_WARN,
87
ER_WARN_DATA_TRUNCATED,
88
from, len, DRIZZLE_TIMESTAMP_DATE, 1);
95
int Field_date::store(double nr)
97
if (nr < 0.0 || nr > 99991231235959.0)
99
int3store(ptr,(int32_t) 0);
100
set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
101
ER_WARN_DATA_TRUNCATED, nr, DRIZZLE_TIMESTAMP_DATE);
104
return Field_date::store((int64_t) rint(nr), false);
108
int Field_date::store(int64_t nr,
109
bool unsigned_val __attribute__((unused)))
114
Session *session= table ? table->in_use : current_session;
115
if (number_to_datetime(nr, &l_time,
117
(session->variables.sql_mode &
118
(MODE_NO_ZERO_DATE | MODE_INVALID_DATES))),
119
&error) == INT64_C(-1))
125
tmp= l_time.day + l_time.month*32 + l_time.year*16*32;
127
if (!error && l_time.time_type != DRIZZLE_TIMESTAMP_DATE &&
128
(l_time.hour || l_time.minute || l_time.second || l_time.second_part))
132
set_datetime_warning(error == 3 ? DRIZZLE_ERROR::WARN_LEVEL_NOTE :
133
DRIZZLE_ERROR::WARN_LEVEL_WARN,
135
ER_WARN_DATA_OUT_OF_RANGE : ER_WARN_DATA_TRUNCATED,
136
nr,DRIZZLE_TIMESTAMP_DATE, 1);
143
int Field_date::store_time(DRIZZLE_TIME *ltime,
144
enum enum_drizzle_timestamp_type time_type)
133
if (time_type == type::DRIZZLE_TIMESTAMP_DATE || time_type == type::DRIZZLE_TIMESTAMP_DATETIME)
148
if (time_type == DRIZZLE_TIMESTAMP_DATE ||
149
time_type == DRIZZLE_TIMESTAMP_DATETIME)
135
tmp= ltime.year*10000 + ltime.month*100 + ltime.day;
137
Session *session= getTable() ? getTable()->in_use : current_session;
138
type::cut_t cut_error= type::VALID;
139
if (ltime.check(tmp != 0,
141
(session->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_INVALID_DATES))), cut_error))
151
tmp=ltime->year*16*32+ltime->month*32+ltime->day;
152
if (check_date(ltime, tmp != 0,
154
(current_session->variables.sql_mode &
155
(MODE_NO_ZERO_DATE | MODE_INVALID_DATES))), &error))
143
char buff[type::Time::MAX_STRING_LENGTH];
157
char buff[MAX_DATE_STRING_REP_LENGTH];
144
158
String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
145
ltime.convert(str, type::DRIZZLE_TIMESTAMP_DATE);
159
make_date((DATE_TIME_FORMAT *) 0, ltime, &str);
146
160
set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED,
147
str.ptr(), str.length(), type::DRIZZLE_TIMESTAMP_DATE, 1);
161
str.ptr(), str.length(), DRIZZLE_TIMESTAMP_DATE, 1);
150
error= static_cast<int>(cut_error);
152
if (not error && ltime.time_type != type::DRIZZLE_TIMESTAMP_DATE &&
153
(ltime.hour || ltime.minute || ltime.second || ltime.second_part))
163
if (!error && ltime->time_type != DRIZZLE_TIMESTAMP_DATE &&
164
(ltime->hour || ltime->minute || ltime->second || ltime->second_part))
155
char buff[type::Time::MAX_STRING_LENGTH];
166
char buff[MAX_DATE_STRING_REP_LENGTH];
156
167
String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
168
make_datetime((DATE_TIME_FORMAT *) 0, ltime, &str);
158
169
set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_NOTE,
159
170
ER_WARN_DATA_TRUNCATED,
160
str.ptr(), str.length(), type::DRIZZLE_TIMESTAMP_DATE, 1);
171
str.ptr(), str.length(), DRIZZLE_TIMESTAMP_DATE, 1);
168
179
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
176
double Field_date::val_real(void) const
186
bool Field_date::send_binary(Protocol *protocol)
189
Field_date::get_date(&tm,0);
190
return protocol->store_date(&tm);
194
double Field_date::val_real(void)
178
196
return (double) Field_date::val_int();
181
int64_t Field_date::val_int(void) const
200
int64_t Field_date::val_int(void)
185
ASSERT_COLUMN_MARKED_FOR_READ;
202
uint32_t j= uint3korr(ptr);
203
j= (j % 32L)+(j / 32L % 16L)*100L + (j/(16L*32L))*10000L;
189
204
return (int64_t) j;
192
String *Field_date::val_str(String *val_buffer, String *) const
208
String *Field_date::val_str(String *val_buffer,
209
String *val_ptr __attribute__((unused)))
194
211
val_buffer->alloc(field_length);
195
212
val_buffer->length(field_length);
196
uint32_t tmp=(uint32_t) uint4korr(ptr);
213
uint32_t tmp=(uint32_t) uint3korr(ptr);
198
215
char *pos=(char*) val_buffer->ptr()+10;
200
ASSERT_COLUMN_MARKED_FOR_READ;
202
217
/* Open coded to get more speed */
203
218
*pos--=0; // End NULL
204
part=(int32_t) (tmp % 100);
205
*pos--= (char) ('0'+part%10);
206
*pos--= (char) ('0'+part/10);
208
part=(int32_t) (tmp/100%100);
209
*pos--= (char) ('0'+part%10);
210
*pos--= (char) ('0'+part/10);
212
part=(int32_t) (tmp/10000);
219
part=(int) (tmp & 31);
220
*pos--= (char) ('0'+part%10);
221
*pos--= (char) ('0'+part/10);
223
part=(int) (tmp >> 5 & 15);
224
*pos--= (char) ('0'+part%10);
225
*pos--= (char) ('0'+part/10);
227
part=(int) (tmp >> 9);
213
228
*pos--= (char) ('0'+part%10); part/=10;
214
229
*pos--= (char) ('0'+part%10); part/=10;
215
230
*pos--= (char) ('0'+part%10); part/=10;
217
232
return val_buffer;
220
bool Field_date::get_date(type::Time <ime, uint32_t fuzzydate) const
236
bool Field_date::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
222
uint32_t tmp=(uint32_t) uint4korr(ptr);
223
ltime.day= (int) (tmp%100);
224
ltime.month= (int) (tmp/100%100);
225
ltime.year= (int) (tmp/10000);
226
ltime.time_type= type::DRIZZLE_TIMESTAMP_DATE;
227
ltime.hour= ltime.minute= ltime.second= ltime.second_part= ltime.neg= 0;
229
return ((!(fuzzydate & TIME_FUZZY_DATE) && (!ltime.month || !ltime.day)) ?
238
uint32_t tmp=(uint32_t) uint3korr(ptr);
239
ltime->day= tmp & 31;
240
ltime->month= (tmp >> 5) & 15;
241
ltime->year= (tmp >> 9);
242
ltime->time_type= DRIZZLE_TIMESTAMP_DATE;
243
ltime->hour= ltime->minute= ltime->second= ltime->second_part= ltime->neg= 0;
244
return ((!(fuzzydate & TIME_FUZZY_DATE) && (!ltime->month || !ltime->day)) ?
233
bool Field_date::get_time(type::Time <ime) const
249
bool Field_date::get_time(DRIZZLE_TIME *ltime)
235
return Field_date::get_date(ltime ,0);
251
return Field_date::get_date(ltime,0);
238
255
int Field_date::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
241
a=(uint32_t) uint4korr(a_ptr);
242
b=(uint32_t) uint4korr(b_ptr);
258
a=(uint32_t) uint3korr(a_ptr);
259
b=(uint32_t) uint3korr(b_ptr);
243
260
return (a < b) ? -1 : (a > b) ? 1 : 0;
246
void Field_date::sort_string(unsigned char *to,uint32_t )
264
void Field_date::sort_string(unsigned char *to,uint32_t length __attribute__((unused)))
254
272
void Field_date::sql_type(String &res) const
256
274
res.set_ascii(STRING_WITH_LEN("date"));
259
} /* namespace drizzled */