Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make result set getColumn by name case insensitive. Add test for same. #43

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/org/duckdb/DuckDBResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public int findColumn(String columnLabel) throws SQLException {
throw new SQLException("ResultSet was closed");
}
for (int col_idx = 0; col_idx < meta.column_count; col_idx++) {
if (meta.column_names[col_idx].contentEquals(columnLabel)) {
if (meta.column_names[col_idx].equalsIgnoreCase(columnLabel)) {
return col_idx + 1;
}
}
Expand Down
39 changes: 39 additions & 0 deletions src/test/java/org/duckdb/TestDuckDBJDBC.java
Original file line number Diff line number Diff line change
Expand Up @@ -4374,6 +4374,45 @@ public static void test_get_bytes() throws Exception {

}

public static void test_case_insensitivity() throws Exception {
try(Connection connection = DriverManager.getConnection("jdbc:duckdb:")) {
try(Statement s = connection.createStatement()) {
s.execute("CREATE TABLE someTable (lowercase INT, mixedCASE INT, UPPERCASE INT)");
s.execute("INSERT INTO someTable VALUES (0, 1, 2)");
}

String [] tableNameVariations = new String [] { "sometable", "someTable", "SOMETABLE"};
String [][] columnNameVariations = new String[][]{
{"lowercase", "mixedcase", "uppercase"},
{"lowerCASE", "mixedCASE", "upperCASE"},
{"LOWERCASE", "MIXEDCASE", "UPPERCASE"}};

int totalTestsRun = 0;

// Test every combination of upper, lower and mixedcase column and table names.
for(String tableName : tableNameVariations) {
for(int columnVariation = 0; columnVariation < columnNameVariations.length; columnVariation++) {
try (Statement s = connection.createStatement()) {
String query = String.format("SELECT %s, %s, %s from %s;", columnNameVariations[0][0],
columnNameVariations[0][1], columnNameVariations[0][2], tableName);

ResultSet resultSet = s.executeQuery(query);
assertTrue(resultSet.next());
for(int i = 0; i < columnNameVariations[0].length; i++) {
assertEquals(resultSet.getInt(columnNameVariations[columnVariation][i]), i,
"Query " + query + " did not get correct result back for column number " + i);
totalTestsRun++;
}
}
}
}

assertEquals(totalTestsRun,
tableNameVariations.length * columnNameVariations.length * columnNameVariations[0].length,
"Number of test cases actually run did not match number expected to be run.");
}
}

public static void test_fractional_time() throws Exception {
try (Connection conn = DriverManager.getConnection(JDBC_URL);
PreparedStatement stmt = conn.prepareStatement("SELECT '01:02:03.123'::TIME");
Expand Down
Loading