~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2008-07-03 00:14:39 UTC
  • Revision ID: brian@tangent.org-20080703001439-pit0mcl0wk8elxlq
Cleanup of sql-common and mysqldump

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
#include "config.h"
21
 
#include "drizzled/function/time/from_days.h"
22
 
#include "drizzled/error.h"
23
 
#include "drizzled/temporal.h"
24
 
 
25
 
#include <sstream>
26
 
#include <string>
27
 
 
28
 
namespace drizzled
29
 
{
30
 
 
31
 
/**
32
 
 * Interpret the first argument as a Julian Day Number and fill
33
 
 * our supplied temporal object.
34
 
 */
35
 
bool Item_func_from_days::get_temporal(Date &to)
36
 
{
37
 
  assert(fixed);
38
 
 
39
 
  /* 
40
 
   * We MUST call val_int() before checking null_value because, stupidly, 
41
 
   * a subselect does not evaluate it's scalar items as null until val_xxx()
42
 
   * has been called. :(
43
 
   */
44
 
  int64_t int_value= args[0]->val_int();
45
 
 
46
 
  /* We return NULL from FROM_DAYS() only when supplied a NULL argument */
47
 
  if (args[0]->null_value)
48
 
  {
49
 
    null_value= true;
50
 
    return false;
51
 
  }
52
 
 
53
 
  /* OK, now try to convert from our integer */
54
 
  if (! to.from_julian_day_number(int_value))
55
 
  {
56
 
    /* Bad input, throw an error */
57
 
    std::stringstream ss;
58
 
    std::string tmp;
59
 
    ss << int_value; ss >> tmp;
60
 
 
61
 
    my_error(ER_ARGUMENT_OUT_OF_RANGE, MYF(ME_FATALERROR), tmp.c_str(), func_name());
62
 
    return false;
63
 
  }
64
 
  return true;
65
 
}
66
 
 
67
 
} /* namespace drizzled */