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 */
16
16
/**********************************************************************
17
17
This file contains the implementation of error and warnings related
42
42
***********************************************************************/
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>
61
51
Store a new message in an error object
85
75
void drizzle_reset_errors(Session *session, bool force)
87
if (session->getQueryId() != session->getWarningQueryId() || force)
77
if (session->query_id != session->warn_id || force)
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));
93
83
session->total_warn_count= 0;
94
session->warn_list.clear();
84
session->warn_list.empty();
95
85
session->row_count= 1; // by default point to row 1
115
105
DRIZZLE_ERROR *push_warning(Session *session, DRIZZLE_ERROR::enum_warning_level level,
116
drizzled::error_t code, const char *msg)
106
uint32_t code, const char *msg)
118
108
DRIZZLE_ERROR *err= 0;
120
if (level == DRIZZLE_ERROR::WARN_LEVEL_NOTE && !(session->options & OPTION_SQL_NOTES))
110
if (level == DRIZZLE_ERROR::WARN_LEVEL_NOTE &&
111
!(session->options & OPTION_SQL_NOTES))
125
if (session->getQueryId() != session->getWarningQueryId())
114
if (session->query_id != session->warn_id)
126
115
drizzle_reset_errors(session, 0);
127
116
session->got_warning= 1;
129
118
/* Abort if we are using strict mode and we are not using IGNORE */
130
119
if ((int) level >= (int) DRIZZLE_ERROR::WARN_LEVEL_WARN &&
131
session->abortOnWarning())
120
session->really_abort_on_warning())
133
122
/* Avoid my_message() calling push_warning */
134
123
bool no_warnings_for_error= session->no_warnings_for_error;
136
125
session->no_warnings_for_error= 1;
138
session->setKilled(Session::KILL_BAD_DATA);
127
session->killed= Session::KILL_BAD_DATA;
139
128
my_message(code, msg, MYF(0));
141
130
session->no_warnings_for_error= no_warnings_for_error;
146
135
if (session->handle_error(code, msg, level))
149
138
if (session->warn_list.elements < session->variables.max_error_count)
151
140
/* We have to use warn_root, as mem_root is freed after each query */
152
141
if ((err= new (&session->warn_root) DRIZZLE_ERROR(session, code, level, msg)))
154
142
session->warn_list.push_back(err, &session->warn_root);
157
session->warn_count[(uint32_t) level]++;
144
session->warn_count[(uint) level]++;
158
145
session->total_warn_count++;
174
160
void push_warning_printf(Session *session, DRIZZLE_ERROR::enum_warning_level level,
175
drizzled::error_t code, const char *format, ...)
161
uint32_t code, const char *format, ...)
178
164
char warning[ERRMSGSIZE+20];
181
167
vsnprintf(warning, sizeof(warning), format, args);
183
169
push_warning(session, level, code, warning);
208
195
{ C_STRING_WITH_LEN("?") }
211
bool show_warnings(Session *session,
212
bitset<DRIZZLE_ERROR::NUM_ERRORS> &levels_to_show)
198
bool mysqld_show_warnings(Session *session, uint32_t levels_to_show)
214
200
List<Item> field_list;
217
203
field_list.push_back(new Item_return_int("Code",4, DRIZZLE_TYPE_LONG));
218
204
field_list.push_back(new Item_empty_string("Message",DRIZZLE_ERRMSG_SIZE));
220
if (session->getClient()->sendFields(&field_list))
206
if (session->protocol->send_fields(&field_list,
207
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
223
210
DRIZZLE_ERROR *err;
224
Select_Lex *sel= &session->getLex()->select_lex;
225
Select_Lex_Unit *unit= &session->getLex()->unit;
211
Select_Lex *sel= &session->lex->select_lex;
212
Select_Lex_Unit *unit= &session->lex->unit;
214
Protocol *protocol=session->protocol;
228
216
unit->set_limit(sel);
230
List<DRIZZLE_ERROR>::iterator it(session->warn_list.begin());
218
List_iterator_fast<DRIZZLE_ERROR> it(session->warn_list);
231
219
while ((err= it++))
233
221
/* Skip levels that the user is not interested in */
234
if (! levels_to_show.test(err->level))
222
if (!(levels_to_show & ((ulong) 1 << err->level)))
236
224
if (++idx <= unit->offset_limit_cnt)
238
226
if (idx > unit->select_limit_cnt)
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())
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())
247
236
session->my_eof();
251
} /* namespace drizzled */