Skip to content

Commit

Permalink
fix keyword-like columns in db must be quoted for new versions of liq…
Browse files Browse the repository at this point in the history
…uibase and h2
  • Loading branch information
max402 committed Sep 19, 2023
1 parent 50c159a commit 633ec76
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.testing.compile.Compilation;
import com.google.testing.compile.JavaFileObjects;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
Expand Down
6 changes: 0 additions & 6 deletions datasafe-storage/datasafe-storage-impl-db/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- test -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ public class DatabaseStorageService implements StorageService {
@Override
public boolean objectExists(AbsoluteLocation location) {
ParsedLocation parsed = new ParsedLocation(location, allowedTables);
String sql = "SELECT COUNT(*) FROM " + parsed.getTableName() + " WHERE `key` = ?";
String sql = "SELECT COUNT(*) FROM " + parsed.getTableName() + " WHERE \"key\" = ?";
return 0 != conn.jdbcTemplate(location).queryForObject(sql, Integer.class, parsed.getPathWithUser());
}

@SneakyThrows
@Override
public Stream<AbsoluteLocation<ResolvedResource>> list(AbsoluteLocation location) {
ParsedLocation parsed = new ParsedLocation(location, allowedTables);
String sql = "SELECT `key`,`last_modified` FROM " + parsed.getTableName() + " WHERE `key` LIKE '"
String sql = "SELECT \"key\",`last_modified` FROM " + parsed.getTableName() + " WHERE \"key\" LIKE '"
+ parsed.getPathWithUser() + "%'";

List<Map<String, Object>> keys = conn.jdbcTemplate(location).queryForList(sql);
Expand All @@ -80,7 +80,7 @@ public Stream<AbsoluteLocation<ResolvedResource>> list(AbsoluteLocation location
@Override
public InputStream read(AbsoluteLocation location) {
ParsedLocation parsed = new ParsedLocation(location, allowedTables);
final String sql = "SELECT value FROM " + parsed.getTableName() + " WHERE `key` = ?";
final String sql = "SELECT \"value\" FROM " + parsed.getTableName() + " WHERE \"key\" = ?";
RowMapper<InputStream> rowMapper = (rs, i) -> rs.getClob("value").getAsciiStream();
List<InputStream> values = conn.jdbcTemplate(location).query(
sql,
Expand All @@ -98,7 +98,7 @@ public InputStream read(AbsoluteLocation location) {
@Override
public void remove(AbsoluteLocation location) {
ParsedLocation parsed = new ParsedLocation(location, allowedTables);
String sql = "DELETE FROM " + parsed.getTableName() + " WHERE `key` = ?";
String sql = "DELETE FROM " + parsed.getTableName() + " WHERE \"key\" = ?";
conn.jdbcTemplate(location).update(sql, parsed.getPathWithUser());
}

Expand Down Expand Up @@ -138,7 +138,7 @@ private static final class PutBlobOnClose extends ByteArrayOutputStream {

@Override
public void close() throws IOException {
String sql = "INSERT INTO " + tableName + " (`key`, `value`) VALUES(?, ?)";
String sql = "INSERT INTO " + tableName + " (\"key\", \"value\") VALUES(?, ?)";
KeyHolder holder = new GeneratedKeyHolder();
jdbcTemplate.update(writeData(sql), holder);
super.close();
Expand Down

0 comments on commit 633ec76

Please sign in to comment.