~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_error.cc

move math functions to drizzled/function/math directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    (If we would reset after each command, we could not retrieve the number
30
30
     of warnings)
31
31
 
32
 
  - When client requests the information using SHOW command, then 
33
 
    server processes from this list and returns back in the form of 
 
32
  - When client requests the information using SHOW command, then
 
33
    server processes from this list and returns back in the form of
34
34
    resultset.
35
35
 
36
36
    Supported syntaxes:
42
42
***********************************************************************/
43
43
 
44
44
#include <drizzled/server_includes.h>
 
45
#include <drizzled/session.h>
 
46
#include <drizzled/sql_base.h>
 
47
#include <drizzled/item/empty_string.h>
 
48
#include <drizzled/item/return_int.h>
45
49
 
46
50
/*
47
51
  Store a new message in an error object
49
53
  This is used to in group_concat() to register how many warnings we actually
50
54
  got after the query has been executed.
51
55
*/
52
 
void DRIZZLE_ERROR::set_msg(THD *thd, const char *msg_arg)
 
56
void DRIZZLE_ERROR::set_msg(Session *session, const char *msg_arg)
53
57
{
54
 
  msg= strdup_root(&thd->warn_root, msg_arg);
 
58
  msg= strdup_root(&session->warn_root, msg_arg);
55
59
}
56
60
 
57
61
/*
59
63
 
60
64
  SYNOPSIS
61
65
    drizzle_reset_errors()
62
 
    thd                 Thread handle
 
66
    session                     Thread handle
63
67
    force               Reset warnings even if it has been done before
64
68
 
65
69
  IMPLEMENTATION
66
70
    Don't reset warnings if this has already been called for this query.
67
71
    This may happen if one gets a warning during the parsing stage,
68
72
    in which case push_warnings() has already called this function.
69
 
*/  
 
73
*/
70
74
 
71
 
void drizzle_reset_errors(THD *thd, bool force)
 
75
void drizzle_reset_errors(Session *session, bool force)
72
76
{
73
 
  if (thd->query_id != thd->warn_id || force)
 
77
  if (session->query_id != session->warn_id || force)
74
78
  {
75
 
    thd->warn_id= thd->query_id;
76
 
    free_root(&thd->warn_root,MYF(0));
77
 
    memset(thd->warn_count, 0, sizeof(thd->warn_count));
 
79
    session->warn_id= session->query_id;
 
80
    free_root(&session->warn_root,MYF(0));
 
81
    memset(session->warn_count, 0, sizeof(session->warn_count));
78
82
    if (force)
79
 
      thd->total_warn_count= 0;
80
 
    thd->warn_list.empty();
81
 
    thd->row_count= 1; // by default point to row 1
 
83
      session->total_warn_count= 0;
 
84
    session->warn_list.empty();
 
85
    session->row_count= 1; // by default point to row 1
82
86
  }
83
87
  return;
84
88
}
85
89
 
86
90
 
87
 
/* 
 
91
/*
88
92
  Push the warning/error to error list if there is still room in the list
89
93
 
90
94
  SYNOPSIS
91
95
    push_warning()
92
 
    thd                 Thread handle
 
96
    session                     Thread handle
93
97
    level               Severity of warning (note, warning, error ...)
94
98
    code                Error number
95
99
    msg                 Clear error message
96
 
    
 
100
 
97
101
  RETURN
98
102
    pointer on DRIZZLE_ERROR object
99
103
*/
100
104
 
101
 
DRIZZLE_ERROR *push_warning(THD *thd, DRIZZLE_ERROR::enum_warning_level level, 
102
 
                          uint code, const char *msg)
 
105
DRIZZLE_ERROR *push_warning(Session *session, DRIZZLE_ERROR::enum_warning_level level,
 
106
                          uint32_t code, const char *msg)
103
107
{
104
108
  DRIZZLE_ERROR *err= 0;
105
109
 
106
110
  if (level == DRIZZLE_ERROR::WARN_LEVEL_NOTE &&
107
 
      !(thd->options & OPTION_SQL_NOTES))
 
111
      !(session->options & OPTION_SQL_NOTES))
108
112
    return(0);
109
113
 
110
 
  if (thd->query_id != thd->warn_id)
111
 
    drizzle_reset_errors(thd, 0);
112
 
  thd->got_warning= 1;
 
114
  if (session->query_id != session->warn_id)
 
115
    drizzle_reset_errors(session, 0);
 
116
  session->got_warning= 1;
113
117
 
114
118
  /* Abort if we are using strict mode and we are not using IGNORE */
115
119
  if ((int) level >= (int) DRIZZLE_ERROR::WARN_LEVEL_WARN &&
116
 
      thd->really_abort_on_warning())
 
120
      session->really_abort_on_warning())
117
121
  {
118
122
    /* Avoid my_message() calling push_warning */
119
 
    bool no_warnings_for_error= thd->no_warnings_for_error;
120
 
 
121
 
    thd->no_warnings_for_error= 1;
122
 
 
123
 
    thd->killed= THD::KILL_BAD_DATA;
 
123
    bool no_warnings_for_error= session->no_warnings_for_error;
 
124
 
 
125
    session->no_warnings_for_error= 1;
 
126
 
 
127
    session->killed= Session::KILL_BAD_DATA;
124
128
    my_message(code, msg, MYF(0));
125
129
 
126
 
    thd->no_warnings_for_error= no_warnings_for_error;
 
130
    session->no_warnings_for_error= no_warnings_for_error;
127
131
    /* Store error in error list (as my_message() didn't do it) */
128
132
    level= DRIZZLE_ERROR::WARN_LEVEL_ERROR;
129
133
  }
130
134
 
131
 
  if (thd->handle_error(code, msg, level))
 
135
  if (session->handle_error(code, msg, level))
132
136
    return(NULL);
133
137
 
134
 
  if (thd->warn_list.elements < thd->variables.max_error_count)
 
138
  if (session->warn_list.elements < session->variables.max_error_count)
135
139
  {
136
140
    /* We have to use warn_root, as mem_root is freed after each query */
137
 
    if ((err= new (&thd->warn_root) DRIZZLE_ERROR(thd, code, level, msg)))
138
 
      thd->warn_list.push_back(err, &thd->warn_root);
 
141
    if ((err= new (&session->warn_root) DRIZZLE_ERROR(session, code, level, msg)))
 
142
      session->warn_list.push_back(err, &session->warn_root);
139
143
  }
140
 
  thd->warn_count[(uint) level]++;
141
 
  thd->total_warn_count++;
 
144
  session->warn_count[(uint) level]++;
 
145
  session->total_warn_count++;
142
146
  return(err);
143
147
}
144
148
 
147
151
 
148
152
  SYNOPSIS
149
153
    push_warning_printf()
150
 
    thd                 Thread handle
 
154
    session                     Thread handle
151
155
    level               Severity of warning (note, warning, error ...)
152
156
    code                Error number
153
157
    msg                 Clear error message
154
158
*/
155
159
 
156
 
void push_warning_printf(THD *thd, DRIZZLE_ERROR::enum_warning_level level,
157
 
                         uint code, const char *format, ...)
 
160
void push_warning_printf(Session *session, DRIZZLE_ERROR::enum_warning_level level,
 
161
                         uint32_t code, const char *format, ...)
158
162
{
159
163
  va_list args;
160
164
  char    warning[ERRMSGSIZE+20];
161
 
  
 
165
 
162
166
  va_start(args,format);
163
167
  vsnprintf(warning, sizeof(warning), format, args);
164
168
  va_end(args);
165
 
  push_warning(thd, level, code, warning);
 
169
  push_warning(session, level, code, warning);
166
170
  return;
167
171
}
168
172
 
172
176
 
173
177
  SYNOPSIS
174
178
    mysqld_show_warnings()
175
 
    thd                 Thread handler
 
179
    session                     Thread handler
176
180
    levels_to_show      Bitmap for which levels to show
177
181
 
178
182
  DESCRIPTION
191
195
  { C_STRING_WITH_LEN("?") }
192
196
};
193
197
 
194
 
bool mysqld_show_warnings(THD *thd, uint32_t levels_to_show)
195
 
{  
 
198
bool mysqld_show_warnings(Session *session, uint32_t levels_to_show)
 
199
{
196
200
  List<Item> field_list;
197
201
 
198
202
  field_list.push_back(new Item_empty_string("Level", 7));
199
203
  field_list.push_back(new Item_return_int("Code",4, DRIZZLE_TYPE_LONG));
200
204
  field_list.push_back(new Item_empty_string("Message",DRIZZLE_ERRMSG_SIZE));
201
205
 
202
 
  if (thd->protocol->send_fields(&field_list,
 
206
  if (session->protocol->send_fields(&field_list,
203
207
                                 Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
204
208
    return(true);
205
209
 
206
210
  DRIZZLE_ERROR *err;
207
 
  SELECT_LEX *sel= &thd->lex->select_lex;
208
 
  SELECT_LEX_UNIT *unit= &thd->lex->unit;
 
211
  SELECT_LEX *sel= &session->lex->select_lex;
 
212
  SELECT_LEX_UNIT *unit= &session->lex->unit;
209
213
  ha_rows idx= 0;
210
 
  Protocol *protocol=thd->protocol;
 
214
  Protocol *protocol=session->protocol;
211
215
 
212
216
  unit->set_limit(sel);
213
217
 
214
 
  List_iterator_fast<DRIZZLE_ERROR> it(thd->warn_list);
 
218
  List_iterator_fast<DRIZZLE_ERROR> it(session->warn_list);
215
219
  while ((err= it++))
216
220
  {
217
221
    /* Skip levels that the user is not interested in */
229
233
    if (protocol->write())
230
234
      return(true);
231
235
  }
232
 
  my_eof(thd);
 
236
  my_eof(session);
233
237
  return(false);
234
238
}