SQLite

Check-in [5c6146b5]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Handle expressions like "expr IS TRUE COLLATE xyz" in the same way as "expr IS TRUE". Fix for [4d01eda8115b10d1].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 5c6146b56a75a94f4baa10e95407c54dd0b9314a57a8702a4b96b15c4d7ac48c
User & Date: dan 2019-06-12 13:49:32
References
2019-06-12
13:50 Closed ticket [4d01eda8]: IS TRUE operator malfunctions with COLLATE and REAL value plus 6 other changes (artifact: 75b45c09 user: dan)
Context
2019-06-12
20:51
As a special case, casting '-0.0' into numeric should yield 0. Fix for ticket [674385aeba91c774]. (check-in: 491f0f9b user: drh tags: trunk)
20:11
Enhancements to the printf() logic in order to render a negative zero with a minus sign. (Leaf check-in: 6ba4be66 user: drh tags: negative-zero)
13:49
Handle expressions like "expr IS TRUE COLLATE xyz" in the same way as "expr IS TRUE". Fix for [4d01eda8115b10d1]. (check-in: 5c6146b5 user: dan tags: trunk)
2019-06-11
21:02
The affinity of the unlikely() function and its cousins should be "none". Ticket [0c620df60bffd9ef] (check-in: 614ecb0a user: drh tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/expr.c.

1809
1810
1811
1812
1813
1814
1815

1816
1817
1818
1819
1820
1821
1822
}

/*
** The argument must be a TK_TRUEFALSE Expr node.  Return 1 if it is TRUE
** and 0 if it is FALSE.
*/
int sqlite3ExprTruthValue(const Expr *pExpr){

  assert( pExpr->op==TK_TRUEFALSE );
  assert( sqlite3StrICmp(pExpr->u.zToken,"true")==0
       || sqlite3StrICmp(pExpr->u.zToken,"false")==0 );
  return pExpr->u.zToken[4]==0;
}

/*







>







1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
}

/*
** The argument must be a TK_TRUEFALSE Expr node.  Return 1 if it is TRUE
** and 0 if it is FALSE.
*/
int sqlite3ExprTruthValue(const Expr *pExpr){
  pExpr = sqlite3ExprSkipCollate((Expr*)pExpr);
  assert( pExpr->op==TK_TRUEFALSE );
  assert( sqlite3StrICmp(pExpr->u.zToken,"true")==0
       || sqlite3StrICmp(pExpr->u.zToken,"false")==0 );
  return pExpr->u.zToken[4]==0;
}

/*

Changes to src/resolve.c.

926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
    }
    case TK_VARIABLE: {
      notValid(pParse, pNC, "parameters", NC_IsCheck|NC_PartIdx|NC_IdxExpr);
      break;
    }
    case TK_IS:
    case TK_ISNOT: {
      Expr *pRight;
      assert( !ExprHasProperty(pExpr, EP_Reduced) );
      /* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE",
      ** and "x IS NOT FALSE". */
      if( (pRight = pExpr->pRight)->op==TK_ID ){
        int rc = resolveExprStep(pWalker, pRight);
        if( rc==WRC_Abort ) return WRC_Abort;
        if( pRight->op==TK_TRUEFALSE ){
          pExpr->op2 = pExpr->op;
          pExpr->op = TK_TRUTH;
          return WRC_Continue;
        }







|



|







926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
    }
    case TK_VARIABLE: {
      notValid(pParse, pNC, "parameters", NC_IsCheck|NC_PartIdx|NC_IdxExpr);
      break;
    }
    case TK_IS:
    case TK_ISNOT: {
      Expr *pRight = sqlite3ExprSkipCollate(pExpr->pRight);
      assert( !ExprHasProperty(pExpr, EP_Reduced) );
      /* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE",
      ** and "x IS NOT FALSE". */
      if( pRight->op==TK_ID ){
        int rc = resolveExprStep(pWalker, pRight);
        if( rc==WRC_Abort ) return WRC_Abort;
        if( pRight->op==TK_TRUEFALSE ){
          pExpr->op2 = pExpr->op;
          pExpr->op = TK_TRUTH;
          return WRC_Continue;
        }

Changes to src/treeview.c.

510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
    case TK_TRUTH: {
      int x;
      const char *azOp[] = {
         "IS-FALSE", "IS-TRUE", "IS-NOT-FALSE", "IS-NOT-TRUE"
      };
      assert( pExpr->op2==TK_IS || pExpr->op2==TK_ISNOT );
      assert( pExpr->pRight );
      assert( pExpr->pRight->op==TK_TRUEFALSE );
      x = (pExpr->op2==TK_ISNOT)*2 + sqlite3ExprTruthValue(pExpr->pRight);
      zUniOp = azOp[x];
      break;
    }

    case TK_SPAN: {
      sqlite3TreeViewLine(pView, "SPAN %Q", pExpr->u.zToken);







|







510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
    case TK_TRUTH: {
      int x;
      const char *azOp[] = {
         "IS-FALSE", "IS-TRUE", "IS-NOT-FALSE", "IS-NOT-TRUE"
      };
      assert( pExpr->op2==TK_IS || pExpr->op2==TK_ISNOT );
      assert( pExpr->pRight );
      assert( sqlite3ExprSkipCollate(pExpr->pRight)->op==TK_TRUEFALSE );
      x = (pExpr->op2==TK_ISNOT)*2 + sqlite3ExprTruthValue(pExpr->pRight);
      zUniOp = azOp[x];
      break;
    }

    case TK_SPAN: {
      sqlite3TreeViewLine(pView, "SPAN %Q", pExpr->u.zToken);

Changes to test/istrue.test.

153
154
155
156
157
158
159














160
161
  INSERT INTO t7(a,b,c) VALUES(2,true,false);
  ALTER TABLE t7 ADD COLUMN d BOOLEAN DEFAULT false;
  ALTER TABLE t7 ADD COLUMN e BOOLEAN DEFAULT true;
  INSERT INTO t7(a,b,c) VALUES(3,true,false);
  INSERT INTO t7 VALUES(4,false,true,true,false);
  SELECT *,'x' FROM t7 ORDER BY a;
} {1 0 1 0 1 x 2 1 0 0 1 x 3 1 0 0 1 x 4 0 1 1 0 x}















finish_test







>
>
>
>
>
>
>
>
>
>
>
>
>
>


153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
  INSERT INTO t7(a,b,c) VALUES(2,true,false);
  ALTER TABLE t7 ADD COLUMN d BOOLEAN DEFAULT false;
  ALTER TABLE t7 ADD COLUMN e BOOLEAN DEFAULT true;
  INSERT INTO t7(a,b,c) VALUES(3,true,false);
  INSERT INTO t7 VALUES(4,false,true,true,false);
  SELECT *,'x' FROM t7 ORDER BY a;
} {1 0 1 0 1 x 2 1 0 0 1 x 3 1 0 0 1 x 4 0 1 1 0 x}

do_execsql_test istrue-710 {
  SELECT 0.5 IS TRUE COLLATE NOCASE;
  SELECT 0.5 IS TRUE COLLATE RTRIM;
  SELECT 0.5 IS TRUE COLLATE BINARY;

  SELECT 0.5 IS TRUE;
  SELECT 0.5 COLLATE NOCASE IS TRUE;
  SELECT 0.0 IS FALSE;

  SELECT 0.0 IS FALSE COLLATE NOCASE;
  SELECT 0.0 IS FALSE COLLATE RTRIM;
  SELECT 0.0 IS FALSE COLLATE BINARY;
} {1 1 1   1 1 1  1 1 1}

finish_test