~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_error.cc

  • Committer: Mark Atwood
  • Date: 2008-10-16 11:33:16 UTC
  • mto: (520.1.13 drizzle)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: mark@fallenpegasus.com-20081016113316-ff6jdt31ck90sjdh
an implemention of the errmsg plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
***********************************************************************/
43
43
 
44
44
#include <drizzled/server_includes.h>
45
 
#include <drizzled/session.h>
46
 
#include <drizzled/sql_base.h>
47
45
 
48
46
/*
49
47
  Store a new message in an error object
51
49
  This is used to in group_concat() to register how many warnings we actually
52
50
  got after the query has been executed.
53
51
*/
54
 
void DRIZZLE_ERROR::set_msg(Session *session, const char *msg_arg)
 
52
void DRIZZLE_ERROR::set_msg(THD *thd, const char *msg_arg)
55
53
{
56
 
  msg= strdup_root(&session->warn_root, msg_arg);
 
54
  msg= strdup_root(&thd->warn_root, msg_arg);
57
55
}
58
56
 
59
57
/*
61
59
 
62
60
  SYNOPSIS
63
61
    drizzle_reset_errors()
64
 
    session                     Thread handle
 
62
    thd                 Thread handle
65
63
    force               Reset warnings even if it has been done before
66
64
 
67
65
  IMPLEMENTATION
70
68
    in which case push_warnings() has already called this function.
71
69
*/  
72
70
 
73
 
void drizzle_reset_errors(Session *session, bool force)
 
71
void drizzle_reset_errors(THD *thd, bool force)
74
72
{
75
 
  if (session->query_id != session->warn_id || force)
 
73
  if (thd->query_id != thd->warn_id || force)
76
74
  {
77
 
    session->warn_id= session->query_id;
78
 
    free_root(&session->warn_root,MYF(0));
79
 
    memset(session->warn_count, 0, sizeof(session->warn_count));
 
75
    thd->warn_id= thd->query_id;
 
76
    free_root(&thd->warn_root,MYF(0));
 
77
    memset(thd->warn_count, 0, sizeof(thd->warn_count));
80
78
    if (force)
81
 
      session->total_warn_count= 0;
82
 
    session->warn_list.empty();
83
 
    session->row_count= 1; // by default point to row 1
 
79
      thd->total_warn_count= 0;
 
80
    thd->warn_list.empty();
 
81
    thd->row_count= 1; // by default point to row 1
84
82
  }
85
83
  return;
86
84
}
91
89
 
92
90
  SYNOPSIS
93
91
    push_warning()
94
 
    session                     Thread handle
 
92
    thd                 Thread handle
95
93
    level               Severity of warning (note, warning, error ...)
96
94
    code                Error number
97
95
    msg                 Clear error message
100
98
    pointer on DRIZZLE_ERROR object
101
99
*/
102
100
 
103
 
DRIZZLE_ERROR *push_warning(Session *session, DRIZZLE_ERROR::enum_warning_level level, 
 
101
DRIZZLE_ERROR *push_warning(THD *thd, DRIZZLE_ERROR::enum_warning_level level, 
104
102
                          uint32_t code, const char *msg)
105
103
{
106
104
  DRIZZLE_ERROR *err= 0;
107
105
 
108
106
  if (level == DRIZZLE_ERROR::WARN_LEVEL_NOTE &&
109
 
      !(session->options & OPTION_SQL_NOTES))
 
107
      !(thd->options & OPTION_SQL_NOTES))
110
108
    return(0);
111
109
 
112
 
  if (session->query_id != session->warn_id)
113
 
    drizzle_reset_errors(session, 0);
114
 
  session->got_warning= 1;
 
110
  if (thd->query_id != thd->warn_id)
 
111
    drizzle_reset_errors(thd, 0);
 
112
  thd->got_warning= 1;
115
113
 
116
114
  /* Abort if we are using strict mode and we are not using IGNORE */
117
115
  if ((int) level >= (int) DRIZZLE_ERROR::WARN_LEVEL_WARN &&
118
 
      session->really_abort_on_warning())
 
116
      thd->really_abort_on_warning())
119
117
  {
120
118
    /* Avoid my_message() calling push_warning */
121
 
    bool no_warnings_for_error= session->no_warnings_for_error;
122
 
 
123
 
    session->no_warnings_for_error= 1;
124
 
 
125
 
    session->killed= Session::KILL_BAD_DATA;
 
119
    bool no_warnings_for_error= thd->no_warnings_for_error;
 
120
 
 
121
    thd->no_warnings_for_error= 1;
 
122
 
 
123
    thd->killed= THD::KILL_BAD_DATA;
126
124
    my_message(code, msg, MYF(0));
127
125
 
128
 
    session->no_warnings_for_error= no_warnings_for_error;
 
126
    thd->no_warnings_for_error= no_warnings_for_error;
129
127
    /* Store error in error list (as my_message() didn't do it) */
130
128
    level= DRIZZLE_ERROR::WARN_LEVEL_ERROR;
131
129
  }
132
130
 
133
 
  if (session->handle_error(code, msg, level))
 
131
  if (thd->handle_error(code, msg, level))
134
132
    return(NULL);
135
133
 
136
 
  if (session->warn_list.elements < session->variables.max_error_count)
 
134
  if (thd->warn_list.elements < thd->variables.max_error_count)
137
135
  {
138
136
    /* We have to use warn_root, as mem_root is freed after each query */
139
 
    if ((err= new (&session->warn_root) DRIZZLE_ERROR(session, code, level, msg)))
140
 
      session->warn_list.push_back(err, &session->warn_root);
 
137
    if ((err= new (&thd->warn_root) DRIZZLE_ERROR(thd, code, level, msg)))
 
138
      thd->warn_list.push_back(err, &thd->warn_root);
141
139
  }
142
 
  session->warn_count[(uint) level]++;
143
 
  session->total_warn_count++;
 
140
  thd->warn_count[(uint) level]++;
 
141
  thd->total_warn_count++;
144
142
  return(err);
145
143
}
146
144
 
149
147
 
150
148
  SYNOPSIS
151
149
    push_warning_printf()
152
 
    session                     Thread handle
 
150
    thd                 Thread handle
153
151
    level               Severity of warning (note, warning, error ...)
154
152
    code                Error number
155
153
    msg                 Clear error message
156
154
*/
157
155
 
158
 
void push_warning_printf(Session *session, DRIZZLE_ERROR::enum_warning_level level,
 
156
void push_warning_printf(THD *thd, DRIZZLE_ERROR::enum_warning_level level,
159
157
                         uint32_t code, const char *format, ...)
160
158
{
161
159
  va_list args;
164
162
  va_start(args,format);
165
163
  vsnprintf(warning, sizeof(warning), format, args);
166
164
  va_end(args);
167
 
  push_warning(session, level, code, warning);
 
165
  push_warning(thd, level, code, warning);
168
166
  return;
169
167
}
170
168
 
174
172
 
175
173
  SYNOPSIS
176
174
    mysqld_show_warnings()
177
 
    session                     Thread handler
 
175
    thd                 Thread handler
178
176
    levels_to_show      Bitmap for which levels to show
179
177
 
180
178
  DESCRIPTION
193
191
  { C_STRING_WITH_LEN("?") }
194
192
};
195
193
 
196
 
bool mysqld_show_warnings(Session *session, uint32_t levels_to_show)
 
194
bool mysqld_show_warnings(THD *thd, uint32_t levels_to_show)
197
195
{  
198
196
  List<Item> field_list;
199
197
 
201
199
  field_list.push_back(new Item_return_int("Code",4, DRIZZLE_TYPE_LONG));
202
200
  field_list.push_back(new Item_empty_string("Message",DRIZZLE_ERRMSG_SIZE));
203
201
 
204
 
  if (session->protocol->send_fields(&field_list,
 
202
  if (thd->protocol->send_fields(&field_list,
205
203
                                 Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
206
204
    return(true);
207
205
 
208
206
  DRIZZLE_ERROR *err;
209
 
  SELECT_LEX *sel= &session->lex->select_lex;
210
 
  SELECT_LEX_UNIT *unit= &session->lex->unit;
 
207
  SELECT_LEX *sel= &thd->lex->select_lex;
 
208
  SELECT_LEX_UNIT *unit= &thd->lex->unit;
211
209
  ha_rows idx= 0;
212
 
  Protocol *protocol=session->protocol;
 
210
  Protocol *protocol=thd->protocol;
213
211
 
214
212
  unit->set_limit(sel);
215
213
 
216
 
  List_iterator_fast<DRIZZLE_ERROR> it(session->warn_list);
 
214
  List_iterator_fast<DRIZZLE_ERROR> it(thd->warn_list);
217
215
  while ((err= it++))
218
216
  {
219
217
    /* Skip levels that the user is not interested in */
231
229
    if (protocol->write())
232
230
      return(true);
233
231
  }
234
 
  my_eof(session);
 
232
  my_eof(thd);
235
233
  return(false);
236
234
}