~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2011-02-12 08:10:17 UTC
  • mto: This revision was merged to the branch mainline in revision 2161.
  • Revision ID: brian@tangent.org-20110212081017-7793i41ybt7gp5ty
More removal of session from includes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#pragma once
 
20
#ifndef DRIZZLED_FUNCTION_STR_CONV_CHARSET_H
 
21
#define DRIZZLED_FUNCTION_STR_CONV_CHARSET_H
21
22
 
22
23
#include <drizzled/function/str/strfunc.h>
23
24
 
24
 
namespace drizzled {
 
25
namespace drizzled
 
26
{
25
27
 
26
28
class Item_func_conv_charset :public Item_str_func
27
29
{
28
30
  bool use_cached_value;
29
31
public:
30
32
  bool safe;
31
 
  const charset_info_st *conv_charset; // keep it public
32
 
  Item_func_conv_charset(Item *a, const charset_info_st * const cs) :Item_str_func(a)
 
33
  const CHARSET_INFO *conv_charset; // keep it public
 
34
  Item_func_conv_charset(Item *a, const CHARSET_INFO * const cs) :Item_str_func(a)
33
35
  { 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)
 
36
  Item_func_conv_charset(Item *a, const CHARSET_INFO * const cs, bool cache_if_const)
35
37
    :Item_str_func(a)
36
38
  {
37
39
    assert(args[0]->fixed);
38
40
    conv_charset= cs;
39
41
    if (cache_if_const && args[0]->const_item())
40
42
    {
 
43
      size_t errors= 0;
41
44
      String tmp, *str= args[0]->val_str(&tmp);
42
 
      if (!str)
 
45
      if (!str || str_value.copy(str->ptr(), str->length(),
 
46
                                 str->charset(), conv_charset, &errors))
43
47
        null_value= 1;
44
 
      else
45
 
        str_value.copy(str->ptr(), str->length(), conv_charset);
46
48
      use_cached_value= 1;
47
49
      str_value.mark_as_const();
48
 
      safe= true;
 
50
      safe= (errors == 0);
49
51
    }
50
52
    else
51
53
    {
52
 
      use_cached_value= false;
 
54
      use_cached_value= 0;
53
55
      /*
54
56
        Conversion from and to "binary" is safe.
55
57
        Conversion to Unicode is safe.
63
65
  String *val_str(String *);
64
66
  void fix_length_and_dec();
65
67
  const char *func_name() const { return "convert"; }
66
 
  virtual void print(String *str);
 
68
  virtual void print(String *str, enum_query_type query_type);
67
69
};
68
70
 
69
71
} /* namespace drizzled */
70
72
 
 
73
#endif /* DRIZZLED_FUNCTION_STR_CONV_CHARSET_H */