Drizzled Public API Documentation

date.h

00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #pragma once
00021 
00022 #include <drizzled/function/func.h>
00023 #include <drizzled/function/str/strfunc.h>
00024 #include <drizzled/temporal.h>
00025 
00026 namespace drizzled
00027 {
00028 
00029 /* A function which evaluates to a Date */
00030 class Item_date :public Item_func
00031 {
00032 public:
00033   using Item_func::tmp_table_field;
00034 
00035   Item_date() :Item_func() {}
00036   Item_date(Item *a) :Item_func(a) {}
00037   enum Item_result result_type () const { return STRING_RESULT; }
00038   enum_field_types field_type() const { return DRIZZLE_TYPE_DATE; }
00039   String *val_str(String *str);
00040   int64_t val_int();
00041   double val_real() { return val_real_from_decimal(); }
00042   const char *func_name() const { return "date"; }
00043   void fix_length_and_dec()
00044   {
00045     collation.set(&my_charset_bin);
00046     decimals=0;
00047     max_length=Date::MAX_STRING_LENGTH*MY_CHARSET_BIN_MB_MAXLEN;
00048   }
00060   virtual bool get_temporal(Date &temporal)= 0;
00061   Field *tmp_table_field(Table *table)
00062   {
00063     return tmp_table_field_from_field_type(table, 0);
00064   }
00065   bool result_as_int64_t() { return true; }
00066   type::Decimal *val_decimal(type::Decimal *decimal_value)
00067   {
00068     assert(fixed == 1);
00069     return  val_decimal_from_date(decimal_value);
00070   }
00071   int save_in_field(Field *field,
00072                     bool )
00073   {
00074     return save_date_in_field(field);
00075   }
00076 };
00077 
00078 class Item_date_func :public Item_str_func
00079 {
00080 public:
00081   Item_date_func() :Item_str_func() {}
00082   Item_date_func(Item *a) :Item_str_func(a) {}
00083   Item_date_func(Item *a,Item *b) :Item_str_func(a,b) {}
00084   Item_date_func(Item *a,Item *b, Item *c) :Item_str_func(a,b,c) {}
00085   enum_field_types field_type() const { return DRIZZLE_TYPE_DATETIME; }
00086 
00087   using Item_func::tmp_table_field;
00088   Field *tmp_table_field(Table *table)
00089   {
00090     return tmp_table_field_from_field_type(table, 0);
00091   }
00092   bool result_as_int64_t() { return true; }
00093   double val_real() { return (double) val_int(); }
00094   type::Decimal *val_decimal(type::Decimal *decimal_value)
00095   {
00096     assert(fixed == 1);
00097     return  val_decimal_from_date(decimal_value);
00098   }
00099   int save_in_field(Field *field,
00100                     bool )
00101   {
00102     return save_date_in_field(field);
00103   }
00104 };
00105 
00106 } /* namespace drizzled */
00107