From: danielk1977 Date: Thu, 15 Jun 2006 07:29:00 +0000 (+0000) Subject: Simple tests and fixes for writing to virtual tables. (CVS 3252) X-Git-Tag: version-3.6.10~2915 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c7d5410126f223d004b921d70e3dd93983953d49;p=thirdparty%2Fsqlite.git Simple tests and fixes for writing to virtual tables. (CVS 3252) FossilOrigin-Name: 88fa510e4c684513bbb59031d034fdb5c51a6a15 --- diff --git a/manifest b/manifest index 33cbbb08f0..df09f47782 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\svoid*\sargument\sto\ssqlite3_create_module\sto\sreplace\ssqlite3_module.pAux.\s(CVS\s3251) -D 2006-06-15T04:28:13 +C Simple\stests\sand\sfixes\sfor\swriting\sto\svirtual\stables.\s(CVS\s3252) +D 2006-06-15T07:29:01 F Makefile.in 200f6dc376ecfd9b01e5359c4e0c10c02f649b34 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -36,7 +36,7 @@ F src/attach.c 27a31d3b89d7ebb5b358847607b1ec795384123c F src/auth.c 9ae84d2d94eb96195e04515715e08e85963e96c2 F src/btree.c ed343b3dbcbc7da9ac481ef2b98c4239fe6d9629 F src/btree.h 40055cfc09defd1146bc5b922399c035f969e56d -F src/build.c 076619b2a5cbdbdabf5201fc45dda488d7f3cbe6 +F src/build.c a295396a6a5624604c729c3b895902c8b2b1dc5e F src/callback.c fd9bb39f7ff6b52bad8365617abc61c720640429 F src/complete.c 7d1a44be8f37de125fcafd3d3a018690b3799675 F src/date.c cd2bd5d1ebc6fa12d6312f69789ae5b0a2766f2e @@ -46,7 +46,7 @@ F src/expr.c 78b521337d628b1fd9d87b12dbbe771247aab585 F src/func.c 01e559893b5e43bea85135ad3e481d86c447942a F src/hash.c 449f3d6620193aa557f5d86cbc5cc6b87702b185 F src/hash.h 1b3f7e2609141fd571f62199fc38687d262e9564 -F src/insert.c bda00a0e4be8bf4e591186e710075662781293d0 +F src/insert.c eba160c6d7f2c44232ff0f168f7b047e20d6f473 F src/legacy.c fa15d505dd4e45044177ee4d1c6aeaf8c836d390 F src/loadext.c d8c7bd14e6ebc4e9f1ff269475bf63e131919449 F src/main.c 7875e8835539d4f16e8b62fad1dee9bda2091272 @@ -84,7 +84,7 @@ F src/test4.c 8b784cd82de158a2317cb4ac4bc86f91ad315e25 F src/test5.c 7162f8526affb771c4ed256826eee7bb9eca265f F src/test6.c 60a02961ceb7b3edc25f5dc5c1ac2556622a76de F src/test7.c 03fa8d787f6aebc6d1f72504d52f33013ad2c8e3 -F src/test8.c c8da12c237a507273dba8cb11a9f88d2252bd031 +F src/test8.c e88baeff5530fbf0d028a48fbffab71440a5b953 F src/test_async.c e3deaedd4d86a56391b81808fde9e44fbd92f1d3 F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8 F src/test_md5.c 6c42bc0a3c0b54be34623ff77a0eec32b2fa96e3 @@ -96,14 +96,14 @@ F src/update.c 5e638a61102776c0f0333994e18361b40598b44f F src/utf.c ab81ac59084ff1c07d421eb1a0a84ec809603b44 F src/util.c ca6ee72772c0f5dc04d2e0ab1973fd3b6a9bf79d F src/vacuum.c 5b37d0f436f8e1ffacd17934e44720b38d2247f9 -F src/vdbe.c 64427e4b088ee26e9a8710724ef0a8ab5b9fd1e6 +F src/vdbe.c 4a66e5815c50e7f39454fe75d2e3f342785ea20a F src/vdbe.h 258b5d1c0aaa72192f09ff0568ce42b383f156fa F src/vdbeInt.h 6ccb7eaae76ebd761470f6a035501ff33aa92c20 F src/vdbeapi.c 6af0e7160af260052a7a4500464221a03dada75f F src/vdbeaux.c de49c1943146ad97538bc2bb0bce7f2c5e5db4f2 F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5 F src/vdbemem.c 5f0afe3b92bb2c037f8d5d697f7c151fa50783a3 -F src/vtab.c 3b58aa4a54288efe7b1b0cddcdeac239ffa3f071 +F src/vtab.c 745148c6f83f7c146ce93cc22c6716ff05a246e2 F src/where.c d7c3cc011834882b2d58ebb3a6a1a569ead7ebd7 F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -290,7 +290,7 @@ F test/vacuum.test 37f998b841cb335397c26d9bbc3457182af2565f F test/vacuum2.test 5aea8c88a65cb29f7d175296e7c819c6158d838c F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102 F test/view.test 16e2774fe35e47a07ac4471b7f0bcc948b1aa6d5 -F test/vtab1.test 3897a14010f3e74cd64dd03c71e8c87248facbea +F test/vtab1.test 89937da89d774b9174b93a327330e4ea3fb0f03a F test/where.test ee7c9a6659b07e1ee61177f6e7ff71565ee2c9df F test/where2.test a16476a5913e75cf65b38f2daa6157a6b7791394 F test/where3.test 3b5ad2c58069e12be2bd86bc5e211a82810521aa @@ -366,7 +366,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P 9e96511f83476e489fa62a05241393a851cbac5c -R 3b2eab4f54e22efb7b510b16ba4f9657 +P 470a3a0b20775be1226fb4d477c798d8da2d5708 +R 2a51dd29d0ce74e2c7cf789f7bd17241 U danielk1977 -Z 15129ea2cdd7a9095da7badd4764cc47 +Z 0d507f27fec3f378ea4bc0c20801973d diff --git a/manifest.uuid b/manifest.uuid index 1934aba7aa..8a20fa80a2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -470a3a0b20775be1226fb4d477c798d8da2d5708 \ No newline at end of file +88fa510e4c684513bbb59031d034fdb5c51a6a15 \ No newline at end of file diff --git a/src/build.c b/src/build.c index cd6f290c47..124f9a6247 100644 --- a/src/build.c +++ b/src/build.c @@ -22,7 +22,7 @@ ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.400 2006/06/14 19:00:21 drh Exp $ +** $Id: build.c,v 1.401 2006/06/15 07:29:01 danielk1977 Exp $ */ #include "sqliteInt.h" #include @@ -1099,7 +1099,7 @@ void sqlite3AddPrimaryKey( Table *pTab = pParse->pNewTable; char *zType = 0; int iCol = -1, i; - if( pTab==0 ) goto primary_key_exit; + if( pTab==0 || IN_DECLARE_VTAB ) goto primary_key_exit; if( pTab->hasPrimKey ){ sqlite3ErrorMsg(pParse, "table \"%s\" has more than one primary key", pTab->zName); @@ -1154,7 +1154,7 @@ void sqlite3AddCheckConstraint( ){ #ifndef SQLITE_OMIT_CHECK Table *pTab = pParse->pNewTable; - if( pTab ){ + if( pTab && !IN_DECLARE_VTAB ){ /* The CHECK expression must be duplicated so that tokens refer ** to malloced space and not the (ephemeral) text of the CREATE TABLE ** statement */ @@ -1172,7 +1172,7 @@ void sqlite3AddCollateType(Parse *pParse, const char *zType, int nType){ Table *p; int i; - if( (p = pParse->pNewTable)==0 ) return; + if( (p = pParse->pNewTable)==0 || IN_DECLARE_VTAB ) return; i = p->nCol-1; if( sqlite3LocateCollSeq(pParse, zType, nType) ){ @@ -2027,7 +2027,7 @@ void sqlite3CreateForeignKey( char *z; assert( pTo!=0 ); - if( p==0 || pParse->nErr ) goto fk_end; + if( p==0 || pParse->nErr || IN_DECLARE_VTAB ) goto fk_end; if( pFromCol==0 ){ int iCol = p->nCol-1; if( iCol<0 ) goto fk_end; diff --git a/src/insert.c b/src/insert.c index 3d34feda98..e36417767c 100644 --- a/src/insert.c +++ b/src/insert.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle INSERT statements in SQLite. ** -** $Id: insert.c,v 1.166 2006/06/14 19:00:21 drh Exp $ +** $Id: insert.c,v 1.167 2006/06/15 07:29:01 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -632,7 +632,7 @@ void sqlite3Insert( */ #ifndef SQLITE_OMIT_VIRTUALTABLE if( IsVirtual(pTab) ){ - sqlite3VdbeOp3(v, OP_VUpdate, 0, pTab->nCol+1, + sqlite3VdbeOp3(v, OP_VUpdate, 0, pTab->nCol+2, (const char*)pTab->pVtab, P3_VTAB); }else #endif diff --git a/src/test8.c b/src/test8.c index ead66444f7..5a8eaeee2f 100644 --- a/src/test8.c +++ b/src/test8.c @@ -13,7 +13,7 @@ ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test8.c,v 1.20 2006/06/15 04:28:13 danielk1977 Exp $ +** $Id: test8.c,v 1.21 2006/06/15 07:29:01 danielk1977 Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -560,6 +560,7 @@ int echoUpdate(sqlite3_vtab *tab, int nData, sqlite3_value **apData){ rc = sqlite3_prepare(db, zDelete, -1, &pStmt, 0); assert( rc!=SQLITE_OK || pStmt ); if( rc==SQLITE_OK ){ + sqlite3_bind_value(pStmt, 1, apData[0]); sqlite3_step(pStmt); rc = sqlite3_finalize(pStmt); } @@ -579,11 +580,11 @@ int echoUpdate(sqlite3_vtab *tab, int nData, sqlite3_value **apData){ for(ii=0; iinCol && zInsert && zValues; ii++){ char *zNew = sqlite3_mprintf("%s, %Q", zInsert, pVtab->aCol[ii]); - sqliteFree(zInsert); + sqlite3_free(zInsert); zInsert = zNew; zNew = sqlite3_mprintf("%s, ?", zValues); - sqliteFree(zValues); + sqlite3_free(zValues); zValues = zNew; } @@ -604,10 +605,11 @@ int echoUpdate(sqlite3_vtab *tab, int nData, sqlite3_value **apData){ } } - sqliteFree(zValues); - sqliteFree(zInsert); - sqliteFree(zQuery); + sqlite3_free(zValues); + sqlite3_free(zInsert); + sqlite3_free(zQuery); if( rc==SQLITE_OK && (!zValues || !zInsert || !zQuery) ){ + sqlite3FailedMalloc(); rc = SQLITE_NOMEM; } } diff --git a/src/vdbe.c b/src/vdbe.c index 050ab337b5..035dc94878 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -43,7 +43,7 @@ ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.560 2006/06/14 19:00:22 drh Exp $ +** $Id: vdbe.c,v 1.561 2006/06/15 07:29:01 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -4811,7 +4811,9 @@ case OP_VUpdate: { /* no-push */ for(i = 0; iflags ? storeTypeInfo(pX,0), pX : 0; } + if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse; rc = pModule->xUpdate(pVtab, nArg, apArg); + if( sqlite3SafetyOn(db) ) goto abort_due_to_misuse; } popStack(&pTos, nArg); break; @@ -4854,8 +4856,12 @@ default: { ** the evaluator loop. So we can leave it out when NDEBUG is defined. */ #ifndef NDEBUG - /* Sanity checking on the top element of the stack */ - if( pTos>=p->aStack ){ + /* Sanity checking on the top element of the stack. If the previous + ** instruction was VNoChange, then the flags field of the top + ** of the stack is set to 0. This is technically invalid for a memory + ** cell, so avoid calling MemSanity() in this case. + */ + if( pTos>=p->aStack && pTos->flags ){ sqlite3VdbeMemSanity(pTos); } assert( pc>=-1 && pcnOp ); diff --git a/src/vtab.c b/src/vtab.c index 727ee5117a..e870a2b341 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code used to help implement virtual tables. ** -** $Id: vtab.c,v 1.12 2006/06/15 04:28:13 danielk1977 Exp $ +** $Id: vtab.c,v 1.13 2006/06/15 07:29:01 danielk1977 Exp $ */ #ifndef SQLITE_OMIT_VIRTUALTABLE #include "sqliteInt.h" @@ -194,12 +194,8 @@ void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){ } /* If we are rereading the sqlite_master table create the in-memory - ** record of the table. - ** - ** TODO: If the module is already registered, should we call xConnect() - ** here, or should it wait until the table is first referenced? Maybe - ** it's better to be lazy here, in case xConnect() is expensive to call - ** and the schema is reparsed a number of times. + ** record of the table. If the module has already been registered, + ** also call the xConnect method here. */ else { Table *pOld; diff --git a/test/vtab1.test b/test/vtab1.test index 4084650946..0b1a96022a 100644 --- a/test/vtab1.test +++ b/test/vtab1.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this file is creating and dropping virtual tables. # -# $Id: vtab1.test,v 1.15 2006/06/14 22:07:11 drh Exp $ +# $Id: vtab1.test,v 1.16 2006/06/15 07:29:01 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -36,9 +36,9 @@ ifcapable !vtab { # in that file for the special behaviour of the Tcl $echo_module variable. # # TODO: -# -# * How to test the sqlite3_index_constraint_usage.omit field? Or -# sqlite3_index_info.orderByConsumed? +# * How to test the sqlite3_index_constraint_usage.omit field? +# * vtab1-5.* +# * # @@ -404,4 +404,43 @@ do_test vtab1-4.4 { } [list xBestIndex {SELECT rowid, * FROM 'treal'} \ xFilter {SELECT rowid, * FROM 'treal'} ] +execsql { + DROP TABLE t1; + DROP TABLE treal; +} + +#---------------------------------------------------------------------- +# Test cases vtab1-6 test INSERT, UPDATE and DELETE operations +# on virtual tables. +do_test vtab1-6-1 { + execsql { SELECT sql FROM sqlite_master } +} {} +do_test vtab1-6-2 { + execsql { + CREATE TABLE treal(a PRIMARY KEY, b, c); + CREATE VIRTUAL TABLE techo USING echo(treal); + SELECT name FROM sqlite_master WHERE type = 'table'; + } +} {treal techo} +do_test vtab1-6-3 { + execsql { + INSERT INTO techo VALUES(1, 2, 3); + SELECT * FROM techo; + } +} {1 2 3} +do_test vtab1-6-4 { + execsql { + UPDATE techo SET a = 5; + SELECT * FROM techo; + } +} {5 2 3} +do_test vtab1-6-5 { + execsql { + DELETE FROM techo; + SELECT * FROM techo; + } +} {} +# check_echo_table vtab1-6.3 treal techo + finish_test +