From 0dde4739f32df29f390f961e7b63d60a1594f807 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 19 Dec 2012 13:41:03 +0000 Subject: [PATCH] Add commentary to the ExprList object to explain how zSpan is overloaded. Add test cases for the new name resolution functionality. FossilOrigin-Name: 3e7d84db7861911c9b2c7dcdabe0b213bf483d79 --- manifest | 16 +++++----- manifest.uuid | 2 +- src/sqliteInt.h | 22 ++++++++----- test/selectD.test | 78 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 17 deletions(-) create mode 100644 test/selectD.test diff --git a/manifest b/manifest index 276e397897..f327e2ee10 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Better\sresolution\sof\stable\sand\scolumn\snames\sin\sjoins\swhere\ssome\sof\sthe\nterms\sof\sthe\sFROM\sclause\sare\sparenthesized. -D 2012-12-19T02:36:45.854 +C Add\scommentary\sto\sthe\sExprList\sobject\sto\sexplain\show\szSpan\sis\soverloaded.\nAdd\stest\scases\sfor\sthe\snew\sname\sresolution\sfunctionality. +D 2012-12-19T13:41:03.688 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 690d441a758cbffd13e814dc2724a721a6ebd400 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -179,7 +179,7 @@ F src/shell.c e392dd1ccbb77cc1d75a8367a89b473c24bea019 F src/sqlite.h.in 39cc33bb08897c748fe3383c29ccf56585704177 F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0 F src/sqlite3ext.h 6904f4aadf976f95241311fbffb00823075d9477 -F src/sqliteInt.h f7581eb79d822a6993d6aa31baf1e67e6ff17d19 +F src/sqliteInt.h c708c868f10c491bd32a7e1210f4a314448fa728 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c bedc37ec1a6bb9399944024d63f4c769971955a9 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -698,6 +698,7 @@ F test/select9.test c0ca3cd87a8ebb04de2cb1402c77df55d911a0ea F test/selectA.test 06d1032fa9009314c95394f2ca2e60d9f7ae8532 F test/selectB.test 954e4e49cf1f896d61794e440669e03a27ceea25 F test/selectC.test 871fb55d884d3de5943c4057ebd22c2459e71977 +F test/selectD.test 243db87cd12f62aca4fe3f8b9465dfeab30b4d7a F test/server1.test 46803bd3fe8b99b30dbc5ff38ffc756f5c13a118 F test/shared.test 1da9dbad400cee0d93f252ccf76e1ae007a63746 F test/shared2.test 03eb4a8d372e290107d34b6ce1809919a698e879 @@ -1026,10 +1027,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 7fecced466d86a66b0b751c5b5608141e134fe2d -R edfa9398c5c900d8f6d5f20d3c0d802e -T *branch * name-resolution-fix -T *sym-name-resolution-fix * -T -sym-trunk * +P 7344e791b9456286ecdca6d45f2f5260fb3f10e2 +R be36637b6c87220d87a455d3dd649bed U drh -Z 3b6c2dbf5da1f286c0c463d165d85b47 +Z 4a19eec8d8a61f22fdf7238cb2d39c20 diff --git a/manifest.uuid b/manifest.uuid index ee37ee7967..47a5e32c0e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7344e791b9456286ecdca6d45f2f5260fb3f10e2 \ No newline at end of file +3e7d84db7861911c9b2c7dcdabe0b213bf483d79 \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 8a04ab47b0..6c10c38625 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1771,18 +1771,26 @@ struct Expr { ** list of "ID = expr" items in an UPDATE. A list of expressions can ** also be used as the argument to a function, in which case the a.zName ** field is not used. +** +** By default the Expr.zSpan field holds a human-readable description of +** the expression that is used in the generation of error messages and +** column labels. In this case, Expr.zSpan is typically the text of a +** column expression as it exists in a SELECT statement. However, if +** the bSpanIsTab flag is set, then zSpan is overloaded to mean the name +** of the table to which the column of a FROM-clause subquery refers. */ struct ExprList { int nExpr; /* Number of expressions on the list */ int iECursor; /* VDBE Cursor associated with this ExprList */ struct ExprList_item { /* For each expression in the list */ - Expr *pExpr; /* The list of expressions */ - char *zName; /* Token associated with this expression */ - char *zSpan; /* Original text of the expression */ - u8 sortOrder; /* 1 for DESC or 0 for ASC */ - u8 done; /* A flag to indicate when processing is finished */ - u16 iOrderByCol; /* For ORDER BY, column number in result set */ - u16 iAlias; /* Index into Parse.aAlias[] for zName */ + Expr *pExpr; /* The list of expressions */ + char *zName; /* Token associated with this expression */ + char *zSpan; /* Original text of the expression */ + u8 sortOrder; /* 1 for DESC or 0 for ASC */ + unsigned done :1; /* A flag to indicate when processing is finished */ + unsigned bSpanIsTab :1; /* zSpan holds table name, not the span */ + u16 iOrderByCol; /* For ORDER BY, column number in result set */ + u16 iAlias; /* Index into Parse.aAlias[] for zName */ } *a; /* Alloc a power of two greater or equal to nExpr */ }; diff --git a/test/selectD.test b/test/selectD.test new file mode 100644 index 0000000000..8c86226434 --- /dev/null +++ b/test/selectD.test @@ -0,0 +1,78 @@ +# 2012 December 19 +# +# 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 name resolution in SELECT +# statements that have parenthesized FROM clauses. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +do_test selectD-1.1 { + db eval { + CREATE TABLE t1(a,b); INSERT INTO t1 VALUES(111,'x1'); + CREATE TABLE t2(a,b); INSERT INTO t2 VALUES(222,'x2'); + CREATE TABLE t3(a,b); INSERT INTO t3 VALUES(333,'x3'); + CREATE TABLE t4(a,b); INSERT INTO t4 VALUES(444,'x4'); + + SELECT * + FROM (t1), (t2), (t3), (t4) + WHERE t4.a=t3.a+111 + AND t3.a=t2.a+111 + AND t2.a=t1.a+111; + } +} {111 x1 222 x2 333 x3 444 x4} +do_test selectD-1.2 { + db eval { + SELECT * + FROM t1 JOIN (t2 JOIN (t3 JOIN t4 ON t4.a=t3.a+111) + ON t3.a=t2.a+111) + ON t2.a=t1.a+111; + } +} {111 x1 222 x2 333 x3 444 x4} +do_test selectD-1.3 { + db eval { + UPDATE t2 SET a=111; + UPDATE t3 SET a=111; + UPDATE t4 SET a=111; + SELECT * + FROM t1 JOIN (t2 JOIN (t3 JOIN t4 USING(a)) USING (a)) USING (a); + } +} {111 x1 x2 x3 x4} +do_test selectD-1.4 { + db eval { + UPDATE t2 SET a=111; + UPDATE t3 SET a=111; + UPDATE t4 SET a=111; + SELECT * + FROM t1 LEFT JOIN (t2 LEFT JOIN (t3 LEFT JOIN t4 USING(a)) + USING (a)) + USING (a); + } +} {111 x1 x2 x3 x4} +do_test selectD-1.5 { + db eval { + UPDATE t3 SET a=222; + UPDATE t4 SET a=222; + SELECT * + FROM (t1 LEFT JOIN t2 USING(a)) JOIN (t3 LEFT JOIN t4 USING(a)) + ON t1.a=t3.a-111; + } +} {111 x1 x2 222 x3 x4} +do_test selectD-1.6 { + db eval { + UPDATE t4 SET a=333; + SELECT * + FROM (t1 LEFT JOIN t2 USING(a)) JOIN (t3 LEFT JOIN t4 USING(a)) + ON t1.a=t3.a-111; + } +} {111 x1 x2 222 x3 {}} + +finish_test -- 2.47.2