~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/timestamp.cc

  • Committer: Monty Taylor
  • Date: 2008-10-23 23:53:49 UTC
  • mto: This revision was merged to the branch mainline in revision 557.
  • Revision ID: monty@inaugust.com-20081023235349-317wgwqwgccuacmq
SplitĀ outĀ nested_join.h.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
24
21
 
25
22
#include <drizzled/server_includes.h>
26
23
#include <drizzled/field/timestamp.h>
 
24
#include <drizzled/error.h>
27
25
 
28
26
/**
29
27
  TIMESTAMP type holds datetime values in range from 1970-01-01 00:00:01 UTC to 
150
148
  int error;
151
149
  bool have_smth_to_conv;
152
150
  bool in_dst_time_gap;
153
 
  THD *thd= table ? table->in_use : current_thd;
 
151
  Session *session= table ? table->in_use : current_session;
154
152
 
155
153
  /* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */
156
154
  have_smth_to_conv= (str_to_datetime(from, len, &l_time, 1, &error) >
166
164
  /* Only convert a correct date (not a zero date) */
167
165
  if (have_smth_to_conv && l_time.month)
168
166
  {
169
 
    if (!(tmp= TIME_to_timestamp(thd, &l_time, &in_dst_time_gap)))
 
167
    if (!(tmp= TIME_to_timestamp(session, &l_time, &in_dst_time_gap)))
170
168
    {
171
169
      set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
172
170
                           ER_WARN_DATA_OUT_OF_RANGE,
209
207
  my_time_t timestamp= 0;
210
208
  int error;
211
209
  bool in_dst_time_gap;
212
 
  THD *thd= table ? table->in_use : current_thd;
 
210
  Session *session= table ? table->in_use : current_session;
213
211
 
214
212
  /* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */
215
 
  int64_t tmp= number_to_datetime(nr, &l_time, (thd->variables.sql_mode &
 
213
  int64_t tmp= number_to_datetime(nr, &l_time, (session->variables.sql_mode &
216
214
                                                 MODE_NO_ZERO_DATE), &error);
217
215
  if (tmp == INT64_C(-1))
218
216
  {
221
219
 
222
220
  if (!error && tmp)
223
221
  {
224
 
    if (!(timestamp= TIME_to_timestamp(thd, &l_time, &in_dst_time_gap)))
 
222
    if (!(timestamp= TIME_to_timestamp(session, &l_time, &in_dst_time_gap)))
225
223
    {
226
224
      set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
227
225
                           ER_WARN_DATA_OUT_OF_RANGE,
253
251
{
254
252
  uint32_t temp;
255
253
  DRIZZLE_TIME time_tmp;
256
 
  THD  *thd= table ? table->in_use : current_thd;
 
254
  Session  *session= table ? table->in_use : current_session;
257
255
 
258
 
  thd->time_zone_used= 1;
 
256
  session->time_zone_used= 1;
259
257
#ifdef WORDS_BIGENDIAN
260
258
  if (table && table->s->db_low_byte_first)
261
259
    temp=uint4korr(ptr);
266
264
  if (temp == 0L)                               // No time
267
265
    return(0);                                  /* purecov: inspected */
268
266
  
269
 
  thd->variables.time_zone->gmt_sec_to_TIME(&time_tmp, (my_time_t)temp);
 
267
  session->variables.time_zone->gmt_sec_to_TIME(&time_tmp, (my_time_t)temp);
270
268
  
271
269
  return time_tmp.year * INT64_C(10000000000) +
272
270
         time_tmp.month * INT64_C(100000000) +
279
277
{
280
278
  uint32_t temp, temp2;
281
279
  DRIZZLE_TIME time_tmp;
282
 
  THD *thd= table ? table->in_use : current_thd;
 
280
  Session *session= table ? table->in_use : current_session;
283
281
  char *to;
284
282
 
285
283
  val_buffer->alloc(field_length+1);
286
284
  to= (char*) val_buffer->ptr();
287
285
  val_buffer->length(field_length);
288
286
 
289
 
  thd->time_zone_used= 1;
 
287
  session->time_zone_used= 1;
290
288
#ifdef WORDS_BIGENDIAN
291
289
  if (table && table->s->db_low_byte_first)
292
290
    temp=uint4korr(ptr);
301
299
  }
302
300
  val_buffer->set_charset(&my_charset_bin);     // Safety
303
301
  
304
 
  thd->variables.time_zone->gmt_sec_to_TIME(&time_tmp,(my_time_t)temp);
 
302
  session->variables.time_zone->gmt_sec_to_TIME(&time_tmp,(my_time_t)temp);
305
303
 
306
304
  temp= time_tmp.year % 100;
307
305
  if (temp < YY_PART_YEAR - 1)
350
348
bool Field_timestamp::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate)
351
349
{
352
350
  long temp;
353
 
  THD *thd= table ? table->in_use : current_thd;
354
 
  thd->time_zone_used= 1;
 
351
  Session *session= table ? table->in_use : current_session;
 
352
  session->time_zone_used= 1;
355
353
#ifdef WORDS_BIGENDIAN
356
354
  if (table && table->s->db_low_byte_first)
357
355
    temp=uint4korr(ptr);
366
364
  }
367
365
  else
368
366
  {
369
 
    thd->variables.time_zone->gmt_sec_to_TIME(ltime, (my_time_t)temp);
 
367
    session->variables.time_zone->gmt_sec_to_TIME(ltime, (my_time_t)temp);
370
368
  }
371
369
  return 0;
372
370
}
433
431
 
434
432
void Field_timestamp::set_time()
435
433
{
436
 
  THD *thd= table ? table->in_use : current_thd;
437
 
  long tmp= (long) thd->query_start();
 
434
  Session *session= table ? table->in_use : current_session;
 
435
  long tmp= (long) session->query_start();
438
436
  set_notnull();
439
437
  store_timestamp(tmp);
440
438
}