mirror of https://github.com/sqlite/sqlite
SQLite now always chooses the column names for compound selects using
the left-most select. This makes SQLite work like other SQL database, but it also is a change from historical behavior and may break some scripts. Ticket #1721. (CVS 3153) FossilOrigin-Name: 80cda9f7ce83f2de6cd2fdaf6150bbc35b670fee
This commit is contained in:
parent
229caa369a
commit
923782530b
22
manifest
22
manifest
|
@ -1,5 +1,5 @@
|
|||
C Add\scode\sto\sreport\san\serror\son\sa\srecursive\strigger,\sbut\sleave\sit\ncommented\sout\s-\sturning\sit\son\swill\slikely\sbreak\sa\slot\sof\scode.\s(CVS\s3152)
|
||||
D 2006-03-25T15:52:20
|
||||
C SQLite\snow\salways\schooses\sthe\scolumn\snames\sfor\scompound\sselects\susing\nthe\sleft-most\sselect.\s\sThis\smakes\sSQLite\swork\slike\sother\sSQL\sdatabase,\nbut\sit\salso\sis\sa\schange\sfrom\shistorical\sbehavior\sand\smay\sbreak\ssome\nscripts.\s\sTicket\s#1721.\s(CVS\s3153)
|
||||
D 2006-03-26T01:21:23
|
||||
F Makefile.in 5d8dff443383918b700e495de42ec65bc1c8865b
|
||||
F Makefile.linux-gcc 74ba0eadf88748a9ce3fd03d2a3ede2e6715baec
|
||||
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
|
||||
|
@ -66,7 +66,7 @@ F src/pragma.c 27d5e395c5d950931c7ac4fe610e7c2993e2fa55
|
|||
F src/prepare.c 6afd730cc8851c0920b5f9050294646b1c2ab28c
|
||||
F src/printf.c 6801501273c060ffe58160a2aa9a7ff7d0ac162f
|
||||
F src/random.c d40f8d356cecbd351ccfab6eaedd7ec1b54f5261
|
||||
F src/select.c eefb46a67c8d154aa87e9fad2ffb0671f1fe4027
|
||||
F src/select.c ca8ee9b54a52e31c22c23ae5264d323f723d253b
|
||||
F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
|
||||
F src/shell.c 5cce3dabcad1f61fa80f8cbcd29bcb5776bda585
|
||||
F src/sqlite.h.in 0bf6f03f9a14dde5f3a4f87471840803acaa4497
|
||||
|
@ -165,7 +165,7 @@ F test/enc3.test 890508efff6677345e93bf2a8adb0489b30df030
|
|||
F test/expr.test 7b4b349abdb05ab1862c1cfcf7607e3731efc5d2
|
||||
F test/fkey1.test 153004438d51e6769fb1ce165f6313972d6263ce
|
||||
F test/format4.test 9f31d41d4f926cab97b2ebe6be00a6ab12dece87
|
||||
F test/func.test 0996e47cb5bb24007cec76f1a4cac9f4417360be
|
||||
F test/func.test 27d02fd00b7c2a6b5c8c302d02f9f20876ce5cc8
|
||||
F test/hook.test 7e7645fd9a033f79cce8fdff151e32715e7ec50a
|
||||
F test/in.test 40feeebc7e38576255051aad428322be1545e0f1
|
||||
F test/index.test c478459611ded74745fee57f99f424da8a5f5fbd
|
||||
|
@ -199,7 +199,7 @@ F test/malloc5.test 7425272e263325fda7d32cb55706e52b5c09e7e0
|
|||
F test/manydb.test 8de36b8d33aab5ef295b11d9e95310aeded31af8
|
||||
F test/memdb.test a67bda4ff90a38f2b19f6c7f95aa7289e051d893
|
||||
F test/memleak.test df2b2b96e77f8ba159a332299535b1e5f18e49ac
|
||||
F test/minmax.test cad887abca5504396718e2cd5729ca40758743e8
|
||||
F test/minmax.test 66434d8ee04869fe4c220b665b73748accbb9163
|
||||
F test/misc1.test 5a9cfffc59e5da583492a1c07efcb08a48cd1135
|
||||
F test/misc2.test 09388e5a2c5c1017ad3ff1c4bf469375def2a0c2
|
||||
F test/misc3.test 7bd937e2c62bcc6be71939faf068d506467b1e03
|
||||
|
@ -222,10 +222,10 @@ F test/rollback.test 673cd8c44c685ad54987fe7f0eeba84efa09685d
|
|||
F test/rowid.test 040a3bef06f970c45f5fcd14b2355f7f4d62f0cf
|
||||
F test/safety.test 4a06934e45d03b8b50ebcd8d174eb0367d2fd851
|
||||
F test/schema.test 8a2ae440fb15f5798a68059e8746402f3137be46
|
||||
F test/select1.test db53c257559a0ed817a5be23947dccc48828edb7
|
||||
F test/select1.test cf2553f611a3393e4424e61eac8eafcb04b86cd7
|
||||
F test/select2.test f3c2678c3a9f3cf08ec4988a3845bda64be6d9e3
|
||||
F test/select3.test 8fece41cd8f2955131b3f973a7123bec60b6e65e
|
||||
F test/select4.test c239f516aa31f42f2ef7c6d7cd01105f08f934ca
|
||||
F test/select4.test d0280e3b6d760d1cff0fcc2a65ecb0611aec3df2
|
||||
F test/select5.test 0b47058d3e916c1fc9fe81f44b438e02bade21ce
|
||||
F test/select6.test d8ea108b65607399580f2765df0aee5e464b0fd8
|
||||
F test/select7.test 1bf795b948c133a15a2a5e99d3270e652ec58ce6
|
||||
|
@ -279,7 +279,7 @@ F test/utf16align.test 7360e84472095518c56746f76b1f9d4dce99fb4d
|
|||
F test/vacuum.test 37f998b841cb335397c26d9bbc3457182af2565f
|
||||
F test/vacuum2.test 5aea8c88a65cb29f7d175296e7c819c6158d838c
|
||||
F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102
|
||||
F test/view.test ef328f28f5658988f1a521720fb9cf940c9532a2
|
||||
F test/view.test b0aeb933cc9dc5bb44d87f3859f3763d770f0153
|
||||
F test/where.test ee7c9a6659b07e1ee61177f6e7ff71565ee2c9df
|
||||
F test/where2.test fde821b9cb8e20d53ccd2e71482b063c5b1e222a
|
||||
F test/where3.test 6356013ce1c8ddc22a65c880dfff2b2c985634cb
|
||||
|
@ -355,7 +355,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
|
|||
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
|
||||
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
|
||||
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
|
||||
P b0111f43e4f82f0c3144d1e6348d9e5fae504d95
|
||||
R 07f26df1ae14843844bd0e7a7c105a61
|
||||
P c83ec81d53f756660cafbbdaf9cf92e9e4bab4ad
|
||||
R 3cde0732a4aff50430bbc2aaeb80af28
|
||||
U drh
|
||||
Z 8dfcbbac72e2253b5a292c2031f2b098
|
||||
Z 51ed0eb85034f61e3452cfde62b62d0e
|
||||
|
|
|
@ -1 +1 @@
|
|||
c83ec81d53f756660cafbbdaf9cf92e9e4bab4ad
|
||||
80cda9f7ce83f2de6cd2fdaf6150bbc35b670fee
|
11
src/select.c
11
src/select.c
|
@ -12,7 +12,7 @@
|
|||
** This file contains C code routines that are called by the parser
|
||||
** to handle SELECT statements in SQLite.
|
||||
**
|
||||
** $Id: select.c,v 1.309 2006/03/17 13:56:34 drh Exp $
|
||||
** $Id: select.c,v 1.310 2006/03/26 01:21:23 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
|
@ -1047,6 +1047,7 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, char *zTabName, Select *pSelect){
|
|||
ExprList *pEList;
|
||||
Column *aCol, *pCol;
|
||||
|
||||
while( pSelect->pPrior ) pSelect = pSelect->pPrior;
|
||||
if( prepSelectStmt(pParse, pSelect) ){
|
||||
return 0;
|
||||
}
|
||||
|
@ -1765,7 +1766,9 @@ static int multiSelect(
|
|||
int iCont, iBreak, iStart;
|
||||
assert( p->pEList );
|
||||
if( eDest==SRT_Callback ){
|
||||
generateColumnNames(pParse, 0, p->pEList);
|
||||
Select *pFirst = p;
|
||||
while( pFirst->pPrior ) pFirst = pFirst->pPrior;
|
||||
generateColumnNames(pParse, 0, pFirst->pEList);
|
||||
}
|
||||
iBreak = sqlite3VdbeMakeLabel(v);
|
||||
iCont = sqlite3VdbeMakeLabel(v);
|
||||
|
@ -1841,7 +1844,9 @@ static int multiSelect(
|
|||
*/
|
||||
assert( p->pEList );
|
||||
if( eDest==SRT_Callback ){
|
||||
generateColumnNames(pParse, 0, p->pEList);
|
||||
Select *pFirst = p;
|
||||
while( pFirst->pPrior ) pFirst = pFirst->pPrior;
|
||||
generateColumnNames(pParse, 0, pFirst->pEList);
|
||||
}
|
||||
iBreak = sqlite3VdbeMakeLabel(v);
|
||||
iCont = sqlite3VdbeMakeLabel(v);
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing built-in functions.
|
||||
#
|
||||
# $Id: func.test,v 1.50 2006/03/02 03:02:48 drh Exp $
|
||||
# $Id: func.test,v 1.51 2006/03/26 01:21:23 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
@ -411,6 +411,7 @@ do_test func-12.7 {
|
|||
# Test that the auxdata API for scalar functions works. This test uses
|
||||
# a special user-defined function only available in test builds,
|
||||
# test_auxdata(). Function test_auxdata() takes any number of arguments.
|
||||
btree_breakpoint
|
||||
do_test func-13.1 {
|
||||
execsql {
|
||||
SELECT test_auxdata('hello world');
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
# aggregate min() and max() functions and which are handled as
|
||||
# as a special case.
|
||||
#
|
||||
# $Id: minmax.test,v 1.18 2005/09/08 19:45:58 drh Exp $
|
||||
# $Id: minmax.test,v 1.19 2006/03/26 01:21:23 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
@ -144,14 +144,14 @@ ifcapable {compound && subquery} {
|
|||
do_test minmax-4.2 {
|
||||
execsql {
|
||||
SELECT y, coalesce(sum(x),0) FROM
|
||||
(SELECT null, y+1 FROM t1 UNION SELECT * FROM t1)
|
||||
(SELECT null AS x, y+1 AS y FROM t1 UNION SELECT * FROM t1)
|
||||
GROUP BY y ORDER BY y;
|
||||
}
|
||||
} {1 1 2 5 3 22 4 92 5 90 6 0}
|
||||
do_test minmax-4.3 {
|
||||
execsql {
|
||||
SELECT y, count(x), count(*) FROM
|
||||
(SELECT null, y+1 FROM t1 UNION SELECT * FROM t1)
|
||||
(SELECT null AS x, y+1 AS y FROM t1 UNION SELECT * FROM t1)
|
||||
GROUP BY y ORDER BY y;
|
||||
}
|
||||
} {1 1 1 2 2 3 3 4 5 4 8 9 5 5 6 6 0 1}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing the SELECT statement.
|
||||
#
|
||||
# $Id: select1.test,v 1.49 2006/03/14 13:10:43 drh Exp $
|
||||
# $Id: select1.test,v 1.50 2006/03/26 01:21:23 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
@ -473,14 +473,14 @@ do_test select1-6.10 {
|
|||
ORDER BY f2;
|
||||
}} msg]
|
||||
lappend v $msg
|
||||
} {0 {f2 11 f2 22 f2 33 f2 44}}
|
||||
} {0 {f1 11 f1 22 f1 33 f1 44}}
|
||||
do_test select1-6.11 {
|
||||
set v [catch {execsql2 {
|
||||
SELECT f1 FROM test1 UNION SELECT f2+100 FROM test1
|
||||
ORDER BY f2+100;
|
||||
}} msg]
|
||||
lappend v $msg
|
||||
} {0 {f2+100 11 f2+100 33 f2+100 122 f2+100 144}}
|
||||
} {0 {f1 11 f1 33 f1 122 f1 144}}
|
||||
} ;#ifcapable compound
|
||||
|
||||
do_test select1-7.1 {
|
||||
|
@ -787,14 +787,14 @@ ifcapable {compound && subquery} {
|
|||
do_test select1-12.9 {
|
||||
execsql2 {
|
||||
SELECT x FROM (
|
||||
SELECT a,b FROM t3 UNION SELECT a AS 'x', b AS 'y' FROM t4 ORDER BY a,b
|
||||
SELECT a AS x, b AS y FROM t3 UNION SELECT a,b FROM t4 ORDER BY a,b
|
||||
) ORDER BY x;
|
||||
}
|
||||
} {x 1 x 3}
|
||||
do_test select1-12.10 {
|
||||
execsql2 {
|
||||
SELECT z.x FROM (
|
||||
SELECT a,b FROM t3 UNION SELECT a AS 'x', b AS 'y' FROM t4 ORDER BY a,b
|
||||
SELECT a AS x,b AS y FROM t3 UNION SELECT a, b FROM t4 ORDER BY a,b
|
||||
) AS 'z' ORDER BY x;
|
||||
}
|
||||
} {x 1 x 3}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
# focus of this file is testing UNION, INTERSECT and EXCEPT operators
|
||||
# in SELECT statements.
|
||||
#
|
||||
# $Id: select4.test,v 1.18 2005/01/21 04:25:47 danielk1977 Exp $
|
||||
# $Id: select4.test,v 1.19 2006/03/26 01:21:23 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
@ -510,5 +510,97 @@ do_test select4-8.2 {
|
|||
}
|
||||
} {1.1 1.10 1.2 1.3}
|
||||
|
||||
# Make sure the names of columns are takenf rom the right-most subquery
|
||||
# right in a compound query. Ticket #1721
|
||||
#
|
||||
do_test select4-9.1 {
|
||||
execsql2 {
|
||||
SELECT x, y FROM t2 UNION SELECT a, b FROM t3 ORDER BY x LIMIT 1
|
||||
}
|
||||
} {x 0 y 1}
|
||||
do_test select4-9.2 {
|
||||
execsql2 {
|
||||
SELECT x, y FROM t2 UNION ALL SELECT a, b FROM t3 ORDER BY x LIMIT 1
|
||||
}
|
||||
} {x 0 y 1}
|
||||
do_test select4-9.3 {
|
||||
execsql2 {
|
||||
SELECT x, y FROM t2 EXCEPT SELECT a, b FROM t3 ORDER BY x LIMIT 1
|
||||
}
|
||||
} {x 0 y 1}
|
||||
do_test select4-9.4 {
|
||||
execsql2 {
|
||||
SELECT x, y FROM t2 INTERSECT SELECT 0 AS a, 1 AS b;
|
||||
}
|
||||
} {x 0 y 1}
|
||||
do_test select4-9.5 {
|
||||
execsql2 {
|
||||
SELECT 0 AS x, 1 AS y
|
||||
UNION
|
||||
SELECT 2 AS p, 3 AS q
|
||||
UNION
|
||||
SELECT 4 AS a, 5 AS b
|
||||
ORDER BY x LIMIT 1
|
||||
}
|
||||
} {x 0 y 1}
|
||||
do_test select4-9.6 {
|
||||
execsql2 {
|
||||
SELECT * FROM (
|
||||
SELECT 0 AS x, 1 AS y
|
||||
UNION
|
||||
SELECT 2 AS p, 3 AS q
|
||||
UNION
|
||||
SELECT 4 AS a, 5 AS b
|
||||
) ORDER BY 1 LIMIT 1;
|
||||
}
|
||||
} {x 0 y 1}
|
||||
do_test select4-9.7 {
|
||||
execsql2 {
|
||||
SELECT * FROM (
|
||||
SELECT 0 AS x, 1 AS y
|
||||
UNION
|
||||
SELECT 2 AS p, 3 AS q
|
||||
UNION
|
||||
SELECT 4 AS a, 5 AS b
|
||||
) ORDER BY x LIMIT 1;
|
||||
}
|
||||
} {x 0 y 1}
|
||||
do_test select4-9.8 {
|
||||
execsql2 {
|
||||
SELECT 0 AS x, 1 AS y
|
||||
UNION
|
||||
SELECT 2 AS y, -3 AS x
|
||||
ORDER BY x LIMIT 1;
|
||||
}
|
||||
} {x 0 y 1}
|
||||
do_test select4-9.9 {
|
||||
execsql2 {
|
||||
SELECT 1 AS a, 2 AS b UNION ALL SELECT 3 AS b, 4 AS a
|
||||
}
|
||||
} {a 1 b 2 a 3 b 4}
|
||||
do_test select4-9.9 {
|
||||
execsql2 {
|
||||
SELECT * FROM (SELECT 1 AS a, 2 AS b UNION ALL SELECT 3 AS b, 4 AS a)
|
||||
WHERE b=3
|
||||
}
|
||||
} {}
|
||||
do_test select4-9.10 {
|
||||
execsql2 {
|
||||
SELECT * FROM (SELECT 1 AS a, 2 AS b UNION ALL SELECT 3 AS b, 4 AS a)
|
||||
WHERE b=2
|
||||
}
|
||||
} {a 1 b 2}
|
||||
do_test select4-9.11 {
|
||||
execsql2 {
|
||||
SELECT * FROM (SELECT 1 AS a, 2 AS b UNION ALL SELECT 3 AS e, 4 AS b)
|
||||
WHERE b=2
|
||||
}
|
||||
} {a 1 b 2}
|
||||
do_test select4-9.12 {
|
||||
execsql2 {
|
||||
SELECT * FROM (SELECT 1 AS a, 2 AS b UNION ALL SELECT 3 AS e, 4 AS b)
|
||||
WHERE b>0
|
||||
}
|
||||
} {a 1 b 2 a 3 b 4}
|
||||
|
||||
finish_test
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing VIEW statements.
|
||||
#
|
||||
# $Id: view.test,v 1.30 2006/03/09 17:28:13 drh Exp $
|
||||
# $Id: view.test,v 1.31 2006/03/26 01:21:23 drh Exp $
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
|
@ -153,7 +153,7 @@ do_test view-3.4 {
|
|||
CREATE VIEW v3 AS SELECT a FROM t1 UNION SELECT b FROM t1 ORDER BY b;
|
||||
SELECT * FROM v3 LIMIT 4;
|
||||
}
|
||||
} {b 2 b 3 b 5 b 6}
|
||||
} {a 2 a 3 a 5 a 6}
|
||||
do_test view-3.5 {
|
||||
execsql2 {
|
||||
CREATE VIEW v4 AS
|
||||
|
@ -161,9 +161,9 @@ do_test view-3.5 {
|
|||
UNION
|
||||
SELECT b AS 'x', a AS 'y' FROM t1
|
||||
ORDER BY x, y;
|
||||
SELECT y FROM v4 ORDER BY y LIMIT 4;
|
||||
SELECT b FROM v4 ORDER BY b LIMIT 4;
|
||||
}
|
||||
} {y 2 y 3 y 5 y 6}
|
||||
} {b 2 b 3 b 5 b 6}
|
||||
} ;# ifcapable compound
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue