From 1550771a6ad4b5a16ed5b2d2f3d8f6d57c0d70a7 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 15 May 2024 21:38:04 +0000 Subject: [PATCH 1/2] Fix a case where an error in the ORDER BY clause of an aggregate function that is part of a trigger body might cause an assert() to fail in an ALTER TABLE command. FossilOrigin-Name: b79a8be37b44c1eff7d00f7af7cd9d0e13614ce5961bb88ddb9ec63f6a846c78 --- manifest | 17 ++++++++++------- manifest.uuid | 2 +- src/resolve.c | 4 +--- test/altertab2.test | 22 ++++++++++++++++++++++ 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 78d7bf26c8..5ee97b85cd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sthere\sis\sno\sdata\savailable\sfor\sa\sfield\sin\sa\scorrupted\srecord,\sbut\sthe\stype\sis\savailable,\shave\sthe\srecovery\sextension\ssubstitute\s0,\s0.0,\s''\sor\sX''\sinstead\sof\sa\sNULL\svalue. -D 2024-05-15T15:06:27.777 +C Fix\sa\scase\swhere\san\serror\sin\sthe\sORDER\sBY\sclause\sof\san\saggregate\sfunction\sthat\sis\spart\sof\sa\strigger\sbody\smight\scause\san\sassert()\sto\sfail\sin\san\sALTER\sTABLE\scommand. +D 2024-05-15T21:38:04.100 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -752,7 +752,7 @@ F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c d99931f45416652895e502328ca49fe782cfc4e1ebdcda13b3736d991ebf42ce F src/printf.c 8b250972305e14b365561be5117ed0fd364e4fd58968776df1ce64c6280b90f9 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c -F src/resolve.c 8816212645e4e9bdf3cc2f2d298304f388d699f8fab47f3a5712ef5bbc5b6ccc +F src/resolve.c 6adf4bf10151bca046f3206ae8ff07dbf90b49de20bea49197f010276f5f494d F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c ce81687d769b174aa547b8216a34fabc9cafc05789b615494ab78dc2c1e799fa F src/shell.c.in 8f2406e4e8d726452e48058d117f52e86b789f47435157b0418fb06c631349b6 @@ -870,7 +870,7 @@ F test/altermalloc2.test 17fb3724c4b004c469c27dc4ef181608aa644555fbd3f3236767584 F test/altermalloc3.test 8040e486368403f2fdd6fc3998258b499bd4cc2f3ddbb5f8f874cd436f076e81 F test/alterqf.test 8ec03d776de9c391daa0078ea8f838903bdcfb11dfae4ba3576b48436834ccba F test/altertab.test 8a2712f9076da5012a002d0b5cc0a421398a5bf61c25bab41b77c427586a7a27 -F test/altertab2.test 62597b6fd08feaba1b6bfe7d31dac6117c67e06dc9ce9c478a3abe75b5926de0 +F test/altertab2.test fff90e3f01e8eb0e09282f538b8ec7cfeb035dbedbe570fe1983440f4613ad0e F test/altertab3.test b331ae34e69594e19605e3297805202d6156fcc8f75379dfd972a2e51cae8721 F test/altertrig.test aacc980b657354fe2d3d4d3a004f07d04ccc1a93e5ef82d68a79088c274ddc6b F test/amatch1.test b5ae7065f042b7f4c1c922933f4700add50cdb9f @@ -2191,8 +2191,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 58d938c0e03c3c8d8796c537f89e69734ba6263d60ba37e345259cb6fdffbea5 -R cd015e2f2734629b19947eb11f0220ff +P 8eb326c24981647e2df90e4b9d75db52a552bd997bd821f5898c7ff3fb93a57d +R 0bf8213edb19e5bc165e2308c6d79a06 +T *branch * alter-table-fix +T *sym-alter-table-fix * +T -sym-trunk * U dan -Z be5ac0bdafce0ff1c422be3037819109 +Z c2a36fdf7fb0d25294933bfa681979d4 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 205cf17a54..b79cfa76c6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8eb326c24981647e2df90e4b9d75db52a552bd997bd821f5898c7ff3fb93a57d \ No newline at end of file +b79a8be37b44c1eff7d00f7af7cd9d0e13614ce5961bb88ddb9ec63f6a846c78 \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index 898c78654c..546731afe5 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -1281,11 +1281,9 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){ #endif } } -#ifndef SQLITE_OMIT_WINDOWFUNC - else if( ExprHasProperty(pExpr, EP_WinFunc) ){ + else if( ExprHasProperty(pExpr, EP_WinFunc) || pExpr->pLeft ){ is_agg = 1; } -#endif sqlite3WalkExprList(pWalker, pList); if( is_agg ){ if( pExpr->pLeft ){ diff --git a/test/altertab2.test b/test/altertab2.test index def9e56686..576dc49670 100644 --- a/test/altertab2.test +++ b/test/altertab2.test @@ -360,4 +360,26 @@ do_catchsql_test 8.6 { SELECT sql FROM sqlite_master WHERE name='i0'; } {1 {error in index i0: second argument to likelihood() must be a constant between 0.0 and 1.0}} + +reset_db + +do_execsql_test 9.0 { + CREATE TABLE t1(a,b,c,d); + CREATE TABLE t2(a,b,c,d,x); + + CREATE TRIGGER AFTER INSERT ON t2 BEGIN + + SELECT group_conct( + 123 ORDER BY ( + SELECT 1 FROM ( VALUES(a, 'b'), ('c') ) + )) + FROM t1; + + END; +} + +do_catchsql_test 9.1 { + ALTER TABLE t2 RENAME TO newname; +} {1 {error in trigger AFTER: all VALUES must have the same number of terms}} + finish_test From 61f2ee6ab88dbc230b6c95af7d731327ddb727ce Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 15 May 2024 23:36:24 +0000 Subject: [PATCH 2/2] Back out the assert() fixes from [a9443dbfbe25e588] and [3afaeac56dff58db] (but keep the corresponding test cases) because they are both made obsolete by the previous fix on this branch. FossilOrigin-Name: 3120c7c8a3565b8a3ca321129c09db96839c2f9af1777fc7a1668fef81973603 --- manifest | 17 +++++++---------- manifest.uuid | 2 +- src/select.c | 6 ++---- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 5ee97b85cd..9e0cc7c88b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\scase\swhere\san\serror\sin\sthe\sORDER\sBY\sclause\sof\san\saggregate\sfunction\sthat\sis\spart\sof\sa\strigger\sbody\smight\scause\san\sassert()\sto\sfail\sin\san\sALTER\sTABLE\scommand. -D 2024-05-15T21:38:04.100 +C Back\sout\sthe\sassert()\sfixes\sfrom\s[a9443dbfbe25e588]\sand\n[3afaeac56dff58db]\s(but\skeep\sthe\scorresponding\stest\scases)\sbecause\sthey\nare\sboth\smade\sobsolete\sby\sthe\sprevious\sfix\son\sthis\sbranch. +D 2024-05-15T23:36:24.437 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -754,7 +754,7 @@ F src/printf.c 8b250972305e14b365561be5117ed0fd364e4fd58968776df1ce64c6280b90f9 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 6adf4bf10151bca046f3206ae8ff07dbf90b49de20bea49197f010276f5f494d F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 -F src/select.c ce81687d769b174aa547b8216a34fabc9cafc05789b615494ab78dc2c1e799fa +F src/select.c 1a841c38974d45cf15a7611398479182b61ad4c187423c380741d8b1688fe607 F src/shell.c.in 8f2406e4e8d726452e48058d117f52e86b789f47435157b0418fb06c631349b6 F src/sqlite.h.in 32389e0d584551b300d0157881336162c14315a424cbf385c0d65eb7c2e31f7b F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -2191,11 +2191,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8eb326c24981647e2df90e4b9d75db52a552bd997bd821f5898c7ff3fb93a57d -R 0bf8213edb19e5bc165e2308c6d79a06 -T *branch * alter-table-fix -T *sym-alter-table-fix * -T -sym-trunk * -U dan -Z c2a36fdf7fb0d25294933bfa681979d4 +P b79a8be37b44c1eff7d00f7af7cd9d0e13614ce5961bb88ddb9ec63f6a846c78 +R 91267a6a1982f21ea275bc49553555c1 +U drh +Z d62affd8eb7ffd4672ed09ea764a6e2a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b79cfa76c6..ffce3cc964 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b79a8be37b44c1eff7d00f7af7cd9d0e13614ce5961bb88ddb9ec63f6a846c78 \ No newline at end of file +3120c7c8a3565b8a3ca321129c09db96839c2f9af1777fc7a1668fef81973603 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 532fbd19e5..9278ea18b8 100644 --- a/src/select.c +++ b/src/select.c @@ -2324,8 +2324,7 @@ void sqlite3SubqueryColumnTypes( NameContext sNC; assert( pSelect!=0 ); - testcase( (pSelect->selFlags & SF_Resolved)==0 ); - assert( (pSelect->selFlags & SF_Resolved)!=0 || IN_RENAME_OBJECT ); + assert( (pSelect->selFlags & SF_Resolved)!=0 ); assert( pTab->nCol==pSelect->pEList->nExpr || pParse->nErr>0 ); assert( aff==SQLITE_AFF_NONE || aff==SQLITE_AFF_BLOB ); if( db->mallocFailed || IN_RENAME_OBJECT ) return; @@ -6412,8 +6411,7 @@ static void selectAddSubqueryTypeInfo(Walker *pWalker, Select *p){ if( p->selFlags & SF_HasTypeInfo ) return; p->selFlags |= SF_HasTypeInfo; pParse = pWalker->pParse; - testcase( (p->selFlags & SF_Resolved)==0 ); - assert( (p->selFlags & SF_Resolved) || IN_RENAME_OBJECT ); + assert( (p->selFlags & SF_Resolved) ); pTabList = p->pSrc; for(i=0, pFrom=pTabList->a; inSrc; i++, pFrom++){ Table *pTab = pFrom->pTab;