~drizzle-trunk/drizzle/development

574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
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
1241.9.36 by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h.
20
#include "config.h"
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
21
670.1.20 by Monty Taylor
Renamed functions to function... everything else is singular.
22
#include <drizzled/function/time/sysdate_local.h>
574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
23
#include <drizzled/tztime.h>
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
24
#include <drizzled/session.h>
574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
25
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
26
namespace drizzled
27
{
28
574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
29
/**
726.1.1 by Toru Maesaka
Use time_t instead of my_time_t which should be safe (as in wide enough) on POSIX compliant systems.
30
    Converts current time in time_t to DRIZZLE_TIME represenatation for local
574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
31
    time zone. Defines time zone (local) used for whole SYSDATE function.
32
*/
33
void Item_func_sysdate_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
34
{
35
  Session *session= current_session;
685.3.4 by Toru Maesaka
Fixed the issues pointed out by Jay's code review
36
  session->variables.time_zone->gmt_sec_to_TIME(now_time, time(NULL));
574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
37
}
38
39
779.1.27 by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files.
40
String *Item_func_sysdate_local::val_str(String *)
574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
41
{
42
  assert(fixed == 1);
43
  store_now_in_TIME(&ltime);
44
  buff_length= (uint) my_datetime_to_str(&ltime, buff);
45
  str_value.set(buff, buff_length, &my_charset_bin);
46
  return &str_value;
47
}
48
49
50
int64_t Item_func_sysdate_local::val_int()
51
{
52
  assert(fixed == 1);
53
  store_now_in_TIME(&ltime);
54
  return (int64_t) TIME_to_uint64_t_datetime(&ltime);
55
}
56
57
double Item_func_sysdate_local::val_real()
58
{
59
  assert(fixed == 1);
60
  store_now_in_TIME(&ltime);
61
  return uint64_t2double(TIME_to_uint64_t_datetime(&ltime));
62
}
63
64
65
void Item_func_sysdate_local::fix_length_and_dec()
66
{
67
  decimals= 0;
68
  collation.set(&my_charset_bin);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
69
  max_length= DateTime::MAX_STRING_LENGTH*MY_CHARSET_BIN_MB_MAXLEN;
574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
70
}
71
72
73
bool Item_func_sysdate_local::get_date(DRIZZLE_TIME *res,
779.1.27 by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files.
74
                                       uint32_t )
574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
75
{
76
  store_now_in_TIME(&ltime);
77
  *res= ltime;
78
  return 0;
79
}
80
81
779.1.27 by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files.
82
int Item_func_sysdate_local::save_in_field(Field *to, bool )
574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
83
{
84
  store_now_in_TIME(&ltime);
85
  to->set_notnull();
86
  to->store_time(&ltime, DRIZZLE_TIMESTAMP_DATETIME);
87
  return 0;
88
}
89
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
90
} /* namespace drizzled */