520.4.14
by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf. |
1 |
/* -*- mode: c++ c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
3 |
*
|
|
520.4.14
by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf. |
4 |
* Copyright (C) 2008 Sun Microsystems
|
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; either version 2 of the License, or
|
|
9 |
* (at your option) any later version.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with this program; if not, write to the Free Software
|
|
18 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
19 |
*/
|
|
20 |
||
21 |
||
243.1.17
by Jay Pipes
FINAL PHASE removal of mysql_priv.h (Bye, bye my friend.) |
22 |
#include <drizzled/server_includes.h> |
214
by Brian Aker
Rename of fields (fix issue with string and decimal .h clashing). |
23 |
#include <drizzled/field/timestamp.h> |
550
by Monty Taylor
Moved error.h into just the files that need it. |
24 |
#include <drizzled/error.h> |
520.4.14
by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf. |
25 |
#include <drizzled/tztime.h> |
572.1.4
by Monty Taylor
Removed a bunch of unusued tests and defines from autoconf. |
26 |
#include CMATH_H
|
27 |
||
28 |
#if defined(CMATH_NAMESPACE)
|
|
29 |
using namespace CMATH_NAMESPACE; |
|
30 |
#endif
|
|
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
31 |
|
32 |
/**
|
|
33 |
TIMESTAMP type holds datetime values in range from 1970-01-01 00:00:01 UTC to
|
|
34 |
2038-01-01 00:00:00 UTC stored as number of seconds since Unix
|
|
35 |
Epoch in UTC.
|
|
36 |
|
|
37 |
Up to one of timestamps columns in the table can be automatically
|
|
38 |
set on row update and/or have NOW() as default value.
|
|
39 |
TABLE::timestamp_field points to Field object for such timestamp with
|
|
40 |
auto-set-on-update. TABLE::time_stamp holds offset in record + 1 for this
|
|
41 |
field, and is used by handler code which performs updates required.
|
|
42 |
|
|
43 |
Actually SQL-99 says that we should allow niladic functions (like NOW())
|
|
44 |
as defaults for any field. Current limitations (only NOW() and only
|
|
45 |
for one TIMESTAMP field) are because of restricted binary .frm format
|
|
46 |
and should go away in the future.
|
|
47 |
|
|
48 |
Also because of this limitation of binary .frm format we use 5 different
|
|
49 |
unireg_check values with TIMESTAMP field to distinguish various cases of
|
|
50 |
DEFAULT or ON UPDATE values. These values are:
|
|
51 |
|
|
52 |
TIMESTAMP_OLD_FIELD - old timestamp, if there was not any fields with
|
|
53 |
auto-set-on-update (or now() as default) in this table before, then this
|
|
54 |
field has NOW() as default and is updated when row changes, else it is
|
|
55 |
field which has 0 as default value and is not automatically updated.
|
|
56 |
TIMESTAMP_DN_FIELD - field with NOW() as default but not set on update
|
|
57 |
automatically (TIMESTAMP DEFAULT NOW())
|
|
58 |
TIMESTAMP_UN_FIELD - field which is set on update automatically but has not
|
|
59 |
NOW() as default (but it may has 0 or some other const timestamp as
|
|
60 |
default) (TIMESTAMP ON UPDATE NOW()).
|
|
61 |
TIMESTAMP_DNUN_FIELD - field which has now() as default and is auto-set on
|
|
62 |
update. (TIMESTAMP DEFAULT NOW() ON UPDATE NOW())
|
|
63 |
NONE - field which is not auto-set on update with some other than NOW()
|
|
64 |
default value (TIMESTAMP DEFAULT 0).
|
|
65 |
||
66 |
Note that TIMESTAMP_OLD_FIELDs are never created explicitly now, they are
|
|
67 |
left only for preserving ability to read old tables. Such fields replaced
|
|
68 |
with their newer analogs in CREATE TABLE and in SHOW CREATE TABLE. This is
|
|
69 |
because we want to prefer NONE unireg_check before TIMESTAMP_OLD_FIELD for
|
|
70 |
"TIMESTAMP DEFAULT 'Const'" field. (Old timestamps allowed such
|
|
71 |
specification too but ignored default value for first timestamp, which of
|
|
72 |
course is non-standard.) In most cases user won't notice any change, only
|
|
73 |
exception is different behavior of old/new timestamps during ALTER TABLE.
|
|
74 |
*/
|
|
75 |
||
481
by Brian Aker
Remove all of uchar. |
76 |
Field_timestamp::Field_timestamp(unsigned char *ptr_arg, |
212.1.3
by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)). |
77 |
uint32_t len_arg __attribute__((unused)), |
481
by Brian Aker
Remove all of uchar. |
78 |
unsigned char *null_ptr_arg, unsigned char null_bit_arg, |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
79 |
enum utype unireg_check_arg, |
80 |
const char *field_name_arg, |
|
81 |
TABLE_SHARE *share, |
|
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
82 |
const CHARSET_INFO * const cs) |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
83 |
:Field_str(ptr_arg, MAX_DATETIME_WIDTH, null_ptr_arg, null_bit_arg, |
84 |
unireg_check_arg, field_name_arg, cs) |
|
85 |
{
|
|
86 |
/* For 4.0 MYD and 4.0 InnoDB compatibility */
|
|
216
by Brian Aker
Remove completely ZEROFILL |
87 |
flags|= UNSIGNED_FLAG; |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
88 |
if (!share->timestamp_field && unireg_check != NONE) |
89 |
{
|
|
90 |
/* This timestamp has auto-update */
|
|
91 |
share->timestamp_field= this; |
|
92 |
flags|= TIMESTAMP_FLAG; |
|
93 |
if (unireg_check != TIMESTAMP_DN_FIELD) |
|
94 |
flags|= ON_UPDATE_NOW_FLAG; |
|
95 |
}
|
|
96 |
}
|
|
97 |
||
98 |
||
99 |
Field_timestamp::Field_timestamp(bool maybe_null_arg, |
|
100 |
const char *field_name_arg, |
|
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
101 |
const CHARSET_INFO * const cs) |
481
by Brian Aker
Remove all of uchar. |
102 |
:Field_str((unsigned char*) 0, MAX_DATETIME_WIDTH, |
103 |
maybe_null_arg ? (unsigned char*) "": 0, 0, |
|
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
104 |
NONE, field_name_arg, cs) |
105 |
{
|
|
106 |
/* For 4.0 MYD and 4.0 InnoDB compatibility */
|
|
216
by Brian Aker
Remove completely ZEROFILL |
107 |
flags|= UNSIGNED_FLAG; |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
108 |
if (unireg_check != TIMESTAMP_DN_FIELD) |
109 |
flags|= ON_UPDATE_NOW_FLAG; |
|
110 |
}
|
|
111 |
||
112 |
||
113 |
/**
|
|
114 |
Get auto-set type for TIMESTAMP field.
|
|
115 |
||
116 |
Returns value indicating during which operations this TIMESTAMP field
|
|
117 |
should be auto-set to current timestamp.
|
|
118 |
*/
|
|
119 |
timestamp_auto_set_type Field_timestamp::get_auto_set_type() const |
|
120 |
{
|
|
121 |
switch (unireg_check) |
|
122 |
{
|
|
123 |
case TIMESTAMP_DN_FIELD: |
|
124 |
return TIMESTAMP_AUTO_SET_ON_INSERT; |
|
125 |
case TIMESTAMP_UN_FIELD: |
|
126 |
return TIMESTAMP_AUTO_SET_ON_UPDATE; |
|
127 |
case TIMESTAMP_OLD_FIELD: |
|
128 |
/*
|
|
129 |
Although we can have several such columns in legacy tables this
|
|
130 |
function should be called only for first of them (i.e. the one
|
|
131 |
having auto-set property).
|
|
132 |
*/
|
|
133 |
assert(table->timestamp_field == this); |
|
134 |
/* Fall-through */
|
|
135 |
case TIMESTAMP_DNUN_FIELD: |
|
136 |
return TIMESTAMP_AUTO_SET_ON_BOTH; |
|
137 |
default: |
|
138 |
/*
|
|
139 |
Normally this function should not be called for TIMESTAMPs without
|
|
140 |
auto-set property.
|
|
141 |
*/
|
|
142 |
assert(0); |
|
143 |
return TIMESTAMP_NO_AUTO_SET; |
|
144 |
}
|
|
145 |
}
|
|
146 |
||
147 |
||
148 |
int Field_timestamp::store(const char *from, |
|
482
by Brian Aker
Remove uint. |
149 |
uint32_t len, |
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
150 |
const CHARSET_INFO * const cs __attribute__((unused))) |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
151 |
{
|
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
152 |
DRIZZLE_TIME l_time; |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
153 |
my_time_t tmp= 0; |
154 |
int error; |
|
155 |
bool have_smth_to_conv; |
|
156 |
bool in_dst_time_gap; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
157 |
Session *session= table ? table->in_use : current_session; |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
158 |
|
159 |
/* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */
|
|
160 |
have_smth_to_conv= (str_to_datetime(from, len, &l_time, 1, &error) > |
|
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
161 |
DRIZZLE_TIMESTAMP_ERROR); |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
162 |
|
163 |
if (error || !have_smth_to_conv) |
|
164 |
{
|
|
165 |
error= 1; |
|
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
166 |
set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, |
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
167 |
from, len, DRIZZLE_TIMESTAMP_DATETIME, 1); |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
168 |
}
|
169 |
||
170 |
/* Only convert a correct date (not a zero date) */
|
|
171 |
if (have_smth_to_conv && l_time.month) |
|
172 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
173 |
if (!(tmp= TIME_to_timestamp(session, &l_time, &in_dst_time_gap))) |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
174 |
{
|
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
175 |
set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
176 |
ER_WARN_DATA_OUT_OF_RANGE, |
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
177 |
from, len, DRIZZLE_TIMESTAMP_DATETIME, !error); |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
178 |
error= 1; |
179 |
}
|
|
180 |
else if (in_dst_time_gap) |
|
181 |
{
|
|
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
182 |
set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
183 |
ER_WARN_INVALID_TIMESTAMP, |
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
184 |
from, len, DRIZZLE_TIMESTAMP_DATETIME, !error); |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
185 |
error= 1; |
186 |
}
|
|
187 |
}
|
|
188 |
store_timestamp(tmp); |
|
189 |
return error; |
|
190 |
}
|
|
191 |
||
192 |
||
193 |
int Field_timestamp::store(double nr) |
|
194 |
{
|
|
195 |
int error= 0; |
|
196 |
if (nr < 0 || nr > 99991231235959.0) |
|
197 |
{
|
|
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
198 |
set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
199 |
ER_WARN_DATA_OUT_OF_RANGE, |
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
200 |
nr, DRIZZLE_TIMESTAMP_DATETIME); |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
201 |
nr= 0; // Avoid overflow on buff |
202 |
error= 1; |
|
203 |
}
|
|
204 |
error|= Field_timestamp::store((int64_t) rint(nr), false); |
|
205 |
return error; |
|
206 |
}
|
|
207 |
||
208 |
||
209 |
int Field_timestamp::store(int64_t nr, |
|
212.1.3
by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)). |
210 |
bool unsigned_val __attribute__((unused))) |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
211 |
{
|
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
212 |
DRIZZLE_TIME l_time; |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
213 |
my_time_t timestamp= 0; |
214 |
int error; |
|
215 |
bool in_dst_time_gap; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
216 |
Session *session= table ? table->in_use : current_session; |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
217 |
|
218 |
/* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
219 |
int64_t tmp= number_to_datetime(nr, &l_time, (session->variables.sql_mode & |
361
by Brian Aker
One more mode down, two more left to go! |
220 |
MODE_NO_ZERO_DATE), &error); |
422
by Monty
Various int64 constant fixes. |
221 |
if (tmp == INT64_C(-1)) |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
222 |
{
|
223 |
error= 2; |
|
224 |
}
|
|
225 |
||
226 |
if (!error && tmp) |
|
227 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
228 |
if (!(timestamp= TIME_to_timestamp(session, &l_time, &in_dst_time_gap))) |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
229 |
{
|
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
230 |
set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
231 |
ER_WARN_DATA_OUT_OF_RANGE, |
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
232 |
nr, DRIZZLE_TIMESTAMP_DATETIME, 1); |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
233 |
error= 1; |
234 |
}
|
|
235 |
if (in_dst_time_gap) |
|
236 |
{
|
|
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
237 |
set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
238 |
ER_WARN_INVALID_TIMESTAMP, |
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
239 |
nr, DRIZZLE_TIMESTAMP_DATETIME, 1); |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
240 |
error= 1; |
241 |
}
|
|
242 |
} else if (error) |
|
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
243 |
set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, |
212.5.42
by Monty Taylor
Ding dong include is dead. |
244 |
ER_WARN_DATA_TRUNCATED, |
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
245 |
nr, DRIZZLE_TIMESTAMP_DATETIME, 1); |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
246 |
|
247 |
store_timestamp(timestamp); |
|
248 |
return error; |
|
249 |
}
|
|
250 |
||
251 |
double Field_timestamp::val_real(void) |
|
252 |
{
|
|
253 |
return (double) Field_timestamp::val_int(); |
|
254 |
}
|
|
255 |
||
256 |
int64_t Field_timestamp::val_int(void) |
|
257 |
{
|
|
205
by Brian Aker
uint32 -> uin32_t |
258 |
uint32_t temp; |
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
259 |
DRIZZLE_TIME time_tmp; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
260 |
Session *session= table ? table->in_use : current_session; |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
261 |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
262 |
session->time_zone_used= 1; |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
263 |
#ifdef WORDS_BIGENDIAN
|
264 |
if (table && table->s->db_low_byte_first) |
|
265 |
temp=uint4korr(ptr); |
|
266 |
else
|
|
267 |
#endif
|
|
268 |
longget(temp,ptr); |
|
269 |
||
270 |
if (temp == 0L) // No time |
|
271 |
return(0); /* purecov: inspected */ |
|
272 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
273 |
session->variables.time_zone->gmt_sec_to_TIME(&time_tmp, (my_time_t)temp); |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
274 |
|
422
by Monty
Various int64 constant fixes. |
275 |
return time_tmp.year * INT64_C(10000000000) + |
276 |
time_tmp.month * INT64_C(100000000) + |
|
277 |
time_tmp.day * 1000000 + time_tmp.hour * 10000 + |
|
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
278 |
time_tmp.minute * 100 + time_tmp.second; |
279 |
}
|
|
280 |
||
281 |
||
282 |
String *Field_timestamp::val_str(String *val_buffer, String *val_ptr) |
|
283 |
{
|
|
205
by Brian Aker
uint32 -> uin32_t |
284 |
uint32_t temp, temp2; |
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
285 |
DRIZZLE_TIME time_tmp; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
286 |
Session *session= table ? table->in_use : current_session; |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
287 |
char *to; |
288 |
||
289 |
val_buffer->alloc(field_length+1); |
|
290 |
to= (char*) val_buffer->ptr(); |
|
291 |
val_buffer->length(field_length); |
|
292 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
293 |
session->time_zone_used= 1; |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
294 |
#ifdef WORDS_BIGENDIAN
|
295 |
if (table && table->s->db_low_byte_first) |
|
296 |
temp=uint4korr(ptr); |
|
297 |
else
|
|
298 |
#endif
|
|
299 |
longget(temp,ptr); |
|
300 |
||
301 |
if (temp == 0L) |
|
302 |
{ /* Zero time is "000000" */ |
|
303 |
val_ptr->set(STRING_WITH_LEN("0000-00-00 00:00:00"), &my_charset_bin); |
|
304 |
return val_ptr; |
|
305 |
}
|
|
306 |
val_buffer->set_charset(&my_charset_bin); // Safety |
|
307 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
308 |
session->variables.time_zone->gmt_sec_to_TIME(&time_tmp,(my_time_t)temp); |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
309 |
|
310 |
temp= time_tmp.year % 100; |
|
311 |
if (temp < YY_PART_YEAR - 1) |
|
312 |
{
|
|
313 |
*to++= '2'; |
|
314 |
*to++= '0'; |
|
315 |
}
|
|
316 |
else
|
|
317 |
{
|
|
318 |
*to++= '1'; |
|
319 |
*to++= '9'; |
|
320 |
}
|
|
321 |
temp2=temp/10; temp=temp-temp2*10; |
|
322 |
*to++= (char) ('0'+(char) (temp2)); |
|
323 |
*to++= (char) ('0'+(char) (temp)); |
|
324 |
*to++= '-'; |
|
325 |
temp=time_tmp.month; |
|
326 |
temp2=temp/10; temp=temp-temp2*10; |
|
327 |
*to++= (char) ('0'+(char) (temp2)); |
|
328 |
*to++= (char) ('0'+(char) (temp)); |
|
329 |
*to++= '-'; |
|
330 |
temp=time_tmp.day; |
|
331 |
temp2=temp/10; temp=temp-temp2*10; |
|
332 |
*to++= (char) ('0'+(char) (temp2)); |
|
333 |
*to++= (char) ('0'+(char) (temp)); |
|
334 |
*to++= ' '; |
|
335 |
temp=time_tmp.hour; |
|
336 |
temp2=temp/10; temp=temp-temp2*10; |
|
337 |
*to++= (char) ('0'+(char) (temp2)); |
|
338 |
*to++= (char) ('0'+(char) (temp)); |
|
339 |
*to++= ':'; |
|
340 |
temp=time_tmp.minute; |
|
341 |
temp2=temp/10; temp=temp-temp2*10; |
|
342 |
*to++= (char) ('0'+(char) (temp2)); |
|
343 |
*to++= (char) ('0'+(char) (temp)); |
|
344 |
*to++= ':'; |
|
345 |
temp=time_tmp.second; |
|
346 |
temp2=temp/10; temp=temp-temp2*10; |
|
347 |
*to++= (char) ('0'+(char) (temp2)); |
|
348 |
*to++= (char) ('0'+(char) (temp)); |
|
349 |
*to= 0; |
|
350 |
return val_buffer; |
|
351 |
}
|
|
352 |
||
353 |
||
482
by Brian Aker
Remove uint. |
354 |
bool Field_timestamp::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate) |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
355 |
{
|
356 |
long temp; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
357 |
Session *session= table ? table->in_use : current_session; |
358 |
session->time_zone_used= 1; |
|
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
359 |
#ifdef WORDS_BIGENDIAN
|
360 |
if (table && table->s->db_low_byte_first) |
|
361 |
temp=uint4korr(ptr); |
|
362 |
else
|
|
363 |
#endif
|
|
364 |
longget(temp,ptr); |
|
365 |
if (temp == 0L) |
|
366 |
{ /* Zero time is "000000" */ |
|
367 |
if (fuzzydate & TIME_NO_ZERO_DATE) |
|
368 |
return 1; |
|
212.6.6
by Mats Kindahl
Removing redundant use of casts in drizzled/ for memcmp(), memcpy(), memset(), and memmove(). |
369 |
memset(ltime, 0, sizeof(*ltime)); |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
370 |
}
|
371 |
else
|
|
372 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
373 |
session->variables.time_zone->gmt_sec_to_TIME(ltime, (my_time_t)temp); |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
374 |
}
|
375 |
return 0; |
|
376 |
}
|
|
377 |
||
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
378 |
bool Field_timestamp::get_time(DRIZZLE_TIME *ltime) |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
379 |
{
|
380 |
return Field_timestamp::get_date(ltime,0); |
|
381 |
}
|
|
382 |
||
383 |
||
384 |
bool Field_timestamp::send_binary(Protocol *protocol) |
|
385 |
{
|
|
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
386 |
DRIZZLE_TIME tm; |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
387 |
Field_timestamp::get_date(&tm, 0); |
388 |
return protocol->store(&tm); |
|
389 |
}
|
|
390 |
||
391 |
||
481
by Brian Aker
Remove all of uchar. |
392 |
int Field_timestamp::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr) |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
393 |
{
|
205
by Brian Aker
uint32 -> uin32_t |
394 |
int32_t a,b; |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
395 |
#ifdef WORDS_BIGENDIAN
|
396 |
if (table && table->s->db_low_byte_first) |
|
397 |
{
|
|
398 |
a=sint4korr(a_ptr); |
|
399 |
b=sint4korr(b_ptr); |
|
400 |
}
|
|
401 |
else
|
|
402 |
#endif
|
|
403 |
{
|
|
404 |
longget(a,a_ptr); |
|
405 |
longget(b,b_ptr); |
|
406 |
}
|
|
205
by Brian Aker
uint32 -> uin32_t |
407 |
return ((uint32_t) a < (uint32_t) b) ? -1 : ((uint32_t) a > (uint32_t) b) ? 1 : 0; |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
408 |
}
|
409 |
||
410 |
||
482
by Brian Aker
Remove uint. |
411 |
void Field_timestamp::sort_string(unsigned char *to,uint32_t length __attribute__((unused))) |
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
412 |
{
|
413 |
#ifdef WORDS_BIGENDIAN
|
|
414 |
if (!table || !table->s->db_low_byte_first) |
|
415 |
{
|
|
416 |
to[0] = ptr[0]; |
|
417 |
to[1] = ptr[1]; |
|
418 |
to[2] = ptr[2]; |
|
419 |
to[3] = ptr[3]; |
|
420 |
}
|
|
421 |
else
|
|
422 |
#endif
|
|
423 |
{
|
|
424 |
to[0] = ptr[3]; |
|
425 |
to[1] = ptr[2]; |
|
426 |
to[2] = ptr[1]; |
|
427 |
to[3] = ptr[0]; |
|
428 |
}
|
|
429 |
}
|
|
430 |
||
431 |
||
432 |
void Field_timestamp::sql_type(String &res) const |
|
433 |
{
|
|
434 |
res.set_ascii(STRING_WITH_LEN("timestamp")); |
|
435 |
}
|
|
436 |
||
437 |
||
438 |
void Field_timestamp::set_time() |
|
439 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
440 |
Session *session= table ? table->in_use : current_session; |
441 |
long tmp= (long) session->query_start(); |
|
173.1.6
by Toru Maesaka
ripped out TIMESTAMP and move to field/ |
442 |
set_notnull(); |
443 |
store_timestamp(tmp); |
|
444 |
}
|
|
445 |