~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2008-12-18 07:42:01 UTC
  • mto: This revision was merged to the branch mainline in revision 714.
  • Revision ID: monty@inaugust.com-20081218074201-4m7d63t72qfuplwx
Fixed max() problem for solaris

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <config.h>
21
 
 
 
20
#include <drizzled/server_includes.h>
 
21
#include CSTDINT_H
22
22
#include <drizzled/function/time/sysdate_local.h>
23
23
#include <drizzled/tztime.h>
24
24
#include <drizzled/session.h>
25
25
 
26
 
namespace drizzled
27
 
{
28
 
 
29
26
/**
30
 
    Converts current time in time_t to type::Time represenatation for local
 
27
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for local
31
28
    time zone. Defines time zone (local) used for whole SYSDATE function.
32
29
*/
33
 
void Item_func_sysdate_local::store_now_in_TIME(type::Time &now_time)
 
30
void Item_func_sysdate_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
34
31
{
35
 
  getSession().variables.time_zone->gmt_sec_to_TIME(now_time, time(NULL));
 
32
  Session *session= current_session;
 
33
  session->variables.time_zone->gmt_sec_to_TIME(now_time, (my_time_t) time(0));
36
34
}
37
35
 
38
36
 
39
 
String *Item_func_sysdate_local::val_str(String *)
 
37
String *Item_func_sysdate_local::val_str(String *str __attribute__((unused)))
40
38
{
41
39
  assert(fixed == 1);
42
 
  store_now_in_TIME(ltime);
43
 
 
44
 
  size_t length= type::Time::MAX_STRING_LENGTH;
45
 
  ltime.convert(buff, length);
46
 
  buff_length= length;
47
 
  str_value.set(buff, length, &my_charset_bin);
48
 
 
 
40
  store_now_in_TIME(&ltime);
 
41
  buff_length= (uint) my_datetime_to_str(&ltime, buff);
 
42
  str_value.set(buff, buff_length, &my_charset_bin);
49
43
  return &str_value;
50
44
}
51
45
 
53
47
int64_t Item_func_sysdate_local::val_int()
54
48
{
55
49
  assert(fixed == 1);
56
 
  store_now_in_TIME(ltime);
57
 
  int64_t tmp;
58
 
  ltime.convert(tmp);
59
 
 
60
 
  return tmp;
 
50
  store_now_in_TIME(&ltime);
 
51
  return (int64_t) TIME_to_uint64_t_datetime(&ltime);
61
52
}
62
53
 
63
54
double Item_func_sysdate_local::val_real()
64
55
{
65
56
  assert(fixed == 1);
66
 
 
67
 
  store_now_in_TIME(ltime);
68
 
  int64_t tmp;
69
 
  ltime.convert(tmp);
70
 
 
71
 
  return int64_t2double(tmp);
 
57
  store_now_in_TIME(&ltime);
 
58
  return uint64_t2double(TIME_to_uint64_t_datetime(&ltime));
72
59
}
73
60
 
74
61
 
76
63
{
77
64
  decimals= 0;
78
65
  collation.set(&my_charset_bin);
79
 
  max_length= DateTime::MAX_STRING_LENGTH*MY_CHARSET_BIN_MB_MAXLEN;
 
66
  max_length= MAX_DATETIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
80
67
}
81
68
 
82
69
 
83
 
bool Item_func_sysdate_local::get_date(type::Time &res, uint32_t )
 
70
bool Item_func_sysdate_local::get_date(DRIZZLE_TIME *res,
 
71
                                       uint32_t fuzzy_date __attribute__((unused)))
84
72
{
85
 
  store_now_in_TIME(ltime);
86
 
  res= ltime;
 
73
  store_now_in_TIME(&ltime);
 
74
  *res= ltime;
87
75
  return 0;
88
76
}
89
77
 
90
78
 
91
 
int Item_func_sysdate_local::save_in_field(Field *to, bool )
 
79
int Item_func_sysdate_local::save_in_field(Field *to, bool no_conversions __attribute__((unused)))
92
80
{
93
 
  store_now_in_TIME(ltime);
 
81
  store_now_in_TIME(&ltime);
94
82
  to->set_notnull();
95
 
  to->store_time(ltime, type::DRIZZLE_TIMESTAMP_DATETIME);
96
 
 
 
83
  to->store_time(&ltime, DRIZZLE_TIMESTAMP_DATETIME);
97
84
  return 0;
98
85
}
99
86
 
100
 
} /* namespace drizzled */