~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/date.cc

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* - mode: c++ c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
4
 *  Copyright (C) 2008 MySQL
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
 
21
#ifdef USE_PRAGMA_IMPLEMENTATION
 
22
#pragma implementation                          // gcc: Class implementation
 
23
#endif
21
24
 
22
25
#include <drizzled/server_includes.h>
23
26
#include <drizzled/field/date.h>
24
 
#include <drizzled/error.h>
25
 
#include CMATH_H
26
 
 
27
 
#if defined(CMATH_NAMESPACE)
28
 
using namespace CMATH_NAMESPACE;
29
 
#endif
30
27
 
31
28
/****************************************************************************
32
29
** The new date type
54
51
*/
55
52
 
56
53
int Field_newdate::store(const char *from,
57
 
                         uint32_t len,
 
54
                         uint len,
58
55
                         const CHARSET_INFO * const cs __attribute__((unused)))
59
56
{
60
57
  long tmp;
61
58
  DRIZZLE_TIME l_time;
62
59
  int error;
63
 
  Session *session= table ? table->in_use : current_session;
 
60
  THD *thd= table ? table->in_use : current_thd;
64
61
  enum enum_drizzle_timestamp_type ret;
65
62
  if ((ret= str_to_datetime(from, len, &l_time,
66
63
                            (TIME_FUZZY_DATE |
67
 
                             (session->variables.sql_mode &
 
64
                             (thd->variables.sql_mode &
68
65
                              (MODE_NO_ZERO_DATE | MODE_INVALID_DATES))),
69
66
                            &error)) <= DRIZZLE_TIMESTAMP_ERROR)
70
67
  {
109
106
  DRIZZLE_TIME l_time;
110
107
  int64_t tmp;
111
108
  int error;
112
 
  Session *session= table ? table->in_use : current_session;
 
109
  THD *thd= table ? table->in_use : current_thd;
113
110
  if (number_to_datetime(nr, &l_time,
114
111
                         (TIME_FUZZY_DATE |
115
 
                          (session->variables.sql_mode &
 
112
                          (thd->variables.sql_mode &
116
113
                           (MODE_NO_ZERO_DATE | MODE_INVALID_DATES))),
117
 
                         &error) == INT64_C(-1))
 
114
                         &error) == -1LL)
118
115
  {
119
116
    tmp= 0L;
120
117
    error= 2;
138
135
}
139
136
 
140
137
 
141
 
int Field_newdate::store_time(DRIZZLE_TIME *ltime,
142
 
                              enum enum_drizzle_timestamp_type time_type)
 
138
int Field_newdate::store_time(DRIZZLE_TIME *ltime,timestamp_type time_type)
143
139
{
144
140
  long tmp;
145
141
  int error= 0;
149
145
    tmp=ltime->year*16*32+ltime->month*32+ltime->day;
150
146
    if (check_date(ltime, tmp != 0,
151
147
                   (TIME_FUZZY_DATE |
152
 
                    (current_session->variables.sql_mode &
 
148
                    (current_thd->variables.sql_mode &
153
149
                     (MODE_NO_ZERO_DATE | MODE_INVALID_DATES))), &error))
154
150
    {
155
151
      char buff[MAX_DATE_STRING_REP_LENGTH];
156
 
      String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
 
152
      String str(buff, sizeof(buff), &my_charset_latin1);
157
153
      make_date((DATE_TIME_FORMAT *) 0, ltime, &str);
158
154
      set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED,
159
155
                           str.ptr(), str.length(), DRIZZLE_TIMESTAMP_DATE, 1);
162
158
        (ltime->hour || ltime->minute || ltime->second || ltime->second_part))
163
159
    {
164
160
      char buff[MAX_DATE_STRING_REP_LENGTH];
165
 
      String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
 
161
      String str(buff, sizeof(buff), &my_charset_latin1);
166
162
      make_datetime((DATE_TIME_FORMAT *) 0, ltime, &str);
167
163
      set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_NOTE,
168
164
                           ER_WARN_DATA_TRUNCATED,
231
227
}
232
228
 
233
229
 
234
 
bool Field_newdate::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
230
bool Field_newdate::get_date(DRIZZLE_TIME *ltime,uint fuzzydate)
235
231
{
236
232
  uint32_t tmp=(uint32_t) uint3korr(ptr);
237
233
  ltime->day=   tmp & 31;
250
246
}
251
247
 
252
248
 
253
 
int Field_newdate::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
 
249
int Field_newdate::cmp(const uchar *a_ptr, const uchar *b_ptr)
254
250
{
255
251
  uint32_t a,b;
256
252
  a=(uint32_t) uint3korr(a_ptr);
259
255
}
260
256
 
261
257
 
262
 
void Field_newdate::sort_string(unsigned char *to,uint32_t length __attribute__((unused)))
 
258
void Field_newdate::sort_string(uchar *to,uint length __attribute__((unused)))
263
259
{
264
260
  to[0] = ptr[2];
265
261
  to[1] = ptr[1];