~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2009-04-27 14:36:40 UTC
  • Revision ID: brian@gaz-20090427143640-f6zjmtt9vm55qgm2
Patch on show processlist from  davi@apache.org

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/function/time/to_days.h"
23
23
#include "drizzled/error.h"
24
24
#include "drizzled/temporal.h"
25
25
 
26
 
namespace drizzled
27
 
{
28
 
 
29
26
/* 
30
27
 * We intepret the first argument as a DateTime and then convert
31
28
 * it to a Julian Day Number and return it.
51
48
   * error and return 0, setting the null_value flag to true.
52
49
   */
53
50
  /* Grab the first argument as a DateTime object */
54
 
  DateTime temporal;
 
51
  drizzled::DateTime temporal;
55
52
  Item_result arg0_result_type= args[0]->result_type();
56
53
  
57
54
  switch (arg0_result_type)
82
79
          return false;
83
80
        }
84
81
 
85
 
        if (res != &tmp)
86
 
        {
87
 
          tmp.copy(*res);
88
 
        }
89
 
 
90
 
        if (! temporal.from_string(tmp.c_ptr(), tmp.length()))
 
82
        if (! temporal.from_string(res->c_ptr(), res->length()))
91
83
        {
92
84
          /* 
93
85
          * Could not interpret the function argument as a temporal value, 
94
86
          * so throw an error and return 0
95
87
          */
96
 
          my_error(ER_INVALID_DATETIME_VALUE, MYF(0), tmp.c_ptr());
 
88
          my_error(ER_INVALID_DATETIME_VALUE, MYF(0), res->c_ptr());
97
89
          return 0;
98
90
        }
99
91
      }
125
117
          return false;
126
118
        }
127
119
 
128
 
        if (res != &tmp)
129
 
        {
130
 
          tmp.copy(*res);
131
 
        }
132
 
 
133
 
        my_error(ER_INVALID_DATETIME_VALUE, MYF(0), tmp.c_ptr());
 
120
        my_error(ER_INVALID_DATETIME_VALUE, MYF(0), res->c_ptr());
134
121
        return 0;
135
122
      }
136
123
  }
139
126
  return julian_day_number;
140
127
}
141
128
 
 
129
/*
 
130
  Get information about this Item tree monotonicity
 
131
 
 
132
  SYNOPSIS
 
133
    Item_func_to_days::get_monotonicity_info()
 
134
 
 
135
  DESCRIPTION
 
136
  Get information about monotonicity of the function represented by this item
 
137
  tree.
 
138
 
 
139
  RETURN
 
140
    See enum_monotonicity_info.
 
141
*/
 
142
enum_monotonicity_info Item_func_to_days::get_monotonicity_info() const
 
143
{
 
144
  if (args[0]->type() == Item::FIELD_ITEM)
 
145
  {
 
146
    if (args[0]->field_type() == DRIZZLE_TYPE_DATE)
 
147
      return MONOTONIC_STRICT_INCREASING;
 
148
    if (args[0]->field_type() == DRIZZLE_TYPE_DATETIME)
 
149
      return MONOTONIC_INCREASING;
 
150
  }
 
151
  return NON_MONOTONIC;
 
152
}
 
153
 
142
154
int64_t Item_func_to_days::val_int_endpoint(bool left_endp, bool *incl_endp)
143
155
{
144
156
  assert(fixed);
153
165
   * the appropriate end-point integer.
154
166
   */
155
167
  /* Grab the first argument as a DateTime object */
156
 
  DateTime temporal;
 
168
  drizzled::DateTime temporal;
157
169
  Item_result arg0_result_type= args[0]->result_type();
158
170
  
159
171
  switch (arg0_result_type)
184
196
          return 0;
185
197
        }
186
198
 
187
 
        if (res != &tmp)
188
 
        {
189
 
          tmp.copy(*res);
190
 
        }
191
 
 
192
 
        if (! temporal.from_string(tmp.c_ptr(), tmp.length()))
 
199
        if (! temporal.from_string(res->c_ptr(), res->length()))
193
200
        {
194
201
          /* 
195
202
          * Could not interpret the function argument as a temporal value, 
196
203
          * so throw an error and return 0
197
204
          */
198
 
          my_error(ER_INVALID_DATETIME_VALUE, MYF(0), tmp.c_ptr());
 
205
          my_error(ER_INVALID_DATETIME_VALUE, MYF(0), res->c_ptr());
199
206
          return 0;
200
207
        }
201
208
      }
227
234
          return 0;
228
235
        }
229
236
 
230
 
        if (res != &tmp)
231
 
        {
232
 
          tmp.copy(*res);
233
 
        }
234
 
 
235
 
        my_error(ER_INVALID_DATETIME_VALUE, MYF(0), tmp.c_ptr());
 
237
        my_error(ER_INVALID_DATETIME_VALUE, MYF(0), res->c_ptr());
236
238
        return 0;
237
239
      }
238
240
  }
276
278
    *incl_endp= true;
277
279
  return julian_day_number;
278
280
}
279
 
 
280
 
} /* namespace drizzled */