Skip to content

Commit

Permalink
Fixed bug when using null
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinAlpert committed Oct 27, 2018
1 parent a365120 commit 1152655
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ You can include the Maven dependency:
<dependency>
<groupId>com.github.collinalpert</groupId>
<artifactId>lambda2sql</artifactId>
<version>1.8.2</version>
<version>1.8.3</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.collinalpert</groupId>
<artifactId>lambda2sql</artifactId>
<version>1.8.2</version>
<version>1.8.3</version>
<packaging>jar</packaging>

<name>lambda2sql</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,7 @@ public StringBuilder visit(BinaryExpression e) {
if (quote) sb.append('(');

e.getFirst().accept(this);
sb.append(' ');
if (!arguments.isEmpty() && arguments.top().get(0).getValue() == null) {
sb.append("IS");
} else {
sb.append(toSqlOp(e.getExpressionType()));
}
sb.append(' ');
sb.append(' ').append(toSqlOp(e.getExpressionType())).append(' ');
e.getSecond().accept(this);

if (quote) sb.append(')');
Expand All @@ -90,7 +84,9 @@ public StringBuilder visit(BinaryExpression e) {
@Override
public StringBuilder visit(ConstantExpression e) {
if (e.getValue() == null) {
return sb.append("NULL");
sb.deleteCharAt(sb.length() - 1);
sb.delete(sb.lastIndexOf(" "), sb.length());
return sb.append(" IS NULL");
}
if (e.getValue() instanceof String) {
return sb.append("'").append(e.getValue().toString()).append("'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,13 @@ void testNestedProperties() {
@Test
void testNull() {
String isNull = null;
Integer i = null;
SqlPredicate<IPerson> p = person -> person.getName() == isNull;
SqlPredicate<IPerson> p2 = person -> person.getName() == null;
SqlPredicate<IPerson> p3 = person -> person.getAge() >= i;
assertPredicateEqual("person.name IS NULL", p);
assertPredicateEqual("person.name IS NULL", p2);
assertPredicateEqual("person.age IS NULL", p3);
}

private void assertPredicateEqual(String expectedSql, SqlPredicate<IPerson> p) {
Expand Down

0 comments on commit 1152655

Please sign in to comment.