~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/time_functions.cc

  • Committer: Brian Aker
  • Date: 2011-01-06 05:17:09 UTC
  • Revision ID: brian@tangent.org-20110106051709-oa0se8ur02uc6i9o
Added native functions into the function table.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008-2009 Sun Microsystems
 
4
 *  Copyright (C) 2008-2009 Sun Microsystems, Inc.
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
39
39
}
40
40
 
41
41
 
42
 
uint32_t calc_week(DRIZZLE_TIME *l_time, uint32_t week_behaviour, uint32_t *year)
 
42
uint32_t calc_week(type::Time *l_time, uint32_t week_behaviour, uint32_t *year)
43
43
{
44
44
  uint32_t days;
45
45
  uint32_t daynr= calc_daynr(l_time->year,l_time->month,l_time->day);
127
127
enum enum_drizzle_timestamp_type
128
128
str_to_datetime_with_warn(const char *str, 
129
129
                          uint32_t length, 
130
 
                          DRIZZLE_TIME *l_time,
 
130
                          type::Time *l_time,
131
131
                          uint32_t flags)
132
132
{
133
133
  int was_cut;
 
134
  enum enum_drizzle_timestamp_type ts_type;
134
135
  Session *session= current_session;
135
 
  enum enum_drizzle_timestamp_type ts_type;
136
136
 
137
137
  ts_type= str_to_datetime(str, length, l_time,
138
138
                           (flags | (session->variables.sql_mode &
140
140
                                      MODE_NO_ZERO_DATE))),
141
141
                           &was_cut);
142
142
  if (was_cut || ts_type <= DRIZZLE_TIMESTAMP_ERROR)
143
 
    make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
143
    make_truncated_value_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
144
144
                                 str, length, ts_type,  NULL);
145
145
  return ts_type;
146
146
}
147
147
 
148
148
 
149
149
bool
150
 
str_to_time_with_warn(const char *str, uint32_t length, DRIZZLE_TIME *l_time)
 
150
str_to_time_with_warn(const char *str, uint32_t length, type::Time *l_time)
151
151
{
152
152
  int warning;
153
153
  bool ret_val= str_to_time(str, length, l_time, &warning);
158
158
}
159
159
 
160
160
 
161
 
void localtime_to_TIME(DRIZZLE_TIME *to, struct tm *from)
 
161
void localtime_to_TIME(type::Time *to, struct tm *from)
162
162
{
163
163
  to->neg=0;
164
164
  to->second_part=0;
170
170
  to->second=   (int) from->tm_sec;
171
171
}
172
172
 
173
 
void make_date(const DRIZZLE_TIME *l_time, String *str)
 
173
void make_time(const type::Time *l_time, String *str)
 
174
{
 
175
  str->alloc(MAX_DATE_STRING_REP_LENGTH);
 
176
  uint32_t length= (uint32_t) my_time_to_str(l_time, str->c_ptr());
 
177
  str->length(length);
 
178
  str->set_charset(&my_charset_bin);
 
179
}
 
180
 
 
181
void make_date(const type::Time *l_time, String *str)
174
182
{
175
183
  str->alloc(MAX_DATE_STRING_REP_LENGTH);
176
184
  uint32_t length= (uint32_t) my_date_to_str(l_time, str->c_ptr());
179
187
}
180
188
 
181
189
 
182
 
void make_datetime(const DRIZZLE_TIME *l_time, String *str)
 
190
void make_datetime(const type::Time *l_time, String *str)
183
191
{
184
192
  str->alloc(MAX_DATE_STRING_REP_LENGTH);
185
193
  uint32_t length= (uint32_t) my_datetime_to_str(l_time, str->c_ptr());
216
224
      break;
217
225
  }
218
226
  if (field_name)
 
227
  {
219
228
    cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff),
220
229
                       ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
221
230
                       type_str, str.c_ptr(), field_name,
222
231
                       (uint32_t) session->row_count);
 
232
  }
223
233
  else
224
234
  {
225
235
    if (time_type > DRIZZLE_TIMESTAMP_ERROR)
236
246
 
237
247
 
238
248
bool
239
 
calc_time_diff(DRIZZLE_TIME *l_time1, DRIZZLE_TIME *l_time2, int l_sign, int64_t *seconds_out,
 
249
calc_time_diff(type::Time *l_time1, type::Time *l_time2, int l_sign, int64_t *seconds_out,
240
250
               long *microseconds_out)
241
251
{
242
252
  long days;