~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Stewart Smith
  • Date: 2009-01-12 05:43:13 UTC
  • mto: (784.1.4 for-brian)
  • mto: This revision was merged to the branch mainline in revision 785.
  • Revision ID: stewart@flamingspork.com-20090112054313-edk6kpf4l6kpz4j7
fix archive_basic for drizzle

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/tztime.h>
 
24
#include <drizzled/session.h>
 
25
 
 
26
String *Item_func_now::val_str(String *)
 
27
{
 
28
  assert(fixed == 1);
 
29
  str_value.set(buff, buff_length, &my_charset_bin);
 
30
  return &str_value;
 
31
}
 
32
 
 
33
 
 
34
void Item_func_now::fix_length_and_dec()
 
35
{
 
36
  decimals= DATETIME_DEC;
 
37
  collation.set(&my_charset_bin);
 
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;
 
44
}
 
45
 
 
46
/**
 
47
    Converts current time in time_t to DRIZZLE_TIME represenatation for local
 
48
    time zone. Defines time zone (local) used for whole NOW function.
 
49
*/
 
50
void Item_func_now_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
51
{
 
52
  Session *session= current_session;
 
53
  session->variables.time_zone->gmt_sec_to_TIME(now_time,
 
54
                                                (time_t)session->query_start());
 
55
}
 
56
 
 
57
 
 
58
/**
 
59
    Converts current time in time_t to DRIZZLE_TIME represenatation for UTC
 
60
    time zone. Defines time zone (UTC) used for whole UTC_TIMESTAMP function.
 
61
*/
 
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
                             (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;
 
76
  return 0;
 
77
}
 
78
 
 
79
 
 
80
int Item_func_now::save_in_field(Field *to, bool no_conversions __attribute__((unused)))
 
81
{
 
82
  to->set_notnull();
 
83
  return to->store_time(&ltime, DRIZZLE_TIMESTAMP_DATETIME);
 
84
}
 
85