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