~hartmut-php/drizzle/drizzle-codegen

« back to all changes in this revision

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

  • Committer: Hartmut Holzgraefe
  • Date: 2009-02-21 11:38:51 UTC
  • mfrom: (884.1.12 drizzle)
  • Revision ID: hartmut@mysql.com-20090221113851-p2n577trxbr8ip7v
mergeĀ fromĀ lp:drizzle

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 <drizzled/server_includes.h>
 
20
#include "drizzled/server_includes.h"
21
21
#include CSTDINT_H
22
 
#include <drizzled/function/time/from_days.h>
23
 
 
24
 
bool Item_func_from_days::get_date(DRIZZLE_TIME *ltime, uint32_t )
 
22
#include "drizzled/function/time/from_days.h"
 
23
#include "drizzled/error.h"
 
24
#include "drizzled/temporal.h"
 
25
 
 
26
#include <sstream>
 
27
#include <string>
 
28
 
 
29
/**
 
30
 * Interpret the first argument as a Julian Day Number and fill
 
31
 * our supplied temporal object.
 
32
 */
 
33
bool Item_func_from_days::get_temporal(drizzled::Date &to)
25
34
{
26
 
  int64_t value=args[0]->val_int();
27
 
  if ((null_value=args[0]->null_value))
28
 
    return 1;
29
 
  memset(ltime, 0, sizeof(DRIZZLE_TIME));
30
 
  get_date_from_daynr((long) value, &ltime->year, &ltime->month, &ltime->day);
31
 
  ltime->time_type= DRIZZLE_TIMESTAMP_DATE;
32
 
  return 0;
 
35
  assert(fixed);
 
36
 
 
37
  /* 
 
38
   * We MUST call val_int() before checking null_value because, stupidly, 
 
39
   * a subselect does not evaluate it's scalar items as null until val_xxx()
 
40
   * has been called. :(
 
41
   */
 
42
  int64_t int_value= args[0]->val_int();
 
43
 
 
44
  /* We return NULL from FROM_DAYS() only when supplied a NULL argument */
 
45
  if (args[0]->null_value)
 
46
  {
 
47
    null_value= true;
 
48
    return false;
 
49
  }
 
50
 
 
51
  /* OK, now try to convert from our integer */
 
52
  if (! to.from_julian_day_number(int_value))
 
53
  {
 
54
    /* Bad input, throw an error */
 
55
    std::stringstream ss;
 
56
    std::string tmp;
 
57
    ss << int_value; ss >> tmp;
 
58
 
 
59
    my_error(ER_ARGUMENT_OUT_OF_RANGE, MYF(ME_FATALERROR), tmp.c_str(), func_name());
 
60
    return false;
 
61
  }
 
62
  return true;
33
63
}
34