1
/* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
21
/* Functions to map drizzle errno to sql_state */
26
#include <drizzled/sql_state.h>
1
/* Copyright (C) 2000-2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
/* Functions to map mysqld errno to sql_state */
27
19
#include <drizzled/error.h>
34
typedef struct st_map_errno_to_sqlstate
36
uint32_t drizzle_errno;
37
const char *odbc_state;
38
const char *jdbc_state;
41
errno_sqlstate_map sqlstate_map[]=
43
{ ER_DUP_KEY ,"23000", "" },
44
{ ER_OUTOFMEMORY ,"HY001", "S1001" },
45
{ ER_OUT_OF_SORTMEMORY ,"HY001", "S1001" },
46
{ ER_CON_COUNT_ERROR ,"08004", "" },
47
{ ER_BAD_HOST_ERROR ,"08S01", "" },
48
{ ER_HANDSHAKE_ERROR ,"08S01", "" },
49
{ ER_DBACCESS_DENIED_ERROR ,"42000", "" },
50
{ ER_ACCESS_DENIED_ERROR ,"28000", "" },
51
{ ER_NO_DB_ERROR ,"3D000", "" },
52
{ ER_UNKNOWN_COM_ERROR ,"08S01", "" },
53
{ ER_BAD_NULL_ERROR ,"23000", "" },
54
{ ER_BAD_DB_ERROR ,"42000", "" },
55
{ ER_TABLE_EXISTS_ERROR ,"42S01", "" },
56
{ ER_BAD_TABLE_ERROR ,"42S02", "" },
57
{ ER_NON_UNIQ_ERROR ,"23000", "" },
58
{ ER_SERVER_SHUTDOWN ,"08S01", "" },
59
{ ER_BAD_FIELD_ERROR ,"42S22", "S0022" },
60
{ ER_WRONG_FIELD_WITH_GROUP ,"42000", "S1009" },
61
{ ER_WRONG_GROUP_FIELD ,"42000", "S1009" },
62
{ ER_WRONG_SUM_SELECT ,"42000", "S1009" },
63
{ ER_WRONG_VALUE_COUNT ,"21S01", "" },
64
{ ER_TOO_LONG_IDENT ,"42000", "S1009" },
65
{ ER_DUP_FIELDNAME ,"42S21", "S1009" },
66
{ ER_DUP_KEYNAME ,"42000", "S1009" },
67
{ ER_DUP_ENTRY ,"23000", "S1009" },
68
{ ER_WRONG_FIELD_SPEC ,"42000", "S1009" },
69
{ ER_PARSE_ERROR ,"42000", "s1009" },
70
{ ER_EMPTY_QUERY ,"42000", "" },
71
{ ER_NONUNIQ_TABLE ,"42000", "S1009" },
72
{ ER_INVALID_DEFAULT ,"42000", "S1009" },
73
{ ER_MULTIPLE_PRI_KEY ,"42000", "S1009" },
74
{ ER_TOO_MANY_KEYS ,"42000", "S1009" },
75
{ ER_TOO_MANY_KEY_PARTS ,"42000", "S1009" },
76
{ ER_TOO_LONG_KEY ,"42000", "S1009" },
77
{ ER_KEY_COLUMN_DOES_NOT_EXITS ,"42000", "S1009" },
78
{ ER_BLOB_USED_AS_KEY ,"42000", "S1009" },
79
{ ER_TOO_BIG_FIELDLENGTH ,"42000", "S1009" },
80
{ ER_WRONG_AUTO_KEY ,"42000", "S1009" },
81
{ ER_FORCING_CLOSE ,"08S01", "" },
82
{ ER_IPSOCK_ERROR ,"08S01", "" },
83
{ ER_NO_SUCH_INDEX ,"42S12", "S1009" },
84
{ ER_WRONG_FIELD_TERMINATORS ,"42000", "S1009" },
85
{ ER_BLOBS_AND_NO_TERMINATED ,"42000", "S1009" },
86
{ ER_CANT_REMOVE_ALL_FIELDS ,"42000", "" },
87
{ ER_CANT_DROP_FIELD_OR_KEY ,"42000", "" },
88
{ ER_BLOB_CANT_HAVE_DEFAULT ,"42000", "" },
89
{ ER_WRONG_DB_NAME ,"42000", "" },
90
{ ER_WRONG_TABLE_NAME ,"42000", "" },
91
{ ER_TOO_BIG_SELECT ,"42000", "" },
92
{ ER_UNKNOWN_PROCEDURE ,"42000", "" },
93
{ ER_WRONG_PARAMCOUNT_TO_PROCEDURE ,"42000", "" },
94
{ ER_UNKNOWN_TABLE ,"42S02", "" },
95
{ ER_FIELD_SPECIFIED_TWICE ,"42000", "" },
96
{ ER_UNSUPPORTED_EXTENSION ,"42000", "" },
97
{ ER_TABLE_MUST_HAVE_COLUMNS ,"42000", "" },
98
{ ER_TOO_BIG_ROWSIZE ,"42000", "" },
99
{ ER_WRONG_OUTER_JOIN ,"42000", "" },
100
{ ER_NULL_COLUMN_IN_INDEX ,"42000", "" },
101
{ ER_WRONG_VALUE_COUNT_ON_ROW ,"21S01", "" },
102
{ ER_MIX_OF_GROUP_FUNC_AND_FIELDS ,"42000", "" },
103
{ ER_NO_SUCH_TABLE ,"42S02", "" },
104
{ ER_SYNTAX_ERROR ,"42000", "" },
105
{ ER_NET_PACKET_TOO_LARGE ,"08S01", "" },
106
{ ER_NET_PACKETS_OUT_OF_ORDER ,"08S01", "" },
107
{ ER_TABLE_CANT_HANDLE_BLOB ,"42000", "" },
108
{ ER_TABLE_CANT_HANDLE_AUTO_INCREMENT ,"42000", "" },
109
{ ER_WRONG_COLUMN_NAME ,"42000", "" },
110
{ ER_WRONG_KEY_COLUMN ,"42000", "" },
111
{ ER_DUP_UNIQUE ,"23000", "" },
112
{ ER_BLOB_KEY_WITHOUT_LENGTH ,"42000", "" },
113
{ ER_PRIMARY_CANT_HAVE_NULL ,"42000", "" },
114
{ ER_TOO_MANY_ROWS ,"42000", "" },
115
{ ER_REQUIRES_PRIMARY_KEY ,"42000", "" },
116
{ ER_KEY_DOES_NOT_EXITS ,"42000", "S1009" },
117
{ ER_CHECK_NO_SUCH_TABLE ,"42000", "" },
118
{ ER_CHECK_NOT_IMPLEMENTED ,"42000", "" },
119
{ ER_NEW_ABORTING_CONNECTION ,"08S01", "" },
120
{ ER_READ_ONLY_TRANSACTION ,"25000", "" },
121
{ ER_LOCK_DEADLOCK ,"40001", "" },
122
{ ER_NO_REFERENCED_ROW ,"23000", "" },
123
{ ER_ROW_IS_REFERENCED ,"23000", "" },
124
{ ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT ,"21000", "" },
125
{ ER_NO_DEFAULT ,"42000", "" },
126
{ ER_WRONG_VALUE_FOR_VAR ,"42000", "" },
127
{ ER_WRONG_TYPE_FOR_VAR ,"42000", "" },
128
{ ER_CANT_USE_OPTION_HERE ,"42000", "" },
129
{ ER_NOT_SUPPORTED_YET ,"42000", "" },
130
{ ER_WRONG_FK_DEF ,"42000", "" },
131
{ ER_OPERAND_COLUMNS ,"21000", "" },
132
{ ER_SUBQUERY_NO_1_ROW ,"21000", "" },
133
{ ER_ILLEGAL_REFERENCE ,"42S22", "" },
134
{ ER_DERIVED_MUST_HAVE_ALIAS ,"42000", "" },
135
{ ER_SELECT_REDUCED ,"01000", "" },
136
{ ER_TABLENAME_NOT_ALLOWED_HERE ,"42000", "" },
137
{ ER_SPATIAL_CANT_HAVE_NULL ,"42000", "" },
138
{ ER_COLLATION_CHARSET_MISMATCH ,"42000", "" },
139
{ ER_WARN_TOO_FEW_RECORDS ,"01000", "" },
140
{ ER_WARN_TOO_MANY_RECORDS ,"01000", "" },
141
{ ER_WARN_NULL_TO_NOTNULL ,"22004", "" },
142
{ ER_WARN_DATA_OUT_OF_RANGE ,"22003", "" },
143
{ ER_WARN_DATA_TRUNCATED ,"01000", "" },
144
{ ER_WRONG_NAME_FOR_INDEX ,"42000", "" },
145
{ ER_WRONG_NAME_FOR_CATALOG ,"42000", "" },
146
{ ER_UNKNOWN_STORAGE_ENGINE ,"42000", "" },
147
{ ER_TRUNCATED_WRONG_VALUE ,"22007", "" },
148
{ ER_SP_DOES_NOT_EXIST ,"42000", "" },
149
{ ER_QUERY_INTERRUPTED ,"70100", "" },
150
{ ER_DIVISION_BY_ZERO ,"22012", "" },
151
{ ER_ILLEGAL_VALUE_FOR_TYPE ,"22007", "" },
152
{ ER_XAER_RMFAIL ,"XAE07", "" },
153
{ ER_DATA_TOO_LONG ,"22001", "" },
154
{ ER_SP_NO_RETSET ,"0A000", "" },
155
{ ER_CANT_CREATE_GEOMETRY_OBJECT ,"22003", "" },
156
{ ER_TOO_BIG_SCALE ,"42000", "S1009" },
157
{ ER_TOO_BIG_PRECISION ,"42000", "S1009" },
158
{ ER_M_BIGGER_THAN_D ,"42000", "S1009" },
159
{ ER_TOO_BIG_DISPLAYWIDTH ,"42000", "S1009" },
160
{ ER_DATETIME_FUNCTION_OVERFLOW ,"22008", "" },
161
{ ER_ROW_IS_REFERENCED_2 ,"23000", "" },
162
{ ER_NO_REFERENCED_ROW_2 ,"23000", "" },
163
{ ER_NON_GROUPING_FIELD_USED ,"42000", "" },
164
{ ER_FOREIGN_DUPLICATE_KEY ,"23000", "S1009" },
165
{ ER_CANT_CHANGE_TX_ISOLATION ,"25001", "" },
166
{ ER_WRONG_PARAMCOUNT_TO_FUNCTION ,"42000", "" },
167
{ ER_WRONG_PARAMETERS_TO_NATIVE_FCT ,"42000", "" },
168
{ ER_DUP_ENTRY_WITH_KEY_NAME ,"23000", "S1009" },
171
static bool compare_errno_map(errno_sqlstate_map a,
172
errno_sqlstate_map b)
174
return (a.drizzle_errno < b.drizzle_errno);
177
const char *drizzle_errno_to_sqlstate(uint32_t drizzle_errno)
180
errno_sqlstate_map drizzle_err_state= {drizzle_errno, NULL, NULL};
181
errno_sqlstate_map* result=
182
lower_bound(&sqlstate_map[0],
183
&sqlstate_map[sizeof(sqlstate_map)/sizeof(*sqlstate_map)],
184
drizzle_err_state, compare_errno_map);
186
if ((*result).drizzle_errno == drizzle_errno)
187
return (*result).odbc_state;
193
} /* namespace drizzled */
20
#include <libdrizzle/drizzle.h>
21
#include "sql_state.h"
23
const char *drizzle_errno_to_sqlstate(uint mysql_errno)
25
uint first=0, end= array_elements(sqlstate_map)-1;
26
struct st_map_errno_to_sqlstate *map;
28
/* Do binary search in the sorted array */
31
uint mid= (first+end)/2;
32
map= sqlstate_map+mid;
33
if (map->mysql_errno < mysql_errno)
38
map= sqlstate_map+first;
39
if (map->mysql_errno == mysql_errno)
40
return map->odbc_state;
41
return "HY000"; /* General error */