]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix the assert() that attempts to verify that the table-reference to
authordrh <>
Mon, 21 Mar 2022 13:55:56 +0000 (13:55 +0000)
committerdrh <>
Mon, 21 Mar 2022 13:55:56 +0000 (13:55 +0000)
index-reference translator finds all required translations.
[forum:/forumpost/929168fdd6|Forum post 929168fdd6].

FossilOrigin-Name: ccd2a2a7e197736a18dce28272fdb4acdf8447342523819c545d28e744c99562

manifest
manifest.uuid
src/where.c
test/upfrom2.test

index 5f73aa9c339f88993806fe36c42de7af601f9cd3..3e0f716756f9c9aa78166c7297291884682f8b6e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\san\sassert()\sin\ssqlite3TableAffinity()\sthat\smight\shave\sbeen\sfalse\sif\sthere\nwas\sa\sprior\ssyntax\serror\sin\sthe\squery.
-D 2022-03-21T11:50:28.476
+C Fix\sthe\sassert()\sthat\sattempts\sto\sverify\sthat\sthe\stable-reference\sto\nindex-reference\stranslator\sfinds\sall\srequired\stranslations.\n[forum:/forumpost/929168fdd6|Forum\spost\s929168fdd6].
+D 2022-03-21T13:55:56.962
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -639,7 +639,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
 F src/wal.c b9df133a705093da8977da5eb202eaadb844839f1c7297c08d33471f5491843d
 F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a
 F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b
-F src/where.c 3f6926af089c0070dd627bef9e16f6890262b43341d5627097bc26fa121d0e12
+F src/where.c 0904231c9f1bca20031665c2c524c11a7e6544107b21aa715895ad72924b9c8d
 F src/whereInt.h 15d2975c3b4c193c78c26674400a840da8647fe1777ae3b026e2d15937b38a03
 F src/wherecode.c 84be340684393248b9f3ecbce9b87c8a6f818149b52302702ea0b8d2a9d51faf
 F src/whereexpr.c 2a71f5491798460c9590317329234d332d9eb1717cba4f3403122189a75c465e
@@ -1680,7 +1680,7 @@ F test/update.test eb7f4eb172ce270e51bb67d7867521f33a63635bb671e261bbafccaef3bd6
 F test/update2.test 67455bc61fcbcf96923c45b3bc4f87bc72be7d67575ad35f134906148c7b06d3
 F test/upfrom1.tcl 8859d9d437f03b44174c4524a7a734a391fd4526fcff65be08285dafc9dc9041
 F test/upfrom1.test 8cb06689e99cd707d884faa16da0e8eb26ff658bb01c47ddf72fadade666e6e1
-F test/upfrom2.test 88d39cb755db5789541e645d4e2764abc697a56958f28a3f8451a0e9342bbd6b
+F test/upfrom2.test 66f3ebf721b3cebd922faee5c386bf244f816d416b57c000753ff51af62328a1
 F test/upfrom3.test 6130f24ebf97f5ea865e5d2a14a2d543fe5428a62e87cc60f62d875e45c1f5f0
 F test/upfromfault.test 3a10075a0043f0c4fad6614b2c371f88a8ba5a4acab68b907438413865d6a8d6
 F test/upsert1.test b0ae2f58680c5205b4bc1cdeed3c3d444057c506f6c44494fa3eac60731d68a2
@@ -1944,9 +1944,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P b75c6bad3a5a165948077026441f02188ba30c7960815486c1973e18992401b3
-Q +23fdb169ca1622369cd44fd641946c37fef09071625838b3b9c86c31244ed205
-R 7981343976c9cb9f550d077ddc08d9db
+P 940f1a400bcd58c2dc135955f261df5f96615339645c25583947f1a7dedae4ce
+Q +fa9bd1fce47e8db1cfc4cd8efd2c09f8711ea917ce7d116dc7226c575cb9a6d4
+R ff32f969bf97b20e46802e232859abfb
 U drh
-Z d24b53430093290f13f878c13c1ec08f
+Z 737911afed397ed6fbd98e27ed973447
 # Remove this line to create a well-formed Fossil manifest.
index 837eb982cbf465c85564f25a31c2797e5f754e13..6fdfa097307abd6bcab93b6ce77a478390aadfcb 100644 (file)
@@ -1 +1 @@
-940f1a400bcd58c2dc135955f261df5f96615339645c25583947f1a7dedae4ce
\ No newline at end of file
+ccd2a2a7e197736a18dce28272fdb4acdf8447342523819c545d28e744c99562
\ No newline at end of file
index 83bd63fc30b2ebd98562ec5da39340178e61957a..9eac7f7db2912146a7ed9534d4e9d86d45d428b3 100644 (file)
@@ -5894,6 +5894,26 @@ whereBeginError:
   }
 #endif
 
+#ifdef SQLITE_DEBUG
+/*
+** Return true if cursor iCur is opened by instruction k of the
+** bytecode.  Used inside of assert() only.
+*/
+static int cursorIsOpen(Vdbe *v, int iCur, int k){
+  while( k>=0 ){
+    VdbeOp *pOp = sqlite3VdbeGetOp(v,k--);
+    if( pOp->p1!=iCur ) continue;
+    if( pOp->opcode==OP_Close ) return 0;
+    if( pOp->opcode==OP_OpenRead ) return 1;
+    if( pOp->opcode==OP_OpenWrite ) return 1;
+    if( pOp->opcode==OP_OpenDup ) return 1;
+    if( pOp->opcode==OP_OpenAutoindex ) return 1;
+    if( pOp->opcode==OP_OpenEphemeral ) return 1;
+  }
+  return 0;
+}
+#endif /* SQLITE_DEBUG */
+
 /*
 ** Generate the end of the WHERE loop.  See comments on 
 ** sqlite3WhereBegin() for additional information.
@@ -6164,12 +6184,15 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){
             pOp->p2 = x;
             pOp->p1 = pLevel->iIdxCur;
             OpcodeRewriteTrace(db, k, pOp);
+          }else{
+            /* Unable to translate the table reference into an index
+            ** reference.  Verify that this is harmless - that the
+            ** table being referenced really is open.
+            */
+            assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
+                 || cursorIsOpen(v,pOp->p1,k)
+            );
           }
-          assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0 
-#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
-              || pOp->opcode==OP_Offset
-#endif
-              || pWInfo->eOnePass );
         }else if( pOp->opcode==OP_Rowid ){
           pOp->p1 = pLevel->iIdxCur;
           pOp->opcode = OP_IdxRowid;
index a1f00953e62c5ae1b41002f4a582044f32efd0b9..600fa05e4bb3ae16d357780bf121e47c2333e2e2 100644 (file)
@@ -382,4 +382,24 @@ do_execsql_test 6.2 {
   )
 } {}
 
+# 2022-03-21
+# https://sqlite.org/forum/forumpost/929168fdd6
+#
+reset_db
+do_execsql_test 7.0 {
+  CREATE TABLE t1(a);
+  INSERT INTO t1(a) VALUES(11),(22),(33),(44),(55);
+  CREATE VIEW t2(b,c) AS SELECT a, COUNT(*) OVER () FROM t1;
+  CREATE TABLE t3(x,y);
+  CREATE TRIGGER t2r1 INSTEAD OF UPDATE ON t2 BEGIN
+    INSERT INTO t3(x,y) VALUES(new.b,new.c);
+  END;
+  SELECT * FROM t2;
+} {11 5 22 5 33 5 44 5 55 5}
+do_execsql_test 7.1 {
+  UPDATE t2 SET c=t1.a FROM t1 WHERE t2.b=t1.a;
+  SELECT * FROM t3;
+} {11 11 22 22 33 33 44 44 55 55}
+
+
 finish_test