Skip to content

Commit

Permalink
0003868: quote table names used in SQLITE3 pragma statements
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredfrees committed May 22, 2019
1 parent 77efc59 commit 6f96748
Showing 1 changed file with 8 additions and 3 deletions.
Expand Up @@ -98,10 +98,15 @@ public Table readTable(String catalog, String schema, String tableName, String s
throw new NotImplementedException();
}

private String quote(String name) {
String quote = platform.getDatabaseInfo().getDelimiterToken();
return quote + name + quote;
}

public Table readTable(String catalog, String schema, String tableName) {
Table table = null;

List<Column> columns = platform.getSqlTemplate().query("pragma table_info(" + tableName + ")", COLUMN_MAPPER);
List<Column> columns = platform.getSqlTemplate().query("pragma table_info(" + quote(tableName) + ")", COLUMN_MAPPER);

checkForAutoIncrementColumn(columns, tableName);

Expand All @@ -111,7 +116,7 @@ public Table readTable(String catalog, String schema, String tableName) {
table.addColumn(column);
}

List<IIndex> indexes = platform.getSqlTemplate().query("pragma index_list(" + tableName + ")", INDEX_MAPPER);
List<IIndex> indexes = platform.getSqlTemplate().query("pragma index_list(" + quote(tableName) + ")", INDEX_MAPPER);
for (IIndex index : indexes) {

List<IndexColumn> indexColumns = platform.getSqlTemplate().query("pragma index_info(" + index.getName() + ")",
Expand All @@ -135,7 +140,7 @@ public Table readTable(String catalog, String schema, String tableName) {
}

Map<Integer, ForeignKey> keys = new HashMap<Integer, ForeignKey>();
List<Row> rows = platform.getSqlTemplate().query("pragma foreign_key_list(" + tableName + ")", new RowMapper());
List<Row> rows = platform.getSqlTemplate().query("pragma foreign_key_list(" + quote(tableName) + ")", new RowMapper());
for (Row row : rows) {
Integer id = row.getInt("id");
ForeignKey fk = keys.get(id);
Expand Down

0 comments on commit 6f96748

Please sign in to comment.