~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_error.cc

  • Committer: Monty Taylor
  • Date: 2008-10-04 22:26:22 UTC
  • Revision ID: monty@inaugust.com-20081004222622-89vkm3px5b1jujc2
Made sql_state and stacktrace compile as C++. drizzled/ is pure c++ now.

Show diffs side-by-side

added added

removed removed

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