~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/string.cc

  • Committer: Mark Atwood
  • Date: 2011-08-12 04:08:33 UTC
  • mfrom: (2385.2.17 refactor5)
  • Revision ID: me@mark.atwood.name-20110812040833-u6j85nc6ahuc0dtz
mergeĀ lp:~olafvdspek/drizzle/refactor5

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <drizzled/error.h>
24
24
#include <drizzled/item/string.h>
25
25
 
26
 
namespace drizzled
27
 
{
 
26
namespace drizzled {
28
27
 
29
 
Item *Item_string::safe_charset_converter(const CHARSET_INFO * const tocs)
 
28
Item *Item_string::safe_charset_converter(const charset_info_st * const tocs)
30
29
{
31
 
  Item_string *conv;
32
 
  size_t conv_errors;
33
 
  char *ptr;
34
30
  String tmp, cstr, *ostr= val_str(&tmp);
35
 
  cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
36
 
  if (conv_errors || !(conv= new Item_string(cstr.ptr(), cstr.length(),
37
 
                                             cstr.charset(),
38
 
                                             collation.derivation)))
39
 
  {
40
 
    /*
41
 
      Safe conversion is not possible (or EOM).
42
 
      We could not convert a string into the requested character set
43
 
      without data loss. The target charset does not cover all the
44
 
      characters from the string. Operation cannot be done correctly.
45
 
    */
46
 
    return NULL;
47
 
  }
48
 
 
49
 
  if (!(ptr= getSession().strmake(cstr.ptr(), cstr.length())))
50
 
    return NULL;
 
31
  cstr.copy(ostr->ptr(), ostr->length(), tocs);
 
32
  Item_string* conv= new Item_string(cstr.ptr(), cstr.length(), cstr.charset(), collation.derivation);
 
33
  char* ptr= getSession().mem.strdup(cstr);
51
34
 
52
35
  conv->str_value.set(ptr, cstr.length(), cstr.charset());
53
36
  /* Ensure that no one is going to change the result string */
56
39
}
57
40
 
58
41
 
59
 
Item *Item_static_string_func::safe_charset_converter(const CHARSET_INFO * const tocs)
 
42
Item *Item_static_string_func::safe_charset_converter(const charset_info_st * const tocs)
60
43
{
61
 
  Item_string *conv;
62
 
  size_t conv_errors;
63
44
  String tmp, cstr, *ostr= val_str(&tmp);
64
 
  cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
65
 
  if (conv_errors ||
66
 
      !(conv= new Item_static_string_func(func_name,
67
 
                                          cstr.ptr(), cstr.length(),
68
 
                                          cstr.charset(),
69
 
                                          collation.derivation)))
70
 
  {
71
 
    /*
72
 
      Safe conversion is not possible (or EOM).
73
 
      We could not convert a string into the requested character set
74
 
      without data loss. The target charset does not cover all the
75
 
      characters from the string. Operation cannot be done correctly.
76
 
    */
77
 
    return NULL;
78
 
  }
 
45
  cstr.copy(ostr->ptr(), ostr->length(), tocs);
 
46
  Item_string* conv= new Item_static_string_func(func_name, cstr.ptr(), cstr.length(), cstr.charset(), collation.derivation);
79
47
  conv->str_value.copy();
80
48
  /* Ensure that no one is going to change the result string */
81
49
  conv->str_value.mark_as_const();
95
63
  return 0;
96
64
}
97
65
 
98
 
void Item_string::print(String *str, enum_query_type query_type)
 
66
void Item_string::print(String *str)
99
67
{
100
 
  if (query_type == QT_ORDINARY && is_cs_specified())
101
 
  {
102
 
    str->append('_');
103
 
    str->append(collation.collation->csname);
104
 
  }
105
 
 
106
68
  str->append('\'');
107
 
 
108
 
  str_value.print(str);
109
 
 
 
69
  str_value.print(*str);
110
70
  str->append('\'');
111
71
}
112
72
 
114
74
{
115
75
  assert(fixed == 1);
116
76
  int error;
117
 
  char *end, *org_end;
118
 
  double tmp;
119
 
  const CHARSET_INFO * const cs= str_value.charset();
 
77
  char *end;
 
78
  const charset_info_st* cs= str_value.charset();
120
79
 
121
 
  org_end= (char*) str_value.ptr() + str_value.length();
122
 
  tmp= my_strntod(cs, (char*) str_value.ptr(), str_value.length(), &end,
123
 
                  &error);
 
80
  char* org_end= (char*) str_value.ptr() + str_value.length();
 
81
  double tmp= my_strntod(cs, (char*) str_value.ptr(), str_value.length(), &end, &error);
124
82
  if (error || (end != org_end && !check_if_only_end_space(cs, end, org_end)))
125
83
  {
126
84
    /*
127
85
      We can use str_value.ptr() here as Item_string is gurantee to put an
128
86
      end \0 here.
129
87
    */
130
 
    push_warning_printf(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_WARN,
131
 
                        ER_TRUNCATED_WRONG_VALUE,
132
 
                        ER(ER_TRUNCATED_WRONG_VALUE), "DOUBLE",
133
 
                        str_value.ptr());
 
88
    push_warning_printf(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, ER(ER_TRUNCATED_WRONG_VALUE), "DOUBLE", str_value.ptr());
134
89
  }
135
90
  return tmp;
136
91
}
143
98
{
144
99
  assert(fixed == 1);
145
100
  int err;
146
 
  int64_t tmp;
147
101
  char *end= (char*) str_value.ptr()+ str_value.length();
148
102
  char *org_end= end;
149
 
  const CHARSET_INFO * const cs= str_value.charset();
 
103
  const charset_info_st * const cs= str_value.charset();
150
104
 
151
 
  tmp= (*(cs->cset->strtoll10))(cs, str_value.ptr(), &end, &err);
 
105
  int64_t tmp= (*(cs->cset->strtoll10))(cs, str_value.ptr(), &end, &err);
152
106
  /*
153
107
    TODO: Give error if we wanted a signed integer and we got an unsigned
154
108
    one
155
109
  */
156
 
  if (err > 0 ||
157
 
      (end != org_end && !check_if_only_end_space(cs, end, org_end)))
 
110
  if (err > 0 || (end != org_end && !check_if_only_end_space(cs, end, org_end)))
158
111
  {
159
 
    push_warning_printf(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_WARN,
160
 
                        ER_TRUNCATED_WRONG_VALUE,
161
 
                        ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER",
162
 
                        str_value.ptr());
 
112
    push_warning_printf(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER", str_value.ptr());
163
113
  }
164
114
  return tmp;
165
115
}
171
121
 
172
122
int Item_string::save_in_field(Field *field, bool)
173
123
{
174
 
  String *result;
175
 
  result=val_str(&str_value);
 
124
  String* result=val_str(&str_value);
176
125
  return save_str_value_in_field(field, result);
177
126
}
178
127