~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2009-02-21 00:18:15 UTC
  • Revision ID: brian@tangent.org-20090221001815-x20e8h71e984lvs1
Completion (?) of uint conversion.

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/unix_timestamp.h>
23
 
#include <drizzled/field/epoch.h>
 
23
#include <drizzled/field/timestamp.h>
24
24
#include <drizzled/session.h>
25
25
 
26
 
#include "drizzled/temporal.h"
27
 
 
28
 
namespace drizzled
29
 
{
30
 
 
31
26
int64_t Item_func_unix_timestamp::val_int()
32
27
{
33
 
  type::Time ltime;
 
28
  DRIZZLE_TIME ltime;
 
29
  bool not_used;
34
30
 
35
31
  assert(fixed == 1);
36
32
  if (arg_count == 0)
37
 
    return (int64_t) current_session->getCurrentTimestampEpoch();
38
 
 
 
33
    return (int64_t) current_session->query_start();
39
34
  if (args[0]->type() == FIELD_ITEM)
40
35
  {                                             // Optimize timestamp field
41
36
    Field *field=((Item_field*) args[0])->field;
42
37
    if (field->type() == DRIZZLE_TYPE_TIMESTAMP)
43
 
      return ((field::Epoch::pointer) field)->get_timestamp(&null_value);
 
38
      return ((Field_timestamp*) field)->get_timestamp(&null_value);
44
39
  }
45
40
 
46
 
  if (get_arg0_date(ltime, 0))
 
41
  if (get_arg0_date(&ltime, 0))
47
42
  {
48
43
    /*
49
44
      We have to set null_value again because get_arg0_date will also set it
54
49
    return 0;
55
50
  }
56
51
 
57
 
  Timestamp temporal;
58
 
 
59
 
  temporal.set_years(ltime.year);
60
 
  temporal.set_months(ltime.month);
61
 
  temporal.set_days(ltime.day);
62
 
  temporal.set_hours(ltime.hour);
63
 
  temporal.set_minutes(ltime.minute);
64
 
  temporal.set_seconds(ltime.second);
65
 
  temporal.set_epoch_seconds();
66
 
 
67
 
  if (! temporal.is_valid())
68
 
  {
69
 
    null_value= true;
70
 
    char buff[DateTime::MAX_STRING_LENGTH];
71
 
    int buff_len;
72
 
    buff_len= temporal.to_string(buff, DateTime::MAX_STRING_LENGTH);
73
 
    assert((buff_len+1) < DateTime::MAX_STRING_LENGTH);
74
 
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(0), buff);
75
 
    return 0;
76
 
  }
77
 
 
78
 
  time_t tmp;
79
 
  temporal.to_time_t(tmp);
80
 
 
81
 
  return (int64_t) tmp;
 
52
  return (int64_t) TIME_to_timestamp(current_session, &ltime, &not_used);
82
53
}
83
54
 
84
 
} /* namespace drizzled */