From: dan Date: Mon, 9 Sep 2019 20:17:24 +0000 (+0000) Subject: Ensure the columns of views and sub-selects in the FROM clause of a select are always... X-Git-Tag: version-3.30.0~66 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d5deb6b3c4faaf6b6c225f9dd5aa9ca2da81b06c;p=thirdparty%2Fsqlite.git Ensure the columns of views and sub-selects in the FROM clause of a select are always assigned implicit collation sequences, just as table columns are. Fix for [a7debbe0]. FossilOrigin-Name: b9ec72203c19c2b95e648ac1dfad74eec98d4ff82581cdc10dc4221ba551728f --- d5deb6b3c4faaf6b6c225f9dd5aa9ca2da81b06c diff --cc manifest index ad787c3946,df599d99d4..41eb8b12cd --- a/manifest +++ b/manifest @@@ -1,5 -1,5 +1,5 @@@ - C Fix\shandling\sof\sNULL,\stext\sand\sblob\svalues\sin\swindow\squeries\sthat\suse\s"RANGE\sBETWEEN\sA\sFOLLOWING\sAND\sB\sFOLLOWING",\sor\s"B\sPRECEDING\sAND\sA\sPRECEDING",\swhere\sA>B. - D 2019-09-04T06:56:43.134 -C Ensure\sthe\scolumns\sof\sviews\sand\ssub-selects\sin\sthe\sFROM\sclause\sof\sa\sselect\sare\salways\sassigned\simplicit\scollation\ssequences,\sjust\sas\stable\scolumns\sare.\sPossible\sfix\sfor\s[a7debbe0]. -D 2019-09-09T19:49:42.715 ++C Ensure\sthe\scolumns\sof\sviews\sand\ssub-selects\sin\sthe\sFROM\sclause\sof\sa\sselect\sare\salways\sassigned\simplicit\scollation\ssequences,\sjust\sas\stable\scolumns\sare.\sFix\sfor\s[a7debbe0]. ++D 2019-09-09T20:17:24.283 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@@ -1448,6 -1448,7 +1448,7 @@@ F test/tkt-9a8b09f8e6.test b2ef151d0984 F test/tkt-9d68c883.test 16f7cb96781ba579bc2e19bb14b4ad609d9774b6 F test/tkt-9f2eb3abac.test cb6123ac695a08b4454c3792fbe85108f67fabf8 F test/tkt-a7b7803e.test 159ef554234fa1f9fb318c751b284bd1cf858da4 -F test/tkt-a7debbe0.test 27b977fea9d42021d9ef67e5811bdc56fd0b9599517e0244c528dddd3264ed4e ++F test/tkt-a7debbe0.test 65a647034e3416d068f81e7d86fffc07edfae371c70b8761714edb56ec1c7521 F test/tkt-a8a0d2996a.test 002e1cde8fc30c39611b52cf981c88200b858765748556822da72e0d32fac73e F test/tkt-b1d3a2e531.test 8f7576e41ca179289ee1a8fee28386fd8e4b0550 F test/tkt-b351d95f9.test d14a503c414c5c58fdde3e80f9a3cfef986498c0 @@@ -1839,8 -1840,10 +1840,8 @@@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a9 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 - P 3044cf6917ea8324175fc91657e9a5978af9748f72e1914bc361753f0b2d897d - R 8115b1008885358de7df7c995955e272 - T +closed 91875000a76cad5b7615ea87aafb2d1fec09441592b37424da4f51e7e025cbfd -P cb3e2be674316e1d39968eb6567f1fe1b72f9d89af49640a9e83f944979c4cf0 -R 8499ff2bdbcbd0ce456fbfc5655f865d -T *branch * tkt-a7debbe0. -T *sym-tkt-a7debbe0. * -T -sym-trunk * ++P cb3e2be674316e1d39968eb6567f1fe1b72f9d89af49640a9e83f944979c4cf0 1863b7bf12521bdd2b51c5b8d3a4634bff3e15d3713e0b5343952df7da02f794 ++R 9270371da6f28852caf725eea0dfbe33 ++T +closed 1863b7bf12521bdd2b51c5b8d3a4634bff3e15d3713e0b5343952df7da02f794 U dan - Z 35e89c49c4707a04ab0cfaf64c9b5bb4 -Z b93432e9313cfc8d7991fd66b06bef63 ++Z e9dd23bc0c9ea40830f2a6e0c2945039 diff --cc manifest.uuid index 8dd06dd0f1,9e8c7a5c15..bfa3f56c30 --- a/manifest.uuid +++ b/manifest.uuid @@@ -1,1 -1,1 +1,1 @@@ - cb3e2be674316e1d39968eb6567f1fe1b72f9d89af49640a9e83f944979c4cf0 -1863b7bf12521bdd2b51c5b8d3a4634bff3e15d3713e0b5343952df7da02f794 ++b9ec72203c19c2b95e648ac1dfad74eec98d4ff82581cdc10dc4221ba551728f diff --cc test/tkt-a7debbe0.test index 0000000000,a49a0bac88..974f6d66b0 mode 000000,100644..100644 --- a/test/tkt-a7debbe0.test +++ b/test/tkt-a7debbe0.test @@@ -1,0 -1,103 +1,103 @@@ + # 2019 September 10 + # + # The author disclaims copyright to this source code. In place of + # a legal notice, here is a blessing: + # + # May you do good and not evil. + # May you find forgiveness for yourself and forgive others. + # May you share freely, never taking more than you give. + # + #*********************************************************************** + # This file implements regression tests for SQLite library. In particular, + # that problems related to ticket a7debbe0ad1 have been fixed. + # + + set testdir [file dirname $argv0] + source $testdir/tester.tcl + set testprefix tkt-a7debbe0 + + foreach tn {1 2} { + reset_db + if {$tn==1} { + # Disable the flattener + optimization_control db query-flattener 0 + } else { + # Enable the flattener + optimization_control db query-flattener 1 + } + + do_execsql_test $tn.1.0 { + CREATE TABLE t0(xyz INTEGER); + INSERT INTO t0(xyz) VALUES(456); + CREATE VIEW v2(a, B) AS + SELECT 'a', 'B' COLLATE NOCASE FROM t0; + CREATE TABLE t2(a, B COLLATE NOCASE); + INSERT INTO t2 VALUES('a', 'B'); + CREATE VIEW v3(a, B) AS + SELECT 'a' COLLATE BINARY, 'B' COLLATE NOCASE FROM t0; + + CREATE VIEW v4(a, B) AS + SELECT 'a', +CAST('B' COLLATE NOCASE AS TEXT) FROM t0; + + CREATE VIEW v5(a, B) AS + SELECT 'a', ('B' COLLATE NOCASE) || '' FROM t0; + } + + # Table t2 and views v2 through v5 should all be equivalent. + do_execsql_test $tn.1.1.1 { SELECT a >= B FROM t2; } 1 + do_execsql_test $tn.1.1.2 { SELECT 'a' >= 'B' COLLATE NOCASE } 0 + do_execsql_test $tn.1.1.3 { SELECT a >= B FROM v2 } 1 + do_execsql_test $tn.1.1.4 { SELECT a >= B FROM v3 } 1 + do_execsql_test $tn.1.1.5 { SELECT a >= B FROM v4 } 1 + do_execsql_test $tn.1.1.6 { SELECT a >= B FROM v5 } 1 + + do_execsql_test $tn.1.2.1 { SELECT B < a FROM t2 } 0 + do_execsql_test $tn.1.2.2 { SELECT 'B' COLLATE NOCASE < 'a' } 0 + do_execsql_test $tn.1.2.3 { SELECT B < a FROM v2 } 0 + do_execsql_test $tn.1.2.4 { SELECT B < a FROM v3 } 0 + do_execsql_test $tn.1.2.5 { SELECT a < B FROM v4 } 0 + do_execsql_test $tn.1.2.6 { SELECT a < B FROM v5 } 0 + + #------------------------------------------------------------------------- - do_execsql_test 2.0 { ++ do_execsql_test $tn.2.0 { + CREATE TABLE t5(a, b COLLATE NOCASE); + INSERT INTO t5 VALUES(1, 'XYZ'); + } + + # Result should be 0, as column "xyz" from the sub-query has implicit + # collation sequence BINARY. - do_execsql_test 2.1 { ++ do_execsql_test $tn.2.1 { + SELECT xyz==b FROM ( SELECT a, 'xyz' AS xyz FROM t5 ), t5; + } {0} + + # Result should be 1, as literal 'xyz' has no collation sequence, so + # the comparison uses the implicit collation sequence of the RHS - NOCASE. - do_execsql_test 2.2 { ++ do_execsql_test $tn.2.2 { + SELECT 'xyz'==b FROM ( SELECT a, 'xyz' AS xyz FROM t5 ), t5; + } {1} + + #----------------------------------------------------------------------- + # The test case submitted with the ticket. + # - do_execsql_test 3.0 { ++ do_execsql_test $tn.3.0 { + DROP TABLE t0; + DROP VIEW v2; + + CREATE TABLE t0(c0); + INSERT INTO t0(c0) VALUES(''); + CREATE VIEW v2(c0, c1) AS + SELECT 'B' COLLATE NOCASE, 'a' FROM t0 ORDER BY t0.c0; + SELECT SUM(count) FROM ( + SELECT v2.c1 BETWEEN v2.c0 AND v2.c1 as count FROM v2 + ); + } 1 + + # The result is 1, as the collation used is the implicit collation sequence + # of v2.c1 - BINARY. - do_execsql_test 3.1 { ++ do_execsql_test $tn.3.1 { + SELECT v2.c1 BETWEEN v2.c0 AND v2.c1 as count FROM v2; + } 1 + } + + finish_test +