~drizzle-trunk/drizzle/development

467 by Monty Taylor
Made sql_state and stacktrace compile as C++. drizzled/ is pure c++ now.
1
/* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 Sun Microsystems
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
1 by brian
clean slate
20
481.1.20 by Monty Taylor
Removed extraneous vector from sql_state.
21
/* Functions to map drizzle errno to sql_state */
612.2.4 by Monty Taylor
Moved some defines to config.h. Stopped including config.h directly anywhere.
22
#include <drizzled/global.h>
481.1.20 by Monty Taylor
Removed extraneous vector from sql_state.
23
24
#include CSTDINT_H
25
#include <algorithm>
26
27
#include <drizzled/sql_state.h>
212.5.42 by Monty Taylor
Ding dong include is dead.
28
#include <drizzled/error.h>
468 by Monty Taylor
Repaced sql_state stuff with template function and c++ algorithm.
29
30
using namespace std;
31
481.1.20 by Monty Taylor
Removed extraneous vector from sql_state.
32
typedef struct st_map_errno_to_sqlstate
33
{
971.3.4 by Eric Day
Further drizzleclient cleanup. Starting to move all NET related functions into Protocol, removed some dead code, removing drizzleclient dependencies spread throughout drizzled.
34
  uint32_t drizzle_errno;
481.1.20 by Monty Taylor
Removed extraneous vector from sql_state.
35
  const char *odbc_state;
36
  const char *jdbc_state;
37
} errno_sqlstate_map;
38
39
errno_sqlstate_map sqlstate_map[]=
468 by Monty Taylor
Repaced sql_state stuff with template function and c++ algorithm.
40
{
41
  { ER_DUP_KEY                              ,"23000", "" },
42
  { ER_OUTOFMEMORY                          ,"HY001", "S1001" },
43
  { ER_OUT_OF_SORTMEMORY                    ,"HY001", "S1001" },
44
  { ER_CON_COUNT_ERROR                      ,"08004", "" },
45
  { ER_BAD_HOST_ERROR                       ,"08S01", "" },
46
  { ER_HANDSHAKE_ERROR                      ,"08S01", "" },
47
  { ER_DBACCESS_DENIED_ERROR                ,"42000", "" },
48
  { ER_ACCESS_DENIED_ERROR                  ,"28000", "" },
49
  { ER_NO_DB_ERROR                          ,"3D000", "" },
50
  { ER_UNKNOWN_COM_ERROR                    ,"08S01", "" },
51
  { ER_BAD_NULL_ERROR                       ,"23000", "" },
52
  { ER_BAD_DB_ERROR                         ,"42000", "" },
53
  { ER_TABLE_EXISTS_ERROR                   ,"42S01", "" },
54
  { ER_BAD_TABLE_ERROR                      ,"42S02", "" },
55
  { ER_NON_UNIQ_ERROR                       ,"23000", "" },
56
  { ER_SERVER_SHUTDOWN                      ,"08S01", "" },
57
  { ER_BAD_FIELD_ERROR                      ,"42S22", "S0022" },
58
  { ER_WRONG_FIELD_WITH_GROUP               ,"42000", "S1009" },
59
  { ER_WRONG_GROUP_FIELD                    ,"42000", "S1009" },
60
  { ER_WRONG_SUM_SELECT                     ,"42000", "S1009" },
61
  { ER_WRONG_VALUE_COUNT                    ,"21S01", "" },
62
  { ER_TOO_LONG_IDENT                       ,"42000", "S1009" },
63
  { ER_DUP_FIELDNAME                        ,"42S21", "S1009" },
64
  { ER_DUP_KEYNAME                          ,"42000", "S1009" },
65
  { ER_DUP_ENTRY                            ,"23000", "S1009" },
66
  { ER_WRONG_FIELD_SPEC                     ,"42000", "S1009" },
67
  { ER_PARSE_ERROR                          ,"42000", "s1009" },
68
  { ER_EMPTY_QUERY                          ,"42000", "" },
69
  { ER_NONUNIQ_TABLE                        ,"42000", "S1009" },
70
  { ER_INVALID_DEFAULT                      ,"42000", "S1009" },
71
  { ER_MULTIPLE_PRI_KEY                     ,"42000", "S1009" },
72
  { ER_TOO_MANY_KEYS                        ,"42000", "S1009" },
73
  { ER_TOO_MANY_KEY_PARTS                   ,"42000", "S1009" },
74
  { ER_TOO_LONG_KEY                         ,"42000", "S1009" },
75
  { ER_KEY_COLUMN_DOES_NOT_EXITS            ,"42000", "S1009" },
76
  { ER_BLOB_USED_AS_KEY                     ,"42000", "S1009" },
77
  { ER_TOO_BIG_FIELDLENGTH                  ,"42000", "S1009" },
78
  { ER_WRONG_AUTO_KEY                       ,"42000", "S1009" },
79
  { ER_FORCING_CLOSE                        ,"08S01", "" },
80
  { ER_IPSOCK_ERROR                         ,"08S01", "" },
81
  { ER_NO_SUCH_INDEX                        ,"42S12", "S1009" },
82
  { ER_WRONG_FIELD_TERMINATORS              ,"42000", "S1009" },
83
  { ER_BLOBS_AND_NO_TERMINATED              ,"42000", "S1009" },
84
  { ER_CANT_REMOVE_ALL_FIELDS               ,"42000", "" },
85
  { ER_CANT_DROP_FIELD_OR_KEY               ,"42000", "" },
86
  { ER_BLOB_CANT_HAVE_DEFAULT               ,"42000", "" },
87
  { ER_WRONG_DB_NAME                        ,"42000", "" },
88
  { ER_WRONG_TABLE_NAME                     ,"42000", "" },
89
  { ER_TOO_BIG_SELECT                       ,"42000", "" },
90
  { ER_UNKNOWN_PROCEDURE                    ,"42000", "" },
91
  { ER_WRONG_PARAMCOUNT_TO_PROCEDURE        ,"42000", "" },
92
  { ER_UNKNOWN_TABLE                        ,"42S02", "" },
93
  { ER_FIELD_SPECIFIED_TWICE                ,"42000", "" },
94
  { ER_UNSUPPORTED_EXTENSION                ,"42000", "" },
95
  { ER_TABLE_MUST_HAVE_COLUMNS              ,"42000", "" },
96
  { ER_UNKNOWN_CHARACTER_SET                ,"42000", "" },
97
  { ER_TOO_BIG_ROWSIZE                      ,"42000", "" },
98
  { ER_WRONG_OUTER_JOIN                     ,"42000", "" },
99
  { ER_NULL_COLUMN_IN_INDEX                 ,"42000", "" },
100
  { ER_PASSWORD_ANONYMOUS_USER              ,"42000", "" },
101
  { ER_PASSWORD_NOT_ALLOWED                 ,"42000", "" },
102
  { ER_PASSWORD_NO_MATCH                    ,"42000", "" },
103
  { ER_WRONG_VALUE_COUNT_ON_ROW             ,"21S01", "" },
104
  { ER_INVALID_USE_OF_NULL                  ,"22004", "" },
105
  { ER_REGEXP_ERROR                         ,"42000", "" },
106
  { ER_MIX_OF_GROUP_FUNC_AND_FIELDS         ,"42000", "" },
107
  { ER_NONEXISTING_GRANT                    ,"42000", "" },
108
  { ER_TABLEACCESS_DENIED_ERROR             ,"42000", "" },
109
  { ER_COLUMNACCESS_DENIED_ERROR            ,"42000", "" },
110
  { ER_ILLEGAL_GRANT_FOR_TABLE              ,"42000", "" },
111
  { ER_GRANT_WRONG_HOST_OR_USER             ,"42000", "" },
112
  { ER_NO_SUCH_TABLE                        ,"42S02", "" },
113
  { ER_NONEXISTING_TABLE_GRANT              ,"42000", "" },
114
  { ER_NOT_ALLOWED_COMMAND                  ,"42000", "" },
115
  { ER_SYNTAX_ERROR                         ,"42000", "" },
116
  { ER_ABORTING_CONNECTION                  ,"08S01", "" },
117
  { ER_NET_PACKET_TOO_LARGE                 ,"08S01", "" },
118
  { ER_NET_READ_ERROR_FROM_PIPE             ,"08S01", "" },
119
  { ER_NET_FCNTL_ERROR                      ,"08S01", "" },
120
  { ER_NET_PACKETS_OUT_OF_ORDER             ,"08S01", "" },
121
  { ER_NET_UNCOMPRESS_ERROR                 ,"08S01", "" },
122
  { ER_NET_READ_ERROR                       ,"08S01", "" },
123
  { ER_NET_READ_INTERRUPTED                 ,"08S01", "" },
124
  { ER_NET_ERROR_ON_WRITE                   ,"08S01", "" },
125
  { ER_NET_WRITE_INTERRUPTED                ,"08S01", "" },
126
  { ER_TOO_LONG_STRING                      ,"42000", "" },
127
  { ER_TABLE_CANT_HANDLE_BLOB               ,"42000", "" },
128
  { ER_TABLE_CANT_HANDLE_AUTO_INCREMENT     ,"42000", "" },
129
  { ER_WRONG_COLUMN_NAME                    ,"42000", "" },
130
  { ER_WRONG_KEY_COLUMN                     ,"42000", "" },
131
  { ER_DUP_UNIQUE                           ,"23000", "" },
132
  { ER_BLOB_KEY_WITHOUT_LENGTH              ,"42000", "" },
133
  { ER_PRIMARY_CANT_HAVE_NULL               ,"42000", "" },
134
  { ER_TOO_MANY_ROWS                        ,"42000", "" },
135
  { ER_REQUIRES_PRIMARY_KEY                 ,"42000", "" },
136
  { ER_KEY_DOES_NOT_EXITS                   ,"42000", "S1009" },
137
  { ER_CHECK_NO_SUCH_TABLE                  ,"42000", "" },
138
  { ER_CHECK_NOT_IMPLEMENTED                ,"42000", "" },
139
  { ER_CANT_DO_THIS_DURING_AN_TRANSACTION   ,"25000", "" },
140
  { ER_NEW_ABORTING_CONNECTION              ,"08S01", "" },
141
  { ER_MASTER_NET_READ                      ,"08S01", "" },
142
  { ER_MASTER_NET_WRITE                     ,"08S01", "" },
143
  { ER_TOO_MANY_USER_CONNECTIONS            ,"42000", "" },
144
  { ER_READ_ONLY_TRANSACTION                ,"25000", "" },
145
  { ER_NO_PERMISSION_TO_CREATE_USER         ,"42000", "" },
146
  { ER_LOCK_DEADLOCK                        ,"40001", "" },
147
  { ER_NO_REFERENCED_ROW                    ,"23000", "" },
148
  { ER_ROW_IS_REFERENCED                    ,"23000", "" },
149
  { ER_CONNECT_TO_MASTER                    ,"08S01", "" },
150
  { ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT    ,"21000", "" },
151
  { ER_USER_LIMIT_REACHED                   ,"42000", "" },
152
  { ER_SPECIFIC_ACCESS_DENIED_ERROR         ,"42000", "" },
153
  { ER_NO_DEFAULT                           ,"42000", "" },
154
  { ER_WRONG_VALUE_FOR_VAR                  ,"42000", "" },
155
  { ER_WRONG_TYPE_FOR_VAR                   ,"42000", "" },
156
  { ER_CANT_USE_OPTION_HERE                 ,"42000", "" },
157
  { ER_NOT_SUPPORTED_YET                    ,"42000", "" },
158
  { ER_WRONG_FK_DEF                         ,"42000", "" },
159
  { ER_OPERAND_COLUMNS                      ,"21000", "" },
160
  { ER_SUBQUERY_NO_1_ROW                    ,"21000", "" },
161
  { ER_ILLEGAL_REFERENCE                    ,"42S22", "" },
162
  { ER_DERIVED_MUST_HAVE_ALIAS              ,"42000", "" },
163
  { ER_SELECT_REDUCED                       ,"01000", "" },
164
  { ER_TABLENAME_NOT_ALLOWED_HERE           ,"42000", "" },
165
  { ER_NOT_SUPPORTED_AUTH_MODE              ,"08004", "" },
166
  { ER_SPATIAL_CANT_HAVE_NULL               ,"42000", "" },
167
  { ER_COLLATION_CHARSET_MISMATCH           ,"42000", "" },
168
  { ER_WARN_TOO_FEW_RECORDS                 ,"01000", "" },
169
  { ER_WARN_TOO_MANY_RECORDS                ,"01000", "" },
170
  { ER_WARN_NULL_TO_NOTNULL                 ,"22004", "" },
171
  { ER_WARN_DATA_OUT_OF_RANGE               ,"22003", "" },
172
  { ER_WARN_DATA_TRUNCATED                  ,"01000", "" },
173
  { ER_WRONG_NAME_FOR_INDEX                 ,"42000", "" },
174
  { ER_WRONG_NAME_FOR_CATALOG               ,"42000", "" },
175
  { ER_UNKNOWN_STORAGE_ENGINE               ,"42000", "" },
176
  { ER_TRUNCATED_WRONG_VALUE                ,"22007", "" },
177
  { ER_SP_NO_RECURSIVE_CREATE               ,"2F003", "" },
178
  { ER_SP_ALREADY_EXISTS                    ,"42000", "" },
179
  { ER_SP_DOES_NOT_EXIST                    ,"42000", "" },
180
  { ER_SP_LILABEL_MISMATCH                  ,"42000", "" },
181
  { ER_SP_LABEL_REDEFINE                    ,"42000", "" },
182
  { ER_SP_LABEL_MISMATCH                    ,"42000", "" },
183
  { ER_SP_UNINIT_VAR                        ,"01000", "" },
184
  { ER_SP_BADSELECT                         ,"0A000", "" },
185
  { ER_SP_BADRETURN                         ,"42000", "" },
186
  { ER_SP_BADSTATEMENT                      ,"0A000", "" },
187
  { ER_UPDATE_LOG_DEPRECATED_IGNORED        ,"42000", "" },
188
  { ER_UPDATE_LOG_DEPRECATED_TRANSLATED     ,"42000", "" },
189
  { ER_QUERY_INTERRUPTED                    ,"70100", "" },
190
  { ER_SP_WRONG_NO_OF_ARGS                  ,"42000", "" },
191
  { ER_SP_COND_MISMATCH                     ,"42000", "" },
192
  { ER_SP_NORETURN                          ,"42000", "" },
193
  { ER_SP_NORETURNEND                       ,"2F005", "" },
194
  { ER_SP_BAD_CURSOR_QUERY                  ,"42000", "" },
195
  { ER_SP_BAD_CURSOR_SELECT                 ,"42000", "" },
196
  { ER_SP_CURSOR_MISMATCH                   ,"42000", "" },
197
  { ER_SP_CURSOR_ALREADY_OPEN               ,"24000", "" },
198
  { ER_SP_CURSOR_NOT_OPEN                   ,"24000", "" },
199
  { ER_SP_UNDECLARED_VAR                    ,"42000", "" },
200
  { ER_SP_FETCH_NO_DATA                     ,"02000", "" },
201
  { ER_SP_DUP_PARAM                         ,"42000", "" },
202
  { ER_SP_DUP_VAR                           ,"42000", "" },
203
  { ER_SP_DUP_COND                          ,"42000", "" },
204
  { ER_SP_DUP_CURS                          ,"42000", "" },
205
  { ER_SP_SUBSELECT_NYI                     ,"0A000", "" },
206
  { ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG        ,"0A000", "" },
207
  { ER_SP_VARCOND_AFTER_CURSHNDLR           ,"42000", "" },
208
  { ER_SP_CURSOR_AFTER_HANDLER              ,"42000", "" },
209
  { ER_SP_CASE_NOT_FOUND                    ,"20000", "" },
210
  { ER_DIVISION_BY_ZERO                     ,"22012", "" },
211
  { ER_ILLEGAL_VALUE_FOR_TYPE               ,"22007", "" },
212
  { ER_PROCACCESS_DENIED_ERROR              ,"42000", "" },
213
  { ER_XAER_NOTA                            ,"XAE04", "" },
214
  { ER_XAER_INVAL                           ,"XAE05", "" },
215
  { ER_XAER_RMFAIL                          ,"XAE07", "" },
216
  { ER_XAER_OUTSIDE                         ,"XAE09", "" },
217
  { ER_XAER_RMERR                           ,"XAE03", "" },
218
  { ER_XA_RBROLLBACK                        ,"XA100", "" },
219
  { ER_NONEXISTING_PROC_GRANT               ,"42000", "" },
220
  { ER_DATA_TOO_LONG                        ,"22001", "" },
221
  { ER_SP_BAD_SQLSTATE                      ,"42000", "" },
222
  { ER_CANT_CREATE_USER_WITH_GRANT          ,"42000", "" },
223
  { ER_SP_DUP_HANDLER                       ,"42000", "" },
224
  { ER_SP_NOT_VAR_ARG                       ,"42000", "" },
225
  { ER_SP_NO_RETSET                         ,"0A000", "" },
226
  { ER_CANT_CREATE_GEOMETRY_OBJECT          ,"22003", "" },
227
  { ER_TOO_BIG_SCALE                        ,"42000", "S1009" },
228
  { ER_TOO_BIG_PRECISION                    ,"42000", "S1009" },
229
  { ER_M_BIGGER_THAN_D                      ,"42000", "S1009" },
230
  { ER_TOO_LONG_BODY                        ,"42000", "S1009" },
231
  { ER_TOO_BIG_DISPLAYWIDTH                 ,"42000", "S1009" },
232
  { ER_XAER_DUPID                           ,"XAE08", "" },
233
  { ER_DATETIME_FUNCTION_OVERFLOW           ,"22008", "" },
234
  { ER_ROW_IS_REFERENCED_2                  ,"23000", "" },
235
  { ER_NO_REFERENCED_ROW_2                  ,"23000", "" },
236
  { ER_SP_BAD_VAR_SHADOW                    ,"42000", "" },
237
  { ER_SP_WRONG_NAME                        ,"42000", "" },
238
  { ER_SP_NO_AGGREGATE                      ,"42000", "" },
239
  { ER_MAX_PREPARED_STMT_COUNT_REACHED      ,"42000", "" },
240
  { ER_NON_GROUPING_FIELD_USED              ,"42000", "" },
241
  { ER_FOREIGN_DUPLICATE_KEY                ,"23000", "S1009" },
242
  { ER_CANT_CHANGE_TX_ISOLATION             ,"25001", "" },
1124.3.2 by Diego Medina
Renamed ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT to ER_WRONG_PARAMCOUNT_TO_FUNCTION
243
  { ER_WRONG_PARAMCOUNT_TO_FUNCTION         ,"42000", "" },
468 by Monty Taylor
Repaced sql_state stuff with template function and c++ algorithm.
244
  { ER_WRONG_PARAMETERS_TO_NATIVE_FCT       ,"42000", "" },
245
  { ER_WRONG_PARAMETERS_TO_STORED_FCT       ,"42000", "" },
246
  { ER_DUP_ENTRY_WITH_KEY_NAME              ,"23000", "S1009" },
247
};
248
1085.1.2 by Monty Taylor
Fixed -Wmissing-declarations
249
static bool compare_errno_map(errno_sqlstate_map a,
250
                              errno_sqlstate_map b)
468 by Monty Taylor
Repaced sql_state stuff with template function and c++ algorithm.
251
{
971.3.4 by Eric Day
Further drizzleclient cleanup. Starting to move all NET related functions into Protocol, removed some dead code, removing drizzleclient dependencies spread throughout drizzled.
252
  return (a.drizzle_errno < b.drizzle_errno);
468 by Monty Taylor
Repaced sql_state stuff with template function and c++ algorithm.
253
}
254
971.3.4 by Eric Day
Further drizzleclient cleanup. Starting to move all NET related functions into Protocol, removed some dead code, removing drizzleclient dependencies spread throughout drizzled.
255
const char *drizzle_errno_to_sqlstate(uint32_t drizzle_errno)
468 by Monty Taylor
Repaced sql_state stuff with template function and c++ algorithm.
256
{
257
971.3.4 by Eric Day
Further drizzleclient cleanup. Starting to move all NET related functions into Protocol, removed some dead code, removing drizzleclient dependencies spread throughout drizzled.
258
  errno_sqlstate_map drizzle_err_state= {drizzle_errno, NULL, NULL};
481.1.20 by Monty Taylor
Removed extraneous vector from sql_state.
259
  errno_sqlstate_map* result=
260
    lower_bound(&sqlstate_map[0],
261
                &sqlstate_map[sizeof(sqlstate_map)/sizeof(*sqlstate_map)],
262
                drizzle_err_state, compare_errno_map);
468 by Monty Taylor
Repaced sql_state stuff with template function and c++ algorithm.
263
971.3.4 by Eric Day
Further drizzleclient cleanup. Starting to move all NET related functions into Protocol, removed some dead code, removing drizzleclient dependencies spread throughout drizzled.
264
  if ((*result).drizzle_errno == drizzle_errno)
468 by Monty Taylor
Repaced sql_state stuff with template function and c++ algorithm.
265
    return (*result).odbc_state;
266
  /* General error */
267
  return "HY000";
268
1 by brian
clean slate
269
}