Drizzled Public API Documentation

conv_charset.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/str/strfunc.h>
00023 
00024 namespace drizzled {
00025 
00026 class Item_func_conv_charset :public Item_str_func
00027 {
00028   bool use_cached_value;
00029 public:
00030   bool safe;
00031   const charset_info_st *conv_charset; // keep it public
00032   Item_func_conv_charset(Item *a, const charset_info_st * const cs) :Item_str_func(a)
00033   { conv_charset= cs; use_cached_value= 0; safe= 0; }
00034   Item_func_conv_charset(Item *a, const charset_info_st * const cs, bool cache_if_const)
00035     :Item_str_func(a)
00036   {
00037     assert(args[0]->fixed);
00038     conv_charset= cs;
00039     if (cache_if_const && args[0]->const_item())
00040     {
00041       String tmp, *str= args[0]->val_str(&tmp);
00042       if (!str)
00043         null_value= 1;
00044       else
00045         str_value.copy(str->ptr(), str->length(), conv_charset);
00046       use_cached_value= 1;
00047       str_value.mark_as_const();
00048       safe= true;
00049     }
00050     else
00051     {
00052       use_cached_value= false;
00053       /*
00054         Conversion from and to "binary" is safe.
00055         Conversion to Unicode is safe.
00056         Other kind of conversions are potentially lossy.
00057       */
00058       safe= (args[0]->collation.collation == &my_charset_bin ||
00059              cs == &my_charset_bin ||
00060              (cs->state & MY_CS_UNICODE));
00061     }
00062   }
00063   String *val_str(String *);
00064   void fix_length_and_dec();
00065   const char *func_name() const { return "convert"; }
00066   virtual void print(String *str);
00067 };
00068 
00069 } /* namespace drizzled */
00070