1
// vim:ts=2 sts=2 sw=2:et ai:
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2
20
#include <drizzled/global.h>
3
21
#include <drizzled/error.h>
4
22
#include <drizzled/session.h>
6
24
#include <drizzled/function/time/date.h>
7
25
#include <drizzled/temporal_interval.h>
9
bool drizzled::TemporalInterval::value_from_item(Item *args, interval_type int_type, String *str_value)
27
bool drizzled::TemporalInterval::initFromItem(Item *args, interval_type int_type, String *str_value)
80
98
case INTERVAL_YEAR_MONTH: // Allow YEAR-MONTH YYYYYMM
81
if (get_interval_info(str,length,cs,2,array,0))
99
if (getIntervalInfo(str,length,cs,2,array,0))
83
101
year= (ulong) array[0];
84
102
month= (ulong) array[1];
86
104
case INTERVAL_DAY_HOUR:
87
if (get_interval_info(str,length,cs,2,array,0))
105
if (getIntervalInfo(str,length,cs,2,array,0))
89
107
day= (ulong) array[0];
90
108
hour= (ulong) array[1];
92
110
case INTERVAL_DAY_MICROSECOND:
93
if (get_interval_info(str,length,cs,5,array,1))
111
if (getIntervalInfo(str,length,cs,5,array,1))
95
113
day= (ulong) array[0];
96
114
hour= (ulong) array[1];
99
117
second_part= array[4];
101
119
case INTERVAL_DAY_MINUTE:
102
if (get_interval_info(str,length,cs,3,array,0))
120
if (getIntervalInfo(str,length,cs,3,array,0))
104
122
day= (ulong) array[0];
105
123
hour= (ulong) array[1];
106
124
minute= array[2];
108
126
case INTERVAL_DAY_SECOND:
109
if (get_interval_info(str,length,cs,4,array,0))
127
if (getIntervalInfo(str,length,cs,4,array,0))
111
129
day= (ulong) array[0];
112
130
hour= (ulong) array[1];
114
132
second= array[3];
116
134
case INTERVAL_HOUR_MICROSECOND:
117
if (get_interval_info(str,length,cs,4,array,1))
135
if (getIntervalInfo(str,length,cs,4,array,1))
119
137
hour= (ulong) array[0];
120
138
minute= array[1];
122
140
second_part= array[3];
124
142
case INTERVAL_HOUR_MINUTE:
125
if (get_interval_info(str,length,cs,2,array,0))
143
if (getIntervalInfo(str,length,cs,2,array,0))
127
145
hour= (ulong) array[0];
128
146
minute= array[1];
130
148
case INTERVAL_HOUR_SECOND:
131
if (get_interval_info(str,length,cs,3,array,0))
149
if (getIntervalInfo(str,length,cs,3,array,0))
133
151
hour= (ulong) array[0];
134
152
minute= array[1];
135
153
second= array[2];
137
155
case INTERVAL_MINUTE_MICROSECOND:
138
if (get_interval_info(str,length,cs,3,array,1))
156
if (getIntervalInfo(str,length,cs,3,array,1))
140
158
minute= array[0];
141
159
second= array[1];
142
160
second_part= array[2];
144
162
case INTERVAL_MINUTE_SECOND:
145
if (get_interval_info(str,length,cs,2,array,0))
163
if (getIntervalInfo(str,length,cs,2,array,0))
147
165
minute= array[0];
148
166
second= array[1];
150
168
case INTERVAL_SECOND_MICROSECOND:
151
if (get_interval_info(str,length,cs,2,array,1))
169
if (getIntervalInfo(str,length,cs,2,array,1))
153
171
second= array[0];
154
172
second_part= array[1];
271
bool drizzled::TemporalInterval::get_interval_info(const char *str,uint32_t length, const CHARSET_INFO * const cs,
289
bool drizzled::TemporalInterval::getIntervalInfo(const char *str,uint32_t length, const CHARSET_INFO * const cs,
272
290
uint32_t count, uint64_t *values,
273
291
bool transform_msec)
275
293
const char *end=str+length;
277
296
while (str != end && !my_isdigit(cs,*str))
280
for (i=0 ; i < count ; i++)
299
for (x= 0 ; x < count ; x++)
283
302
const char *start= str;
284
for (value=0; str != end && my_isdigit(cs,*str) ; str++)
303
for (value= 0 ; str != end && my_isdigit(cs,*str) ; str++)
285
304
value= value * 10L + (int64_t) (*str - '0');
286
if (transform_msec && i == count - 1) // microseconds always last
305
if (transform_msec && x == count - 1) // microseconds always last
288
307
long msec_length= 6 - (str - start);
289
308
if (msec_length > 0)
290
309
value*= (long) log_10_int[msec_length];
293
312
while (str != end && !my_isdigit(cs,*str))
295
if (str == end && i != count-1)
314
if (str == end && x != count-1)
298
/* Change values[0...i-1] -> values[0...count-1] */
299
bmove_upp((unsigned char*) (values+count), (unsigned char*) (values+i),
301
memset(values, 0, sizeof(*values)*(count-i));
317
/* Change values[0...x-1] -> values[0...count-1] */
318
bmove_upp((unsigned char*) (values+count), (unsigned char*) (values+x),
320
memset(values, 0, sizeof(*values)*(count-x));