Skip to content

Commit 426d829

Browse files
committed
[misc] error improvement on wrong label
1 parent d792793 commit 426d829

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed

src/main/java/org/mariadb/jdbc/internal/com/read/dao/ColumnLabelIndexer.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,15 @@ public int getIndex(String name) throws SQLException {
131131
res = originalMap.get(lowerName);
132132

133133
if (res == null) {
134-
throw ExceptionFactory.INSTANCE.create("No such column: " + name, "42S22", 1054);
134+
Map<String, Integer> possible = new HashMap<>();
135+
possible.putAll(aliasMap);
136+
possible.putAll(originalMap);
137+
throw ExceptionFactory.INSTANCE.create(
138+
String.format(
139+
"No such column: '%s'. '%s' must be in %s",
140+
name, lowerName, possible.keySet().toString()),
141+
"42S22",
142+
1054);
135143
}
136144
return res;
137145
}

src/test/java/org/mariadb/jdbc/ConnectionTest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,22 +1007,24 @@ public void readOnly() throws SQLException {
10071007
stmt.execute("DROP TABLE testReadOnly");
10081008
}
10091009

1010-
10111010
@Test
10121011
public void connectionAttributes() throws SQLException {
10131012

1014-
try (MariaDbConnection conn = (MariaDbConnection) setConnection("&connectionAttributes=test:test1")) {
1013+
try (MariaDbConnection conn =
1014+
(MariaDbConnection) setConnection("&connectionAttributes=test:test1")) {
10151015
Statement stmt = conn.createStatement();
10161016
ResultSet rs1 = stmt.executeQuery("SELECT @@performance_schema");
10171017
rs1.next();
10181018
if ("1".equals(rs1.getString(1))) {
1019-
ResultSet rs = stmt.executeQuery("SELECT * from performance_schema.session_connect_attrs where processlist_id="
1020-
+ conn.getServerThreadId() + " AND ATTR_NAME='test'");
1019+
ResultSet rs =
1020+
stmt.executeQuery(
1021+
"SELECT * from performance_schema.session_connect_attrs where processlist_id="
1022+
+ conn.getServerThreadId()
1023+
+ " AND ATTR_NAME='test'");
10211024
while (rs.next()) {
10221025
assertEquals("test1", rs.getString("ATTR_VALUE"));
10231026
}
10241027
}
1025-
};
1028+
}
10261029
}
1027-
10281030
}

src/test/java/org/mariadb/jdbc/ResultSetTest.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,19 +1196,31 @@ public void checkInvisibleMetaData() throws SQLException {
11961196

11971197
@Test
11981198
public void columnNamesMappingError() throws SQLException {
1199-
createTable("columnNamesMappingError", "xx tinyint(1)");
1199+
createTable(
1200+
"columnNamesMappingError", "xX INT NOT NULL AUTO_INCREMENT, " + " PRIMARY KEY(xX)");
1201+
12001202
Statement stmt = sharedConnection.createStatement();
12011203
stmt.executeUpdate("INSERT INTO columnNamesMappingError VALUES (4)");
1202-
ResultSet rs = stmt.executeQuery("SELECT * FROM columnNamesMappingError");
1203-
assertTrue(rs.next());
1204-
assertEquals(4, rs.getInt("xx"));
1205-
try {
1206-
rs.getInt("wrong_column_name");
1207-
fail("must have fail, column 'wrong_column_name' does not exists");
1208-
} catch (SQLException e) {
1209-
assertEquals("42S22", e.getSQLState());
1210-
assertEquals(1054, e.getErrorCode());
1211-
assertEquals("No such column: wrong_column_name", e.getMessage());
1204+
try (PreparedStatement preparedStatement =
1205+
sharedConnection.prepareStatement(
1206+
"SELECT * FROM " + "columnNamesMappingError",
1207+
ResultSet.TYPE_FORWARD_ONLY,
1208+
ResultSet.CONCUR_UPDATABLE)) {
1209+
ResultSet rs = preparedStatement.executeQuery();
1210+
assertTrue(rs.next());
1211+
assertEquals(4, rs.getInt("xx"));
1212+
try {
1213+
rs.getInt("wrong_column_name");
1214+
fail("must have fail, column 'wrong_column_name' does not exists");
1215+
} catch (SQLException e) {
1216+
assertEquals("42S22", e.getSQLState());
1217+
assertEquals(1054, e.getErrorCode());
1218+
assertTrue(
1219+
e.getMessage()
1220+
.contains(
1221+
"No such column: 'wrong_column_name'. 'wrong_column_name' must be in "
1222+
+ "[xx, columnnamesmappingerror.xx]"));
1223+
}
12121224
}
12131225
}
12141226

0 commit comments

Comments
 (0)