~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/time.cc

  • Committer: Brian Aker
  • Date: 2008-10-20 04:28:21 UTC
  • mto: (492.3.21 drizzle-clean-code)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: brian@tangent.org-20081020042821-rqqdrccuu8195k3y
Second pass of thd cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
222
222
                          uint32_t flags)
223
223
{
224
224
  int was_cut;
225
 
  Session *thd= current_thd;
 
225
  Session *session= current_session;
226
226
  enum enum_drizzle_timestamp_type ts_type;
227
227
  
228
228
  ts_type= str_to_datetime(str, length, l_time,
229
 
                           (flags | (thd->variables.sql_mode &
 
229
                           (flags | (session->variables.sql_mode &
230
230
                                     (MODE_INVALID_DATES |
231
231
                                      MODE_NO_ZERO_DATE))),
232
232
                           &was_cut);
233
233
  if (was_cut || ts_type <= DRIZZLE_TIMESTAMP_ERROR)
234
 
    make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
234
    make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
235
235
                                 str, length, ts_type,  NULL);
236
236
  return ts_type;
237
237
}
243
243
 
244
244
  SYNOPSIS
245
245
    TIME_to_timestamp()
246
 
      thd             - current thread
 
246
      session             - current thread
247
247
      t               - datetime in broken-down representation, 
248
248
      in_dst_time_gap - pointer to bool which is set to true if t represents
249
249
                        value which doesn't exists (falls into the spring 
254
254
     0 - t contains datetime value which is out of TIMESTAMP range.
255
255
     
256
256
*/
257
 
my_time_t TIME_to_timestamp(Session *thd, const DRIZZLE_TIME *t, bool *in_dst_time_gap)
 
257
my_time_t TIME_to_timestamp(Session *session, const DRIZZLE_TIME *t, bool *in_dst_time_gap)
258
258
{
259
259
  my_time_t timestamp;
260
260
 
261
261
  *in_dst_time_gap= 0;
262
 
  thd->time_zone_used= 1;
 
262
  session->time_zone_used= 1;
263
263
 
264
 
  timestamp= thd->variables.time_zone->TIME_to_gmt_sec(t, in_dst_time_gap);
 
264
  timestamp= session->variables.time_zone->TIME_to_gmt_sec(t, in_dst_time_gap);
265
265
  if (timestamp)
266
266
  {
267
267
    return timestamp;
285
285
  int warning;
286
286
  bool ret_val= str_to_time(str, length, l_time, &warning);
287
287
  if (ret_val || warning)
288
 
    make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
288
    make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
289
289
                                 str, length, DRIZZLE_TIMESTAMP_TIME, NULL);
290
290
  return ret_val;
291
291
}
603
603
 
604
604
  SYNOPSIS
605
605
    date_and_time_format_copy()
606
 
    thd                 Set if variable should be allocated in thread mem
 
606
    session                     Set if variable should be allocated in thread mem
607
607
    format              format to copy
608
608
 
609
609
  NOTES
614
614
    new object
615
615
*/
616
616
 
617
 
DATE_TIME_FORMAT *date_time_format_copy(Session *thd, DATE_TIME_FORMAT *format)
 
617
DATE_TIME_FORMAT *date_time_format_copy(Session *session, DATE_TIME_FORMAT *format)
618
618
{
619
619
  DATE_TIME_FORMAT *new_format;
620
620
  uint32_t length= sizeof(*format) + format->format.length + 1;
621
621
 
622
 
  if (thd)
623
 
    new_format= (DATE_TIME_FORMAT *) thd->alloc(length);
 
622
  if (session)
 
623
    new_format= (DATE_TIME_FORMAT *) session->alloc(length);
624
624
  else
625
625
    new_format=  (DATE_TIME_FORMAT *) my_malloc(length, MYF(MY_WME));
626
626
  if (new_format)
714
714
}
715
715
 
716
716
 
717
 
void make_truncated_value_warning(Session *thd, DRIZZLE_ERROR::enum_warning_level level,
 
717
void make_truncated_value_warning(Session *session, DRIZZLE_ERROR::enum_warning_level level,
718
718
                                  const char *str_val,
719
719
                                  uint32_t str_length,
720
720
                                  enum enum_drizzle_timestamp_type time_type,
744
744
    cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff),
745
745
                       ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
746
746
                       type_str, str.c_ptr(), field_name,
747
 
                       (uint32_t) thd->row_count);
 
747
                       (uint32_t) session->row_count);
748
748
  else
749
749
  {
750
750
    if (time_type > DRIZZLE_TIMESTAMP_ERROR)
755
755
      cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff),
756
756
                         ER(ER_WRONG_VALUE), type_str, str.c_ptr());
757
757
  }
758
 
  push_warning(thd, level,
 
758
  push_warning(session, level,
759
759
               ER_TRUNCATED_WRONG_VALUE, warn_buff);
760
760
}
761
761
 
862
862
  return 0;                                     // Ok
863
863
 
864
864
invalid_date:
865
 
  push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
865
  push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
866
866
                      ER_DATETIME_FUNCTION_OVERFLOW,
867
867
                      ER(ER_DATETIME_FUNCTION_OVERFLOW),
868
868
                      "datetime");