~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/sql_error.cc

Merge/fix in FAQ.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
***********************************************************************/
43
43
 
44
 
#include <drizzled/server_includes.h>
 
44
#include "mysql_priv.h"
45
45
 
46
46
/*
47
47
  Store a new message in an error object
49
49
  This is used to in group_concat() to register how many warnings we actually
50
50
  got after the query has been executed.
51
51
*/
52
 
void DRIZZLE_ERROR::set_msg(THD *thd, const char *msg_arg)
 
52
void MYSQL_ERROR::set_msg(THD *thd, const char *msg_arg)
53
53
{
54
54
  msg= strdup_root(&thd->warn_root, msg_arg);
55
55
}
58
58
  Reset all warnings for the thread
59
59
 
60
60
  SYNOPSIS
61
 
    drizzle_reset_errors()
 
61
    mysql_reset_errors()
62
62
    thd                 Thread handle
63
63
    force               Reset warnings even if it has been done before
64
64
 
68
68
    in which case push_warnings() has already called this function.
69
69
*/  
70
70
 
71
 
void drizzle_reset_errors(THD *thd, bool force)
 
71
void mysql_reset_errors(THD *thd, bool force)
72
72
{
73
73
  if (thd->query_id != thd->warn_id || force)
74
74
  {
75
75
    thd->warn_id= thd->query_id;
76
76
    free_root(&thd->warn_root,MYF(0));
77
 
    memset(thd->warn_count, 0, sizeof(thd->warn_count));
 
77
    bzero((char*) thd->warn_count, sizeof(thd->warn_count));
78
78
    if (force)
79
79
      thd->total_warn_count= 0;
80
80
    thd->warn_list.empty();
95
95
    msg                 Clear error message
96
96
    
97
97
  RETURN
98
 
    pointer on DRIZZLE_ERROR object
 
98
    pointer on MYSQL_ERROR object
99
99
*/
100
100
 
101
 
DRIZZLE_ERROR *push_warning(THD *thd, DRIZZLE_ERROR::enum_warning_level level, 
102
 
                          uint32_t code, const char *msg)
 
101
MYSQL_ERROR *push_warning(THD *thd, MYSQL_ERROR::enum_warning_level level, 
 
102
                          uint code, const char *msg)
103
103
{
104
 
  DRIZZLE_ERROR *err= 0;
 
104
  MYSQL_ERROR *err= 0;
105
105
 
106
 
  if (level == DRIZZLE_ERROR::WARN_LEVEL_NOTE &&
 
106
  if (level == MYSQL_ERROR::WARN_LEVEL_NOTE &&
107
107
      !(thd->options & OPTION_SQL_NOTES))
108
108
    return(0);
109
109
 
110
110
  if (thd->query_id != thd->warn_id)
111
 
    drizzle_reset_errors(thd, 0);
 
111
    mysql_reset_errors(thd, 0);
112
112
  thd->got_warning= 1;
113
113
 
114
114
  /* Abort if we are using strict mode and we are not using IGNORE */
115
 
  if ((int) level >= (int) DRIZZLE_ERROR::WARN_LEVEL_WARN &&
 
115
  if ((int) level >= (int) MYSQL_ERROR::WARN_LEVEL_WARN &&
116
116
      thd->really_abort_on_warning())
117
117
  {
118
118
    /* Avoid my_message() calling push_warning */
125
125
 
126
126
    thd->no_warnings_for_error= no_warnings_for_error;
127
127
    /* Store error in error list (as my_message() didn't do it) */
128
 
    level= DRIZZLE_ERROR::WARN_LEVEL_ERROR;
 
128
    level= MYSQL_ERROR::WARN_LEVEL_ERROR;
129
129
  }
130
130
 
131
131
  if (thd->handle_error(code, msg, level))
134
134
  if (thd->warn_list.elements < thd->variables.max_error_count)
135
135
  {
136
136
    /* We have to use warn_root, as mem_root is freed after each query */
137
 
    if ((err= new (&thd->warn_root) DRIZZLE_ERROR(thd, code, level, msg)))
 
137
    if ((err= new (&thd->warn_root) MYSQL_ERROR(thd, code, level, msg)))
138
138
      thd->warn_list.push_back(err, &thd->warn_root);
139
139
  }
140
140
  thd->warn_count[(uint) level]++;
153
153
    msg                 Clear error message
154
154
*/
155
155
 
156
 
void push_warning_printf(THD *thd, DRIZZLE_ERROR::enum_warning_level level,
157
 
                         uint32_t code, const char *format, ...)
 
156
void push_warning_printf(THD *thd, MYSQL_ERROR::enum_warning_level level,
 
157
                         uint code, const char *format, ...)
158
158
{
159
159
  va_list args;
160
160
  char    warning[ERRMSGSIZE+20];
191
191
  { C_STRING_WITH_LEN("?") }
192
192
};
193
193
 
194
 
bool mysqld_show_warnings(THD *thd, uint32_t levels_to_show)
 
194
bool mysqld_show_warnings(THD *thd, ulong levels_to_show)
195
195
{  
196
196
  List<Item> field_list;
197
197
 
198
198
  field_list.push_back(new Item_empty_string("Level", 7));
199
 
  field_list.push_back(new Item_return_int("Code",4, DRIZZLE_TYPE_LONG));
200
 
  field_list.push_back(new Item_empty_string("Message",DRIZZLE_ERRMSG_SIZE));
 
199
  field_list.push_back(new Item_return_int("Code",4, MYSQL_TYPE_LONG));
 
200
  field_list.push_back(new Item_empty_string("Message",MYSQL_ERRMSG_SIZE));
201
201
 
202
202
  if (thd->protocol->send_fields(&field_list,
203
203
                                 Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
204
204
    return(true);
205
205
 
206
 
  DRIZZLE_ERROR *err;
 
206
  MYSQL_ERROR *err;
207
207
  SELECT_LEX *sel= &thd->lex->select_lex;
208
208
  SELECT_LEX_UNIT *unit= &thd->lex->unit;
209
209
  ha_rows idx= 0;
211
211
 
212
212
  unit->set_limit(sel);
213
213
 
214
 
  List_iterator_fast<DRIZZLE_ERROR> it(thd->warn_list);
 
214
  List_iterator_fast<MYSQL_ERROR> it(thd->warn_list);
215
215
  while ((err= it++))
216
216
  {
217
217
    /* Skip levels that the user is not interested in */
224
224
    protocol->prepare_for_resend();
225
225
    protocol->store(warning_level_names[err->level].str,
226
226
                    warning_level_names[err->level].length, system_charset_info);
227
 
    protocol->store((uint32_t) err->code);
 
227
    protocol->store((uint32) err->code);
228
228
    protocol->store(err->msg, strlen(err->msg), system_charset_info);
229
229
    if (protocol->write())
230
230
      return(true);