[#2729] Emulate IS DISTINCT FROM through IS / IS NOT in SQLite
This commit is contained in:
parent
4c5777e79f
commit
d1c0d45f66
@ -864,6 +864,12 @@ public interface Field<T> extends GroupField {
|
||||
* Create a condition to check if this field is <code>DISTINCT</code> from
|
||||
* another value.
|
||||
* <p>
|
||||
* In {@link SQLDialect#MYSQL} and {@link SQLDialect#MARIADB}, this can be
|
||||
* emulated through <code><pre>not([this] <=> [value])</pre></code>
|
||||
* <p>
|
||||
* In {@link SQLDialect#SQLITE}, this can be emulated through
|
||||
* <code><pre>[this] IS NOT [value]</pre></code>
|
||||
* <p>
|
||||
* If this is not supported by the underlying database, jOOQ will render
|
||||
* this instead: <code><pre>
|
||||
* CASE WHEN [this] IS NULL AND [value] IS NULL THEN FALSE
|
||||
@ -886,6 +892,12 @@ public interface Field<T> extends GroupField {
|
||||
* Create a condition to check if this field is <code>DISTINCT</code> from
|
||||
* another field.
|
||||
* <p>
|
||||
* In {@link SQLDialect#MYSQL} and {@link SQLDialect#MARIADB}, this can be
|
||||
* emulated through <code><pre>not([this] <=> [value])</pre></code>
|
||||
* <p>
|
||||
* In {@link SQLDialect#SQLITE}, this can be emulated through
|
||||
* <code><pre>[this] IS NOT [value]</pre></code>
|
||||
* <p>
|
||||
* If this is not supported by the underlying database, jOOQ will render
|
||||
* this instead: <code><pre>
|
||||
* CASE WHEN [this] IS NULL AND [field] IS NULL THEN FALSE
|
||||
@ -908,6 +920,12 @@ public interface Field<T> extends GroupField {
|
||||
* Create a condition to check if this field is <code>NOT DISTINCT</code>
|
||||
* from another value.
|
||||
* <p>
|
||||
* In {@link SQLDialect#MYSQL} and {@link SQLDialect#MARIADB}, this can be
|
||||
* emulated through <code><pre>[this] <=> [value]</pre></code>
|
||||
* <p>
|
||||
* In {@link SQLDialect#SQLITE}, this can be emulated through
|
||||
* <code><pre>[this] IS [value]</pre></code>
|
||||
* <p>
|
||||
* If this is not supported by the underlying database, jOOQ will render
|
||||
* this instead: <code><pre>
|
||||
* CASE WHEN [this] IS NULL AND [value] IS NULL THEN TRUE
|
||||
@ -930,6 +948,12 @@ public interface Field<T> extends GroupField {
|
||||
* Create a condition to check if this field is <code>NOT DISTINCT</code>
|
||||
* from another field.
|
||||
* <p>
|
||||
* In {@link SQLDialect#MYSQL} and {@link SQLDialect#MARIADB}, this can be
|
||||
* emulated through <code><pre>[this] <=> [value]</pre></code>
|
||||
* <p>
|
||||
* In {@link SQLDialect#SQLITE}, this can be emulated through
|
||||
* <code><pre>[this] IS [value]</pre></code>
|
||||
* <p>
|
||||
* If this is not supported by the underlying database, jOOQ will render
|
||||
* this instead: <code><pre>
|
||||
* CASE WHEN [this] IS NULL AND [field] IS NULL THEN TRUE
|
||||
|
||||
@ -77,6 +77,7 @@ class IsDistinctFrom<T> extends AbstractCondition {
|
||||
private final Comparator comparator;
|
||||
|
||||
private transient QueryPartInternal mySQLCondition;
|
||||
private transient QueryPartInternal sqliteCondition;
|
||||
private transient QueryPartInternal compareCondition;
|
||||
private transient QueryPartInternal caseExpression;
|
||||
|
||||
@ -108,8 +109,8 @@ class IsDistinctFrom<T> extends AbstractCondition {
|
||||
*/
|
||||
private final QueryPartInternal delegate(Configuration configuration) {
|
||||
|
||||
// These dialects need to simulate the IS DISTINCT FROM operator
|
||||
if (asList(ASE, CUBRID, DB2, DERBY, INGRES, ORACLE, SQLSERVER, SQLITE, SYBASE).contains(configuration.dialect().family())) {
|
||||
// These dialects need to simulate the IS DISTINCT FROM predicate
|
||||
if (asList(ASE, CUBRID, DB2, DERBY, INGRES, ORACLE, SQLSERVER, SYBASE).contains(configuration.dialect().family())) {
|
||||
if (caseExpression == null) {
|
||||
if (comparator == Comparator.IS_DISTINCT_FROM) {
|
||||
caseExpression = (QueryPartInternal) decode()
|
||||
@ -138,7 +139,7 @@ class IsDistinctFrom<T> extends AbstractCondition {
|
||||
else if (asList(MARIADB, MYSQL).contains(configuration.dialect())) {
|
||||
if (mySQLCondition == null) {
|
||||
if (comparator == Comparator.IS_DISTINCT_FROM) {
|
||||
mySQLCondition = (QueryPartInternal) condition("not({0} <=> {1})", lhs, rhs);
|
||||
mySQLCondition = (QueryPartInternal) condition("{not}({0} <=> {1})", lhs, rhs);
|
||||
}
|
||||
else {
|
||||
mySQLCondition = (QueryPartInternal) condition("{0} <=> {1}", lhs, rhs);
|
||||
@ -148,7 +149,21 @@ class IsDistinctFrom<T> extends AbstractCondition {
|
||||
return mySQLCondition;
|
||||
}
|
||||
|
||||
// These dialects natively support the IS DISTINCT FROM operator:
|
||||
// SQLite knows the IS / IS NOT predicate
|
||||
else if (SQLITE == configuration.dialect()) {
|
||||
if (sqliteCondition == null) {
|
||||
if (comparator == Comparator.IS_DISTINCT_FROM) {
|
||||
sqliteCondition = (QueryPartInternal) condition("{0} {is not} {1}", lhs, rhs);
|
||||
}
|
||||
else {
|
||||
sqliteCondition = (QueryPartInternal) condition("{0} {is} {1}", lhs, rhs);
|
||||
}
|
||||
}
|
||||
|
||||
return sqliteCondition;
|
||||
}
|
||||
|
||||
// These dialects natively support the IS DISTINCT FROM predicate:
|
||||
// H2, Postgres
|
||||
else {
|
||||
if (compareCondition == null) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user