~drizzle-trunk/drizzle/development

574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
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
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
20
#include <config.h>
1775.5.1 by earney
modified files containing stringstream to use boost:lexical_cast instead as
21
#include <boost/lexical_cast.hpp>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
22
#include <drizzled/function/time/from_days.h>
23
#include <drizzled/error.h>
24
#include <drizzled/temporal.h>
873.1.9 by Jay Pipes
This patch fixes the following functions to properly error out
25
26
#include <sstream>
27
#include <string>
28
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
29
namespace drizzled
30
{
31
873.1.9 by Jay Pipes
This patch fixes the following functions to properly error out
32
/**
33
 * Interpret the first argument as a Julian Day Number and fill
34
 * our supplied temporal object.
35
 */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
36
bool Item_func_from_days::get_temporal(Date &to)
574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
37
{
873.1.9 by Jay Pipes
This patch fixes the following functions to properly error out
38
  assert(fixed);
39
873.1.15 by Jay Pipes
This fixes the bug which was not properly evaluating whether a subselect scalar Item_field was null. The issue is that Field::null_value is not set properly until val_xxx() methods are called on it. This is completely stooopid, but that was the cause of this bug.
40
  /* 
41
   * We MUST call val_int() before checking null_value because, stupidly, 
42
   * a subselect does not evaluate it's scalar items as null until val_xxx()
43
   * has been called. :(
44
   */
45
  int64_t int_value= args[0]->val_int();
46
873.1.9 by Jay Pipes
This patch fixes the following functions to properly error out
47
  /* We return NULL from FROM_DAYS() only when supplied a NULL argument */
48
  if (args[0]->null_value)
49
  {
50
    null_value= true;
51
    return false;
52
  }
53
54
  /* OK, now try to convert from our integer */
55
  if (! to.from_julian_day_number(int_value))
56
  {
57
    /* Bad input, throw an error */
1775.5.1 by earney
modified files containing stringstream to use boost:lexical_cast instead as
58
    std::string tmp(boost::lexical_cast<std::string>(int_value));
873.1.9 by Jay Pipes
This patch fixes the following functions to properly error out
59
60
    my_error(ER_ARGUMENT_OUT_OF_RANGE, MYF(ME_FATALERROR), tmp.c_str(), func_name());
61
    return false;
62
  }
63
  return true;
574.3.16 by Lee
moving functions from item_timefunc to functions/time directory
64
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
65
66
} /* namespace drizzled */