~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2009-10-15 00:22:33 UTC
  • mto: (1183.1.11 merge)
  • mto: This revision was merged to the branch mainline in revision 1198.
  • Revision ID: brian@gaz-20091015002233-fa4ao2mbc67wls91
First pass of information engine. OMG, ponies... is it so much easier to
deal with creating and engine.

The list table iterator though... its ass, needs to go. We should also
abstract out share. Very few engines need a custom one. Just say'in

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