~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2009-11-12 16:13:04 UTC
  • mfrom: (1211.1.7 staging)
  • Revision ID: brian@gaz-20091112161304-opamiauv36fg0n6u
Rollup of Brian, Padraig, and Stewart patches.

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"
 
20
#include "drizzled/server_includes.h"
 
21
#include CSTDINT_H
21
22
#include "drizzled/temporal.h"
22
23
#include "drizzled/error.h"
23
24
#include "drizzled/function/time/second.h"
24
25
 
25
 
namespace drizzled
26
 
{
27
 
 
28
26
int64_t Item_func_second::val_int()
29
27
{
30
28
  assert(fixed);
51
49
   *
52
50
   * Oh, and Brian Aker MADE me do this. :) --JRP
53
51
   */
54
 
  Time temporal_time;
 
52
  drizzled::Time temporal_time;
55
53
  
56
54
  char time_buff[DRIZZLE_MAX_LENGTH_DATETIME_AS_STRING];
57
55
  String tmp_time(time_buff,sizeof(time_buff), &my_charset_utf8_bin);
58
56
  String *time_res= args[0]->val_str(&tmp_time);
59
 
 
60
 
  if (time_res && (time_res != &tmp_time))
61
 
  {
62
 
    tmp_time.copy(*time_res);
63
 
  }
64
 
 
65
 
  if (! temporal_time.from_string(tmp_time.c_ptr(), tmp_time.length()))
 
57
  if (! temporal_time.from_string(time_res->c_ptr(), time_res->length()))
66
58
  {
67
59
    /* 
68
60
     * OK, we failed to match the first argument as a string
69
61
     * representing a time value, so we grab the first argument 
70
62
     * as a DateTime object and try that for a match...
71
63
     */
72
 
    DateTime temporal_datetime;
 
64
    drizzled::DateTime temporal_datetime;
73
65
    Item_result arg0_result_type= args[0]->result_type();
74
66
    
75
67
    switch (arg0_result_type)
88
80
          char buff[DRIZZLE_MAX_LENGTH_DATETIME_AS_STRING];
89
81
          String tmp(buff,sizeof(buff), &my_charset_utf8_bin);
90
82
          String *res= args[0]->val_str(&tmp);
91
 
 
92
 
          if (res && (res != &tmp))
93
 
          {
94
 
            tmp.copy(*res);
95
 
          }
96
 
 
97
 
          if (! temporal_datetime.from_string(tmp.c_ptr(), tmp.length()))
 
83
          if (! temporal_datetime.from_string(res->c_ptr(), res->length()))
98
84
          {
99
85
            /* 
100
86
            * Could not interpret the function argument as a temporal value, 
101
87
            * so throw an error and return 0
102
88
            */
103
 
            my_error(ER_INVALID_DATETIME_VALUE, MYF(0), tmp.c_ptr());
 
89
            my_error(ER_INVALID_DATETIME_VALUE, MYF(0), res->c_ptr());
104
90
            return 0;
105
91
          }
106
92
        }
122
108
 
123
109
          res= args[0]->val_str(&tmp);
124
110
 
125
 
          if (res && (res != &tmp))
126
 
          {
127
 
            tmp.copy(*res);
128
 
          }
129
 
 
130
 
          my_error(ER_INVALID_DATETIME_VALUE, MYF(0), tmp.c_ptr());
 
111
          my_error(ER_INVALID_DATETIME_VALUE, MYF(0), res->c_ptr());
131
112
          return 0;
132
113
        }
133
114
    }
136
117
  return (int64_t) temporal_time.seconds();
137
118
}
138
119
 
139
 
} /* namespace drizzled */