~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Lee Bieber
  • Date: 2011-03-29 22:31:41 UTC
  • mfrom: (2257.1.3 build)
  • Revision ID: kalebral@gmail.com-20110329223141-yxc22h3l2he58sk0
Merge Andrew - 743842: Build failure using GCC 4.6
Merge Stewart - 738022: CachedDirectory silently fails to add entries if stat() fails
Merge Olaf - Common fwd: add copyright, add more declaration

Show diffs side-by-side

added added

removed removed

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