Skip to content

Commit 9d146e8

Browse files
committed
Implemented #35 (render empty IN as 1=2)
1 parent 1b1a25c commit 9d146e8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/main/java/org/javawebstack/orm/query/QueryGroup.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.javawebstack.orm.Model;
44
import org.javawebstack.orm.Repo;
55

6+
import java.lang.reflect.Array;
67
import java.util.ArrayList;
78
import java.util.Arrays;
89
import java.util.List;
@@ -64,6 +65,11 @@ public QueryGroup<T> where(Object left, String condition, Object right) {
6465
return whereNull(left);
6566
if(condition.equalsIgnoreCase("!=") && right == null)
6667
return whereNotNull(left);
68+
if((condition.equalsIgnoreCase("IN") || condition.equalsIgnoreCase("NOT IN")) && (right == null || Array.getLength(right) == 0)) {
69+
left = 1;
70+
condition = "=";
71+
right = 2;
72+
}
6773
if (queryElements.size() > 0)
6874
queryElements.add(QueryConjunction.AND);
6975
queryElements.add(new QueryCondition(left instanceof String ? new QueryColumn((String) left) : left, condition, right));
@@ -109,6 +115,11 @@ public QueryGroup<T> orWhere(Object left, String condition, Object right) {
109115
return orIsNull(left);
110116
if(condition.equalsIgnoreCase("!=") && right == null)
111117
return orNotNull(left);
118+
if((condition.equalsIgnoreCase("IN") || condition.equalsIgnoreCase("NOT IN")) && (right == null || Array.getLength(right) == 0)) {
119+
left = 1;
120+
condition = "=";
121+
right = 2;
122+
}
112123
if (queryElements.size() > 0)
113124
queryElements.add(QueryConjunction.OR);
114125
queryElements.add(new QueryCondition(left instanceof String ? new QueryColumn((String) left) : left, condition, right));

0 commit comments

Comments
 (0)