Skip to content

Commit 33eaa19

Browse files
dxbjavidgotson
authored andcommitted
fix(jdbc): escape table type values in getTables metadata query
1 parent a5149f8 commit 33eaa19

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/main/java/org/sqlite/jdbc3/JDBC3DatabaseMetaData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,7 @@ public synchronized ResultSet getTables(
17401740
sql.append(" AND TABLE_TYPE IN (");
17411741
sql.append(
17421742
Arrays.stream(types)
1743-
.map((t) -> "'" + t.toUpperCase() + "'")
1743+
.map((t) -> "'" + escape(t.toUpperCase()) + "'")
17441744
.collect(Collectors.joining(",")));
17451745
sql.append(")");
17461746
}

src/test/java/org/sqlite/DBMetaDataTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,15 @@ public void getColumns() throws SQLException {
477477
assertThat(rs.getString("COLUMN_NAME")).isEqualTo("sql");
478478
}
479479

480+
@Test
481+
public void getTablesTypeWithQuote() throws SQLException {
482+
// a type containing a single quote must be treated as a literal, not break out of the
483+
// TABLE_TYPE IN (...) list; 'X' matches nothing so the result must be empty
484+
try (ResultSet rs = meta.getTables(null, null, null, new String[] {"X') OR ('1'='1"})) {
485+
assertThat(rs.next()).isFalse();
486+
}
487+
}
488+
480489
@Test
481490
public void getColumnsTableNameWithQuote() throws SQLException {
482491
stat.executeUpdate("create table \"o'brien\" (id integer, name text)");

0 commit comments

Comments
 (0)