Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
albogdano committed Dec 19, 2021
1 parent 475763b commit e6fabce
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/java/com/erudika/para/persistence/SqlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public final class SqlUtils {
private static boolean usePGSqlSyntax = false;
private static boolean useOrSqlSyntax = false;
private static boolean useLiSqlSyntax = false;
private static String sqlUrl;

private SqlUtils() { }

Expand All @@ -73,7 +74,7 @@ static Connection getConnection() throws SQLException {
return hikariDataSource.getConnection();
}

String sqlUrl = Config.getConfigParam("sql.url", null);
sqlUrl = Config.getConfigParam("sql.url", null);
String sqlDriver = Config.getConfigParam("sql.driver", null);
String sqlUser = Config.getConfigParam("sql.user", "user");
String sqlPassword = Config.getConfigParam("sql.password", "secret");
Expand Down Expand Up @@ -473,8 +474,8 @@ protected static <P extends ParaObject> List<P> readPage(String appid, Pager pag
int start = pager.getPage() <= 1 ? 0 : (int) (pager.getPage() - 1) * pager.getLimit();
String tableName = getTableNameForAppid(appid);
try (PreparedStatement p = getReadPagePreparedStatement(connection, tableName)) {
p.setInt(useOrSqlSyntax ? 2 : 1, pager.getLimit());
p.setInt(useOrSqlSyntax ? 1 : 2, start);
p.setInt(useOrSqlSyntax || sqlUrl.endsWith(";MODE=Oracle") ? 2 : 1, pager.getLimit());
p.setInt(useOrSqlSyntax || sqlUrl.endsWith(";MODE=Oracle") ? 1 : 2, start);
try (ResultSet res = p.executeQuery()) {
int i = 0;
while (res.next()) {
Expand Down Expand Up @@ -552,11 +553,11 @@ private static PreparedStatement getUpsertRowPreparedStatement(Connection conn,

private static PreparedStatement getReadPagePreparedStatement(Connection conn, String tableName) throws SQLException {
PreparedStatement ps;
if (useMSSqlSyntax) {
if (useMSSqlSyntax || sqlUrl.endsWith(";MODE=MSSQLServer")) {
ps = conn.prepareStatement(Utils.formatMessage("SELECT TOP (?) * FROM (SELECT {0},{1},ROW_NUMBER() OVER "
+ "(ORDER BY ID ASC) AS RN FROM {2}) AS X WHERE RN > ?",
JSON_FIELD_NAME, JSON_UPDATES_FIELD_NAME, tableName));
} else if (useOrSqlSyntax) {
} else if (useOrSqlSyntax || sqlUrl.endsWith(";MODE=Oracle")) {
ps = conn.prepareStatement(Utils.formatMessage("SELECT {0},{1} FROM {2} OFFSET ? ROWS FETCH NEXT ? ROWS ONLY",
JSON_FIELD_NAME, JSON_UPDATES_FIELD_NAME, tableName));
} else {
Expand Down

0 comments on commit e6fabce

Please sign in to comment.