SQLite

Check-in [d8b249e8]
Login

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

Overview
Comment:Avoid treating constant expressions like "? IN ()" or "? NOT IN ()" as integers if they appear in a GROUP BY or ORDER BY clause.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d8b249e8cdf0babe1427d0587dbdc27a52ec06a5ef3a20dfb05a0ea4adb85858
User & Date: dan 2022-05-17 15:01:01
Context
2022-05-17
15:11
Fix harmless compiler warnings in the new unixFullPathname implementation. (check-in: f7e1ceb5 user: drh tags: trunk)
15:01
Avoid treating constant expressions like "? IN ()" or "? NOT IN ()" as integers if they appear in a GROUP BY or ORDER BY clause. (check-in: d8b249e8 user: dan tags: trunk)
14:59
Add the sqlite3_db_name() interface. (check-in: 2ad15223 user: drh tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/parse.y.

1267
1268
1269
1270
1271
1272
1273
1274

1275
1276
1277
1278
1279
1280
1281
      **      expr1 IN ()
      **      expr1 NOT IN ()
      **
      ** simplify to constants 0 (false) and 1 (true), respectively,
      ** regardless of the value of expr1.
      */
      sqlite3ExprUnmapAndDelete(pParse, A);
      A = sqlite3Expr(pParse->db, TK_INTEGER, N ? "1" : "0");

    }else{
      Expr *pRHS = Y->a[0].pExpr;
      if( Y->nExpr==1 && sqlite3ExprIsConstant(pRHS) && A->op!=TK_VECTOR ){
        Y->a[0].pExpr = 0;
        sqlite3ExprListDelete(pParse->db, Y);
        pRHS = sqlite3PExpr(pParse, TK_UPLUS, pRHS, 0);
        A = sqlite3PExpr(pParse, TK_EQ, A, pRHS);







|
>







1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
      **      expr1 IN ()
      **      expr1 NOT IN ()
      **
      ** simplify to constants 0 (false) and 1 (true), respectively,
      ** regardless of the value of expr1.
      */
      sqlite3ExprUnmapAndDelete(pParse, A);
      A = sqlite3Expr(pParse->db, TK_STRING, N ? "true" : "false");
      if( A ) sqlite3ExprIdToTrueFalse(A);
    }else{
      Expr *pRHS = Y->a[0].pExpr;
      if( Y->nExpr==1 && sqlite3ExprIsConstant(pRHS) && A->op!=TK_VECTOR ){
        Y->a[0].pExpr = 0;
        sqlite3ExprListDelete(pParse->db, Y);
        pRHS = sqlite3PExpr(pParse, TK_UPLUS, pRHS, 0);
        A = sqlite3PExpr(pParse, TK_EQ, A, pRHS);

Changes to test/in.test.

793
794
795
796
797
798
799









800
801
} {ok}

# Ticket f3ff1472887
#
do_execsql_test in-20.1 {
  SELECT (1 IN (2 IS TRUE));
} {1}










finish_test







>
>
>
>
>
>
>
>
>


793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
} {ok}

# Ticket f3ff1472887
#
do_execsql_test in-20.1 {
  SELECT (1 IN (2 IS TRUE));
} {1}

# Forum post: https://sqlite.org/forum/forumpost/5782619992.
#
reset_db
do_execsql_test in-21.1 {
  CREATE TABLE t0(c0);
  SELECT COUNT(*) FROM t0 ORDER BY (t0.c0 IN ());
} {0}


finish_test