Drizzled Public API Documentation

conv_charset.h
1 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2008 Sun Microsystems, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #pragma once
21 
22 #include <drizzled/function/str/strfunc.h>
23 
24 namespace drizzled {
25 
27 {
28  bool use_cached_value;
29 public:
30  bool safe;
31  const charset_info_st *conv_charset; // keep it public
33  { conv_charset= cs; use_cached_value= 0; safe= 0; }
34  Item_func_conv_charset(Item *a, const charset_info_st * const cs, bool cache_if_const)
35  :Item_str_func(a)
36  {
37  assert(args[0]->fixed);
38  conv_charset= cs;
39  if (cache_if_const && args[0]->const_item())
40  {
41  String tmp, *str= args[0]->val_str(&tmp);
42  if (!str)
43  null_value= 1;
44  else
45  str_value.copy(str->ptr(), str->length(), conv_charset);
46  use_cached_value= 1;
47  str_value.mark_as_const();
48  safe= true;
49  }
50  else
51  {
52  use_cached_value= false;
53  /*
54  Conversion from and to "binary" is safe.
55  Conversion to Unicode is safe.
56  Other kind of conversions are potentially lossy.
57  */
58  safe= (args[0]->collation.collation == &my_charset_bin ||
59  cs == &my_charset_bin ||
60  (cs->state & MY_CS_UNICODE));
61  }
62  }
63  String *val_str(String *);
64  void fix_length_and_dec();
65  const char *func_name() const { return "convert"; }
66  virtual void print(String *str);
67 };
68 
69 } /* namespace drizzled */
70 
virtual void print(String *str)
Definition: conv_charset.cc:48
bool fixed
Definition: item.h:120
TODO: Rename this file - func.h is stupid.
bool null_value
Definition: item.h:122
virtual bool const_item() const
Definition: func.h:108
virtual String * val_str(String *str)=0
String str_value
Definition: item.h:107