~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
 *
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
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/now.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.
23
#include <drizzled/session.h>
574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
24
907.1.8 by Jay Pipes
Final removal of timezones
25
#include "drizzled/temporal.h"
26
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
27
namespace drizzled
28
{
29
735 by Brian Aker
Refactor session.
30
String *Item_func_now::val_str(String *)
574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
31
{
32
  assert(fixed == 1);
735 by Brian Aker
Refactor session.
33
  str_value.set(buff, buff_length, &my_charset_bin);
574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
34
  return &str_value;
35
}
36
37
38
void Item_func_now::fix_length_and_dec()
39
{
40
  decimals= DATETIME_DEC;
41
  collation.set(&my_charset_bin);
907.1.7 by Jay Pipes
Merged in remove-timezone work
42
  
43
  memset(&ltime, 0, sizeof(DRIZZLE_TIME));
44
45
  ltime.time_type= DRIZZLE_TIMESTAMP_DATETIME;
574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
46
47
  store_now_in_TIME(&ltime);
48
  value= (int64_t) TIME_to_uint64_t_datetime(&ltime);
49
50
  buff_length= (uint) my_datetime_to_str(&ltime, buff);
51
  max_length= buff_length;
52
}
53
54
/**
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.
55
    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
56
    time zone. Defines time zone (local) used for whole NOW function.
57
*/
58
void Item_func_now_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
59
{
60
  Session *session= current_session;
907.1.8 by Jay Pipes
Final removal of timezones
61
  time_t tmp= session->query_start();
62
63
  (void) cached_temporal.from_time_t(tmp);
64
65
  now_time->year= cached_temporal.years();
66
  now_time->month= cached_temporal.months();
67
  now_time->day= cached_temporal.days();
68
  now_time->hour= cached_temporal.hours();
69
  now_time->minute= cached_temporal.minutes();
70
  now_time->second= cached_temporal.seconds();
574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
71
}
72
73
74
/**
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.
75
    Converts current time in time_t to DRIZZLE_TIME represenatation for UTC
574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
76
    time zone. Defines time zone (UTC) used for whole UTC_TIMESTAMP function.
77
*/
78
void Item_func_now_utc::store_now_in_TIME(DRIZZLE_TIME *now_time)
79
{
907.1.8 by Jay Pipes
Final removal of timezones
80
  Session *session= current_session;
81
  time_t tmp= session->query_start();
82
83
  (void) cached_temporal.from_time_t(tmp);
84
85
  now_time->year= cached_temporal.years();
86
  now_time->month= cached_temporal.months();
87
  now_time->day= cached_temporal.days();
88
  now_time->hour= cached_temporal.hours();
89
  now_time->minute= cached_temporal.minutes();
90
  now_time->second= cached_temporal.seconds();
91
}
92
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
93
bool Item_func_now::get_temporal(DateTime &to)
907.1.8 by Jay Pipes
Final removal of timezones
94
{
95
  to= cached_temporal;
96
  return true;
574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
97
}
98
99
bool Item_func_now::get_date(DRIZZLE_TIME *res,
779.1.27 by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files.
100
                             uint32_t )
574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
101
{
102
  *res= ltime;
103
  return 0;
104
}
105
106
779.1.27 by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files.
107
int Item_func_now::save_in_field(Field *to, bool )
574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
108
{
109
  to->set_notnull();
110
  return to->store_time(&ltime, DRIZZLE_TIMESTAMP_DATETIME);
111
}
112
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
113
} /* namespace drizzled */