~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_error.cc

  • Committer: patrick crews
  • Date: 2011-06-08 03:02:27 UTC
  • mto: This revision was merged to the branch mainline in revision 2329.
  • Revision ID: gleebix@gmail.com-20110608030227-updkyv2652zvfajc
Initial voodoo worked to give us a crashme mode.  Need docs still

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
***********************************************************************/
43
43
 
44
 
#include "config.h"
 
44
#include <config.h>
45
45
 
46
46
#include <cstdio>
47
47
#include <stdarg.h>
51
51
#include <drizzled/item/empty_string.h>
52
52
#include <drizzled/item/return_int.h>
53
53
#include <drizzled/plugin/client.h>
 
54
#include <drizzled/sql_lex.h>
 
55
#include <drizzled/system_variables.h>
 
56
#include <drizzled/diagnostics_area.h>
54
57
 
55
58
using namespace std;
56
59
 
57
 
namespace drizzled
58
 
{
 
60
namespace drizzled {
59
61
 
60
62
/*
61
63
  Store a new message in an error object
91
93
    memset(session->warn_count, 0, sizeof(session->warn_count));
92
94
    if (force)
93
95
      session->total_warn_count= 0;
94
 
    session->warn_list.empty();
 
96
    session->main_da().m_warn_list.clear();
95
97
    session->row_count= 1; // by default point to row 1
96
98
  }
97
 
  return;
98
99
}
99
100
 
100
101
 
113
114
*/
114
115
 
115
116
DRIZZLE_ERROR *push_warning(Session *session, DRIZZLE_ERROR::enum_warning_level level,
116
 
                          uint32_t code, const char *msg)
 
117
                            drizzled::error_t code, const char *msg)
117
118
{
118
 
  DRIZZLE_ERROR *err= 0;
119
 
 
120
 
  if (level == DRIZZLE_ERROR::WARN_LEVEL_NOTE &&
121
 
      !(session->options & OPTION_SQL_NOTES))
122
 
    return(0);
 
119
  if (level == DRIZZLE_ERROR::WARN_LEVEL_NOTE && !(session->options & OPTION_SQL_NOTES))
 
120
  {
 
121
    return NULL;
 
122
  }
123
123
 
124
124
  if (session->getQueryId() != session->getWarningQueryId())
125
125
    drizzle_reset_errors(session, 0);
127
127
 
128
128
  /* Abort if we are using strict mode and we are not using IGNORE */
129
129
  if ((int) level >= (int) DRIZZLE_ERROR::WARN_LEVEL_WARN &&
130
 
      session->really_abort_on_warning())
 
130
      session->abortOnWarning())
131
131
  {
132
132
    /* Avoid my_message() calling push_warning */
133
133
    bool no_warnings_for_error= session->no_warnings_for_error;
142
142
    level= DRIZZLE_ERROR::WARN_LEVEL_ERROR;
143
143
  }
144
144
 
145
 
  if (session->handle_error(code, msg, level))
146
 
    return NULL;
147
 
 
148
 
  if (session->warn_list.elements < session->variables.max_error_count)
 
145
  DRIZZLE_ERROR *err= NULL;
 
146
  if (session->main_da().m_warn_list.size() < session->variables.max_error_count)
149
147
  {
150
148
    /* We have to use warn_root, as mem_root is freed after each query */
151
 
    if ((err= new (&session->warn_root) DRIZZLE_ERROR(session, code, level, msg)))
152
 
      session->warn_list.push_back(err, &session->warn_root);
 
149
    err= new (&session->warn_root) DRIZZLE_ERROR(session, code, level, msg);
 
150
    session->main_da().m_warn_list.push_back(err, &session->warn_root);
153
151
  }
154
152
  session->warn_count[(uint32_t) level]++;
155
153
  session->total_warn_count++;
156
 
  return(err);
 
154
 
 
155
  return err;
157
156
}
158
157
 
159
158
/*
168
167
*/
169
168
 
170
169
void push_warning_printf(Session *session, DRIZZLE_ERROR::enum_warning_level level,
171
 
                         uint32_t code, const char *format, ...)
 
170
                         drizzled::error_t code, const char *format, ...)
172
171
{
173
172
  va_list args;
174
173
  char    warning[ERRMSGSIZE+20];
177
176
  vsnprintf(warning, sizeof(warning), format, args);
178
177
  va_end(args);
179
178
  push_warning(session, level, code, warning);
180
 
  return;
181
179
}
182
180
 
183
181
 
185
183
  Send all notes, errors or warnings to the client in a result set
186
184
 
187
185
  SYNOPSIS
188
 
    mysqld_show_warnings()
 
186
    show_warnings()
189
187
    session                     Thread handler
190
188
    levels_to_show      Bitmap for which levels to show
191
189
 
205
203
  { C_STRING_WITH_LEN("?") }
206
204
};
207
205
 
208
 
bool mysqld_show_warnings(Session *session,
209
 
                          bitset<DRIZZLE_ERROR::NUM_ERRORS> &levels_to_show)
 
206
bool show_warnings(Session *session,
 
207
                   bitset<DRIZZLE_ERROR::NUM_ERRORS> &levels_to_show)
210
208
{
211
209
  List<Item> field_list;
212
210
 
214
212
  field_list.push_back(new Item_return_int("Code",4, DRIZZLE_TYPE_LONG));
215
213
  field_list.push_back(new Item_empty_string("Message",DRIZZLE_ERRMSG_SIZE));
216
214
 
217
 
  if (session->client->sendFields(&field_list))
 
215
  if (session->getClient()->sendFields(&field_list))
218
216
    return true;
219
217
 
220
 
  DRIZZLE_ERROR *err;
221
 
  Select_Lex *sel= &session->lex->select_lex;
222
 
  Select_Lex_Unit *unit= &session->lex->unit;
 
218
  Select_Lex *sel= &session->lex().select_lex;
 
219
  Select_Lex_Unit *unit= &session->lex().unit;
223
220
  ha_rows idx= 0;
224
221
 
225
222
  unit->set_limit(sel);
226
223
 
227
 
  List_iterator_fast<DRIZZLE_ERROR> it(session->warn_list);
228
 
  while ((err= it++))
 
224
  List<DRIZZLE_ERROR>::iterator it(session->main_da().m_warn_list.begin());
 
225
  while (DRIZZLE_ERROR* err= it++)
229
226
  {
230
227
    /* Skip levels that the user is not interested in */
231
228
    if (! levels_to_show.test(err->level))
234
231
      continue;
235
232
    if (idx > unit->select_limit_cnt)
236
233
      break;
237
 
    session->client->store(warning_level_names[err->level].str,
238
 
                           warning_level_names[err->level].length);
239
 
    session->client->store((uint32_t) err->code);
240
 
    session->client->store(err->msg, strlen(err->msg));
241
 
    if (session->client->flush())
 
234
    session->getClient()->store(warning_level_names[err->level].str,
 
235
                                warning_level_names[err->level].length);
 
236
    session->getClient()->store((uint32_t) err->code);
 
237
    session->getClient()->store(err->msg, strlen(err->msg));
 
238
    if (session->getClient()->flush())
242
239
      return(true);
243
240
  }
244
241
  session->my_eof();