~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/functions/time/sysdate_local.cc

  • Committer: Brian Aker
  • Date: 2008-11-13 02:56:15 UTC
  • mfrom: (575.4.10 devel)
  • Revision ID: brian@tangent.org-20081113025615-snhsi52yb2ivmx6f
Merging Monty's code.

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/functions/time/sysdate_local.h>
 
23
#include <drizzled/tztime.h>
 
24
 
 
25
 
 
26
/**
 
27
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for local
 
28
    time zone. Defines time zone (local) used for whole SYSDATE function.
 
29
*/
 
30
void Item_func_sysdate_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
31
{
 
32
  Session *session= current_session;
 
33
  session->variables.time_zone->gmt_sec_to_TIME(now_time, (my_time_t) my_time(0));
 
34
  session->time_zone_used= 1;
 
35
}
 
36
 
 
37
 
 
38
String *Item_func_sysdate_local::val_str(String *str __attribute__((unused)))
 
39
{
 
40
  assert(fixed == 1);
 
41
  store_now_in_TIME(&ltime);
 
42
  buff_length= (uint) my_datetime_to_str(&ltime, buff);
 
43
  str_value.set(buff, buff_length, &my_charset_bin);
 
44
  return &str_value;
 
45
}
 
46
 
 
47
 
 
48
int64_t Item_func_sysdate_local::val_int()
 
49
{
 
50
  assert(fixed == 1);
 
51
  store_now_in_TIME(&ltime);
 
52
  return (int64_t) TIME_to_uint64_t_datetime(&ltime);
 
53
}
 
54
 
 
55
double Item_func_sysdate_local::val_real()
 
56
{
 
57
  assert(fixed == 1);
 
58
  store_now_in_TIME(&ltime);
 
59
  return uint64_t2double(TIME_to_uint64_t_datetime(&ltime));
 
60
}
 
61
 
 
62
 
 
63
void Item_func_sysdate_local::fix_length_and_dec()
 
64
{
 
65
  decimals= 0;
 
66
  collation.set(&my_charset_bin);
 
67
  max_length= MAX_DATETIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
 
68
}
 
69
 
 
70
 
 
71
bool Item_func_sysdate_local::get_date(DRIZZLE_TIME *res,
 
72
                                       uint32_t fuzzy_date __attribute__((unused)))
 
73
{
 
74
  store_now_in_TIME(&ltime);
 
75
  *res= ltime;
 
76
  return 0;
 
77
}
 
78
 
 
79
 
 
80
int Item_func_sysdate_local::save_in_field(Field *to, bool no_conversions __attribute__((unused)))
 
81
{
 
82
  store_now_in_TIME(&ltime);
 
83
  to->set_notnull();
 
84
  to->store_time(&ltime, DRIZZLE_TIMESTAMP_DATETIME);
 
85
  return 0;
 
86
}
 
87