~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Merge/fix in FAQ.

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, Inc.
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 <config.h>
21
 
 
22
 
#include <drizzled/function/time/sysdate_local.h>
23
 
#include <drizzled/tztime.h>
24
 
#include <drizzled/session.h>
25
 
 
26
 
namespace drizzled
27
 
{
28
 
 
29
 
/**
30
 
    Converts current time in time_t to type::Time represenatation for local
31
 
    time zone. Defines time zone (local) used for whole SYSDATE function.
32
 
*/
33
 
void Item_func_sysdate_local::store_now_in_TIME(type::Time &now_time)
34
 
{
35
 
  getSession().variables.time_zone->gmt_sec_to_TIME(now_time, time(NULL));
36
 
}
37
 
 
38
 
 
39
 
String *Item_func_sysdate_local::val_str(String *)
40
 
{
41
 
  assert(fixed == 1);
42
 
  store_now_in_TIME(ltime);
43
 
 
44
 
  size_t length= type::Time::MAX_STRING_LENGTH;
45
 
  ltime.convert(buff, length);
46
 
  buff_length= length;
47
 
  str_value.set(buff, length, &my_charset_bin);
48
 
 
49
 
  return &str_value;
50
 
}
51
 
 
52
 
 
53
 
int64_t Item_func_sysdate_local::val_int()
54
 
{
55
 
  assert(fixed == 1);
56
 
  store_now_in_TIME(ltime);
57
 
  int64_t tmp;
58
 
  ltime.convert(tmp);
59
 
 
60
 
  return tmp;
61
 
}
62
 
 
63
 
double Item_func_sysdate_local::val_real()
64
 
{
65
 
  assert(fixed == 1);
66
 
 
67
 
  store_now_in_TIME(ltime);
68
 
  int64_t tmp;
69
 
  ltime.convert(tmp);
70
 
 
71
 
  return int64_t2double(tmp);
72
 
}
73
 
 
74
 
 
75
 
void Item_func_sysdate_local::fix_length_and_dec()
76
 
{
77
 
  decimals= 0;
78
 
  collation.set(&my_charset_bin);
79
 
  max_length= DateTime::MAX_STRING_LENGTH*MY_CHARSET_BIN_MB_MAXLEN;
80
 
}
81
 
 
82
 
 
83
 
bool Item_func_sysdate_local::get_date(type::Time &res, uint32_t )
84
 
{
85
 
  store_now_in_TIME(ltime);
86
 
  res= ltime;
87
 
  return 0;
88
 
}
89
 
 
90
 
 
91
 
int Item_func_sysdate_local::save_in_field(Field *to, bool )
92
 
{
93
 
  store_now_in_TIME(ltime);
94
 
  to->set_notnull();
95
 
  to->store_time(ltime, type::DRIZZLE_TIMESTAMP_DATETIME);
96
 
 
97
 
  return 0;
98
 
}
99
 
 
100
 
} /* namespace drizzled */