~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item_timefunc.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:
119
119
  if (!warning)
120
120
    return 0;
121
121
 
122
 
  make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
122
  make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
123
123
                               str->ptr(), str->length(),
124
124
                               DRIZZLE_TIMESTAMP_TIME, NULL);
125
125
  return make_datetime(format, ltime, str);
146
146
    return 1;
147
147
  if (warning)
148
148
  {
149
 
    make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
149
    make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
150
150
                                 str->ptr(), str->length(),
151
151
                                 DRIZZLE_TIMESTAMP_TIME, NULL);
152
152
    make_time(format, l_time, str);
207
207
  char buf[22];
208
208
  int len= (int)(int64_t10_to_str(seconds, buf, unsigned_flag ? 10 : -10)
209
209
                 - buf);
210
 
  make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
210
  make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
211
211
                               buf, len, DRIZZLE_TIMESTAMP_TIME,
212
212
                               NULL);
213
213
  
575
575
    {
576
576
      if (!my_isspace(&my_charset_utf8_general_ci,*val))
577
577
      {
578
 
        make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
578
        make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
579
579
                                     val_begin, length,
580
580
                                     cached_timestamp_type, NULL);
581
581
        break;
588
588
  {
589
589
    char buff[128];
590
590
    strmake(buff, val_begin, cmin(length, (uint)sizeof(buff)-1));
591
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
591
    push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
592
592
                        ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE),
593
593
                        date_time_type, buff, "str_to_date");
594
594
  }
608
608
  uint32_t weekday;
609
609
  ulong length;
610
610
  const char *ptr, *end;
611
 
  Session *thd= current_thd;
612
 
  MY_LOCALE *locale= thd->variables.lc_time_names;
 
611
  Session *session= current_session;
 
612
  MY_LOCALE *locale= session->variables.lc_time_names;
613
613
 
614
614
  str->length(0);
615
615
 
1022
1022
  assert(fixed == 1);
1023
1023
  const char *month_name;
1024
1024
  uint32_t   month= (uint) val_int();
1025
 
  Session *thd= current_thd;
 
1025
  Session *session= current_session;
1026
1026
 
1027
1027
  if (null_value || !month)
1028
1028
  {
1030
1030
    return (String*) 0;
1031
1031
  }
1032
1032
  null_value=0;
1033
 
  month_name= thd->variables.lc_time_names->month_names->type_names[month-1];
 
1033
  month_name= session->variables.lc_time_names->month_names->type_names[month-1];
1034
1034
  str->set(month_name, strlen(month_name), system_charset_info);
1035
1035
  return str;
1036
1036
}
1162
1162
  assert(fixed == 1);
1163
1163
  uint32_t weekday=(uint) val_int();            // Always Item_func_daynr()
1164
1164
  const char *day_name;
1165
 
  Session *thd= current_thd;
 
1165
  Session *session= current_session;
1166
1166
 
1167
1167
  if (null_value)
1168
1168
    return (String*) 0;
1169
1169
  
1170
 
  day_name= thd->variables.lc_time_names->day_names->type_names[weekday];
 
1170
  day_name= session->variables.lc_time_names->day_names->type_names[weekday];
1171
1171
  str->set(day_name, strlen(day_name), system_charset_info);
1172
1172
  return str;
1173
1173
}
1243
1243
  
1244
1244
  assert(fixed == 1);
1245
1245
  if (arg_count == 0)
1246
 
    return (int64_t) current_thd->query_start();
 
1246
    return (int64_t) current_session->query_start();
1247
1247
  if (args[0]->type() == FIELD_ITEM)
1248
1248
  {                                             // Optimize timestamp field
1249
1249
    Field *field=((Item_field*) args[0])->field;
1262
1262
    return 0;
1263
1263
  }
1264
1264
  
1265
 
  return (int64_t) TIME_to_timestamp(current_thd, &ltime, &not_used);
 
1265
  return (int64_t) TIME_to_timestamp(current_session, &ltime, &not_used);
1266
1266
}
1267
1267
 
1268
1268
 
1505
1505
*/
1506
1506
void Item_func_curdate_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
1507
1507
{
1508
 
  Session *thd= current_thd;
1509
 
  thd->variables.time_zone->gmt_sec_to_TIME(now_time, 
1510
 
                                             (my_time_t)thd->query_start());
1511
 
  thd->time_zone_used= 1;
 
1508
  Session *session= current_session;
 
1509
  session->variables.time_zone->gmt_sec_to_TIME(now_time, 
 
1510
                                             (my_time_t)session->query_start());
 
1511
  session->time_zone_used= 1;
1512
1512
}
1513
1513
 
1514
1514
 
1519
1519
void Item_func_curdate_utc::store_now_in_TIME(DRIZZLE_TIME *now_time)
1520
1520
{
1521
1521
  my_tz_UTC->gmt_sec_to_TIME(now_time, 
1522
 
                             (my_time_t)(current_thd->query_start()));
 
1522
                             (my_time_t)(current_session->query_start()));
1523
1523
  /* 
1524
1524
    We are not flagging this query as using time zone, since it uses fixed
1525
1525
    UTC-SYSTEM time-zone.
1562
1562
*/
1563
1563
void Item_func_curtime_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
1564
1564
{
1565
 
  Session *thd= current_thd;
1566
 
  thd->variables.time_zone->gmt_sec_to_TIME(now_time, 
1567
 
                                             (my_time_t)thd->query_start());
1568
 
  thd->time_zone_used= 1;
 
1565
  Session *session= current_session;
 
1566
  session->variables.time_zone->gmt_sec_to_TIME(now_time, 
 
1567
                                             (my_time_t)session->query_start());
 
1568
  session->time_zone_used= 1;
1569
1569
}
1570
1570
 
1571
1571
 
1576
1576
void Item_func_curtime_utc::store_now_in_TIME(DRIZZLE_TIME *now_time)
1577
1577
{
1578
1578
  my_tz_UTC->gmt_sec_to_TIME(now_time, 
1579
 
                             (my_time_t)(current_thd->query_start()));
 
1579
                             (my_time_t)(current_session->query_start()));
1580
1580
  /* 
1581
1581
    We are not flagging this query as using time zone, since it uses fixed
1582
1582
    UTC-SYSTEM time-zone.
1611
1611
*/
1612
1612
void Item_func_now_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
1613
1613
{
1614
 
  Session *thd= current_thd;
1615
 
  thd->variables.time_zone->gmt_sec_to_TIME(now_time, 
1616
 
                                             (my_time_t)thd->query_start());
1617
 
  thd->time_zone_used= 1;
 
1614
  Session *session= current_session;
 
1615
  session->variables.time_zone->gmt_sec_to_TIME(now_time, 
 
1616
                                             (my_time_t)session->query_start());
 
1617
  session->time_zone_used= 1;
1618
1618
}
1619
1619
 
1620
1620
 
1625
1625
void Item_func_now_utc::store_now_in_TIME(DRIZZLE_TIME *now_time)
1626
1626
{
1627
1627
  my_tz_UTC->gmt_sec_to_TIME(now_time, 
1628
 
                             (my_time_t)(current_thd->query_start()));
 
1628
                             (my_time_t)(current_session->query_start()));
1629
1629
  /* 
1630
1630
    We are not flagging this query as using time zone, since it uses fixed
1631
1631
    UTC-SYSTEM time-zone.
1654
1654
*/
1655
1655
void Item_func_sysdate_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
1656
1656
{
1657
 
  Session *thd= current_thd;
1658
 
  thd->variables.time_zone->gmt_sec_to_TIME(now_time, (my_time_t) my_time(0));
1659
 
  thd->time_zone_used= 1;
 
1657
  Session *session= current_session;
 
1658
  session->variables.time_zone->gmt_sec_to_TIME(now_time, (my_time_t) my_time(0));
 
1659
  session->time_zone_used= 1;
1660
1660
}
1661
1661
 
1662
1662
 
1750
1750
 
1751
1751
void Item_func_date_format::fix_length_and_dec()
1752
1752
{
1753
 
  Session* thd= current_thd;
 
1753
  Session* session= current_session;
1754
1754
  /*
1755
1755
    Must use this_item() in case it's a local SP variable
1756
1756
    (for ->max_length and ->str_value)
1758
1758
  Item *arg1= args[1]->this_item();
1759
1759
 
1760
1760
  decimals=0;
1761
 
  const CHARSET_INFO * const cs= thd->variables.collation_connection;
 
1761
  const CHARSET_INFO * const cs= session->variables.collation_connection;
1762
1762
  uint32_t repertoire= arg1->collation.repertoire;
1763
 
  if (!thd->variables.lc_time_names->is_ascii)
 
1763
  if (!session->variables.lc_time_names->is_ascii)
1764
1764
    repertoire|= MY_REPERTOIRE_EXTENDED;
1765
1765
  collation.set(cs, arg1->collation.derivation, repertoire);
1766
1766
  if (arg1->type() == STRING_ITEM)
1937
1937
 
1938
1938
void Item_func_from_unixtime::fix_length_and_dec()
1939
1939
1940
 
  thd= current_thd;
 
1940
  session= current_session;
1941
1941
  collation.set(&my_charset_bin);
1942
1942
  decimals= DATETIME_DEC;
1943
1943
  max_length=MAX_DATETIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
1944
1944
  maybe_null= 1;
1945
 
  thd->time_zone_used= 1;
 
1945
  session->time_zone_used= 1;
1946
1946
}
1947
1947
 
1948
1948
 
1990
1990
  if ((null_value= (args[0]->null_value || tmp > TIMESTAMP_MAX_VALUE)))
1991
1991
    return 1;
1992
1992
 
1993
 
  thd->variables.time_zone->gmt_sec_to_TIME(ltime, (my_time_t)tmp);
 
1993
  session->variables.time_zone->gmt_sec_to_TIME(ltime, (my_time_t)tmp);
1994
1994
 
1995
1995
  return 0;
1996
1996
}
2195
2195
  case INTERVAL_MONTH:          return ltime.month;
2196
2196
  case INTERVAL_WEEK:
2197
2197
  {
2198
 
    week_format= current_thd->variables.default_week_format;
 
2198
    week_format= current_session->variables.default_week_format;
2199
2199
    return calc_week(&ltime, week_mode(week_format), &year);
2200
2200
  }
2201
2201
  case INTERVAL_DAY:            return ltime.day;
2352
2352
        str_value= *res;                        // Not malloced string
2353
2353
        res= &str_value;
2354
2354
      }
2355
 
      push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2355
      push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2356
2356
                          ER_TRUNCATED_WRONG_VALUE,
2357
2357
                          ER(ER_TRUNCATED_WRONG_VALUE), char_type,
2358
2358
                          res->c_ptr_safe());
2836
2836
    char *ptr= int64_t10_to_str(hour, buf, args[0]->unsigned_flag ? 10 : -10);
2837
2837
    int len = (int)(ptr - buf) +
2838
2838
      sprintf(ptr, ":%02u:%02u", (uint)minute, (uint)second);
2839
 
    make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2839
    make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2840
2840
                                 buf, len, DRIZZLE_TIMESTAMP_TIME,
2841
2841
                                 NULL);
2842
2842
  }