Skip to content

Commit 78451c4

Browse files
committed
WL#16342, Update MySQL error codes mapping.
Change-Id: Ic7305709d2f048d35769c014ce7c9549629ac396
1 parent bac0ea3 commit 78451c4

File tree

56 files changed

+7391
-2046
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+7391
-2046
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
Version 9.0.0
55

6+
- WL#16342, Update MySQL error codes mapping.
7+
68
- WL#16353, Refresh the list of acceptable TLS ciphers.
79

810
- Fix for Bug#114687 (Bug#36529541), Tests fail after mysql_native_password has been made optional in server.

src/build/java/documentation/ErrorMappingsDocGenerator.java

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
package documentation;
2222

23-
import java.util.HashMap;
23+
import java.lang.reflect.Field;
2424
import java.util.Map;
2525
import java.util.TreeMap;
2626

@@ -36,41 +36,24 @@ public static void main(String[] args) throws Exception {
3636
}
3737

3838
public static void dumpSqlStatesMappingsAsXml() throws Exception {
39-
TreeMap<Integer, Integer> allErrorNumbers = new TreeMap<>();
40-
Map<Object, String> mysqlErrorNumbersToNames = new HashMap<>();
39+
Map<Integer, String> mysqlErrors = new TreeMap<>();
4140

42-
// Integer errorNumber = null;
43-
44-
//
45-
// First create a list of all 'known' error numbers that are mapped.
46-
//
47-
for (Integer errorNumber : MysqlErrorNumbers.mysqlToSql99State.keySet()) {
48-
allErrorNumbers.put(errorNumber, errorNumber);
49-
}
50-
51-
//
52-
// Now create a list of the actual MySQL error numbers we know about
53-
//
54-
java.lang.reflect.Field[] possibleFields = MysqlErrorNumbers.class.getDeclaredFields();
55-
56-
for (int i = 0; i < possibleFields.length; i++) {
57-
String fieldName = possibleFields[i].getName();
58-
59-
if (fieldName.startsWith("ER_")) {
60-
mysqlErrorNumbersToNames.put(possibleFields[i].get(null), fieldName);
41+
// Create a list of all MySQL error numbers.
42+
Field[] allFields = MysqlErrorNumbers.class.getDeclaredFields();
43+
for (Field f : allFields) {
44+
if (f.getName().startsWith("ER_") || f.getName().startsWith("WARN_")) {
45+
mysqlErrors.put((Integer) f.get(null), f.getName());
6146
}
6247
}
6348

64-
System.out.println("<ErrorMappings>");
65-
66-
for (Integer errorNumber : allErrorNumbers.keySet()) {
67-
String sql92State = MysqlErrorNumbers.mysqlToSql99(errorNumber.intValue());
68-
69-
System.out.println(" <ErrorMapping mysqlErrorNumber=\"" + errorNumber + "\" mysqlErrorName=\"" + mysqlErrorNumbersToNames.get(errorNumber)
70-
+ "\" legacySqlState=\"" + "" + "\" sql92SqlState=\"" + (sql92State == null ? "" : sql92State) + "\"/>");
49+
// Generate documentation tags for each error mapping.
50+
System.out.printf("<ErrorMappings>%n");
51+
for (Integer error : mysqlErrors.keySet()) {
52+
String sqlstate = MysqlErrorNumbers.mysqlToSqlstate(error);
53+
System.out.printf(" <ErrorMapping mysqlErrorNumber=\"%d\" mysqlErrorName=\"%s\" legacySqlState=\"\" sql92SqlState=\"%s\"/>%n", error,
54+
mysqlErrors.get(error), sqlstate);
7155
}
72-
73-
System.out.println("</ErrorMappings>");
56+
System.out.printf("</ErrorMappings>%n");
7457
}
7558

7659
}

src/main/core-api/java/com/mysql/cj/exceptions/MysqlErrorNumbers.java

Lines changed: 6460 additions & 1385 deletions
Large diffs are not rendered by default.

src/main/core-api/java/com/mysql/cj/exceptions/UnsupportedConnectionStringException.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,27 @@ public class UnsupportedConnectionStringException extends CJException {
2626

2727
public UnsupportedConnectionStringException() {
2828
super();
29-
setSQLState(MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT);
29+
setSQLState(MysqlErrorNumbers.SQLSTATE_CONNJ_ILLEGAL_ARGUMENT);
3030
}
3131

3232
public UnsupportedConnectionStringException(String message) {
3333
super(message);
34-
setSQLState(MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT);
34+
setSQLState(MysqlErrorNumbers.SQLSTATE_CONNJ_ILLEGAL_ARGUMENT);
3535
}
3636

3737
public UnsupportedConnectionStringException(String message, Throwable cause) {
3838
super(message, cause);
39-
setSQLState(MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT);
39+
setSQLState(MysqlErrorNumbers.SQLSTATE_CONNJ_ILLEGAL_ARGUMENT);
4040
}
4141

4242
public UnsupportedConnectionStringException(Throwable cause) {
4343
super(cause);
44-
setSQLState(MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT);
44+
setSQLState(MysqlErrorNumbers.SQLSTATE_CONNJ_ILLEGAL_ARGUMENT);
4545
}
4646

4747
public UnsupportedConnectionStringException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
4848
super(message, cause, enableSuppression, writableStackTrace);
49-
setSQLState(MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT);
49+
setSQLState(MysqlErrorNumbers.SQLSTATE_CONNJ_ILLEGAL_ARGUMENT);
5050
}
5151

5252
}

src/main/core-impl/java/com/mysql/cj/NativeQueryBindings.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ public boolean clearBindValues() {
139139
public void checkParameterSet(int columnIndex) {
140140
if (!this.bindValues[columnIndex].isSet()) {
141141
throw ExceptionFactory.createException(Messages.getString("PreparedStatement.40") + (columnIndex + 1),
142-
MysqlErrorNumbers.SQL_STATE_WRONG_NO_OF_PARAMETERS, 0, true, null, this.session.getExceptionInterceptor());
142+
MysqlErrorNumbers.SQLSTATE_DYNAMIC_SQL_ERROR_USING_CLAUSE_DOES_NOT_MATCH_DYNAMIC_PARAMETER_SPECIFICATIONS, 0, true, null,
143+
this.session.getExceptionInterceptor());
143144
}
144145
}
145146

src/main/core-impl/java/com/mysql/cj/NativeSession.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ public void ping(boolean checkForClosedConnection, int timeoutMillis) {
890890
invokeNormalCloseListeners();
891891

892892
throw ExceptionFactory.createException(Messages.getString("Connection.exceededConnectionLifetime"),
893-
MysqlErrorNumbers.SQL_STATE_COMMUNICATION_LINK_FAILURE, 0, false, null, this.exceptionInterceptor);
893+
MysqlErrorNumbers.SQLSTATE_MYSQL_COMMUNICATION_LINK_FAILURE, 0, false, null, this.exceptionInterceptor);
894894
}
895895
this.protocol.sendCommand(this.commandBuilder.buildComPing(null), false, timeoutMillis); // it isn't safe to use a shared packet here
896896
} catch (Throwable t) {

src/main/core-impl/java/com/mysql/cj/ServerPreparedQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public NativePacketPayload prepareExecutePacket() {
210210
if (firstFound && boundTimeToCheck != bindValues[i].getBoundBeforeExecutionNum()) {
211211
throw ExceptionFactory.createException(
212212
Messages.getString("ServerPreparedStatement.11") + Messages.getString("ServerPreparedStatement.12"),
213-
MysqlErrorNumbers.SQL_STATE_DRIVER_NOT_CAPABLE, 0, true, null, this.session.getExceptionInterceptor());
213+
MysqlErrorNumbers.SQLSTATE_CONNJ_DRIVER_NOT_CAPABLE, 0, true, null, this.session.getExceptionInterceptor());
214214
}
215215
firstFound = true;
216216
boundTimeToCheck = bindValues[i].getBoundBeforeExecutionNum();

src/main/protocol-impl/java/com/mysql/cj/protocol/a/NativeProtocol.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ public void rejectProtocol(NativePacketPayload msg) {
393393
errorBuf.append(serverErrorMessage);
394394
errorBuf.append("\"");
395395

396-
String xOpen = MysqlErrorNumbers.mysqlToSqlState(errno);
396+
String xOpen = MysqlErrorNumbers.mysqlToSqlstate(errno);
397397

398398
throw ExceptionFactory.createException(MysqlErrorNumbers.get(xOpen) + ", " + errorBuf.toString(), xOpen, errno, false, null, getExceptionInterceptor());
399399
}
@@ -593,7 +593,7 @@ public final NativePacketPayload readMessage(NativePacketPayload reuse) {
593593
throw ExceptionFactory.createCommunicationsException(this.propertySet, this.serverSession, getPacketSentTimeHolder(), getPacketReceivedTimeHolder(),
594594
ioEx, getExceptionInterceptor());
595595
} catch (OutOfMemoryError oom) {
596-
throw ExceptionFactory.createException(oom.getMessage(), MysqlErrorNumbers.SQL_STATE_MEMORY_ALLOCATION_ERROR, 0, false, oom,
596+
throw ExceptionFactory.createException(oom.getMessage(), MysqlErrorNumbers.SQLSTATE_CLI_SPECIFIC_CONDITION_MEMORY_ALLOCATION_ERROR, 0, false, oom,
597597
this.exceptionInterceptor);
598598
}
599599
}
@@ -609,7 +609,7 @@ public final NativePacketPayload probeMessage(NativePacketPayload reuse) {
609609
throw ExceptionFactory.createCommunicationsException(this.propertySet, this.serverSession, getPacketSentTimeHolder(), getPacketReceivedTimeHolder(),
610610
ioEx, getExceptionInterceptor());
611611
} catch (OutOfMemoryError oom) {
612-
throw ExceptionFactory.createException(oom.getMessage(), MysqlErrorNumbers.SQL_STATE_MEMORY_ALLOCATION_ERROR, 0, false, oom,
612+
throw ExceptionFactory.createException(oom.getMessage(), MysqlErrorNumbers.SQLSTATE_CLI_SPECIFIC_CONDITION_MEMORY_ALLOCATION_ERROR, 0, false, oom,
613613
this.exceptionInterceptor);
614614
}
615615
}
@@ -805,13 +805,13 @@ public void checkErrorMessage(NativePacketPayload resultPacket) {
805805
serverErrorMessage = serverErrorMessage.substring(6);
806806

807807
if (xOpen.equals("HY000")) {
808-
xOpen = MysqlErrorNumbers.mysqlToSqlState(errno);
808+
xOpen = MysqlErrorNumbers.mysqlToSqlstate(errno);
809809
}
810810
} else {
811-
xOpen = MysqlErrorNumbers.mysqlToSqlState(errno);
811+
xOpen = MysqlErrorNumbers.mysqlToSqlstate(errno);
812812
}
813813
} else {
814-
xOpen = MysqlErrorNumbers.mysqlToSqlState(errno);
814+
xOpen = MysqlErrorNumbers.mysqlToSqlstate(errno);
815815
}
816816

817817
clearInputStream();
@@ -1711,7 +1711,7 @@ public final NativePacketPayload sendFileToServer(String fileName) {
17111711
this.loadFileBufRef = new SoftReference<>(filePacket);
17121712
} catch (OutOfMemoryError oom) {
17131713
throw ExceptionFactory.createException(Messages.getString("MysqlIO.111", new Object[] { packetLength }),
1714-
MysqlErrorNumbers.SQL_STATE_MEMORY_ALLOCATION_ERROR, 0, false, oom, this.exceptionInterceptor);
1714+
MysqlErrorNumbers.SQLSTATE_CLI_SPECIFIC_CONDITION_MEMORY_ALLOCATION_ERROR, 0, false, oom, this.exceptionInterceptor);
17151715
}
17161716
}
17171717

@@ -2107,7 +2107,7 @@ public SQLWarning convertShowWarningsToSQLWarnings(boolean forTruncationOnly) {
21072107
int code = r.getValue(codeFieldIndex, ivf);
21082108

21092109
if (forTruncationOnly) {
2110-
if (code == MysqlErrorNumbers.ER_WARN_DATA_TRUNCATED || code == MysqlErrorNumbers.ER_WARN_DATA_OUT_OF_RANGE) {
2110+
if (code == MysqlErrorNumbers.WARN_DATA_TRUNCATED || code == MysqlErrorNumbers.ER_WARN_DATA_OUT_OF_RANGE) {
21112111
DataTruncation newTruncation = new MysqlDataTruncation(r.getValue(messageFieldIndex, svf), 0, false, false, 0, 0, code);
21122112

21132113
if (currentWarning == null) {
@@ -2120,7 +2120,7 @@ public SQLWarning convertShowWarningsToSQLWarnings(boolean forTruncationOnly) {
21202120
//String level = warnRs.getString("Level");
21212121
String message = r.getValue(messageFieldIndex, svf);
21222122

2123-
SQLWarning newWarning = new SQLWarning(message, MysqlErrorNumbers.mysqlToSqlState(code), code);
2123+
SQLWarning newWarning = new SQLWarning(message, MysqlErrorNumbers.mysqlToSqlstate(code), code);
21242124
if (currentWarning == null) {
21252125
currentWarning = newWarning;
21262126
} else {
@@ -2243,7 +2243,7 @@ public void initServerSession() {
22432243

22442244
if (allowedBlobSendChunkSize <= 0) {
22452245
throw ExceptionFactory.createException(Messages.getString("Connection.15", new Object[] { packetHeaderSize }),
2246-
MysqlErrorNumbers.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE, 0, false, null, this.exceptionInterceptor);
2246+
MysqlErrorNumbers.SQLSTATE_MYSQL_INVALID_CONNECTION_ATTRIBUTE, 0, false, null, this.exceptionInterceptor);
22472247
}
22482248

22492249
blobSendChunkSize.setValue(allowedBlobSendChunkSize);

0 commit comments

Comments
 (0)