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

support NULL in query #227

Closed
wants to merge 1 commit into from
Closed
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
22 changes: 21 additions & 1 deletion library/src/com/orm/query/Condition.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ enum Check {
LESSER_THAN(" < "),
NOT_EQUALS (" != "),
LIKE(" LIKE "),
NOT_LIKE(" NOT LIKE ");
NOT_LIKE(" NOT LIKE "),
IS_NULL(" IS NULL "),
IS_NOT_NULL(" IS NOT NULL ");

private String symbol;

Expand Down Expand Up @@ -40,6 +42,9 @@ public static Condition prop(String property) {
}

public Condition eq(Object value) {
if (value == null) {
return isNull();
}
this.value = value;
check = Check.EQUALS;
return this;
Expand All @@ -58,6 +63,9 @@ public Condition notLike(Object value) {
}

public Condition notEq(Object value) {
if (value == null) {
return isNotNull();
}
this.value = value;
check = Check.NOT_EQUALS;
return this;
Expand All @@ -75,6 +83,18 @@ public Condition lt(Object value) {
return this;
}

public Condition isNull() {
this.value = null;
check = Check.IS_NULL;
return this;
}

public Condition isNotNull() {
this.value = null;
check = Check.IS_NOT_NULL;
return this;
}

public String getProperty() {
return property;
}
Expand Down
6 changes: 5 additions & 1 deletion library/src/com/orm/query/Select.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ private void mergeConditions(Condition[] conditions, Condition.Type type) {
.append("'")
.append(condition.getValue().toString())
.append("'");

} else if (Condition.Check.IS_NULL.equals(condition.getCheck()) ||
Condition.Check.IS_NOT_NULL.equals(condition.getCheck())) {
toAppend
.append(condition.getProperty())
.append(condition.getCheckSymbol());
} else {
toAppend
.append(condition.getProperty())
Expand Down