~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_error.cc

  • Committer: Brian Aker
  • Date: 2009-01-24 09:43:35 UTC
  • Revision ID: brian@gir-3.local-20090124094335-6qdtvc35gl5fvivz
Adding in an example singe thread scheduler

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>
52
48
#include <drizzled/item/return_int.h>
53
 
#include <drizzled/plugin/client.h>
54
 
 
55
 
using namespace std;
56
 
 
57
 
namespace drizzled
58
 
{
59
49
 
60
50
/*
61
51
  Store a new message in an error object
65
55
*/
66
56
void DRIZZLE_ERROR::set_msg(Session *session, const char *msg_arg)
67
57
{
68
 
  msg= session->warn_root.strdup_root(msg_arg);
 
58
  msg= strdup_root(&session->warn_root, msg_arg);
69
59
}
70
60
 
71
61
/*
84
74
 
85
75
void drizzle_reset_errors(Session *session, bool force)
86
76
{
87
 
  if (session->getQueryId() != session->getWarningQueryId() || force)
 
77
  if (session->query_id != session->warn_id || force)
88
78
  {
89
 
    session->setWarningQueryId(session->getQueryId());
90
 
    session->warn_root.free_root(MYF(0));
 
79
    session->warn_id= session->query_id;
 
80
    free_root(&session->warn_root,MYF(0));
91
81
    memset(session->warn_count, 0, sizeof(session->warn_count));
92
82
    if (force)
93
83
      session->total_warn_count= 0;
121
111
      !(session->options & OPTION_SQL_NOTES))
122
112
    return(0);
123
113
 
124
 
  if (session->getQueryId() != session->getWarningQueryId())
 
114
  if (session->query_id != session->warn_id)
125
115
    drizzle_reset_errors(session, 0);
126
116
  session->got_warning= 1;
127
117
 
134
124
 
135
125
    session->no_warnings_for_error= 1;
136
126
 
137
 
    session->setKilled(Session::KILL_BAD_DATA);
 
127
    session->killed= Session::KILL_BAD_DATA;
138
128
    my_message(code, msg, MYF(0));
139
129
 
140
130
    session->no_warnings_for_error= no_warnings_for_error;
143
133
  }
144
134
 
145
135
  if (session->handle_error(code, msg, level))
146
 
    return NULL;
 
136
    return(NULL);
147
137
 
148
138
  if (session->warn_list.elements < session->variables.max_error_count)
149
139
  {
151
141
    if ((err= new (&session->warn_root) DRIZZLE_ERROR(session, code, level, msg)))
152
142
      session->warn_list.push_back(err, &session->warn_root);
153
143
  }
154
 
  session->warn_count[(uint32_t) level]++;
 
144
  session->warn_count[(uint) level]++;
155
145
  session->total_warn_count++;
156
146
  return(err);
157
147
}
205
195
  { C_STRING_WITH_LEN("?") }
206
196
};
207
197
 
208
 
bool mysqld_show_warnings(Session *session,
209
 
                          bitset<DRIZZLE_ERROR::NUM_ERRORS> &levels_to_show)
 
198
bool mysqld_show_warnings(Session *session, uint32_t levels_to_show)
210
199
{
211
200
  List<Item> field_list;
212
201
 
214
203
  field_list.push_back(new Item_return_int("Code",4, DRIZZLE_TYPE_LONG));
215
204
  field_list.push_back(new Item_empty_string("Message",DRIZZLE_ERRMSG_SIZE));
216
205
 
217
 
  if (session->client->sendFields(&field_list))
218
 
    return true;
 
206
  if (session->protocol->send_fields(&field_list,
 
207
                                 Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
 
208
    return(true);
219
209
 
220
210
  DRIZZLE_ERROR *err;
221
 
  Select_Lex *sel= &session->lex->select_lex;
222
 
  Select_Lex_Unit *unit= &session->lex->unit;
 
211
  SELECT_LEX *sel= &session->lex->select_lex;
 
212
  SELECT_LEX_UNIT *unit= &session->lex->unit;
223
213
  ha_rows idx= 0;
 
214
  Protocol *protocol=session->protocol;
224
215
 
225
216
  unit->set_limit(sel);
226
217
 
228
219
  while ((err= it++))
229
220
  {
230
221
    /* Skip levels that the user is not interested in */
231
 
    if (! levels_to_show.test(err->level))
 
222
    if (!(levels_to_show & ((ulong) 1 << err->level)))
232
223
      continue;
233
224
    if (++idx <= unit->offset_limit_cnt)
234
225
      continue;
235
226
    if (idx > unit->select_limit_cnt)
236
227
      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())
 
228
    protocol->prepare_for_resend();
 
229
    protocol->store(warning_level_names[err->level].str,
 
230
                    warning_level_names[err->level].length, system_charset_info);
 
231
    protocol->store((uint32_t) err->code);
 
232
    protocol->store(err->msg, strlen(err->msg), system_charset_info);
 
233
    if (protocol->write())
242
234
      return(true);
243
235
  }
244
 
  session->my_eof();
 
236
  my_eof(session);
245
237
  return(false);
246
238
}
247
 
 
248
 
} /* namespace drizzled */