Skip to content

Commit

Permalink
FMWK-560 Make upper boundary inclusive in the BETWEEN operator
Browse files Browse the repository at this point in the history
  • Loading branch information
reugn committed Sep 19, 2024
1 parent c447e03 commit 2fcd704
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ public QueryPredicateRange(

@Override
public Exp toFilterExpression(boolean withPrimaryKey) {
// ANSI SQL defines the BETWEEN operator to be inclusive,
// so both boundary values are included in the range.
return Exp.and(
Exp.ge(buildLeftExp(), getValueExp(lowValue)),
Exp.lt(buildLeftExp(), getValueExp(highValue))
Exp.le(buildLeftExp(), getValueExp(highValue))
);
}

Expand Down
19 changes: 18 additions & 1 deletion src/test/java/com/aerospike/jdbc/SimpleQueriesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public void testSelectInQuery() throws SQLException {
}

@Test
public void testSelectBetweenQuery() throws SQLException {
public void testSelectLowerBoundaryBetweenQuery() throws SQLException {
Statement statement = null;
ResultSet resultSet = null;
String query = format("SELECT * FROM %s WHERE int2 BETWEEN 1 AND 3", TABLE_NAME);
Expand All @@ -319,4 +319,21 @@ public void testSelectBetweenQuery() throws SQLException {
closeQuietly(resultSet);
}
}

@Test
public void testSelectUpperBoundaryBetweenQuery() throws SQLException {
Statement statement = null;
ResultSet resultSet = null;
String query = format("SELECT * FROM %s WHERE int2 BETWEEN 0 AND 1", TABLE_NAME);
try {
statement = connection.createStatement();
resultSet = statement.executeQuery(query);
assertTrue(resultSet.next());

testRecord.assertResultSet(resultSet);
} finally {
closeQuietly(statement);
closeQuietly(resultSet);
}
}
}

0 comments on commit 2fcd704

Please sign in to comment.