~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2010-12-08 22:35:56 UTC
  • mfrom: (1819.9.158 update-innobase)
  • Revision ID: brian@tangent.org-20101208223556-37mi4omqg7lkjzf3
Merge in Stewart's changes, 1.3 changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <drizzled/server_includes.h>
21
 
#include CSTDINT_H
22
 
#include <drizzled/functions/time/now.h>
23
 
#include <drizzled/tztime.h>
 
20
#include "config.h"
 
21
 
 
22
#include <drizzled/function/time/now.h>
24
23
#include <drizzled/session.h>
25
24
 
26
 
String *Item_func_now::val_str(String *str __attribute__((unused)))
 
25
#include "drizzled/temporal.h"
 
26
 
 
27
namespace drizzled
 
28
{
 
29
 
 
30
String *Item_func_now::val_str(String *)
27
31
{
28
32
  assert(fixed == 1);
29
 
  str_value.set(buff,buff_length, &my_charset_bin);
 
33
  str_value.set(buff, buff_length, &my_charset_bin);
30
34
  return &str_value;
31
35
}
32
36
 
35
39
{
36
40
  decimals= DATETIME_DEC;
37
41
  collation.set(&my_charset_bin);
 
42
  
 
43
  memset(&ltime, 0, sizeof(DRIZZLE_TIME));
 
44
 
 
45
  ltime.time_type= DRIZZLE_TIMESTAMP_DATETIME;
38
46
 
39
47
  store_now_in_TIME(&ltime);
40
48
  value= (int64_t) TIME_to_uint64_t_datetime(&ltime);
44
52
}
45
53
 
46
54
/**
47
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for local
 
55
    Converts current time in time_t to DRIZZLE_TIME represenatation for local
48
56
    time zone. Defines time zone (local) used for whole NOW function.
49
57
*/
50
58
void Item_func_now_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
51
59
{
52
60
  Session *session= current_session;
53
 
  session->variables.time_zone->gmt_sec_to_TIME(now_time,
54
 
                                             (my_time_t)session->query_start());
 
61
  time_t tmp= session->query_start();
 
62
 
 
63
  (void) cached_temporal.from_time_t(tmp);
 
64
 
 
65
  now_time->year= cached_temporal.years();
 
66
  now_time->month= cached_temporal.months();
 
67
  now_time->day= cached_temporal.days();
 
68
  now_time->hour= cached_temporal.hours();
 
69
  now_time->minute= cached_temporal.minutes();
 
70
  now_time->second= cached_temporal.seconds();
55
71
}
56
72
 
57
73
 
58
74
/**
59
 
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for UTC
 
75
    Converts current time in time_t to DRIZZLE_TIME represenatation for UTC
60
76
    time zone. Defines time zone (UTC) used for whole UTC_TIMESTAMP function.
61
77
*/
62
78
void Item_func_now_utc::store_now_in_TIME(DRIZZLE_TIME *now_time)
63
79
{
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
 
  */
 
80
  Session *session= current_session;
 
81
  time_t tmp= session->query_start();
 
82
 
 
83
  (void) cached_temporal.from_time_t(tmp);
 
84
 
 
85
  now_time->year= cached_temporal.years();
 
86
  now_time->month= cached_temporal.months();
 
87
  now_time->day= cached_temporal.days();
 
88
  now_time->hour= cached_temporal.hours();
 
89
  now_time->minute= cached_temporal.minutes();
 
90
  now_time->second= cached_temporal.seconds();
 
91
}
 
92
 
 
93
bool Item_func_now::get_temporal(DateTime &to)
 
94
{
 
95
  to= cached_temporal;
 
96
  return true;
70
97
}
71
98
 
72
99
bool Item_func_now::get_date(DRIZZLE_TIME *res,
73
 
                             uint32_t fuzzy_date __attribute__((unused)))
 
100
                             uint32_t )
74
101
{
75
102
  *res= ltime;
76
103
  return 0;
77
104
}
78
105
 
79
106
 
80
 
int Item_func_now::save_in_field(Field *to, bool no_conversions __attribute__((unused)))
 
107
int Item_func_now::save_in_field(Field *to, bool )
81
108
{
82
109
  to->set_notnull();
83
110
  return to->store_time(&ltime, DRIZZLE_TIMESTAMP_DATETIME);
84
111
}
85
112
 
 
113
} /* namespace drizzled */