~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/date.cc

  • Committer: Brian Aker
  • Date: 2010-07-15 23:18:11 UTC
  • mto: This revision was merged to the branch mainline in revision 1661.
  • Revision ID: brian@gaz-20100715231811-c5erivy1nvwf6bii
Merge in move identifier work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
#include "config.h"
22
 
#include <boost/lexical_cast.hpp>
23
 
 
24
22
#include "drizzled/field/date.h"
25
23
#include "drizzled/error.h"
26
24
#include "drizzled/table.h"
64
62
                         uint32_t len,
65
63
                         const CHARSET_INFO * const )
66
64
{
 
65
#ifdef NOTDEFINED
 
66
  long tmp;
 
67
  DRIZZLE_TIME l_time;
 
68
  int error;
 
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,
 
72
                            (TIME_FUZZY_DATE |
 
73
                             (session->variables.sql_mode &
 
74
                              (MODE_NO_ZERO_DATE | MODE_INVALID_DATES))),
 
75
                            &error)) <= DRIZZLE_TIMESTAMP_ERROR)
 
76
  {
 
77
    tmp= 0;
 
78
    error= 2;
 
79
  }
 
80
  else
 
81
  {
 
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)
 
86
  }
 
87
 
 
88
  if (error)
 
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);
 
93
 
 
94
  int3store(ptr, tmp);
 
95
#endif /* NOTDEFINED */
67
96
  /* 
68
97
   * Try to create a DateTime from the supplied string.  Throw an error
69
98
   * if unable to create a valid DateTime.  A DateTime is used so that
78
107
    return 2;
79
108
  }
80
109
  /* Create the stored integer format. @TODO This should go away. Should be up to engine... */
81
 
  uint32_t int_value= (temporal.years() * 10000) + (temporal.months() * 100) + temporal.days();
82
 
  int4store(ptr, int_value);
 
110
  uint32_t int_value= (temporal.years() * 16 * 32) + (temporal.months() * 32) + temporal.days();
 
111
  int3store(ptr, int_value);
83
112
  return 0;
84
113
}
85
114
 
110
139
  DateTime temporal;
111
140
  if (! temporal.from_int64_t(from))
112
141
  {
113
 
    /* Convert the integer to a string using boost::lexical_cast */
114
 
    std::string tmp(boost::lexical_cast<std::string>(from)); 
 
142
    /* Convert the integer to a string using stringstream */
 
143
    std::stringstream ss;
 
144
    std::string tmp;
 
145
    ss << from; ss >> tmp;
115
146
 
116
147
    my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp.c_str());
117
148
    return 2;
118
149
  }
119
150
 
120
151
  /* Create the stored integer format. @TODO This should go away. Should be up to engine... */
121
 
  uint32_t int_value= (temporal.years() * 10000) + (temporal.months() * 100) + temporal.days();
122
 
  int4store(ptr, int_value);
 
152
  uint32_t int_value= (temporal.years() * 16 * 32) + (temporal.months() * 32) + temporal.days();
 
153
  int3store(ptr, int_value);
123
154
  return 0;
124
155
}
125
156
 
131
162
  if (time_type == DRIZZLE_TIMESTAMP_DATE ||
132
163
      time_type == DRIZZLE_TIMESTAMP_DATETIME)
133
164
  {
134
 
    tmp= ltime->year*10000 + ltime->month*100 + ltime->day;
 
165
    tmp=ltime->year*16*32+ltime->month*32+ltime->day;
135
166
    if (check_date(ltime, tmp != 0,
136
167
                   (TIME_FUZZY_DATE |
137
168
                    (current_session->variables.sql_mode &
161
192
    error= 1;
162
193
    set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
163
194
  }
164
 
  int4store(ptr,tmp);
 
195
  int3store(ptr,tmp);
165
196
  return error;
166
197
}
167
198
 
176
207
 
177
208
  ASSERT_COLUMN_MARKED_FOR_READ;
178
209
 
179
 
  j= uint4korr(ptr);
 
210
  j= uint3korr(ptr);
 
211
  j= (j % 32L)+(j / 32L % 16L)*100L + (j/(16L*32L))*10000L;
180
212
 
181
213
  return (int64_t) j;
182
214
}
183
215
 
184
 
String *Field_date::val_str(String *val_buffer, String *)
 
216
String *Field_date::val_str(String *val_buffer,
 
217
                               String *)
185
218
{
186
219
  val_buffer->alloc(field_length);
187
220
  val_buffer->length(field_length);
188
 
  uint32_t tmp=(uint32_t) uint4korr(ptr);
189
 
  int32_t part;
 
221
  uint32_t tmp=(uint32_t) uint3korr(ptr);
 
222
  int part;
190
223
  char *pos=(char*) val_buffer->ptr()+10;
191
224
 
192
225
  ASSERT_COLUMN_MARKED_FOR_READ;
193
226
 
194
227
  /* Open coded to get more speed */
195
228
  *pos--=0;                                     // End NULL
196
 
  part=(int32_t) (tmp % 100);
197
 
  *pos--= (char) ('0'+part%10);
198
 
  *pos--= (char) ('0'+part/10);
199
 
  *pos--= '-';
200
 
  part=(int32_t) (tmp/100%100);
201
 
  *pos--= (char) ('0'+part%10);
202
 
  *pos--= (char) ('0'+part/10);
203
 
  *pos--= '-';
204
 
  part=(int32_t) (tmp/10000);
 
229
  part=(int) (tmp & 31);
 
230
  *pos--= (char) ('0'+part%10);
 
231
  *pos--= (char) ('0'+part/10);
 
232
  *pos--= '-';
 
233
  part=(int) (tmp >> 5 & 15);
 
234
  *pos--= (char) ('0'+part%10);
 
235
  *pos--= (char) ('0'+part/10);
 
236
  *pos--= '-';
 
237
  part=(int) (tmp >> 9);
205
238
  *pos--= (char) ('0'+part%10); part/=10;
206
239
  *pos--= (char) ('0'+part%10); part/=10;
207
240
  *pos--= (char) ('0'+part%10); part/=10;
211
244
 
212
245
bool Field_date::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
213
246
{
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);
 
247
  uint32_t tmp=(uint32_t) uint3korr(ptr);
 
248
  ltime->day=   tmp & 31;
 
249
  ltime->month= (tmp >> 5) & 15;
 
250
  ltime->year=  (tmp >> 9);
218
251
  ltime->time_type= DRIZZLE_TIMESTAMP_DATE;
219
252
  ltime->hour= ltime->minute= ltime->second= ltime->second_part= ltime->neg= 0;
220
253
  return ((!(fuzzydate & TIME_FUZZY_DATE) && (!ltime->month || !ltime->day)) ?
229
262
int Field_date::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
230
263
{
231
264
  uint32_t a,b;
232
 
  a=(uint32_t) uint4korr(a_ptr);
233
 
  b=(uint32_t) uint4korr(b_ptr);
 
265
  a=(uint32_t) uint3korr(a_ptr);
 
266
  b=(uint32_t) uint3korr(b_ptr);
234
267
  return (a < b) ? -1 : (a > b) ? 1 : 0;
235
268
}
236
269
 
237
270
void Field_date::sort_string(unsigned char *to,uint32_t )
238
271
{
239
 
  to[0] = ptr[3];
240
 
  to[1] = ptr[2];
241
 
  to[2] = ptr[1];
242
 
  to[3] = ptr[0];
 
272
  to[0] = ptr[2];
 
273
  to[1] = ptr[1];
 
274
  to[2] = ptr[0];
243
275
}
244
276
 
245
277
void Field_date::sql_type(String &res) const