Skip to content

Commit

Permalink
WL#16342, Update MySQL error codes mapping.
Browse files Browse the repository at this point in the history
Change-Id: Ic7305709d2f048d35769c014ce7c9549629ac396
  • Loading branch information
fjssilva committed May 3, 2024
1 parent bac0ea3 commit 78451c4
Show file tree
Hide file tree
Showing 56 changed files with 7,391 additions and 2,046 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

Version 9.0.0

- WL#16342, Update MySQL error codes mapping.

- WL#16353, Refresh the list of acceptable TLS ciphers.

- Fix for Bug#114687 (Bug#36529541), Tests fail after mysql_native_password has been made optional in server.
Expand Down
45 changes: 14 additions & 31 deletions src/build/java/documentation/ErrorMappingsDocGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

package documentation;

import java.util.HashMap;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.TreeMap;

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

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

// Integer errorNumber = null;

//
// First create a list of all 'known' error numbers that are mapped.
//
for (Integer errorNumber : MysqlErrorNumbers.mysqlToSql99State.keySet()) {
allErrorNumbers.put(errorNumber, errorNumber);
}

//
// Now create a list of the actual MySQL error numbers we know about
//
java.lang.reflect.Field[] possibleFields = MysqlErrorNumbers.class.getDeclaredFields();

for (int i = 0; i < possibleFields.length; i++) {
String fieldName = possibleFields[i].getName();

if (fieldName.startsWith("ER_")) {
mysqlErrorNumbersToNames.put(possibleFields[i].get(null), fieldName);
// Create a list of all MySQL error numbers.
Field[] allFields = MysqlErrorNumbers.class.getDeclaredFields();
for (Field f : allFields) {
if (f.getName().startsWith("ER_") || f.getName().startsWith("WARN_")) {
mysqlErrors.put((Integer) f.get(null), f.getName());
}
}

System.out.println("<ErrorMappings>");

for (Integer errorNumber : allErrorNumbers.keySet()) {
String sql92State = MysqlErrorNumbers.mysqlToSql99(errorNumber.intValue());

System.out.println(" <ErrorMapping mysqlErrorNumber=\"" + errorNumber + "\" mysqlErrorName=\"" + mysqlErrorNumbersToNames.get(errorNumber)
+ "\" legacySqlState=\"" + "" + "\" sql92SqlState=\"" + (sql92State == null ? "" : sql92State) + "\"/>");
// Generate documentation tags for each error mapping.
System.out.printf("<ErrorMappings>%n");
for (Integer error : mysqlErrors.keySet()) {
String sqlstate = MysqlErrorNumbers.mysqlToSqlstate(error);
System.out.printf(" <ErrorMapping mysqlErrorNumber=\"%d\" mysqlErrorName=\"%s\" legacySqlState=\"\" sql92SqlState=\"%s\"/>%n", error,
mysqlErrors.get(error), sqlstate);
}

System.out.println("</ErrorMappings>");
System.out.printf("</ErrorMappings>%n");
}

}
7,845 changes: 6,460 additions & 1,385 deletions src/main/core-api/java/com/mysql/cj/exceptions/MysqlErrorNumbers.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@ public class UnsupportedConnectionStringException extends CJException {

public UnsupportedConnectionStringException() {
super();
setSQLState(MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT);
setSQLState(MysqlErrorNumbers.SQLSTATE_CONNJ_ILLEGAL_ARGUMENT);
}

public UnsupportedConnectionStringException(String message) {
super(message);
setSQLState(MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT);
setSQLState(MysqlErrorNumbers.SQLSTATE_CONNJ_ILLEGAL_ARGUMENT);
}

public UnsupportedConnectionStringException(String message, Throwable cause) {
super(message, cause);
setSQLState(MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT);
setSQLState(MysqlErrorNumbers.SQLSTATE_CONNJ_ILLEGAL_ARGUMENT);
}

public UnsupportedConnectionStringException(Throwable cause) {
super(cause);
setSQLState(MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT);
setSQLState(MysqlErrorNumbers.SQLSTATE_CONNJ_ILLEGAL_ARGUMENT);
}

public UnsupportedConnectionStringException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
setSQLState(MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT);
setSQLState(MysqlErrorNumbers.SQLSTATE_CONNJ_ILLEGAL_ARGUMENT);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ public boolean clearBindValues() {
public void checkParameterSet(int columnIndex) {
if (!this.bindValues[columnIndex].isSet()) {
throw ExceptionFactory.createException(Messages.getString("PreparedStatement.40") + (columnIndex + 1),
MysqlErrorNumbers.SQL_STATE_WRONG_NO_OF_PARAMETERS, 0, true, null, this.session.getExceptionInterceptor());
MysqlErrorNumbers.SQLSTATE_DYNAMIC_SQL_ERROR_USING_CLAUSE_DOES_NOT_MATCH_DYNAMIC_PARAMETER_SPECIFICATIONS, 0, true, null,
this.session.getExceptionInterceptor());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/core-impl/java/com/mysql/cj/NativeSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ public void ping(boolean checkForClosedConnection, int timeoutMillis) {
invokeNormalCloseListeners();

throw ExceptionFactory.createException(Messages.getString("Connection.exceededConnectionLifetime"),
MysqlErrorNumbers.SQL_STATE_COMMUNICATION_LINK_FAILURE, 0, false, null, this.exceptionInterceptor);
MysqlErrorNumbers.SQLSTATE_MYSQL_COMMUNICATION_LINK_FAILURE, 0, false, null, this.exceptionInterceptor);
}
this.protocol.sendCommand(this.commandBuilder.buildComPing(null), false, timeoutMillis); // it isn't safe to use a shared packet here
} catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public NativePacketPayload prepareExecutePacket() {
if (firstFound && boundTimeToCheck != bindValues[i].getBoundBeforeExecutionNum()) {
throw ExceptionFactory.createException(
Messages.getString("ServerPreparedStatement.11") + Messages.getString("ServerPreparedStatement.12"),
MysqlErrorNumbers.SQL_STATE_DRIVER_NOT_CAPABLE, 0, true, null, this.session.getExceptionInterceptor());
MysqlErrorNumbers.SQLSTATE_CONNJ_DRIVER_NOT_CAPABLE, 0, true, null, this.session.getExceptionInterceptor());
}
firstFound = true;
boundTimeToCheck = bindValues[i].getBoundBeforeExecutionNum();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public void rejectProtocol(NativePacketPayload msg) {
errorBuf.append(serverErrorMessage);
errorBuf.append("\"");

String xOpen = MysqlErrorNumbers.mysqlToSqlState(errno);
String xOpen = MysqlErrorNumbers.mysqlToSqlstate(errno);

throw ExceptionFactory.createException(MysqlErrorNumbers.get(xOpen) + ", " + errorBuf.toString(), xOpen, errno, false, null, getExceptionInterceptor());
}
Expand Down Expand Up @@ -593,7 +593,7 @@ public final NativePacketPayload readMessage(NativePacketPayload reuse) {
throw ExceptionFactory.createCommunicationsException(this.propertySet, this.serverSession, getPacketSentTimeHolder(), getPacketReceivedTimeHolder(),
ioEx, getExceptionInterceptor());
} catch (OutOfMemoryError oom) {
throw ExceptionFactory.createException(oom.getMessage(), MysqlErrorNumbers.SQL_STATE_MEMORY_ALLOCATION_ERROR, 0, false, oom,
throw ExceptionFactory.createException(oom.getMessage(), MysqlErrorNumbers.SQLSTATE_CLI_SPECIFIC_CONDITION_MEMORY_ALLOCATION_ERROR, 0, false, oom,
this.exceptionInterceptor);
}
}
Expand All @@ -609,7 +609,7 @@ public final NativePacketPayload probeMessage(NativePacketPayload reuse) {
throw ExceptionFactory.createCommunicationsException(this.propertySet, this.serverSession, getPacketSentTimeHolder(), getPacketReceivedTimeHolder(),
ioEx, getExceptionInterceptor());
} catch (OutOfMemoryError oom) {
throw ExceptionFactory.createException(oom.getMessage(), MysqlErrorNumbers.SQL_STATE_MEMORY_ALLOCATION_ERROR, 0, false, oom,
throw ExceptionFactory.createException(oom.getMessage(), MysqlErrorNumbers.SQLSTATE_CLI_SPECIFIC_CONDITION_MEMORY_ALLOCATION_ERROR, 0, false, oom,
this.exceptionInterceptor);
}
}
Expand Down Expand Up @@ -805,13 +805,13 @@ public void checkErrorMessage(NativePacketPayload resultPacket) {
serverErrorMessage = serverErrorMessage.substring(6);

if (xOpen.equals("HY000")) {
xOpen = MysqlErrorNumbers.mysqlToSqlState(errno);
xOpen = MysqlErrorNumbers.mysqlToSqlstate(errno);
}
} else {
xOpen = MysqlErrorNumbers.mysqlToSqlState(errno);
xOpen = MysqlErrorNumbers.mysqlToSqlstate(errno);
}
} else {
xOpen = MysqlErrorNumbers.mysqlToSqlState(errno);
xOpen = MysqlErrorNumbers.mysqlToSqlstate(errno);
}

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

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

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

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

SQLWarning newWarning = new SQLWarning(message, MysqlErrorNumbers.mysqlToSqlState(code), code);
SQLWarning newWarning = new SQLWarning(message, MysqlErrorNumbers.mysqlToSqlstate(code), code);
if (currentWarning == null) {
currentWarning = newWarning;
} else {
Expand Down Expand Up @@ -2243,7 +2243,7 @@ public void initServerSession() {

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

blobSendChunkSize.setValue(allowedBlobSendChunkSize);
Expand Down
Loading

0 comments on commit 78451c4

Please sign in to comment.