~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/time/now.cc

  • Committer: Jay Pipes
  • Date: 2008-12-18 15:55:03 UTC
  • mto: This revision was merged to the branch mainline in revision 717.
  • Revision ID: jpipes@serialcoder-20081218155503-u45ygyunrdyyvquq
Fix for Bug#308457.  Gave UTF8 enclosure and escape character on LOAD DATA INFILE and changed the error message to be more descriptive

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <config.h>
21
 
 
 
20
#include <drizzled/server_includes.h>
 
21
#include CSTDINT_H
22
22
#include <drizzled/function/time/now.h>
23
 
#include <drizzled/current_session.h>
 
23
#include <drizzled/tztime.h>
24
24
#include <drizzled/session.h>
25
25
 
26
 
#include <drizzled/temporal.h>
27
 
 
28
 
namespace drizzled
29
 
{
30
 
 
31
 
String *Item_func_now::val_str(String *)
 
26
String *Item_func_now::val_str(String *str __attribute__((unused)))
32
27
{
33
28
  assert(fixed == 1);
34
 
  str_value.set(buff, buff_length, &my_charset_bin);
35
 
 
 
29
  str_value.set(buff,buff_length, &my_charset_bin);
36
30
  return &str_value;
37
31
}
38
32
 
41
35
{
42
36
  decimals= DATETIME_DEC;
43
37
  collation.set(&my_charset_bin);
44
 
  
45
 
  ltime.reset();
46
 
 
47
 
  ltime.time_type= type::DRIZZLE_TIMESTAMP_DATETIME;
48
 
 
49
 
  store_now_in_TIME(ltime);
50
 
 
51
 
  ltime.convert(value);
52
 
 
53
 
  size_t length= type::Time::MAX_STRING_LENGTH;
54
 
  ltime.convert(buff, length);
55
 
 
56
 
  max_length= buff_length= length;
 
38
 
 
39
  store_now_in_TIME(&ltime);
 
40
  value= (int64_t) TIME_to_uint64_t_datetime(&ltime);
 
41
 
 
42
  buff_length= (uint) my_datetime_to_str(&ltime, buff);
 
43
  max_length= buff_length;
57
44
}
58
45
 
59
46
/**
60
 
    Converts current time in time_t to type::Time represenatation for local
 
47
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for local
61
48
    time zone. Defines time zone (local) used for whole NOW function.
62
49
*/
63
 
void Item_func_now_local::store_now_in_TIME(type::Time &now_time)
 
50
void Item_func_now_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
64
51
{
65
52
  Session *session= current_session;
66
 
  uint32_t fractional_seconds= 0;
67
 
  time_t tmp= session->getCurrentTimestampEpoch(fractional_seconds);
68
 
 
69
 
#if 0
70
 
  now_time->store(tmp, fractional_seconds, true);
71
 
#endif
72
 
  now_time.store(tmp, fractional_seconds);
 
53
  session->variables.time_zone->gmt_sec_to_TIME(now_time,
 
54
                                             (my_time_t)session->query_start());
73
55
}
74
56
 
75
57
 
76
58
/**
77
 
    Converts current time in time_t to type::Time represenatation for UTC
 
59
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for UTC
78
60
    time zone. Defines time zone (UTC) used for whole UTC_TIMESTAMP function.
79
61
*/
80
 
void Item_func_now_utc::store_now_in_TIME(type::Time &now_time)
81
 
{
82
 
  Session *session= current_session;
83
 
  uint32_t fractional_seconds= 0;
84
 
  time_t tmp= session->getCurrentTimestampEpoch(fractional_seconds);
85
 
 
86
 
  now_time.store(tmp, fractional_seconds);
87
 
}
88
 
 
89
 
bool Item_func_now::get_temporal(DateTime &to)
90
 
{
91
 
  to= cached_temporal;
92
 
  return true;
93
 
}
94
 
 
95
 
bool Item_func_now::get_date(type::Time &res, uint32_t )
96
 
{
97
 
  res= ltime;
 
62
void Item_func_now_utc::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
63
{
 
64
  my_tz_UTC->gmt_sec_to_TIME(now_time,
 
65
                             (my_time_t)(current_session->query_start()));
 
66
  /*
 
67
    We are not flagging this query as using time zone, since it uses fixed
 
68
    UTC-SYSTEM time-zone.
 
69
  */
 
70
}
 
71
 
 
72
bool Item_func_now::get_date(DRIZZLE_TIME *res,
 
73
                             uint32_t fuzzy_date __attribute__((unused)))
 
74
{
 
75
  *res= ltime;
98
76
  return 0;
99
77
}
100
78
 
101
79
 
102
 
int Item_func_now::save_in_field(Field *to, bool )
 
80
int Item_func_now::save_in_field(Field *to, bool no_conversions __attribute__((unused)))
103
81
{
104
82
  to->set_notnull();
105
 
  return to->store_time(ltime, type::DRIZZLE_TIMESTAMP_DATETIME);
 
83
  return to->store_time(&ltime, DRIZZLE_TIMESTAMP_DATETIME);
106
84
}
107
85
 
108
 
} /* namespace drizzled */