diff --git a/src/main/java/org/mariadb/jdbc/internal/com/read/dao/ColumnLabelIndexer.java b/src/main/java/org/mariadb/jdbc/internal/com/read/dao/ColumnLabelIndexer.java index f284a7007..eb4284f3d 100644 --- a/src/main/java/org/mariadb/jdbc/internal/com/read/dao/ColumnLabelIndexer.java +++ b/src/main/java/org/mariadb/jdbc/internal/com/read/dao/ColumnLabelIndexer.java @@ -131,7 +131,15 @@ public int getIndex(String name) throws SQLException { res = originalMap.get(lowerName); if (res == null) { - throw ExceptionFactory.INSTANCE.create("No such column: " + name, "42S22", 1054); + Map possible = new HashMap<>(); + possible.putAll(aliasMap); + possible.putAll(originalMap); + throw ExceptionFactory.INSTANCE.create( + String.format( + "No such column: '%s'. '%s' must be in %s", + name, lowerName, possible.keySet().toString()), + "42S22", + 1054); } return res; } diff --git a/src/test/java/org/mariadb/jdbc/ConnectionTest.java b/src/test/java/org/mariadb/jdbc/ConnectionTest.java index 69397f61a..c2b1a5fb6 100644 --- a/src/test/java/org/mariadb/jdbc/ConnectionTest.java +++ b/src/test/java/org/mariadb/jdbc/ConnectionTest.java @@ -1007,22 +1007,24 @@ public void readOnly() throws SQLException { stmt.execute("DROP TABLE testReadOnly"); } - @Test public void connectionAttributes() throws SQLException { - try (MariaDbConnection conn = (MariaDbConnection) setConnection("&connectionAttributes=test:test1")) { + try (MariaDbConnection conn = + (MariaDbConnection) setConnection("&connectionAttributes=test:test1")) { Statement stmt = conn.createStatement(); ResultSet rs1 = stmt.executeQuery("SELECT @@performance_schema"); rs1.next(); if ("1".equals(rs1.getString(1))) { - ResultSet rs = stmt.executeQuery("SELECT * from performance_schema.session_connect_attrs where processlist_id=" - + conn.getServerThreadId() + " AND ATTR_NAME='test'"); + ResultSet rs = + stmt.executeQuery( + "SELECT * from performance_schema.session_connect_attrs where processlist_id=" + + conn.getServerThreadId() + + " AND ATTR_NAME='test'"); while (rs.next()) { assertEquals("test1", rs.getString("ATTR_VALUE")); } } - }; + } } - } diff --git a/src/test/java/org/mariadb/jdbc/ResultSetTest.java b/src/test/java/org/mariadb/jdbc/ResultSetTest.java index 05c63358f..820c53e7e 100644 --- a/src/test/java/org/mariadb/jdbc/ResultSetTest.java +++ b/src/test/java/org/mariadb/jdbc/ResultSetTest.java @@ -1196,19 +1196,31 @@ public void checkInvisibleMetaData() throws SQLException { @Test public void columnNamesMappingError() throws SQLException { - createTable("columnNamesMappingError", "xx tinyint(1)"); + createTable( + "columnNamesMappingError", "xX INT NOT NULL AUTO_INCREMENT, " + " PRIMARY KEY(xX)"); + Statement stmt = sharedConnection.createStatement(); stmt.executeUpdate("INSERT INTO columnNamesMappingError VALUES (4)"); - ResultSet rs = stmt.executeQuery("SELECT * FROM columnNamesMappingError"); - assertTrue(rs.next()); - assertEquals(4, rs.getInt("xx")); - try { - rs.getInt("wrong_column_name"); - fail("must have fail, column 'wrong_column_name' does not exists"); - } catch (SQLException e) { - assertEquals("42S22", e.getSQLState()); - assertEquals(1054, e.getErrorCode()); - assertEquals("No such column: wrong_column_name", e.getMessage()); + try (PreparedStatement preparedStatement = + sharedConnection.prepareStatement( + "SELECT * FROM " + "columnNamesMappingError", + ResultSet.TYPE_FORWARD_ONLY, + ResultSet.CONCUR_UPDATABLE)) { + ResultSet rs = preparedStatement.executeQuery(); + assertTrue(rs.next()); + assertEquals(4, rs.getInt("xx")); + try { + rs.getInt("wrong_column_name"); + fail("must have fail, column 'wrong_column_name' does not exists"); + } catch (SQLException e) { + assertEquals("42S22", e.getSQLState()); + assertEquals(1054, e.getErrorCode()); + assertTrue( + e.getMessage() + .contains( + "No such column: 'wrong_column_name'. 'wrong_column_name' must be in " + + "[xx, columnnamesmappingerror.xx]")); + } } }