00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include <config.h>
00045
00046 #include <cstdio>
00047 #include <stdarg.h>
00048
00049 #include <drizzled/session.h>
00050 #include <drizzled/sql_base.h>
00051 #include <drizzled/item/empty_string.h>
00052 #include <drizzled/item/return_int.h>
00053 #include <drizzled/plugin/client.h>
00054 #include <drizzled/sql_lex.h>
00055 #include <drizzled/system_variables.h>
00056 #include <drizzled/diagnostics_area.h>
00057
00058 using namespace std;
00059
00060 namespace drizzled {
00061
00062
00063
00064
00065
00066
00067
00068 void DRIZZLE_ERROR::set_msg(Session *session, const char *msg_arg)
00069 {
00070 msg= session->warn_root.strdup(msg_arg);
00071 }
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 void drizzle_reset_errors(Session& session, bool force)
00088 {
00089 if (session.getQueryId() != session.getWarningQueryId() || force)
00090 {
00091 session.setWarningQueryId(session.getQueryId());
00092 session.warn_root.free_root(MYF(0));
00093 memset(session.warn_count, 0, sizeof(session.warn_count));
00094 if (force)
00095 session.total_warn_count= 0;
00096 session.main_da().m_warn_list.clear();
00097 session.row_count= 1;
00098 }
00099 }
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 DRIZZLE_ERROR *push_warning(Session *session, DRIZZLE_ERROR::enum_warning_level level,
00117 drizzled::error_t code, const char *msg)
00118 {
00119 if (level == DRIZZLE_ERROR::WARN_LEVEL_NOTE && !(session->options & OPTION_SQL_NOTES))
00120 {
00121 return NULL;
00122 }
00123
00124 if (session->getQueryId() != session->getWarningQueryId())
00125 drizzle_reset_errors(*session, false);
00126 session->got_warning= 1;
00127
00128
00129 if ((int) level >= (int) DRIZZLE_ERROR::WARN_LEVEL_WARN &&
00130 session->abortOnWarning())
00131 {
00132
00133 bool no_warnings_for_error= session->no_warnings_for_error;
00134
00135 session->no_warnings_for_error= 1;
00136
00137 session->setKilled(Session::KILL_BAD_DATA);
00138 my_message(code, msg, MYF(0));
00139
00140 session->no_warnings_for_error= no_warnings_for_error;
00141
00142 level= DRIZZLE_ERROR::WARN_LEVEL_ERROR;
00143 }
00144
00145 DRIZZLE_ERROR *err= NULL;
00146 if (session->main_da().m_warn_list.size() < session->variables.max_error_count)
00147 {
00148
00149 err= new (session->warn_root) DRIZZLE_ERROR(session, code, level, msg);
00150 session->main_da().m_warn_list.push_back(err);
00151 }
00152 session->warn_count[level]++;
00153 session->total_warn_count++;
00154
00155 return err;
00156 }
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 void push_warning_printf(Session *session, DRIZZLE_ERROR::enum_warning_level level,
00170 drizzled::error_t code, const char *format, ...)
00171 {
00172 va_list args;
00173 char warning[ERRMSGSIZE+20];
00174
00175 va_start(args,format);
00176 vsnprintf(warning, sizeof(warning), format, args);
00177 va_end(args);
00178 push_warning(session, level, code, warning);
00179 }
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198 const lex_string_t warning_level_names[]=
00199 {
00200 { C_STRING_WITH_LEN("Note") },
00201 { C_STRING_WITH_LEN("Warning") },
00202 { C_STRING_WITH_LEN("Error") },
00203 { C_STRING_WITH_LEN("?") }
00204 };
00205
00206 bool show_warnings(Session *session, bitset<DRIZZLE_ERROR::NUM_ERRORS> &levels_to_show)
00207 {
00208 List<Item> field_list;
00209
00210 field_list.push_back(new Item_empty_string("Level", 7));
00211 field_list.push_back(new Item_return_int("Code",4, DRIZZLE_TYPE_LONG));
00212 field_list.push_back(new Item_empty_string("Message",DRIZZLE_ERRMSG_SIZE));
00213
00214 session->getClient()->sendFields(field_list);
00215
00216 Select_Lex *sel= &session->lex().select_lex;
00217 Select_Lex_Unit *unit= &session->lex().unit;
00218 ha_rows idx= 0;
00219
00220 unit->set_limit(sel);
00221
00222 BOOST_FOREACH(DRIZZLE_ERROR* err, session->main_da().m_warn_list)
00223 {
00224
00225 if (! levels_to_show.test(err->level))
00226 continue;
00227 if (++idx <= unit->offset_limit_cnt)
00228 continue;
00229 if (idx > unit->select_limit_cnt)
00230 break;
00231 session->getClient()->store(warning_level_names[err->level]);
00232 session->getClient()->store((uint32_t) err->code);
00233 session->getClient()->store(err->msg, strlen(err->msg));
00234 if (session->getClient()->flush())
00235 return true;
00236 }
00237 session->my_eof();
00238 return false;
00239 }
00240
00241 }