Drizzled Public API Documentation

now.cc
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/now.h>
23 #include <drizzled/current_session.h>
24 #include <drizzled/session.h>
25 #include <drizzled/session/times.h>
26 #include <drizzled/temporal.h>
27 #include <drizzled/field.h>
28 
29 namespace drizzled {
30 
32 {
33  assert(fixed == 1);
34  str_value.set(buff, buff_length, &my_charset_bin);
35 
36  return &str_value;
37 }
38 
39 
40 void Item_func_now::fix_length_and_dec()
41 {
42  decimals= DATETIME_DEC;
43  collation.set(&my_charset_bin);
44 
45  ltime.reset();
46 
47  ltime.time_type= type::DRIZZLE_TIMESTAMP_DATETIME;
48 
49  store_now_in_TIME(ltime);
50 
51  ltime.convert(value);
52 
53  size_t length= type::Time::MAX_STRING_LENGTH;
54  ltime.convert(buff, length);
55 
56  max_length= buff_length= length;
57 }
58 
64 {
65  Session *session= current_session;
66  uint32_t fractional_seconds= 0;
67  time_t tmp= session->times.getCurrentTimestampEpoch(fractional_seconds);
68 
69 #if 0
70  now_time->store(tmp, fractional_seconds, true);
71 #endif
72  now_time.store(tmp, fractional_seconds);
73 }
74 
75 
81 {
82  uint32_t fractional_seconds= 0;
83  time_t tmp= current_session->times.getCurrentTimestampEpoch(fractional_seconds);
84  now_time.store(tmp, fractional_seconds);
85 }
86 
88 {
89  to= cached_temporal;
90  return true;
91 }
92 
93 bool Item_func_now::get_date(type::Time &res, uint32_t )
94 {
95  res= ltime;
96  return 0;
97 }
98 
99 
100 int Item_func_now::save_in_field(Field *to, bool )
101 {
102  to->set_notnull();
103  return to->store_time(ltime, type::DRIZZLE_TIMESTAMP_DATETIME);
104 }
105 
106 } /* namespace drizzled */