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_info.h>
00024 
00025 namespace drizzled
00026 {
00027 
00028 class Item_string :public Item_basic_constant
00029 {
00030 public:
00031   Item_string(const char *str,uint32_t length,
00032               const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE)
00033     : m_cs_specified(false)
00034   {
00035     str_value.set_or_copy_aligned(str, length, cs);
00036     collation.set(cs, dv);
00037     /*
00038       We have to have a different max_length than 'length' here to
00039       ensure that we get the right length if we do use the item
00040       to create a new table. In this case max_length must be the maximum
00041       number of chars for a string of this type because we in CreateField::
00042       divide the max_length with mbmaxlen).
00043     */
00044     max_length= str_value.numchars()*cs->mbmaxlen;
00045     set_name(str, length, cs);
00046     decimals=NOT_FIXED_DEC;
00047     // it is constant => can be used without fix_fields (and frequently used)
00048     fixed= 1;
00049   }
00050   /* Just create an item and do not fill string representation */
00051   Item_string(const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE)
00052     : m_cs_specified(false)
00053   {
00054     collation.set(cs, dv);
00055     max_length= 0;
00056     set_name(NULL, 0, cs);
00057     decimals= NOT_FIXED_DEC;
00058     fixed= 1;
00059   }
00060   Item_string(const char *name_par, const char *str, uint32_t length,
00061               const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE)
00062     : m_cs_specified(false)
00063   {
00064     str_value.set_or_copy_aligned(str, length, cs);
00065     collation.set(cs, dv);
00066     max_length= str_value.numchars()*cs->mbmaxlen;
00067     set_name(name_par, 0, cs);
00068     decimals=NOT_FIXED_DEC;
00069     // it is constant => can be used without fix_fields (and frequently used)
00070     fixed= 1;
00071   }
00072   enum Type type() const { return STRING_ITEM; }
00073   double val_real();
00074   int64_t val_int();
00075   String *val_str(String*)
00076   {
00077     assert(fixed == 1);
00078     return (String*) &str_value;
00079   }
00080   type::Decimal *val_decimal(type::Decimal *);
00081   int save_in_field(Field *field, bool no_conversions);
00082   enum Item_result result_type () const { return STRING_RESULT; }
00083   enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
00084   bool basic_const_item() const { return 1; }
00085   bool eq(const Item *item, bool binary_cmp) const;
00086   Item *clone_item()
00087   {
00088     return new Item_string(name, str_value.ptr(),
00089              str_value.length(), collation.collation);
00090   }
00091   Item *safe_charset_converter(const CHARSET_INFO * const tocs);
00092   inline void append(char *str, uint32_t length)
00093   {
00094     str_value.append(str, length);
00095     max_length= str_value.numchars() * collation.collation->mbmaxlen;
00096   }
00097   virtual void print(String *str);
00098 
00118   inline bool is_cs_specified() const
00119   {
00120     return m_cs_specified;
00121   }
00122 
00133   inline void set_cs_specified(bool cs_specified)
00134   {
00135     m_cs_specified= cs_specified;
00136   }
00137 
00138 private:
00139   bool m_cs_specified;
00140 };
00141 
00142 
00143 class Item_static_string_func :public Item_string
00144 {
00145   const char *func_name;
00146 public:
00147   Item_static_string_func(const char *name_par, const char *str, uint32_t length,
00148                           const CHARSET_INFO * const cs,
00149                           Derivation dv= DERIVATION_COERCIBLE)
00150     :Item_string(NULL, str, length, cs, dv), func_name(name_par)
00151   {}
00152   Item *safe_charset_converter(const CHARSET_INFO * const tocs);
00153 
00154   virtual inline void print(String *str)
00155   {
00156     str->append(func_name);
00157   }
00158 };
00159 
00160 } /* namespace drizzled */
00161