~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2008-07-05 17:09:05 UTC
  • mto: This revision was merged to the branch mainline in revision 63.
  • Revision ID: monty@inaugust.com-20080705170905-itvcfiincapslw9w
Removed redundant declaration.

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