]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add a simple test case (and corresponding bugfix) for the virtual table xConnect...
authordanielk1977 <danielk1977@noemail.net>
Mon, 12 Jun 2006 12:08:45 +0000 (12:08 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Mon, 12 Jun 2006 12:08:45 +0000 (12:08 +0000)
FossilOrigin-Name: b63dbc794795533f0bfd2d8e25633e6e3dea3ebd

manifest
manifest.uuid
src/build.c
src/sqliteInt.h
src/test8.c
src/vtab.c
test/vtab1.test

index 06fbfbb137e3c9c222f6742726f300f36a829d43..0124af56f6172e6f5d859de87c7c04ae298d5534 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\sfirst\scut\sof\ssqlite3_declare_vtab().\sNot\sat\sall\swell\stested\syet.\s(CVS\s3213)
-D 2006-06-12T11:24:37
+C Add\sa\ssimple\stest\scase\s(and\scorresponding\sbugfix)\sfor\sthe\svirtual\stable\sxConnect\sand\sxDisconnect\smethods.\s(CVS\s3214)
+D 2006-06-12T12:08:45
 F Makefile.in 56fd6261e83f60724e6dcd764e06ab68cbd53909
 F Makefile.linux-gcc 74ba0eadf88748a9ce3fd03d2a3ede2e6715baec
 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 a72a709541c62402665e053e2e173dfdc62ce049
+F src/build.c 0781f85451caefe6419eaa8d04b65fd3150cef2c
 F src/callback.c fd9bb39f7ff6b52bad8365617abc61c720640429
 F src/complete.c 7d1a44be8f37de125fcafd3d3a018690b3799675
 F src/date.c cd2bd5d1ebc6fa12d6312f69789ae5b0a2766f2e
@@ -74,7 +74,7 @@ F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
 F src/shell.c b9eb3ed4d3ab41fbf630eabb602f3c9d20fc737a
 F src/sqlite.h.in cad97e59cfad8337f9f43ea9662714a256ca80b2
 F src/sqlite3ext.h 127bd394c8eea481f2ac9b754bf399dbfc818b75
-F src/sqliteInt.h ef7b936e38858c98c35ab3cad55eea0859c64a94
+F src/sqliteInt.h b77822681ec59f3ec57b921a1d8c1b47a8c3e18f
 F src/table.c f64ec4fbfe333f8df925bc6ba494f55e05b0e75e
 F src/tclsqlite.c 0b2a04cfc1b4298adfbe90a754cfbbe207aca11a
 F src/test1.c 88291fa6674dcd409b1c9d76d3119151d4b81a50
@@ -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 9eb1d2e41b81df15952ee8ee54f95fa214f8813e
+F src/test8.c d25e2c7be5e5bbc8c3343fec186e0c95255beb74
 F src/test_async.c e3deaedd4d86a56391b81808fde9e44fbd92f1d3
 F src/test_md5.c 6c42bc0a3c0b54be34623ff77a0eec32b2fa96e3
 F src/test_server.c a6460daed0b92ecbc2531b6dc73717470e7a648c
@@ -101,7 +101,7 @@ F src/vdbeapi.c 7dc662e7c905ce666bb506dced932e0307115cbf
 F src/vdbeaux.c 4002e6b19d7c9719cb81f9797316b9ad118e4370
 F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5
 F src/vdbemem.c 5f0afe3b92bb2c037f8d5d697f7c151fa50783a3
-F src/vtab.c 36778506d9af9b750e01eeea1e116f3c80b7fa01
+F src/vtab.c 430228a2c920138d528e9937b3123bedffeb10b6
 F src/where.c 3dc5269ba552c0db39247f6bbc98b312ae786863
 F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
@@ -287,7 +287,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 5c7f4a2a53f3894d571239099c0253e27263cc84
+F test/vtab1.test abc34e3ac745871be2ff77adb8f37f7868cee4a8
 F test/where.test ee7c9a6659b07e1ee61177f6e7ff71565ee2c9df
 F test/where2.test a16476a5913e75cf65b38f2daa6157a6b7791394
 F test/where3.test 3b5ad2c58069e12be2bd86bc5e211a82810521aa
@@ -363,7 +363,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 8ffbab79d5a76dea0f87cf551d5b6ad4f0fab337
-R 26c5c53e0c5dda8d367ac8454cb93c3e
+P bbeb93b5bb26ba83ee7b7ae439ca5ceebebac9a0
+R 3b9e31b36c1dc9a00f3889f306c0ed70
 U danielk1977
-Z dfbf7809fd6098db180fe009efbe7300
+Z 1c8aff829bac0910b18af9a0b5f547ac
index 4d6107d6e8b8fd9c4a260e4b80f4fef5fff78d6f..df5b779dee8b13f7efe469e137e7da3399236eb1 100644 (file)
@@ -1 +1 @@
-bbeb93b5bb26ba83ee7b7ae439ca5ceebebac9a0
\ No newline at end of file
+b63dbc794795533f0bfd2d8e25633e6e3dea3ebd
\ No newline at end of file
index b9fa185d59c0cccc894cef675e787c73eee768ad..271e2a6b59ab08d16cfaedfad9be8539d234cca8 100644 (file)
@@ -22,7 +22,7 @@
 **     COMMIT
 **     ROLLBACK
 **
-** $Id: build.c,v 1.397 2006/06/12 11:24:37 danielk1977 Exp $
+** $Id: build.c,v 1.398 2006/06/12 12:08:45 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -1637,7 +1637,7 @@ void sqlite3CreateView(
 }
 #endif /* SQLITE_OMIT_VIEW */
 
-#ifndef SQLITE_OMIT_VIEW
+#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
 /*
 ** The Table structure pTable is really a VIEW.  Fill in the names of
 ** the columns of the view in the pTable structure.  Return the number
@@ -1651,13 +1651,18 @@ int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
 
   assert( pTable );
 
+#ifndef SQLITE_OMIT_VIRTUALTABLE
+  if( sqlite3VtabCallConnect(pParse, pTable) ){
+    return SQLITE_ERROR;
+  }
+  if( pTable->isVirtual ) return 0;
+#endif
+
+#ifndef SQLITE_OMIT_VIEW
   /* A positive nCol means the columns names for this view are
   ** already known.
   */
   if( pTable->nCol>0 ) return 0;
-#ifndef SQLITE_OMIT_VIRTUALTABLE
-  if( pTable->isVirtual ) return 0;
-#endif
 
   /* A negative nCol is a special marker meaning that we are currently
   ** trying to compute the column names.  If we enter this routine with
@@ -1707,8 +1712,9 @@ int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
     nErr++;
   }
   return nErr;  
-}
 #endif /* SQLITE_OMIT_VIEW */
+}
+#endif /* !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) */
 
 #ifndef SQLITE_OMIT_VIEW
 /*
index efd588b346bcf055ba28f4a0ba5eefa11dc02b6e..6edf1e7b429dfa02b809d76b08d2d4458f6101a8 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** Internal interface definitions for SQLite.
 **
-** @(#) $Id: sqliteInt.h,v 1.499 2006/06/12 11:24:37 danielk1977 Exp $
+** @(#) $Id: sqliteInt.h,v 1.500 2006/06/12 12:08:45 danielk1977 Exp $
 */
 #ifndef _SQLITEINT_H_
 #define _SQLITEINT_H_
@@ -1547,8 +1547,9 @@ void sqlite3AddDefaultValue(Parse*,Expr*);
 void sqlite3AddCollateType(Parse*, const char*, int);
 void sqlite3EndTable(Parse*,Token*,Token*,Select*);
 
-#ifndef SQLITE_OMIT_VIEW
-  void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int);
+void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int);
+
+#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
   int sqlite3ViewGetColumnNames(Parse*,Table*);
 #else
 # define sqlite3ViewGetColumnNames(A,B) 0
index b976f84e39cf0486e1a4656e8f82f4da12afb19b..c55f5ccaa13b264ba50c352e0799a8c7b23fccb5 100644 (file)
@@ -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.3 2006/06/12 11:24:37 danielk1977 Exp $
+** $Id: test8.c,v 1.4 2006/06/12 12:08:45 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "tcl.h"
@@ -30,6 +30,11 @@ static void appendToEchoModule(const sqlite3_module *pModule, const char *zArg){
   Tcl_SetVar((Tcl_Interp *)(pModule->pAux), "echo_module", zArg, flags);
 }
 
+static void appendToEchoTable(const sqlite3_vtab *pTab, const char *zArg){
+  int flags = (TCL_APPEND_VALUE | TCL_LIST_ELEMENT | TCL_GLOBAL_ONLY);
+  Tcl_SetVar((Tcl_Interp *)(pTab), "echo_module", zArg, flags);
+}
+
 /*
 ** This function is called from within the echo-modules xCreate and
 ** xConnect methods. The argc and argv arguments are copies of those 
@@ -106,9 +111,7 @@ static int echoConnect(
   return 0;
 }
 static int echoDisconnect(sqlite3_vtab *pVtab){
-  Tcl_Interp *interp = (Tcl_Interp*)pVtab;
-  Tcl_SetVar(interp, "echo_module", "xDisconnect",
-                TCL_APPEND_VALUE | TCL_LIST_ELEMENT | TCL_GLOBAL_ONLY);
+  appendToEchoTable(pVtab, "xDisconnect");
   return 0;
 }
 static int echoDestroy(sqlite3_vtab *pVtab){
index ae7b7930fc1bb3a598cf206ce72e65538a056318..457845c4d462d8fc1bdf29a673dda95557982788 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** This file contains code used to help implement virtual tables.
 **
-** $Id: vtab.c,v 1.3 2006/06/12 11:24:37 danielk1977 Exp $
+** $Id: vtab.c,v 1.4 2006/06/12 12:08:45 danielk1977 Exp $
 */
 #ifndef SQLITE_OMIT_VIRTUALTABLE
 #include "sqliteInt.h"
@@ -186,7 +186,7 @@ void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){
   ** 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
+  ** 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.
   */
@@ -236,16 +236,17 @@ void sqlite3VtabArgExtend(Parse *pParse, Token *p){
 
 /*
 ** This function is invoked by the parser to call the xConnect() method
-** of table pTab. If an error occurs, an error code is returned and an error
-** left in pParse.
+** of the virtual table pTab. If an error occurs, an error code is returned 
+** and an error left in pParse.
+**
+** This call is a no-op if table pTab is not a virtual table.
 */
 int sqlite3VtabCallConnect(Parse *pParse, Table *pTab){
   sqlite3_module *pModule;
   const char *zModule;
   int rc = SQLITE_OK;
 
-  assert(pTab && pTab->isVirtual);
-  if( pTab->pVtab ){
+  if( !pTab || !pTab->isVirtual || pTab->pVtab ){
     return SQLITE_OK;
   }
 
@@ -258,18 +259,29 @@ int sqlite3VtabCallConnect(Parse *pParse, Table *pTab){
   } else {
     char **azArg = pTab->azModuleArg;
     int nArg = pTab->nModuleArg;
-    assert( !pParse->db->pVTab );
-    pParse->db->pVTab = pTab;
-    rc = pModule->xConnect(pParse->db, pModule, nArg, azArg, &pTab->pVtab);
-    pParse->db->pVTab = 0;
+    sqlite3 *db = pParse->db;
+    assert( !db->pVTab );
+    db->pVTab = pTab;
+    rc = sqlite3SafetyOff(db);
+    assert( rc==SQLITE_OK );
+    rc = pModule->xConnect(db, pModule, nArg, azArg, &pTab->pVtab);
+    db->pVTab = 0;
     if( rc ){
       sqlite3ErrorMsg(pParse, "module connect failed: %s", zModule);
+      sqlite3SafetyOn(db);
+    } else {
+      rc = sqlite3SafetyOn(db);
     }
   }
 
   return rc;
 }
 
+/*
+** This function is used to set the schema of a virtual table.  It is only
+** valid to call this function from within the xCreate() or xConnect() of a
+** virtual table module.
+*/
 int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
   Parse sParse;
 
index b0210f09d2e4a6c005ffeeba543826ebfadb5240..31f6ea8233447a88f671282cd619ce869968e53c 100644 (file)
@@ -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.3 2006/06/12 11:24:38 danielk1977 Exp $
+# $Id: vtab1.test,v 1.4 2006/06/12 12:08:45 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -74,5 +74,25 @@ do_test vtab1-2.2 {
   2 c {} 0 {} 0 \
 ]
 
+# Test that the database can be unloaded. This should invoke 
+# the xDisconnect() callback each of the two virtual tables - t1 and t2.
+do_test vtab1-2.3 {
+  set echo_module [list]
+  db close
+  set echo_module
+} [list xDisconnect xDisconnect]
+
+# Re-open the database. Check that the schema of the virtual
+# table is still correct.
+do_test vtab1-2.4 {
+  sqlite3 db test.db
+  register_echo_module [sqlite3_connection_pointer db]
+  execsql { PRAGMA table_info(t2); }
+} [list         \
+  0 a {} 0 {} 0 \
+  1 b {} 0 {} 0 \
+  2 c {} 0 {} 0 \
+]
+
 finish_test