aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielk1977 <danielk1977@noemail.net>2009-04-02 17:23:32 +0000
committerdanielk1977 <danielk1977@noemail.net>2009-04-02 17:23:32 +0000
commite1fb65a0b83dd38692cdd81b37f6e1096f9b883f (patch)
tree40ac0abcde3b8e80aadee2f547024427df712f16
parentde4679856939f285fb796efabe2d0dcd37a8adde (diff)
downloadsqlite-e1fb65a0b83dd38692cdd81b37f6e1096f9b883f.tar.gz
sqlite-e1fb65a0b83dd38692cdd81b37f6e1096f9b883f.zip
Ensure the required VerifyCookie/Transaction/TableLock opcodes are added for "x
IN (SELECT c FROM t)" expressions. Ticket #3771. (CVS 6439) FossilOrigin-Name: 058a2f20930d7707c03c3c27db8e761d5657ee46
-rw-r--r--manifest16
-rw-r--r--manifest.uuid2
-rw-r--r--src/expr.c27
-rw-r--r--test/select1.test22
4 files changed, 45 insertions, 22 deletions
diff --git a/manifest b/manifest
index 6c66bfeac..f77497653 100644
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\scouple\sof\sharmless\snuisance\swarnings.\s(CVS\s6438)
-D 2009-04-02T17:22:42
+C Ensure\sthe\srequired\sVerifyCookie/Transaction/TableLock\sopcodes\sare\sadded\sfor\s"x\nIN\s(SELECT\sc\sFROM\st)"\sexpressions.\sTicket\s#3771.\s(CVS\s6439)
+D 2009-04-02T17:23:33
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 583e87706abc3026960ed759aff6371faf84c211
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -111,7 +111,7 @@ F src/callback.c 73016376d6848ba987709e8c9048d4f0e0776036
F src/complete.c cb14e06dbe79dee031031f0d9e686ff306afe07c
F src/date.c e6263ed8950642f593cb1a2cc8a73dd726cc7888
F src/delete.c eb1066b2f35489fee46ad765d2b66386fc7d8adf
-F src/expr.c 14853cd56107292de6af664a24c6255111a4257d
+F src/expr.c b7ce173d17b80e937473147604bfde4bb339a8a0
F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff
F src/func.c 99ae90d46154952e08282fcdfe72d08e9601e174
F src/global.c 448419c44ce0701104c2121b0e06919b44514c0c
@@ -515,7 +515,7 @@ F test/savepoint5.test 0735db177e0ebbaedc39812c8d065075d563c4fd
F test/savepoint6.test e28f7d8ab8a389d4e5bd1dc08bf2c3312754cc67
F test/schema.test deafe5472099ab5bc65748059dc5182fc8ebad74
F test/schema2.test 906408621ea881fdb496d878b1822572a34e32c5
-F test/select1.test d0a4cad954fd41c030ec16ffbd2d08a4c0548742
+F test/select1.test fff339661707c5bfa0f2bd4974ceabe9b5d7f774
F test/select2.test 9735da20ccd41e42bf2b4c19fd939141b591adae
F test/select3.test 2ce595f8fb8e2ac10071d3b4e424cadd4634a054
F test/select4.test b64d5d248d008e1dc365f451c76090bde907e665
@@ -715,7 +715,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P 23f90d50737a36ebd17152dd4667948ce7049967
-R a1a1a4239b62dbb22521cfb4e8b651fc
-U drh
-Z fa40ccceb3f1316325395133ac351b79
+P 53dac0a455b9a822f710c257711e8d319060cf84
+R 4a174564884f326a4622b10ba400e069
+U danielk1977
+Z 805670f748f6b920a00761168c563c97
diff --git a/manifest.uuid b/manifest.uuid
index 9b6201c25..fe292cdb1 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-53dac0a455b9a822f710c257711e8d319060cf84 \ No newline at end of file
+058a2f20930d7707c03c3c27db8e761d5657ee46 \ No newline at end of file
diff --git a/src/expr.c b/src/expr.c
index 7b3db105d..663af1b12 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -12,7 +12,7 @@
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
-** $Id: expr.c,v 1.424 2009/03/25 16:51:43 drh Exp $
+** $Id: expr.c,v 1.425 2009/04/02 17:23:33 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -1345,11 +1345,17 @@ int sqlite3FindInIndex(Parse *pParse, Expr *pX, int *prNotFound){
*/
p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0);
if( isCandidateForInOpt(p) ){
- sqlite3 *db = pParse->db;
- Index *pIdx;
- Expr *pExpr = p->pEList->a[0].pExpr;
- int iCol = pExpr->iColumn;
- Vdbe *v = sqlite3GetVdbe(pParse);
+ sqlite3 *db = pParse->db; /* Database connection */
+ Expr *pExpr = p->pEList->a[0].pExpr; /* Expression <column> */
+ int iCol = pExpr->iColumn; /* Index of column <column> */
+ Vdbe *v = sqlite3GetVdbe(pParse); /* Virtual machine being coded */
+ Table *pTab = p->pSrc->a[0].pTab; /* Table <table>. */
+ int iDb; /* Database idx for pTab */
+
+ /* Code an OP_VerifyCookie and OP_TableLock for <table>. */
+ iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
+ sqlite3CodeVerifySchema(pParse, iDb);
+ sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
/* This function is only called from two places. In both cases the vdbe
** has already been allocated. So assume sqlite3GetVdbe() is always
@@ -1359,8 +1365,6 @@ int sqlite3FindInIndex(Parse *pParse, Expr *pX, int *prNotFound){
if( iCol<0 ){
int iMem = ++pParse->nMem;
int iAddr;
- Table *pTab = p->pSrc->a[0].pTab;
- int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
sqlite3VdbeUsesBtree(v, iDb);
iAddr = sqlite3VdbeAddOp1(v, OP_If, iMem);
@@ -1371,17 +1375,17 @@ int sqlite3FindInIndex(Parse *pParse, Expr *pX, int *prNotFound){
sqlite3VdbeJumpHere(v, iAddr);
}else{
+ Index *pIdx; /* Iterator variable */
+
/* The collation sequence used by the comparison. If an index is to
** be used in place of a temp-table, it must be ordered according
- ** to this collation sequence.
- */
+ ** to this collation sequence. */
CollSeq *pReq = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pExpr);
/* Check that the affinity that will be used to perform the
** comparison is the same as the affinity of the column. If
** it is not, it is not possible to use any index.
*/
- Table *pTab = p->pSrc->a[0].pTab;
char aff = comparisonAffinity(pX);
int affinity_ok = (pTab->aCol[iCol].affinity==aff||aff==SQLITE_AFF_NONE);
@@ -1390,7 +1394,6 @@ int sqlite3FindInIndex(Parse *pParse, Expr *pX, int *prNotFound){
&& (pReq==sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], -1, 0))
&& (!mustBeUnique || (pIdx->nColumn==1 && pIdx->onError!=OE_None))
){
- int iDb;
int iMem = ++pParse->nMem;
int iAddr;
char *pKey;
diff --git a/test/select1.test b/test/select1.test
index 59c3b5878..145a982d6 100644
--- a/test/select1.test
+++ b/test/select1.test
@@ -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.65 2008/08/04 03:51:24 danielk1977 Exp $
+# $Id: select1.test,v 1.66 2009/04/02 17:23:33 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -1041,4 +1041,24 @@ do_test select1-14.2 {
}
} {0}
+# Check that ticket #3771 has been fixed.
+#
+do_test select1-15.1 {
+ execsql {
+ CREATE TABLE t1(a);
+ CREATE INDEX i1 ON t1(a);
+ INSERT INTO t1 VALUES(1);
+ INSERT INTO t1 VALUES(2);
+ INSERT INTO t1 VALUES(3);
+ }
+} {}
+do_test select1-15.2 {
+ sqlite3 db2 test.db
+ execsql { DROP INDEX i1 } db2
+ db2 close
+} {}
+do_test select1-15.3 {
+ execsql { SELECT 2 IN (SELECT a FROM t1) }
+} {1}
+
finish_test