~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2008-12-16 07:07:50 UTC
  • Revision ID: brian@tangent.org-20081216070750-o5ykltxxqvn2awrx
Fixed errors test.

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/curdate.h>
 
23
#include <drizzled/tztime.h>
 
24
 
 
25
#include <drizzled/session.h>
 
26
 
 
27
void Item_func_curdate::fix_length_and_dec()
 
28
{
 
29
  collation.set(&my_charset_bin);
 
30
  decimals=0;
 
31
  max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
 
32
 
 
33
  store_now_in_TIME(&ltime);
 
34
 
 
35
  /* We don't need to set second_part and neg because they already 0 */
 
36
  ltime.hour= ltime.minute= ltime.second= 0;
 
37
  ltime.time_type= DRIZZLE_TIMESTAMP_DATE;
 
38
  value= (int64_t) TIME_to_uint64_t_date(&ltime);
 
39
}
 
40
 
 
41
String *Item_func_curdate::val_str(String *str)
 
42
{
 
43
  assert(fixed == 1);
 
44
  if (str->alloc(MAX_DATE_STRING_REP_LENGTH))
 
45
  {
 
46
    null_value= 1;
 
47
    return (String *) 0;
 
48
  }
 
49
  make_date((DATE_TIME_FORMAT *) 0, &ltime, str);
 
50
  return str;
 
51
}
 
52
 
 
53
/**
 
54
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for local
 
55
    time zone. Defines time zone (local) used for whole CURDATE function.
 
56
*/
 
57
void Item_func_curdate_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
58
{
 
59
  Session *session= current_session;
 
60
  session->variables.time_zone->gmt_sec_to_TIME(now_time,
 
61
                                             (my_time_t)session->query_start());
 
62
}
 
63
 
 
64
/**
 
65
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for UTC
 
66
    time zone. Defines time zone (UTC) used for whole UTC_DATE function.
 
67
*/
 
68
void Item_func_curdate_utc::store_now_in_TIME(DRIZZLE_TIME *now_time)
 
69
{
 
70
  my_tz_UTC->gmt_sec_to_TIME(now_time,
 
71
                             (my_time_t)(current_session->query_start()));
 
72
  /*
 
73
    We are not flagging this query as using time zone, since it uses fixed
 
74
    UTC-SYSTEM time-zone.
 
75
  */
 
76
}
 
77
 
 
78
bool Item_func_curdate::get_date(DRIZZLE_TIME *res,
 
79
                                 uint32_t fuzzy_date __attribute__((unused)))
 
80
{
 
81
  *res=ltime;
 
82
  return 0;
 
83
}
 
84
 
 
85