~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Merge of Jay

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#include <drizzled/server_includes.h>
 
21
#include CSTDINT_H
 
22
#include <drizzled/function/time/now.h>
 
23
#include <drizzled/session.h>
 
24
 
 
25
#include "drizzled/temporal.h"
 
26
 
 
27
String *Item_func_now::val_str(String *)
 
28
{
 
29
  assert(fixed == 1);
 
30
  str_value.set(buff, buff_length, &my_charset_bin);
 
31
  return &str_value;
 
32
}
 
33
 
 
34
 
 
35
void Item_func_now::fix_length_and_dec()
 
36
{
 
37
  decimals= DATETIME_DEC;
 
38
  collation.set(&my_charset_bin);
 
39
  
 
40
  memset(&ltime, 0, sizeof(DRIZZLE_TIME));
 
41
 
 
42
  ltime.time_type= DRIZZLE_TIMESTAMP_DATETIME;
 
43
 
 
44
  store_now_in_TIME(&ltime);
 
45
  value= (int64_t) TIME_to_uint64_t_datetime(&ltime);
 
46
 
 
47
  buff_length= (uint) my_datetime_to_str(&ltime, buff);
 
48
  max_length= buff_length;
 
49
}
 
50
 
 
51
/**
 
52
    Converts current time in time_t to DRIZZLE_TIME represenatation for local
 
53
    time zone. Defines time zone (local) used for whole NOW function.
 
54
*/
 
55
void Item_func_now_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
56
{
 
57
  Session *session= current_session;
 
58
  time_t tmp= session->query_start();
 
59
 
 
60
  (void) cached_temporal.from_time_t(tmp);
 
61
 
 
62
  now_time->year= cached_temporal.years();
 
63
  now_time->month= cached_temporal.months();
 
64
  now_time->day= cached_temporal.days();
 
65
  now_time->hour= cached_temporal.hours();
 
66
  now_time->minute= cached_temporal.minutes();
 
67
  now_time->second= cached_temporal.seconds();
 
68
}
 
69
 
 
70
 
 
71
/**
 
72
    Converts current time in time_t to DRIZZLE_TIME represenatation for UTC
 
73
    time zone. Defines time zone (UTC) used for whole UTC_TIMESTAMP function.
 
74
*/
 
75
void Item_func_now_utc::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
76
{
 
77
  Session *session= current_session;
 
78
  time_t tmp= session->query_start();
 
79
 
 
80
  (void) cached_temporal.from_time_t(tmp);
 
81
 
 
82
  now_time->year= cached_temporal.years();
 
83
  now_time->month= cached_temporal.months();
 
84
  now_time->day= cached_temporal.days();
 
85
  now_time->hour= cached_temporal.hours();
 
86
  now_time->minute= cached_temporal.minutes();
 
87
  now_time->second= cached_temporal.seconds();
 
88
}
 
89
 
 
90
bool Item_func_now::get_temporal(drizzled::DateTime &to)
 
91
{
 
92
  to= cached_temporal;
 
93
  return true;
 
94
}
 
95
 
 
96
bool Item_func_now::get_date(DRIZZLE_TIME *res,
 
97
                             uint32_t )
 
98
{
 
99
  *res= ltime;
 
100
  return 0;
 
101
}
 
102
 
 
103
 
 
104
int Item_func_now::save_in_field(Field *to, bool )
 
105
{
 
106
  to->set_notnull();
 
107
  return to->store_time(&ltime, DRIZZLE_TIMESTAMP_DATETIME);
 
108
}
 
109