~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2009-10-06 19:14:39 UTC
  • mfrom: (1130.2.18 plugin-base-class)
  • mto: This revision was merged to the branch mainline in revision 1184.
  • Revision ID: mordred@inaugust.com-20091006191439-fd1vvlp22654l3k3
Merged latest plugin-base-class.

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