Drizzled Public API Documentation

copy_string.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/charset.h>
00023 #include <drizzled/item/field.h>
00024 #include <drizzled/item/ident.h>
00025 
00026 namespace drizzled {
00027 
00028 class Item_copy_string : public Item
00029 {
00030   enum enum_field_types cached_field_type;
00031 public:
00032   Item *item;
00033   Item_copy_string(Item *i) :item(i)
00034   {
00035     null_value= maybe_null= item->maybe_null;
00036     decimals=item->decimals;
00037     max_length=item->max_length;
00038     name=item->name;
00039     cached_field_type= item->field_type();
00040   }
00041   enum Type type() const { return COPY_STR_ITEM; }
00042   enum Item_result result_type () const { return STRING_RESULT; }
00043   enum_field_types field_type() const { return cached_field_type; }
00044   double val_real()
00045   {
00046     int err_not_used;
00047     char *end_not_used;
00048     return (null_value ? 0.0 :
00049             my_strntod(str_value.charset(), (char*) str_value.ptr(),
00050                        str_value.length(), &end_not_used, &err_not_used));
00051   }
00052   int64_t val_int()
00053   {
00054     int err;
00055     return null_value ? 0 : my_strntoll(str_value.charset(),str_value.ptr(),
00056                                         str_value.length(),10, (char**) 0,
00057                                         &err);
00058   }
00059   String *val_str(String*);
00060   type::Decimal *val_decimal(type::Decimal *);
00061   void make_field(SendField *field) { item->make_field(field); }
00062   void copy();
00063   int save_in_field(Field *field, bool)
00064   {
00065     return save_str_value_in_field(field, &str_value);
00066   }
00067   table_map used_tables() const { return (table_map) 1; }
00068   bool const_item() const { return false; }
00069   bool is_null() { return null_value; }
00070 };
00071 
00072 } /* namespace drizzled */
00073