2
Copyright (C) 2002 MySQL AB
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
package com.mysql.jdbc;
21
import java.util.Hashtable;
25
* SQLError is a utility class that maps MySQL error codes to X/Open
26
* error codes as is required by the JDBC spec.
28
* @author Mark Matthews <mmatthew_at_worldserver.com>
29
* @version $Id: SQLError.java,v 1.6.2.1 2003/04/22 17:18:32 mmatthew Exp $
33
//~ Instance/static variables .............................................
35
private static Hashtable mysqlToSqlState;
36
private static Hashtable sqlStateMessages;
38
//~ Initializers ..........................................................
41
sqlStateMessages = new Hashtable();
42
sqlStateMessages.put("01002", "Disconnect error");
43
sqlStateMessages.put("01004", "Data truncated");
44
sqlStateMessages.put("01006", "Privilege not revoked");
45
sqlStateMessages.put("01S00", "Invalid connection string attribute");
46
sqlStateMessages.put("01S01", "Error in row");
47
sqlStateMessages.put("01S03", "No rows updated or deleted");
48
sqlStateMessages.put("01S04", "More than one row updated or deleted");
49
sqlStateMessages.put("07001", "Wrong number of parameters");
50
sqlStateMessages.put("08001", "Unable to connect to data source");
51
sqlStateMessages.put("08002", "Connection in use");
52
sqlStateMessages.put("08003", "Connection not open");
53
sqlStateMessages.put("08004", "Data source rejected establishment of connection");
54
sqlStateMessages.put("08007", "Connection failure during transaction");
55
sqlStateMessages.put("08S01", "Communication link failure");
56
sqlStateMessages.put("21S01", "Insert value list does not match column list");
57
sqlStateMessages.put("22003", "Numeric value out of range");
58
sqlStateMessages.put("22005", "Numeric value out of range");
59
sqlStateMessages.put("22008", "Datetime field overflow");
60
sqlStateMessages.put("22012", "Division by zero");
61
sqlStateMessages.put("28000", "Invalid authorization specification");
62
sqlStateMessages.put("42000", "Syntax error or access violation");
63
sqlStateMessages.put("42S02", "Base table or view not found");
64
sqlStateMessages.put("S0001", "Base table or view already exists");
65
sqlStateMessages.put("S0002", "Base table not found");
66
sqlStateMessages.put("S0011", "Index already exists");
67
sqlStateMessages.put("S0012", "Index not found");
68
sqlStateMessages.put("S0021", "Column already exists");
69
sqlStateMessages.put("S0022", "Column not found");
70
sqlStateMessages.put("S0023", "No default for column");
71
sqlStateMessages.put("S1000", "General error");
72
sqlStateMessages.put("S1001", "Memory allocation failure");
73
sqlStateMessages.put("S1002", "Invalid column number");
74
sqlStateMessages.put("S1009", "Invalid argument value");
75
sqlStateMessages.put("S1C00", "Driver not capable");
76
sqlStateMessages.put("S1T00", "Timeout expired");
79
// Map MySQL error codes to X/Open error codes
81
mysqlToSqlState = new Hashtable();
84
// Communications Errors
86
// ER_BAD_HOST_ERROR 1042
87
// ER_HANDSHAKE_ERROR 1043
88
// ER_UNKNOWN_COM_ERROR 1047
89
// ER_IPSOCK_ERROR 1081
91
mysqlToSqlState.put(new Integer(1042), "08S01");
92
mysqlToSqlState.put(new Integer(1043), "08S01");
93
mysqlToSqlState.put(new Integer(1047), "08S01");
94
mysqlToSqlState.put(new Integer(1081), "08S01");
97
// Authentication Errors
99
// ER_ACCESS_DENIED_ERROR 1045
101
mysqlToSqlState.put(new Integer(1045), "28000");
106
// ER_CANT_CREATE_FILE 1004
107
// ER_CANT_CREATE_TABLE 1005
110
// ER_CON_COUNT_ERROR 1040
111
// ER_OUT_OF_RESOURCES 1041
113
// Out-of-memory errors
115
// ER_OUTOFMEMORY 1037
116
// ER_OUT_OF_SORTMEMORY 1038
118
mysqlToSqlState.put(new Integer(1037), "S1001");
119
mysqlToSqlState.put(new Integer(1038), "S1001");
124
// ER_PARSE_ERROR 1064
125
// ER_EMPTY_QUERY 1065
127
mysqlToSqlState.put(new Integer(1064), "42000");
128
mysqlToSqlState.put(new Integer(1065), "42000");
131
// Invalid argument errors
133
// ER_WRONG_FIELD_WITH_GROUP 1055
134
// ER_WRONG_GROUP_FIELD 1056
135
// ER_WRONG_SUM_SELECT 1057
136
// ER_TOO_LONG_IDENT 1059
137
// ER_DUP_FIELDNAME 1060
138
// ER_DUP_KEYNAME 1061
140
// ER_WRONG_FIELD_SPEC 1063
141
// ER_NONUNIQ_TABLE 1066
142
// ER_INVALID_DEFAULT 1067
143
// ER_MULTIPLE_PRI_KEY 1068
144
// ER_TOO_MANY_KEYS 1069
145
// ER_TOO_MANY_KEY_PARTS 1070
146
// ER_TOO_LONG_KEY 1071
147
// ER_KEY_COLUMN_DOES_NOT_EXIST 1072
148
// ER_BLOB_USED_AS_KEY 1073
149
// ER_TOO_BIG_FIELDLENGTH 1074
150
// ER_WRONG_AUTO_KEY 1075
151
// ER_NO_SUCH_INDEX 1082
152
// ER_WRONG_FIELD_TERMINATORS 1083
153
// ER_BLOBS_AND_NO_TERMINATED 1084
155
mysqlToSqlState.put(new Integer(1055), "S1009");
156
mysqlToSqlState.put(new Integer(1056), "S1009");
157
mysqlToSqlState.put(new Integer(1057), "S1009");
158
mysqlToSqlState.put(new Integer(1059), "S1009");
159
mysqlToSqlState.put(new Integer(1060), "S1009");
160
mysqlToSqlState.put(new Integer(1061), "S1009");
161
mysqlToSqlState.put(new Integer(1062), "S1009");
162
mysqlToSqlState.put(new Integer(1063), "S1009");
163
mysqlToSqlState.put(new Integer(1066), "S1009");
164
mysqlToSqlState.put(new Integer(1067), "S1009");
165
mysqlToSqlState.put(new Integer(1068), "S1009");
166
mysqlToSqlState.put(new Integer(1069), "S1009");
167
mysqlToSqlState.put(new Integer(1070), "S1009");
168
mysqlToSqlState.put(new Integer(1071), "S1009");
169
mysqlToSqlState.put(new Integer(1072), "S1009");
170
mysqlToSqlState.put(new Integer(1073), "S1009");
171
mysqlToSqlState.put(new Integer(1074), "S1009");
172
mysqlToSqlState.put(new Integer(1075), "S1009");
173
mysqlToSqlState.put(new Integer(1082), "S1009");
174
mysqlToSqlState.put(new Integer(1083), "S1009");
175
mysqlToSqlState.put(new Integer(1084), "S1009");
178
// ER_WRONG_VALUE_COUNT 1058
180
mysqlToSqlState.put(new Integer(1058), "21S01");
182
// ER_CANT_CREATE_DB 1006
183
// ER_DB_CREATE_EXISTS 1007
184
// ER_DB_DROP_EXISTS 1008
185
// ER_DB_DROP_DELETE 1009
186
// ER_DB_DROP_RMDIR 1010
187
// ER_CANT_DELETE_FILE 1011
188
// ER_CANT_FIND_SYSTEM_REC 1012
189
// ER_CANT_GET_STAT 1013
190
// ER_CANT_GET_WD 1014
191
// ER_UNEXPECTED_EOF 1039
192
// ER_CANT_OPEN_FILE 1016
193
// ER_FILE_NOT_FOUND 1017
194
// ER_CANT_READ_DIR 1018
195
// ER_CANT_SET_WD 1019
198
// ER_ERROR_ON_CLOSE 1023
199
// ER_ERROR_ON_READ 1024
200
// ER_ERROR_ON_RENAME 1025
201
// ER_ERROR_ON_WRITE 1026
203
// ER_FILSORT_ABORT 1028
204
// ER_FORM_NOT_FOUND 1029
206
// ER_ILLEGAL_HA 1031
207
// ER_KEY_NOT_FOUND 1032
208
// ER_NOT_FORM_FILE 1033
209
// ER_DBACCESS_DENIED_ERROR 1044
210
// ER_NO_DB_ERROR 1046
211
// ER_BAD_NULL_ERROR 1048
212
// ER_BAD_DB_ERROR 1049
213
// ER_TABLE_EXISTS_ERROR 1050
214
// ER_BAD_TABLE_ERROR 1051
215
mysqlToSqlState.put(new Integer(1051), "42S02");
216
// ER_NON_UNIQ_ERROR 1052
217
// ER_BAD_FIELD_ERROR 1054
218
mysqlToSqlState.put(new Integer(1054), "S0022");
220
// ER_TEXTFILE_NOT_READABLE 1085
221
// ER_FILE_EXISTS_ERROR 1086
223
// ER_ALTER_INFO 1088
224
// ER_WRONG_SUB_KEY 1089
225
// ER_CANT_REMOVE_ALL_FIELDS 1090
226
// ER_CANT_DROP_FIELD_OR_KEY 1091
227
// ER_INSERT_INFO 1092
228
// ER_INSERT_TABLE_USED 1093
231
//~ Methods ...............................................................
233
static String get(String stateCode) {
235
return (String) sqlStateMessages.get(stateCode);
239
* Map MySQL error codes to X/Open error codes
241
* @param errno the MySQL error code
242
* @return the corresponding X/Open error code
244
static String mysqlToXOpen(int errno) {
246
Integer err = new Integer(errno);
248
if (mysqlToSqlState.containsKey(err)) {
250
return (String) mysqlToSqlState.get(err);