Skip to content

Commit

Permalink
[misc] error improvement on wrong label
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Jul 22, 2020
1 parent d792793 commit 426d829
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Integer> 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;
}
Expand Down
14 changes: 8 additions & 6 deletions src/test/java/org/mariadb/jdbc/ConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
};
}
}

}
34 changes: 23 additions & 11 deletions src/test/java/org/mariadb/jdbc/ResultSetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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]"));
}
}
}

Expand Down

0 comments on commit 426d829

Please sign in to comment.