~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/epoch.cc

  • Committer: Brian Aker
  • Date: 2011-01-12 06:45:23 UTC
  • mto: (2073.1.4 catalogs)
  • mto: This revision was merged to the branch mainline in revision 2080.
  • Revision ID: brian@tangent.org-20110112064523-rqhptaqbph22qmj1
RemoveĀ customĀ error.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include <config.h>
22
 
 
 
21
#include "config.h"
23
22
#include <boost/lexical_cast.hpp>
24
23
#include <drizzled/field/epoch.h>
25
24
#include <drizzled/error.h>
26
25
#include <drizzled/tztime.h>
27
26
#include <drizzled/table.h>
28
27
#include <drizzled/session.h>
29
 
#include <drizzled/current_session.h>
30
28
 
31
29
#include <math.h>
32
30
 
33
31
#include <sstream>
34
32
 
35
 
#include <drizzled/temporal.h>
 
33
#include "drizzled/temporal.h"
36
34
 
37
35
namespace drizzled
38
36
{
164
162
 
165
163
  if (not temporal.from_string(from, (size_t) len))
166
164
  {
167
 
    my_error(ER_INVALID_TIMESTAMP_VALUE, MYF(ME_FATALERROR), from);
 
165
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), from);
168
166
    return 1;
169
167
  }
170
168
 
180
178
{
181
179
  ASSERT_COLUMN_MARKED_FOR_WRITE;
182
180
 
183
 
  uint64_t from_tmp= (uint64_t)from;
184
 
 
185
 
  Timestamp temporal;
186
 
  if (not temporal.from_int64_t(from_tmp))
 
181
  if (from < 0 || from > 99991231235959.0)
187
182
  {
188
 
    /* Convert the integer to a string using boost::lexical_cast */
189
 
    std::string tmp(boost::lexical_cast<std::string>(from));
 
183
    /* Convert the double to a string using stringstream */
 
184
    std::stringstream ss;
 
185
    std::string tmp;
 
186
    ss.precision(18); /* 18 places should be fine for error display of double input. */
 
187
    ss << from; 
 
188
    ss >> tmp;
190
189
 
191
 
    my_error(ER_INVALID_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
 
190
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
192
191
    return 2;
193
192
  }
194
 
 
195
 
  time_t tmp;
196
 
  temporal.to_time_t(tmp);
197
 
 
198
 
  uint64_t tmp_micro= tmp;
199
 
  pack_num(tmp_micro);
200
 
 
201
 
  return 0;
202
 
}
203
 
 
204
 
int Epoch::store_decimal(const type::Decimal *value)
205
 
{
206
 
  double tmp;
207
 
  value->convert(tmp);
208
 
 
209
 
  return store(tmp);
 
193
  return Epoch::store((int64_t) rint(from), false);
210
194
}
211
195
 
212
196
int Epoch::store(int64_t from, bool)
218
202
   * if unable to create a valid DateTime.  
219
203
   */
220
204
  Timestamp temporal;
221
 
  if (not temporal.from_int64_t(from))
 
205
  if (! temporal.from_int64_t(from))
222
206
  {
223
207
    /* Convert the integer to a string using boost::lexical_cast */
224
208
    std::string tmp(boost::lexical_cast<std::string>(from));
225
209
 
226
 
    my_error(ER_INVALID_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
 
210
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
227
211
    return 2;
228
212
  }
229
213
 
236
220
  return 0;
237
221
}
238
222
 
239
 
double Epoch::val_real(void) const
 
223
double Epoch::val_real(void)
240
224
{
241
225
  return (double) Epoch::val_int();
242
226
}
243
227
 
244
 
int64_t Epoch::val_int(void) const
 
228
int64_t Epoch::val_int(void)
245
229
{
246
230
  uint64_t temp;
247
231
 
258
242
  return result;
259
243
}
260
244
 
261
 
String *Epoch::val_str(String *val_buffer, String *) const
 
245
String *Epoch::val_str(String *val_buffer, String *)
262
246
{
263
247
  uint64_t temp= 0;
264
248
  char *to;
282
266
  return val_buffer;
283
267
}
284
268
 
285
 
bool Epoch::get_date(type::Time &ltime, uint32_t) const
 
269
bool Epoch::get_date(type::Time *ltime, uint32_t)
286
270
{
287
271
  uint64_t temp;
288
 
  type::Time::epoch_t time_temp;
289
272
 
290
273
  unpack_num(temp);
291
 
  time_temp= temp;
292
274
  
293
 
  ltime.reset();
294
 
 
295
 
  ltime.store(time_temp);
 
275
  memset(ltime, 0, sizeof(*ltime));
 
276
 
 
277
  Timestamp temporal;
 
278
  (void) temporal.from_time_t((time_t) temp);
 
279
 
 
280
  /* @TODO Goodbye the below code when type::Time is finally gone.. */
 
281
 
 
282
  ltime->time_type= DRIZZLE_TIMESTAMP_DATETIME;
 
283
  ltime->year= temporal.years();
 
284
  ltime->month= temporal.months();
 
285
  ltime->day= temporal.days();
 
286
  ltime->hour= temporal.hours();
 
287
  ltime->minute= temporal.minutes();
 
288
  ltime->second= temporal.seconds();
296
289
 
297
290
  return 0;
298
291
}
299
292
 
300
 
bool Epoch::get_time(type::Time &ltime) const
 
293
bool Epoch::get_time(type::Time *ltime)
301
294
{
302
 
  return Epoch::get_date(ltime, 0);
 
295
  return Epoch::get_date(ltime,0);
303
296
}
304
297
 
305
298
int Epoch::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
368
361
  }
369
362
}
370
363
 
371
 
long Epoch::get_timestamp(bool *null_value) const
 
364
long Epoch::get_timestamp(bool *null_value)
372
365
{
373
366
  if ((*null_value= is_null()))
374
367
    return 0;