~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

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