~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_error.cc

OK, Sun Studio still didn't like that...seems to think that inline means something different than other compilers think it is...

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>
 
44
#include "config.h"
45
45
 
46
 
#include <cstdio>
47
46
#include <stdarg.h>
48
47
 
49
48
#include <drizzled/session.h>
65
64
*/
66
65
void DRIZZLE_ERROR::set_msg(Session *session, const char *msg_arg)
67
66
{
68
 
  msg= session->warn_root.strdup_root(msg_arg);
 
67
  msg= strdup_root(&session->warn_root, msg_arg);
69
68
}
70
69
 
71
70
/*
87
86
  if (session->getQueryId() != session->getWarningQueryId() || force)
88
87
  {
89
88
    session->setWarningQueryId(session->getQueryId());
90
 
    session->warn_root.free_root(MYF(0));
 
89
    free_root(&session->warn_root,MYF(0));
91
90
    memset(session->warn_count, 0, sizeof(session->warn_count));
92
91
    if (force)
93
92
      session->total_warn_count= 0;
94
 
    session->warn_list.clear();
 
93
    session->warn_list.empty();
95
94
    session->row_count= 1; // by default point to row 1
96
95
  }
97
96
  return;
113
112
*/
114
113
 
115
114
DRIZZLE_ERROR *push_warning(Session *session, DRIZZLE_ERROR::enum_warning_level level,
116
 
                            drizzled::error_t code, const char *msg)
 
115
                          uint32_t code, const char *msg)
117
116
{
118
117
  DRIZZLE_ERROR *err= 0;
119
118
 
120
 
  if (level == DRIZZLE_ERROR::WARN_LEVEL_NOTE && !(session->options & OPTION_SQL_NOTES))
121
 
  {
122
 
    return NULL;
123
 
  }
 
119
  if (level == DRIZZLE_ERROR::WARN_LEVEL_NOTE &&
 
120
      !(session->options & OPTION_SQL_NOTES))
 
121
    return(0);
124
122
 
125
123
  if (session->getQueryId() != session->getWarningQueryId())
126
124
    drizzle_reset_errors(session, 0);
128
126
 
129
127
  /* Abort if we are using strict mode and we are not using IGNORE */
130
128
  if ((int) level >= (int) DRIZZLE_ERROR::WARN_LEVEL_WARN &&
131
 
      session->abortOnWarning())
 
129
      session->really_abort_on_warning())
132
130
  {
133
131
    /* Avoid my_message() calling push_warning */
134
132
    bool no_warnings_for_error= session->no_warnings_for_error;
135
133
 
136
134
    session->no_warnings_for_error= 1;
137
135
 
138
 
    session->setKilled(Session::KILL_BAD_DATA);
 
136
    session->killed= Session::KILL_BAD_DATA;
139
137
    my_message(code, msg, MYF(0));
140
138
 
141
139
    session->no_warnings_for_error= no_warnings_for_error;
150
148
  {
151
149
    /* We have to use warn_root, as mem_root is freed after each query */
152
150
    if ((err= new (&session->warn_root) DRIZZLE_ERROR(session, code, level, msg)))
153
 
    {
154
151
      session->warn_list.push_back(err, &session->warn_root);
155
 
    }
156
152
  }
157
153
  session->warn_count[(uint32_t) level]++;
158
154
  session->total_warn_count++;
159
 
 
160
 
  return err;
 
155
  return(err);
161
156
}
162
157
 
163
158
/*
172
167
*/
173
168
 
174
169
void push_warning_printf(Session *session, DRIZZLE_ERROR::enum_warning_level level,
175
 
                         drizzled::error_t code, const char *format, ...)
 
170
                         uint32_t code, const char *format, ...)
176
171
{
177
172
  va_list args;
178
173
  char    warning[ERRMSGSIZE+20];
181
176
  vsnprintf(warning, sizeof(warning), format, args);
182
177
  va_end(args);
183
178
  push_warning(session, level, code, warning);
 
179
  return;
184
180
}
185
181
 
186
182
 
188
184
  Send all notes, errors or warnings to the client in a result set
189
185
 
190
186
  SYNOPSIS
191
 
    show_warnings()
 
187
    mysqld_show_warnings()
192
188
    session                     Thread handler
193
189
    levels_to_show      Bitmap for which levels to show
194
190
 
208
204
  { C_STRING_WITH_LEN("?") }
209
205
};
210
206
 
211
 
bool show_warnings(Session *session,
212
 
                   bitset<DRIZZLE_ERROR::NUM_ERRORS> &levels_to_show)
 
207
bool mysqld_show_warnings(Session *session,
 
208
                          bitset<DRIZZLE_ERROR::NUM_ERRORS> &levels_to_show)
213
209
{
214
210
  List<Item> field_list;
215
211
 
217
213
  field_list.push_back(new Item_return_int("Code",4, DRIZZLE_TYPE_LONG));
218
214
  field_list.push_back(new Item_empty_string("Message",DRIZZLE_ERRMSG_SIZE));
219
215
 
220
 
  if (session->getClient()->sendFields(&field_list))
 
216
  if (session->client->sendFields(&field_list))
221
217
    return true;
222
218
 
223
219
  DRIZZLE_ERROR *err;
224
 
  Select_Lex *sel= &session->getLex()->select_lex;
225
 
  Select_Lex_Unit *unit= &session->getLex()->unit;
 
220
  Select_Lex *sel= &session->lex->select_lex;
 
221
  Select_Lex_Unit *unit= &session->lex->unit;
226
222
  ha_rows idx= 0;
227
223
 
228
224
  unit->set_limit(sel);
229
225
 
230
 
  List<DRIZZLE_ERROR>::iterator it(session->warn_list.begin());
 
226
  List_iterator_fast<DRIZZLE_ERROR> it(session->warn_list);
231
227
  while ((err= it++))
232
228
  {
233
229
    /* Skip levels that the user is not interested in */
237
233
      continue;
238
234
    if (idx > unit->select_limit_cnt)
239
235
      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())
 
236
    session->client->store(warning_level_names[err->level].str,
 
237
                           warning_level_names[err->level].length);
 
238
    session->client->store((uint32_t) err->code);
 
239
    session->client->store(err->msg, strlen(err->msg));
 
240
    if (session->client->flush())
245
241
      return(true);
246
242
  }
247
243
  session->my_eof();