Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FMWK-560 Make upper boundary inclusive in the BETWEEN operator #72

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
Loading