~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

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/now.h>
23
 
#include <drizzled/session.h>
24
 
 
25
 
#include "drizzled/temporal.h"
26
 
 
27
 
namespace drizzled
28
 
{
29
 
 
30
 
String *Item_func_now::val_str(String *)
31
 
{
32
 
  assert(fixed == 1);
33
 
  str_value.set(buff, buff_length, &my_charset_bin);
34
 
 
35
 
  return &str_value;
36
 
}
37
 
 
38
 
 
39
 
void Item_func_now::fix_length_and_dec()
40
 
{
41
 
  decimals= DATETIME_DEC;
42
 
  collation.set(&my_charset_bin);
43
 
  
44
 
  ltime.reset();
45
 
 
46
 
  ltime.time_type= type::DRIZZLE_TIMESTAMP_DATETIME;
47
 
 
48
 
  store_now_in_TIME(ltime);
49
 
 
50
 
  ltime.convert(value);
51
 
 
52
 
  size_t length= type::Time::MAX_STRING_LENGTH;
53
 
  ltime.convert(buff, length);
54
 
 
55
 
  max_length= buff_length= length;
56
 
}
57
 
 
58
 
/**
59
 
    Converts current time in time_t to type::Time represenatation for local
60
 
    time zone. Defines time zone (local) used for whole NOW function.
61
 
*/
62
 
void Item_func_now_local::store_now_in_TIME(type::Time &now_time)
63
 
{
64
 
  Session *session= current_session;
65
 
  uint32_t fractional_seconds= 0;
66
 
  time_t tmp= session->getCurrentTimestampEpoch(fractional_seconds);
67
 
 
68
 
#if 0
69
 
  now_time->store(tmp, fractional_seconds, true);
70
 
#endif
71
 
  now_time.store(tmp, fractional_seconds);
72
 
}
73
 
 
74
 
 
75
 
/**
76
 
    Converts current time in time_t to type::Time represenatation for UTC
77
 
    time zone. Defines time zone (UTC) used for whole UTC_TIMESTAMP function.
78
 
*/
79
 
void Item_func_now_utc::store_now_in_TIME(type::Time &now_time)
80
 
{
81
 
  Session *session= current_session;
82
 
  uint32_t fractional_seconds= 0;
83
 
  time_t tmp= session->getCurrentTimestampEpoch(fractional_seconds);
84
 
 
85
 
  now_time.store(tmp, fractional_seconds);
86
 
}
87
 
 
88
 
bool Item_func_now::get_temporal(DateTime &to)
89
 
{
90
 
  to= cached_temporal;
91
 
  return true;
92
 
}
93
 
 
94
 
bool Item_func_now::get_date(type::Time &res, uint32_t )
95
 
{
96
 
  res= ltime;
97
 
  return 0;
98
 
}
99
 
 
100
 
 
101
 
int Item_func_now::save_in_field(Field *to, bool )
102
 
{
103
 
  to->set_notnull();
104
 
  return to->store_time(ltime, type::DRIZZLE_TIMESTAMP_DATETIME);
105
 
}
106
 
 
107
 
} /* namespace drizzled */