~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/functions/str/conv_charset.h

  • Committer: Brian Aker
  • Date: 2008-11-13 02:56:15 UTC
  • mfrom: (575.4.10 devel)
  • Revision ID: brian@tangent.org-20081113025615-snhsi52yb2ivmx6f
Merging Monty's code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
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
#ifndef DRIZZLED_FUNCTIONS_STR_CONV_CHARSET_H
 
21
#define DRIZZLED_FUNCTIONS_STR_CONV_CHARSET_H
 
22
 
 
23
#include <drizzled/functions/str/strfunc.h> 
 
24
 
 
25
class Item_func_conv_charset :public Item_str_func
 
26
{
 
27
  bool use_cached_value;
 
28
public:
 
29
  bool safe;
 
30
  const CHARSET_INFO *conv_charset; // keep it public
 
31
  Item_func_conv_charset(Item *a, const CHARSET_INFO * const cs) :Item_str_func(a)
 
32
  { conv_charset= cs; use_cached_value= 0; safe= 0; }
 
33
  Item_func_conv_charset(Item *a, const CHARSET_INFO * const cs, bool cache_if_const)
 
34
    :Item_str_func(a)
 
35
  {
 
36
    assert(args[0]->fixed);
 
37
    conv_charset= cs;
 
38
    if (cache_if_const && args[0]->const_item())
 
39
    {
 
40
      uint32_t errors= 0;
 
41
      String tmp, *str= args[0]->val_str(&tmp);
 
42
      if (!str || str_value.copy(str->ptr(), str->length(),
 
43
                                 str->charset(), conv_charset, &errors))
 
44
        null_value= 1;
 
45
      use_cached_value= 1;
 
46
      str_value.mark_as_const();
 
47
      safe= (errors == 0);
 
48
    }
 
49
    else
 
50
    {
 
51
      use_cached_value= 0;
 
52
      /*
 
53
        Conversion from and to "binary" is safe.
 
54
        Conversion to Unicode is safe.
 
55
        Other kind of conversions are potentially lossy.
 
56
      */
 
57
      safe= (args[0]->collation.collation == &my_charset_bin ||
 
58
             cs == &my_charset_bin ||
 
59
             (cs->state & MY_CS_UNICODE));
 
60
    }
 
61
  }
 
62
  String *val_str(String *);
 
63
  void fix_length_and_dec();
 
64
  const char *func_name() const { return "convert"; }
 
65
  virtual void print(String *str, enum_query_type query_type);
 
66
};
 
67
 
 
68
#endif /* DRIZZLED_FUNCTIONS_STR_CONV_CHARSET_H */