63
65
const CHARSET_INFO * const )
69
Session *session= table ? table->in_use : current_session;
70
enum enum_drizzle_timestamp_type ret;
71
if ((ret= str_to_datetime(from, len, &l_time,
73
(session->variables.sql_mode &
74
(MODE_NO_ZERO_DATE | MODE_INVALID_DATES))),
75
&error)) <= DRIZZLE_TIMESTAMP_ERROR)
82
tmp= l_time.day + l_time.month*32 + l_time.year*16*32;
83
if (!error && (ret != DRIZZLE_TIMESTAMP_DATE) &&
84
(l_time.hour || l_time.minute || l_time.second || l_time.second_part))
85
error= 3; // Datetime was cut (note)
89
set_datetime_warning(error == 3 ? DRIZZLE_ERROR::WARN_LEVEL_NOTE :
90
DRIZZLE_ERROR::WARN_LEVEL_WARN,
91
ER_WARN_DATA_TRUNCATED,
92
from, len, DRIZZLE_TIMESTAMP_DATE, 1);
95
#endif /* NOTDEFINED */
97
68
* Try to create a DateTime from the supplied string. Throw an error
98
69
* if unable to create a valid DateTime. A DateTime is used so that
109
80
/* Create the stored integer format. @TODO This should go away. Should be up to engine... */
110
uint32_t int_value= (temporal.years() * 16 * 32) + (temporal.months() * 32) + temporal.days();
111
int3store(ptr, int_value);
81
uint32_t int_value= (temporal.years() * 10000) + (temporal.months() * 100) + temporal.days();
82
int4store(ptr, int_value);
139
110
DateTime temporal;
140
111
if (! temporal.from_int64_t(from))
142
/* Convert the integer to a string using stringstream */
143
std::stringstream ss;
145
ss << from; ss >> tmp;
113
/* Convert the integer to a string using boost::lexical_cast */
114
std::string tmp(boost::lexical_cast<std::string>(from));
147
116
my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp.c_str());
151
120
/* Create the stored integer format. @TODO This should go away. Should be up to engine... */
152
uint32_t int_value= (temporal.years() * 16 * 32) + (temporal.months() * 32) + temporal.days();
153
int3store(ptr, int_value);
121
uint32_t int_value= (temporal.years() * 10000) + (temporal.months() * 100) + temporal.days();
122
int4store(ptr, int_value);
162
131
if (time_type == DRIZZLE_TIMESTAMP_DATE ||
163
132
time_type == DRIZZLE_TIMESTAMP_DATETIME)
165
tmp=ltime->year*16*32+ltime->month*32+ltime->day;
134
tmp= ltime->year*10000 + ltime->month*100 + ltime->day;
166
135
if (check_date(ltime, tmp != 0,
167
136
(TIME_FUZZY_DATE |
168
137
(current_session->variables.sql_mode &
208
177
ASSERT_COLUMN_MARKED_FOR_READ;
211
j= (j % 32L)+(j / 32L % 16L)*100L + (j/(16L*32L))*10000L;
213
181
return (int64_t) j;
216
String *Field_date::val_str(String *val_buffer,
184
String *Field_date::val_str(String *val_buffer, String *)
219
186
val_buffer->alloc(field_length);
220
187
val_buffer->length(field_length);
221
uint32_t tmp=(uint32_t) uint3korr(ptr);
188
uint32_t tmp=(uint32_t) uint4korr(ptr);
223
190
char *pos=(char*) val_buffer->ptr()+10;
225
192
ASSERT_COLUMN_MARKED_FOR_READ;
227
194
/* Open coded to get more speed */
228
195
*pos--=0; // End NULL
229
part=(int) (tmp & 31);
230
*pos--= (char) ('0'+part%10);
231
*pos--= (char) ('0'+part/10);
233
part=(int) (tmp >> 5 & 15);
234
*pos--= (char) ('0'+part%10);
235
*pos--= (char) ('0'+part/10);
237
part=(int) (tmp >> 9);
196
part=(int32_t) (tmp % 100);
197
*pos--= (char) ('0'+part%10);
198
*pos--= (char) ('0'+part/10);
200
part=(int32_t) (tmp/100%100);
201
*pos--= (char) ('0'+part%10);
202
*pos--= (char) ('0'+part/10);
204
part=(int32_t) (tmp/10000);
238
205
*pos--= (char) ('0'+part%10); part/=10;
239
206
*pos--= (char) ('0'+part%10); part/=10;
240
207
*pos--= (char) ('0'+part%10); part/=10;
245
212
bool Field_date::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
247
uint32_t tmp=(uint32_t) uint3korr(ptr);
248
ltime->day= tmp & 31;
249
ltime->month= (tmp >> 5) & 15;
250
ltime->year= (tmp >> 9);
214
uint32_t tmp=(uint32_t) uint4korr(ptr);
215
ltime->day= (int) (tmp%100);
216
ltime->month= (int) (tmp/100%100);
217
ltime->year= (int) (tmp/10000);
251
218
ltime->time_type= DRIZZLE_TIMESTAMP_DATE;
252
219
ltime->hour= ltime->minute= ltime->second= ltime->second_part= ltime->neg= 0;
253
220
return ((!(fuzzydate & TIME_FUZZY_DATE) && (!ltime->month || !ltime->day)) ?
262
229
int Field_date::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
265
a=(uint32_t) uint3korr(a_ptr);
266
b=(uint32_t) uint3korr(b_ptr);
232
a=(uint32_t) uint4korr(a_ptr);
233
b=(uint32_t) uint4korr(b_ptr);
267
234
return (a < b) ? -1 : (a > b) ? 1 : 0;
270
237
void Field_date::sort_string(unsigned char *to,uint32_t )
277
245
void Field_date::sql_type(String &res) const