~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/time_functions.cc

  • Committer: Olaf van der Spek
  • Date: 2011-10-19 14:57:31 UTC
  • mto: This revision was merged to the branch mainline in revision 2445.
  • Revision ID: olafvdspek@gmail.com-20111019145731-y8ycpcinn2pkp3vg
Use str_ref

Show diffs side-by-side

added added

removed removed

Lines of Context:
125
125
}
126
126
 
127
127
 
128
 
type::timestamp_t str_to_datetime_with_warn(Session *session, const char *str,  uint32_t length,  type::Time *l_time, uint32_t flags)
 
128
type::timestamp_t str_to_datetime_with_warn(Session& session, str_ref str, type::Time& l_time, uint32_t flags)
129
129
{
130
130
  type::cut_t was_cut= type::VALID;
131
 
  type::timestamp_t ts_type= l_time->store(str, length, (flags | (session->variables.sql_mode & (MODE_INVALID_DATES | MODE_NO_ZERO_DATE))), was_cut);
 
131
  type::timestamp_t ts_type= l_time.store(str.data(), str.size(), (flags | (session.variables.sql_mode & (MODE_INVALID_DATES | MODE_NO_ZERO_DATE))), was_cut);
132
132
  if (was_cut || ts_type <= type::DRIZZLE_TIMESTAMP_ERROR)
133
 
    make_truncated_value_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, str, length, ts_type,  NULL);
134
 
 
 
133
    make_truncated_value_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, str, ts_type,  NULL);
135
134
  return ts_type;
136
135
}
137
136
 
138
137
 
139
 
bool str_to_time_with_warn(Session *session, const char *str, uint32_t length, type::Time *l_time)
 
138
bool str_to_time_with_warn(Session& session, str_ref str, type::Time& l_time)
140
139
{
141
140
  int warning;
142
 
  bool ret_val= l_time->store(str, length, warning, type::DRIZZLE_TIMESTAMP_TIME);
 
141
  bool ret_val= l_time.store(str.data(), str.size(), warning, type::DRIZZLE_TIMESTAMP_TIME);
143
142
  if (ret_val || warning)
144
 
    make_truncated_value_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, str, length, type::DRIZZLE_TIMESTAMP_TIME, NULL);
 
143
    make_truncated_value_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, str, type::DRIZZLE_TIMESTAMP_TIME, NULL);
145
144
  return ret_val;
146
145
}
147
146
 
148
147
 
149
 
void make_truncated_value_warning(Session *session, 
150
 
                                  DRIZZLE_ERROR::enum_warning_level level,
151
 
                                  const char *str_val,
152
 
                                                          uint32_t str_length,
153
 
                                  type::timestamp_t time_type,
154
 
                                  const char *field_name)
 
148
void make_truncated_value_warning(Session& session, DRIZZLE_ERROR::enum_warning_level level, str_ref str_arg, type::timestamp_t time_type, const char *field_name)
155
149
{
156
150
  char warn_buff[DRIZZLE_ERRMSG_SIZE];
157
 
  const char *type_str;
158
151
  charset_info_st *cs= &my_charset_utf8_general_ci;
159
152
  char buff[128];
160
153
  String str(buff,(uint32_t) sizeof(buff), system_charset_info);
161
 
  str.copy(str_val, str_length, system_charset_info);
162
 
  str[str_length]= 0;               // Ensure we have end 0 for snprintf
 
154
  str.copy(str_arg.data(), str_arg.size(), system_charset_info);
 
155
  assert(not str[str_arg.size()]);               // Ensure we have end 0 for snprintf
163
156
 
164
 
  switch (time_type) {
 
157
  const char *type_str;
 
158
  switch (time_type) 
 
159
  {
165
160
  case type::DRIZZLE_TIMESTAMP_DATE:
166
161
    type_str= "date";
167
162
    break;
173
168
  case type::DRIZZLE_TIMESTAMP_DATETIME:  // FALLTHROUGH
174
169
  default:
175
170
    type_str= "datetime";
176
 
    break;
177
171
  }
178
172
 
179
173
  if (field_name)
181
175
    cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff),
182
176
                       ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
183
177
                       type_str, str.c_ptr(), field_name,
184
 
                       (uint32_t) session->row_count);
 
178
                       (uint32_t) session.row_count);
 
179
  }
 
180
  else if (time_type > type::DRIZZLE_TIMESTAMP_ERROR)
 
181
  {
 
182
    cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff), ER(ER_TRUNCATED_WRONG_VALUE), type_str, str.c_ptr());
185
183
  }
186
184
  else
187
185
  {
188
 
    if (time_type > type::DRIZZLE_TIMESTAMP_ERROR)
189
 
    {
190
 
      cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff),
191
 
                         ER(ER_TRUNCATED_WRONG_VALUE),
192
 
                         type_str, str.c_ptr());
193
 
    }
194
 
    else
195
 
    {
196
 
      cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff),
197
 
                         ER(ER_WRONG_VALUE), type_str, str.c_ptr());
198
 
    }
 
186
    cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff), ER(ER_WRONG_VALUE), type_str, str.c_ptr());
199
187
  }
200
 
  push_warning(session, level,
201
 
               ER_TRUNCATED_WRONG_VALUE, warn_buff);
 
188
  push_warning(&session, level, ER_TRUNCATED_WRONG_VALUE, warn_buff);
202
189
}
203
190
 
204
191