~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_error.cc

  • Committer: Brian Aker
  • Date: 2009-11-24 02:06:37 UTC
  • mfrom: (1223.1.7 push)
  • Revision ID: brian@gaz-20091124020637-9gb65vj98x1arydm
Merge for staging.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA */
15
15
 
16
16
/**********************************************************************
17
17
This file contains the implementation of error and warnings related
41
41
 
42
42
***********************************************************************/
43
43
 
44
 
#include "config.h"
45
 
 
46
 
#include <cstdio>
47
 
#include <stdarg.h>
48
 
 
 
44
#include <drizzled/server_includes.h>
49
45
#include <drizzled/session.h>
50
46
#include <drizzled/sql_base.h>
51
47
#include <drizzled/item/empty_string.h>
53
49
#include <drizzled/plugin/client.h>
54
50
 
55
51
using namespace std;
56
 
 
57
 
namespace drizzled
58
 
{
 
52
using namespace drizzled;
59
53
 
60
54
/*
61
55
  Store a new message in an error object
65
59
*/
66
60
void DRIZZLE_ERROR::set_msg(Session *session, const char *msg_arg)
67
61
{
68
 
  msg= session->warn_root.strdup_root(msg_arg);
 
62
  msg= strdup_root(&session->warn_root, msg_arg);
69
63
}
70
64
 
71
65
/*
84
78
 
85
79
void drizzle_reset_errors(Session *session, bool force)
86
80
{
87
 
  if (session->getQueryId() != session->getWarningQueryId() || force)
 
81
  if (session->query_id != session->warn_id || force)
88
82
  {
89
 
    session->setWarningQueryId(session->getQueryId());
90
 
    session->warn_root.free_root(MYF(0));
 
83
    session->warn_id= session->query_id;
 
84
    free_root(&session->warn_root,MYF(0));
91
85
    memset(session->warn_count, 0, sizeof(session->warn_count));
92
86
    if (force)
93
87
      session->total_warn_count= 0;
113
107
*/
114
108
 
115
109
DRIZZLE_ERROR *push_warning(Session *session, DRIZZLE_ERROR::enum_warning_level level,
116
 
                            drizzled::error_t code, const char *msg)
 
110
                          uint32_t code, const char *msg)
117
111
{
118
112
  DRIZZLE_ERROR *err= 0;
119
113
 
120
 
  if (level == DRIZZLE_ERROR::WARN_LEVEL_NOTE && !(session->options & OPTION_SQL_NOTES))
121
 
  {
122
 
    return NULL;
123
 
  }
 
114
  if (level == DRIZZLE_ERROR::WARN_LEVEL_NOTE &&
 
115
      !(session->options & OPTION_SQL_NOTES))
 
116
    return(0);
124
117
 
125
 
  if (session->getQueryId() != session->getWarningQueryId())
 
118
  if (session->query_id != session->warn_id)
126
119
    drizzle_reset_errors(session, 0);
127
120
  session->got_warning= 1;
128
121
 
129
122
  /* Abort if we are using strict mode and we are not using IGNORE */
130
123
  if ((int) level >= (int) DRIZZLE_ERROR::WARN_LEVEL_WARN &&
131
 
      session->abortOnWarning())
 
124
      session->really_abort_on_warning())
132
125
  {
133
126
    /* Avoid my_message() calling push_warning */
134
127
    bool no_warnings_for_error= session->no_warnings_for_error;
135
128
 
136
129
    session->no_warnings_for_error= 1;
137
130
 
138
 
    session->setKilled(Session::KILL_BAD_DATA);
 
131
    session->killed= Session::KILL_BAD_DATA;
139
132
    my_message(code, msg, MYF(0));
140
133
 
141
134
    session->no_warnings_for_error= no_warnings_for_error;
150
143
  {
151
144
    /* We have to use warn_root, as mem_root is freed after each query */
152
145
    if ((err= new (&session->warn_root) DRIZZLE_ERROR(session, code, level, msg)))
153
 
    {
154
146
      session->warn_list.push_back(err, &session->warn_root);
155
 
    }
156
147
  }
157
148
  session->warn_count[(uint32_t) level]++;
158
149
  session->total_warn_count++;
159
 
 
160
 
  return err;
 
150
  return(err);
161
151
}
162
152
 
163
153
/*
172
162
*/
173
163
 
174
164
void push_warning_printf(Session *session, DRIZZLE_ERROR::enum_warning_level level,
175
 
                         drizzled::error_t code, const char *format, ...)
 
165
                         uint32_t code, const char *format, ...)
176
166
{
177
167
  va_list args;
178
168
  char    warning[ERRMSGSIZE+20];
181
171
  vsnprintf(warning, sizeof(warning), format, args);
182
172
  va_end(args);
183
173
  push_warning(session, level, code, warning);
 
174
  return;
184
175
}
185
176
 
186
177
 
188
179
  Send all notes, errors or warnings to the client in a result set
189
180
 
190
181
  SYNOPSIS
191
 
    show_warnings()
 
182
    mysqld_show_warnings()
192
183
    session                     Thread handler
193
184
    levels_to_show      Bitmap for which levels to show
194
185
 
208
199
  { C_STRING_WITH_LEN("?") }
209
200
};
210
201
 
211
 
bool show_warnings(Session *session,
212
 
                   bitset<DRIZZLE_ERROR::NUM_ERRORS> &levels_to_show)
 
202
bool mysqld_show_warnings(Session *session,
 
203
                          bitset<DRIZZLE_ERROR::NUM_ERRORS> &levels_to_show)
213
204
{
214
205
  List<Item> field_list;
215
206
 
217
208
  field_list.push_back(new Item_return_int("Code",4, DRIZZLE_TYPE_LONG));
218
209
  field_list.push_back(new Item_empty_string("Message",DRIZZLE_ERRMSG_SIZE));
219
210
 
220
 
  if (session->getClient()->sendFields(&field_list))
 
211
  if (session->client->sendFields(&field_list))
221
212
    return true;
222
213
 
223
214
  DRIZZLE_ERROR *err;
237
228
      continue;
238
229
    if (idx > unit->select_limit_cnt)
239
230
      break;
240
 
    session->getClient()->store(warning_level_names[err->level].str,
241
 
                                warning_level_names[err->level].length);
242
 
    session->getClient()->store((uint32_t) err->code);
243
 
    session->getClient()->store(err->msg, strlen(err->msg));
244
 
    if (session->getClient()->flush())
 
231
    session->client->store(warning_level_names[err->level].str,
 
232
                           warning_level_names[err->level].length);
 
233
    session->client->store((uint32_t) err->code);
 
234
    session->client->store(err->msg, strlen(err->msg));
 
235
    if (session->client->flush())
245
236
      return(true);
246
237
  }
247
238
  session->my_eof();
248
239
  return(false);
249
240
}
250
 
 
251
 
} /* namespace drizzled */