Drizzled Public API Documentation

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/item/basic_constant.h>
00023 #include <drizzled/charset.h>
00024 
00025 namespace drizzled {
00026 
00027 class Item_string : public Item_basic_constant
00028 {
00029 public:
00030   Item_string(str_ref str, const charset_info_st* cs, Derivation dv= DERIVATION_COERCIBLE)
00031   {
00032     assert(not (str.size() % cs->mbminlen));
00033     str_value.set(str.data(), str.size(), cs);
00034     collation.set(cs, dv);
00035     /*
00036       We have to have a different max_length than 'length' here to
00037       ensure that we get the right length if we do use the item
00038       to create a new table. In this case max_length must be the maximum
00039       number of chars for a string of this type because we in CreateField::
00040       divide the max_length with mbmaxlen).
00041     */
00042     max_length= str_value.numchars() * cs->mbmaxlen;
00043     set_name(str.data(), str.size(), cs);
00044     decimals=NOT_FIXED_DEC;
00045     // it is constant => can be used without fix_fields (and frequently used)
00046     fixed= 1;
00047   }
00048 
00049   Item_string(const char *str,uint32_t length,
00050               const charset_info_st * const cs, Derivation dv= DERIVATION_COERCIBLE)
00051   {
00052     assert(not (length % cs->mbminlen));
00053     str_value.set(str, length, cs);
00054     collation.set(cs, dv);
00055     /*
00056       We have to have a different max_length than 'length' here to
00057       ensure that we get the right length if we do use the item
00058       to create a new table. In this case max_length must be the maximum
00059       number of chars for a string of this type because we in CreateField::
00060       divide the max_length with mbmaxlen).
00061     */
00062     max_length= str_value.numchars()*cs->mbmaxlen;
00063     set_name(str, length, cs);
00064     decimals=NOT_FIXED_DEC;
00065     // it is constant => can be used without fix_fields (and frequently used)
00066     fixed= 1;
00067   }
00068   /* Just create an item and do not fill string representation */
00069   Item_string(const charset_info_st * const cs, Derivation dv= DERIVATION_COERCIBLE)
00070   {
00071     collation.set(cs, dv);
00072     max_length= 0;
00073     set_name(NULL, 0, cs);
00074     decimals= NOT_FIXED_DEC;
00075     fixed= 1;
00076   }
00077   Item_string(const char *name_par, const char *str, uint32_t length,
00078               const charset_info_st * const cs, Derivation dv= DERIVATION_COERCIBLE)
00079   {
00080     assert(not (length % cs->mbminlen));
00081     str_value.set(str, length, cs);
00082     collation.set(cs, dv);
00083     max_length= str_value.numchars()*cs->mbmaxlen;
00084     set_name(name_par, 0, cs);
00085     decimals=NOT_FIXED_DEC;
00086     // it is constant => can be used without fix_fields (and frequently used)
00087     fixed= 1;
00088   }
00089   enum Type type() const { return STRING_ITEM; }
00090   double val_real();
00091   int64_t val_int();
00092   String *val_str(String*)
00093   {
00094     assert(fixed == 1);
00095     return (String*) &str_value;
00096   }
00097   type::Decimal *val_decimal(type::Decimal *);
00098   int save_in_field(Field *field, bool no_conversions);
00099   enum Item_result result_type () const { return STRING_RESULT; }
00100   enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
00101   bool basic_const_item() const { return 1; }
00102   bool eq(const Item *item, bool binary_cmp) const;
00103   Item *clone_item()
00104   {
00105     return new Item_string(name, str_value.ptr(), str_value.length(), collation.collation);
00106   }
00107   Item *safe_charset_converter(const charset_info_st * const tocs);
00108   inline void append(str_ref v)
00109   {
00110     str_value.append(v);
00111     max_length= str_value.numchars() * collation.collation->mbmaxlen;
00112   }
00113   virtual void print(String *str);
00114 };
00115 
00116 
00117 class Item_static_string_func : public Item_string
00118 {
00119   const char *func_name;
00120 public:
00121   Item_static_string_func(const char *name_par, str_ref str, const charset_info_st* cs, Derivation dv= DERIVATION_COERCIBLE) :
00122     Item_string(NULL, str.data(), str.size(), cs, dv), func_name(name_par)
00123   {}
00124   Item *safe_charset_converter(const charset_info_st*);
00125 
00126   virtual inline void print(String *str)
00127   {
00128     str->append(func_name);
00129   }
00130 };
00131 
00132 } /* namespace drizzled */
00133