~ubuntu-branches/ubuntu/quantal/mysql-connector-java/quantal

« back to all changes in this revision

Viewing changes to com/mysql/jdbc/SQLError.java

  • Committer: Bazaar Package Importer
  • Author(s): Takashi Okamoto
  • Date: 2003-12-30 22:37:53 UTC
  • Revision ID: james.westby@ubuntu.com-20031230223753-5d9n2b0w2ms6puqa
Tags: upstream-3.0.9
ImportĀ upstreamĀ versionĀ 3.0.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (C) 2002 MySQL AB
 
3
   
 
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.
 
8
   
 
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.
 
13
   
 
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
 
17
      
 
18
 */
 
19
package com.mysql.jdbc;
 
20
 
 
21
import java.util.Hashtable;
 
22
 
 
23
 
 
24
/**
 
25
 * SQLError is a utility class that maps MySQL error codes to X/Open
 
26
 * error codes as is required by the JDBC spec.
 
27
 *
 
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 $
 
30
 */
 
31
class SQLError {
 
32
 
 
33
    //~ Instance/static variables .............................................
 
34
 
 
35
    private static Hashtable mysqlToSqlState;
 
36
    private static Hashtable sqlStateMessages;
 
37
 
 
38
    //~ Initializers ..........................................................
 
39
 
 
40
    static {
 
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");
 
77
 
 
78
        //
 
79
        // Map MySQL error codes to X/Open error codes
 
80
        //
 
81
        mysqlToSqlState = new Hashtable();
 
82
 
 
83
        //
 
84
        // Communications Errors
 
85
        //
 
86
        // ER_BAD_HOST_ERROR 1042
 
87
        // ER_HANDSHAKE_ERROR 1043
 
88
        // ER_UNKNOWN_COM_ERROR 1047
 
89
        // ER_IPSOCK_ERROR 1081
 
90
        //
 
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");
 
95
 
 
96
        //
 
97
        // Authentication Errors
 
98
        //
 
99
        // ER_ACCESS_DENIED_ERROR 1045
 
100
        //
 
101
        mysqlToSqlState.put(new Integer(1045), "28000");
 
102
 
 
103
        //
 
104
        // Resource errors
 
105
        //
 
106
        // ER_CANT_CREATE_FILE 1004
 
107
        // ER_CANT_CREATE_TABLE 1005
 
108
        // ER_CANT_LOCK 1015
 
109
        // ER_DISK_FULL 1021
 
110
        // ER_CON_COUNT_ERROR 1040
 
111
        // ER_OUT_OF_RESOURCES 1041
 
112
        //
 
113
        // Out-of-memory errors
 
114
        //
 
115
        // ER_OUTOFMEMORY 1037
 
116
        // ER_OUT_OF_SORTMEMORY 1038
 
117
        //
 
118
        mysqlToSqlState.put(new Integer(1037), "S1001");
 
119
        mysqlToSqlState.put(new Integer(1038), "S1001");
 
120
 
 
121
        //
 
122
        // Syntax Errors
 
123
        //
 
124
        // ER_PARSE_ERROR 1064
 
125
        // ER_EMPTY_QUERY 1065
 
126
        //
 
127
        mysqlToSqlState.put(new Integer(1064), "42000");
 
128
        mysqlToSqlState.put(new Integer(1065), "42000");
 
129
 
 
130
        //
 
131
        // Invalid argument errors
 
132
        //
 
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
 
139
        // ER_DUP_ENTRY 1062
 
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
 
154
        //
 
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");
 
176
 
 
177
        //
 
178
        // ER_WRONG_VALUE_COUNT 1058
 
179
        //
 
180
        mysqlToSqlState.put(new Integer(1058), "21S01");
 
181
 
 
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
 
196
        // ER_CHECKREAD 1020
 
197
        // ER_DUP_KEY 1022
 
198
        // ER_ERROR_ON_CLOSE 1023
 
199
        // ER_ERROR_ON_READ 1024
 
200
        // ER_ERROR_ON_RENAME 1025
 
201
        // ER_ERROR_ON_WRITE 1026
 
202
        // ER_FILE_USED 1027
 
203
        // ER_FILSORT_ABORT 1028
 
204
        // ER_FORM_NOT_FOUND 1029
 
205
        // ER_GET_ERRNO 1030
 
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");
 
219
 
 
220
        // ER_TEXTFILE_NOT_READABLE 1085
 
221
        // ER_FILE_EXISTS_ERROR 1086
 
222
        // ER_LOAD_INFO 1087
 
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
 
229
    }
 
230
 
 
231
    //~ Methods ...............................................................
 
232
 
 
233
    static String get(String stateCode) {
 
234
 
 
235
        return (String) sqlStateMessages.get(stateCode);
 
236
    }
 
237
 
 
238
    /**
 
239
   * Map MySQL error codes to X/Open error codes
 
240
   *
 
241
   * @param errno the MySQL error code
 
242
   * @return the corresponding X/Open error code
 
243
   */
 
244
    static String mysqlToXOpen(int errno) {
 
245
 
 
246
        Integer err = new Integer(errno);
 
247
 
 
248
        if (mysqlToSqlState.containsKey(err)) {
 
249
 
 
250
            return (String) mysqlToSqlState.get(err);
 
251
        } else {
 
252
 
 
253
            return "S1000";
 
254
        }
 
255
    }
 
256
}