From f436620e3fde628d69e5c327a96cfcc06f434312 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 25 Aug 2008 12:14:08 +0000 Subject: [PATCH] Additional coverage testing in the new name resolver module. (CVS 5608) FossilOrigin-Name: 0d61960afd35721d6d07acd75288c20d2cd6fda1 --- manifest | 18 ++++---- manifest.uuid | 2 +- src/resolve.c | 5 +- test/collate8.test | 75 +++++++++++++++++++++++++++++- test/corrupt.test | 5 +- test/triggerB.test | 111 ++++++++++++++++++++++++++++++++++++++++++++- 6 files changed, 198 insertions(+), 18 deletions(-) diff --git a/manifest b/manifest index 17c3f6fc35..42cf73f8c4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Two\sif\sstatements\sshould\sbe\sasserts.\s\sGCC\swas\ssilently\signoring\sthem,\r\nhence\sthe\sproblem\sdid\snot\sshow\sup\sin\scoverage\stesting.\r\nTicket\s#3333.\s(CVS\s5607) -D 2008-08-25T12:08:22 +C Additional\scoverage\stesting\sin\sthe\snew\sname\sresolver\smodule.\s(CVS\s5608) +D 2008-08-25T12:14:09 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 689e14735f862a5553bceef206d8c13e29504e44 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -144,7 +144,7 @@ F src/pragma.c f5b271b090af7fcedd308d7c5807a5503f7a853d F src/prepare.c c197041e0c4770672cda75e6bfe10242f885e510 F src/printf.c 785f87120589c1db672e37c6eb1087c456e6f84d F src/random.c 5c754319d38abdd6acd74601ee0105504adc508a -F src/resolve.c 3c9c04095fbf8a7f9be9fe71a07576d411c67f40 +F src/resolve.c f279cfe052c3f91457de2512fa2510e4ea86b0cc F src/select.c 3db954ccabee38995b16013a390f15c3b07e1265 F src/shell.c d83b578a8ccdd3e0e7fef4388a0887ce9f810967 F src/sqlite.h.in 2373d1d70664f7fcd78e79af3c51792bb0a0753e @@ -242,13 +242,13 @@ F test/collate4.test 4545554388daaa604e5b3def3aa2f7ed6d56e8da F test/collate5.test e54df13eb9e1140273680b3153c6e19b39e59888 F test/collate6.test 8be65a182abaac8011a622131486dafb8076e907 F test/collate7.test fac8db7aac3978466c04ae892cc74dcf2bc031aa -F test/collate8.test 7ed2461305ac959886a064dc1e3cf15e155a183f +F test/collate8.test df26649cfcbddf109c04122b340301616d3a88f6 F test/collate9.test 3adcc799229545940df2f25308dd1ad65869145a F test/collateA.test b8218ab90d1fa5c59dcf156efabb1b2599c580d6 F test/colmeta.test 087c42997754b8c648819832241daf724f813322 F test/colname.test bc396d99a11a855370010c7e95187177592b1dfe F test/conflict.test bb29b052c60a1f7eb6382be77902061d1f305318 -F test/corrupt.test af069d971853dbe12af936910bfa49d92f7b16e9 +F test/corrupt.test 5bcf7a986358123b8055dfa64b45fc2fb54dcaa9 F test/corrupt2.test a6b9051516f7d417e76b6953cc02f568a6e1cbf0 F test/corrupt3.test 263e8bb04e2728df832fddf6973cf54c91db0c32 F test/corrupt4.test acdb01afaedf529004b70e55de1a6f5a05ae7fff @@ -564,7 +564,7 @@ F test/trigger7.test 72feaf8dbc52cea84de0c3e6ce7559ff19c479af F test/trigger8.test 3a09275aa2214fdff56f731b1e775d8dfee4408a F test/trigger9.test e6e8dbab673666b3c0a63f0fefcff2329fe6bba8 F test/triggerA.test 208dbda4d2f7c918b02f8a0dfa3acd2a0fe00691 -F test/triggerB.test 9a4d9d98e2f6c5730841c4b55a6152822f986e02 +F test/triggerB.test 56780c031b454abac2340dbb3b71ac5c56c3d7fe F test/types.test 98e7a631bddf0806204358b452b02d0e319318a6 F test/types2.test 3555aacf8ed8dc883356e59efc314707e6247a84 F test/types3.test a0f66bf12f80fad89493535474f7a6d16fa58150 @@ -623,7 +623,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P eae959ede1b2b50190c60de9249cf141c3031ce2 -R e151136f3c0921b50d046c381c57bb8f +P 635933b1cae6c43656260555089952e2925c3292 +R 425df6baa72dc44cb2b3af4ba0d5d71f U drh -Z 577af3d40ea26b9ad4601f25255d4181 +Z 402656fa4c5ab25e1bc6c1040a95ee16 diff --git a/manifest.uuid b/manifest.uuid index b0a38042fd..3ee9d6acee 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -635933b1cae6c43656260555089952e2925c3292 \ No newline at end of file +0d61960afd35721d6d07acd75288c20d2cd6fda1 \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index 4d33c1a69f..b9d5360932 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -14,7 +14,7 @@ ** resolve all identifiers by associating them with a particular ** table and column. ** -** $Id: resolve.c,v 1.2 2008/08/22 17:34:45 drh Exp $ +** $Id: resolve.c,v 1.3 2008/08/25 12:14:09 drh Exp $ */ #include "sqliteInt.h" #include @@ -93,7 +93,7 @@ static int lookupName( Column *pCol; pTab = pItem->pTab; - assert( pTab!=0 ); + assert( pTab!=0 && pTab->zName!=0 ); iDb = sqlite3SchemaToIndex(db, pTab->pSchema); assert( pTab->nCol>0 ); if( zTab ){ @@ -346,7 +346,6 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){ NameContext *pNC; Parse *pParse; - if( pExpr==0 ) return WRC_Continue; pNC = pWalker->u.pNC; assert( pNC!=0 ); pParse = pNC->pParse; diff --git a/test/collate8.test b/test/collate8.test index 3e90c38c8c..60a89162dd 100644 --- a/test/collate8.test +++ b/test/collate8.test @@ -13,7 +13,7 @@ # focus of this script is making sure collations pass through the # unary + operator. # -# $Id: collate8.test,v 1.1 2007/06/20 16:13:23 drh Exp $ +# $Id: collate8.test,v 1.2 2008/08/25 12:14:09 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -48,5 +48,78 @@ do_test collate8-1.5 { SELECT a FROM t1 ORDER BY +a } } {aaa BBB ccc DDD} +do_test collate8-1.11 { + execsql { + SELECT a AS x FROM t1 ORDER BY "x"; + } +} {aaa BBB ccc DDD} +do_test collate8-1.12 { + execsql { + SELECT a AS x FROM t1 WHERE x<'ccc' ORDER BY 1 + } +} {aaa BBB} +do_test collate8-1.13 { + execsql { + SELECT a AS x FROM t1 WHERE x<'ccc' COLLATE binary ORDER BY [x] + } +} {aaa BBB DDD} +do_test collate8-1.14 { + execsql { + SELECT a AS x FROM t1 WHERE +x<'ccc' ORDER BY 1 + } +} {aaa BBB} +do_test collate8-1.15 { + execsql { + SELECT a AS x FROM t1 ORDER BY +x + } +} {aaa BBB ccc DDD} + + +# When a result-set column is aliased into a WHERE clause, make sure the +# collating sequence logic works correctly. +# +do_test collate8-2.1 { + execsql { + CREATE TABLE t2(a); + INSERT INTO t2 VALUES('abc'); + INSERT INTO t2 VALUES('ABC'); + SELECT a AS x FROM t2 WHERE x='abc'; + } +} {abc} +do_test collate8-2.2 { + execsql { + SELECT a AS x FROM t2 WHERE x='abc' COLLATE nocase; + } +} {abc ABC} +do_test collate8-2.3 { + execsql { + SELECT a AS x FROM t2 WHERE (x COLLATE nocase)='abc'; + } +} {abc ABC} +do_test collate8-2.4 { + execsql { + SELECT a COLLATE nocase AS x FROM t2 WHERE x='abc'; + } +} {abc ABC} +do_test collate8-2.5 { + execsql { + SELECT a COLLATE nocase AS x FROM t2 WHERE (x COLLATE binary)='abc'; + } +} {abc} +do_test collate8-2.6 { + execsql { + SELECT a COLLATE nocase AS x FROM t2 WHERE x='abc' COLLATE binary; + } +} {abc ABC} +do_test collate8-2.7 { + execsql { + SELECT * FROM t2 WHERE (a COLLATE nocase)='abc' COLLATE binary; + } +} {abc ABC} +do_test collate8-2.8 { + execsql { + SELECT a COLLATE nocase AS x FROM t2 WHERE 'abc'=x COLLATE binary; + } +} {abc} finish_test diff --git a/test/corrupt.test b/test/corrupt.test index 30ceeeaaf6..5b86e69493 100644 --- a/test/corrupt.test +++ b/test/corrupt.test @@ -13,10 +13,9 @@ # This file implements tests to make sure SQLite does not crash or # segfault if it sees a corrupt database file. # -# $Id: corrupt.test,v 1.9 2008/05/05 12:09:33 danielk1977 Exp $ +# $Id: corrupt.test,v 1.10 2008/08/25 12:14:09 drh Exp $ -catch {file delete -force test.db} -catch {file delete -force test.db-journal} +catch {file delete -force test.db test.db-journal test.bu} set testdir [file dirname $argv0] source $testdir/tester.tcl diff --git a/test/triggerB.test b/test/triggerB.test index 4ba7b53ac0..ac4f37bcf4 100644 --- a/test/triggerB.test +++ b/test/triggerB.test @@ -1,7 +1,7 @@ # 2008 April 15 # # The author disclaims copyright to this source code. In place of -# a legal notice, here is a blessing: +# a legal notice', here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. @@ -41,4 +41,113 @@ do_test triggerB-1.2 { } } {1 0 0 2 0 0} +# Added 2008-08-22: +# +# Name resolution within triggers. +# +do_test triggerB-2.1 { + catchsql { + CREATE TRIGGER ty AFTER INSERT ON x BEGIN + SELECT wen.x; -- Unrecognized name + END; + INSERT INTO x VALUES(1,2); + } +} {1 {no such column: wen.x}} +do_test triggerB-2.2 { + catchsql { + CREATE TRIGGER tz AFTER UPDATE ON x BEGIN + SELECT dlo.x; -- Unrecognized name + END; + UPDATE x SET y=y+1; + } +} {1 {no such column: dlo.x}} + +do_test triggerB-2.3 { + execsql { + CREATE TABLE t2(a INTEGER PRIMARY KEY, b); + INSERT INTO t2 VALUES(1,2); + CREATE TABLE changes(x,y); + CREATE TRIGGER r1t2 AFTER UPDATE ON t2 BEGIN + INSERT INTO changes VALUES(new.a, new.b); + END; + } + execsql { + UPDATE t2 SET a=a+10; + SELECT * FROM changes; + } +} {11 2} +do_test triggerB-2.4 { + execsql { + CREATE TRIGGER r2t2 AFTER DELETE ON t2 BEGIN + INSERT INTO changes VALUES(old.a, old.c); + END; + } + catchsql { + DELETE FROM t2; + } +} {1 {no such column: old.c}} + +# Triggers maintain a mask of columns from the invoking table that are +# used in the trigger body as NEW.column or OLD.column. That mask is then +# used to reduce the amount of information that needs to be loaded into +# the NEW and OLD pseudo-tables at run-time. +# +# These tests cases check the logic for when there are many columns - more +# than will fit in a bitmask. +# +do_test triggerB-3.1 { + execsql { + CREATE TABLE t3( + c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, + c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, + c20, c21, c22, c23, c24, c25, c26, c27, c28, c29, + c30, c31, c32, c33, c34, c35, c36, c37, c38, c39, + c40, c41, c42, c43, c44, c45, c46, c47, c48, c49, + c50, c51, c52, c53, c54, c55, c56, c57, c58, c59, + c60, c61, c62, c63, c64, c65 + ); + CREATE TABLE t3_changes(colnum, oldval, newval); + INSERT INTO t3 VALUES( + 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', + 'a10','a11','a12','a13','a14','a15','a16','a17','a18','a19', + 'a20','a21','a22','a23','a24','a25','a26','a27','a28','a29', + 'a30','a31','a32','a33','a34','a35','a36','a37','a38','a39', + 'a40','a41','a42','a43','a44','a45','a46','a47','a48','a49', + 'a50','a51','a52','a53','a54','a55','a56','a57','a58','a59', + 'a60','a61','a62','a63','a64','a65' + ); + } + for {set i 0} {$i<=65} {incr i} { + set sql [subst { + CREATE TRIGGER t3c$i AFTER UPDATE ON t3 + WHEN old.c$i!=new.c$i BEGIN + INSERT INTO t3_changes VALUES($i, old.c$i, new.c$i); + END + }] + db eval $sql + } + execsql { + SELECT * FROM t3_changes + } +} {} +for {set i 0} {$i<=64} {incr i} { + do_test triggerB-3.2.$i.1 [subst { + execsql { + UPDATE t3 SET c$i='b$i'; + SELECT * FROM t3_changes ORDER BY rowid DESC LIMIT 1; + } + }] [subst {$i a$i b$i}] + do_test triggerB-3.2.$i.2 [subst { + execsql { + SELECT count(*) FROM t3_changes + } + }] [expr {$i+1}] + do_test triggerB-3.2.$i.2 [subst { + execsql { + SELECT * FROM t3_changes WHERE colnum=$i + } + }] [subst {$i a$i b$i}] +} + + finish_test