]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Progress toward getting the virtual-table code generator to work. (CVS 3220)
authordrh <drh@noemail.net>
Tue, 13 Jun 2006 01:04:52 +0000 (01:04 +0000)
committerdrh <drh@noemail.net>
Tue, 13 Jun 2006 01:04:52 +0000 (01:04 +0000)
FossilOrigin-Name: 3532f1340f939b0231c1d82a7b2d186cb096fb29

manifest
manifest.uuid
src/expr.c
src/sqlite.h.in
src/test8.c
src/vdbe.h
src/vdbeaux.c
src/where.c

index 08d7532f242976f63d99054db266c0aaabb5cb42..854df9be6e071e58d28425705b03beef90457d90 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Added\scode\sto\siterate\sthrough\svirtual\stables.\s\sAll\sregression\stests\spass\nbut\sthe\snew\scode\sis\scompletely\suntested.\s(CVS\s3219)
-D 2006-06-12T21:59:14
+C Progress\stoward\sgetting\sthe\svirtual-table\scode\sgenerator\sto\swork.\s(CVS\s3220)
+D 2006-06-13T01:04:52
 F Makefile.in 56fd6261e83f60724e6dcd764e06ab68cbd53909
 F Makefile.linux-gcc 74ba0eadf88748a9ce3fd03d2a3ede2e6715baec
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -42,7 +42,7 @@ F src/complete.c 7d1a44be8f37de125fcafd3d3a018690b3799675
 F src/date.c cd2bd5d1ebc6fa12d6312f69789ae5b0a2766f2e
 F src/delete.c f9a8c7837adb4bb4810a698a041a88d5ec7bfa9a
 F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b
-F src/expr.c 3ea9b26c6cdb7bcf0715c1b6aa0f7f5e813f61eb
+F src/expr.c 896f642936e9248b50c1449fd4b3924bcb149632
 F src/func.c acbbf533b55221f26760798d99b37de3ac5678fe
 F src/hash.c 449f3d6620193aa557f5d86cbc5cc6b87702b185
 F src/hash.h 1b3f7e2609141fd571f62199fc38687d262e9564
@@ -72,7 +72,7 @@ F src/random.c d40f8d356cecbd351ccfab6eaedd7ec1b54f5261
 F src/select.c 38eda11d950ed5e631ea9054f84a4a8b9e9b39d8
 F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
 F src/shell.c 55bf6335dae7146f7a300039f5d6bb35010f1996
-F src/sqlite.h.in 251b584d707939b38663f5ad9a1a1815d6cce9fb
+F src/sqlite.h.in 6fb7062da7e9c446623fa26b042bcf4b4050d702
 F src/sqlite3ext.h 127bd394c8eea481f2ac9b754bf399dbfc818b75
 F src/sqliteInt.h 9562411b336b77123d1f569d4144fe3ba1ecb3bf
 F src/table.c f64ec4fbfe333f8df925bc6ba494f55e05b0e75e
@@ -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 9bfd5b76f7694d4bc8318bf73d7bc1b607b49886
+F src/test8.c 2a8676c42f20a34371244259a0bfad7a1dbfc419
 F src/test_async.c e3deaedd4d86a56391b81808fde9e44fbd92f1d3
 F src/test_md5.c 6c42bc0a3c0b54be34623ff77a0eec32b2fa96e3
 F src/test_server.c a6460daed0b92ecbc2531b6dc73717470e7a648c
@@ -95,14 +95,14 @@ F src/utf.c ab81ac59084ff1c07d421eb1a0a84ec809603b44
 F src/util.c ca6ee72772c0f5dc04d2e0ab1973fd3b6a9bf79d
 F src/vacuum.c 5b37d0f436f8e1ffacd17934e44720b38d2247f9
 F src/vdbe.c 59cb0d8cd19f090061f41715c44b3ed2af6bf264
-F src/vdbe.h 190d85a37658c2397be75a4c70bbc02ebc4ec0ba
+F src/vdbe.h f72e5c00af759b7ed6fd606d508036d732098cc3
 F src/vdbeInt.h 6ccb7eaae76ebd761470f6a035501ff33aa92c20
 F src/vdbeapi.c 7dc662e7c905ce666bb506dced932e0307115cbf
-F src/vdbeaux.c 60f84a2da6032a6fffa47ed623279b7dee25223b
+F src/vdbeaux.c bcad5264196266118eb4ed0b2db3829fe335a67d
 F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5
 F src/vdbemem.c 5f0afe3b92bb2c037f8d5d697f7c151fa50783a3
 F src/vtab.c 4ec6ac7e5e4fccb38401285d0e329d018622859f
-F src/where.c d312cf79d42e82cec5bddfa23f42bea6e65b4052
+F src/where.c c0f3cd3831cd9defb7c7788038d439a5922e7bd6
 F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/all.test 5df90d015ca63fcef2a4b62c24f7316b66c4bfd4
@@ -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 f0c7c8d12c04376e48c6d53a29cfae3fa13b52cf
-R 24b1712dc081e34b63297df85eac34f4
+P 010965433140fbe508a907d861dbad79343bf7c2
+R 764c40e62a8b536cdb57327045ebbc4d
 U drh
-Z 61dbf9364ee86b719872c787076d19e0
+Z b3815508f49a0543b1d64dd34c187512
index afae5c32b42cac573f6c48d5b6459a9f5b4aac35..e2e3a6310278ec6580ba26de638e4b192638215b 100644 (file)
@@ -1 +1 @@
-010965433140fbe508a907d861dbad79343bf7c2
\ No newline at end of file
+3532f1340f939b0231c1d82a7b2d186cb096fb29
\ No newline at end of file
index 5a721ab8541ef752f831bceed5ecaa09a0fc1c27..94eb8ec3521fb972a44ff3b1e31bdc274cb14a8f 100644 (file)
@@ -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.259 2006/06/11 23:41:55 drh Exp $
+** $Id: expr.c,v 1.260 2006/06/13 01:04:52 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -1489,7 +1489,8 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
       }else if( pExpr->iColumn>=0 ){
         Table *pTab = pExpr->pTab;
         int iCol = pExpr->iColumn;
-        sqlite3VdbeAddOp(v, OP_Column, pExpr->iTable, iCol);
+        sqlite3VdbeAddOp(v, pTab->isVirtual ? OP_VColumn : OP_Column,
+                            pExpr->iTable, iCol);
         sqlite3ColumnDefault(v, pTab, iCol);
 #ifndef SQLITE_OMIT_FLOATING_POINT
         if( pTab && pTab->aCol[iCol].affinity==SQLITE_AFF_REAL ){
@@ -1497,7 +1498,8 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
         }
 #endif
       }else{
-        sqlite3VdbeAddOp(v, OP_Rowid, pExpr->iTable, 0);
+        sqlite3VdbeAddOp(v, pExpr->pTab->isVirtual ? OP_VRowid : OP_Rowid,
+                         pExpr->iTable, 0);
       }
       break;
     }
index f07b4603c4dcdd6357cd7559bc29b1752c608bc5..3d67cb9d5675477083b8faef2227635e93c9adb5 100644 (file)
@@ -12,7 +12,7 @@
 ** This header file defines the interface that the SQLite library
 ** presents to client programs.
 **
-** @(#) $Id: sqlite.h.in,v 1.170 2006/06/12 21:59:14 drh Exp $
+** @(#) $Id: sqlite.h.in,v 1.171 2006/06/13 01:04:53 drh Exp $
 */
 #ifndef _SQLITE3_H_
 #define _SQLITE3_H_
@@ -1657,7 +1657,7 @@ int sqlite3_create_module(
 ** to all module implementations.
 */
 struct sqlite3_vtab {
-  sqlite3_module *pModule;  /* The module for this virtual table */
+  const sqlite3_module *pModule;  /* The module for this virtual table */
   /* Virtual table implementations will typically add additional fields */
 };
 
index a444bf1b8bb5c715300f1e30ef6dcd7dc19c9972..29402f5626152fa663bd6cfd162f9a6554c63785 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.5 2006/06/12 12:50:23 drh Exp $
+** $Id: test8.c,v 1.6 2006/06/13 01:04:53 drh Exp $
 */
 #include "sqliteInt.h"
 #include "tcl.h"
 ** Global Tcl variable $echo_module is a list. This routine appends
 ** the string element zArg to that list in interpreter interp.
 */
-static void appendToEchoModule(const sqlite3_module *pModule, const char *zArg){
+static void appendToEchoModule(Tcl_Interp *interp, const char *zArg){
   int flags = (TCL_APPEND_VALUE | TCL_LIST_ELEMENT | TCL_GLOBAL_ONLY);
-  Tcl_SetVar((Tcl_Interp *)(pModule->pAux), "echo_module", zArg, flags);
+  Tcl_SetVar(interp, "echo_module", zArg, flags);
 }
 
-static void appendToEchoTable(const sqlite3_vtab *pTab, const char *zArg){
+static void appendToEchoTable(Tcl_Interp *interp, const char *zArg){
   int flags = (TCL_APPEND_VALUE | TCL_LIST_ELEMENT | TCL_GLOBAL_ONLY);
-  Tcl_SetVar((Tcl_Interp *)(pTab), "echo_module", zArg, flags);
+  Tcl_SetVar(interp, "echo_module", zArg, flags);
 }
 
 /*
@@ -75,6 +75,13 @@ static int echoDeclareVtab(sqlite3 *db, int argc, char **argv){
   return rc;
 }
 
+/* An echo vtab object */
+typedef struct echo_vtab echo_vtab;
+struct echo_vtab {
+  sqlite3_vtab base;
+  Tcl_Interp *interp;
+};
+
 /* Methods for the echo module */
 static int echoCreate(
   sqlite3 *db,
@@ -83,11 +90,15 @@ static int echoCreate(
   sqlite3_vtab **ppVtab
 ){
   int i;
-  *ppVtab = pModule->pAux;
+  echo_vtab *pVtab;
 
-  appendToEchoModule(pModule, "xCreate");
+  pVtab = sqliteMalloc( sizeof(*pVtab) );
+  *ppVtab = &pVtab->base;
+  pVtab->base.pModule = pModule;
+  pVtab->interp = pModule->pAux;
+  appendToEchoModule(pVtab->interp, "xCreate");
   for(i=0; i<argc; i++){
-    appendToEchoModule(pModule, argv[i]);
+    appendToEchoModule(pVtab->interp, argv[i]);
   }
 
   echoDeclareVtab(db, argc, argv);
@@ -101,8 +112,12 @@ static int echoConnect(
 ){
   int i;
   Tcl_Interp *interp = pModule->pAux;
-  *ppVtab = pModule->pAux;
+  echo_vtab *pVtab;
 
+  pVtab = sqliteMalloc( sizeof(*pVtab) );
+  *ppVtab = &pVtab->base;
+  pVtab->base.pModule = pModule;
+  pVtab->interp = pModule->pAux;
   Tcl_SetVar(interp, "echo_module", "xConnect", TCL_GLOBAL_ONLY);
   for(i=0; i<argc; i++){
     Tcl_SetVar(interp, "echo_module", argv[i],
@@ -113,16 +128,27 @@ static int echoConnect(
   return 0;
 }
 static int echoDisconnect(sqlite3_vtab *pVtab){
-  appendToEchoTable(pVtab, "xDisconnect");
+  echo_vtab *p = (echo_vtab*)pVtab;
+  appendToEchoTable(p->interp, "xDisconnect");
+  sqliteFree(pVtab);
   return 0;
 }
 static int echoDestroy(sqlite3_vtab *pVtab){
-  Tcl_Interp *interp = (Tcl_Interp*)pVtab;
-  Tcl_SetVar(interp, "echo_module", "xDestroy",
+  echo_vtab *p = (echo_vtab*)pVtab;
+  Tcl_SetVar(p->interp, "echo_module", "xDestroy",
                 TCL_APPEND_VALUE | TCL_LIST_ELEMENT | TCL_GLOBAL_ONLY);
   return 0;
 }
 
+/*
+** The xBestIndex method for the echo module always returns
+** an index of 123.
+*/
+static int echoBestIndex(sqlite3_vtab *pVtab, sqlite3_index_info *pIdxInfo){
+  pIdxInfo->idxNum = 123;
+  return SQLITE_OK;
+}
+
 /*
 ** A virtual table module that merely echos method calls into TCL
 ** variables.
@@ -133,7 +159,7 @@ static sqlite3_module echoModule = {
   0,                         /* pAux */
   echoCreate,
   echoConnect,
-  0,                         /* xBestIndex */
+  echoBestIndex,
   echoDisconnect, 
   echoDestroy,
 };
index 3097022f62c708f8980b0a7982e1964965037649..713d0f18b4112e99e6e831c097d551356bab6eb9 100644 (file)
@@ -15,7 +15,7 @@
 ** or VDBE.  The VDBE implements an abstract machine that runs a
 ** simple program to access and modify the underlying database.
 **
-** $Id: vdbe.h,v 1.103 2006/06/11 23:41:56 drh Exp $
+** $Id: vdbe.h,v 1.104 2006/06/13 01:04:53 drh Exp $
 */
 #ifndef _SQLITE_VDBE_H_
 #define _SQLITE_VDBE_H_
@@ -70,6 +70,7 @@ typedef struct VdbeOpList VdbeOpList;
 #define P3_VDBEFUNC (-7)  /* P3 is a pointer to a VdbeFunc structure */
 #define P3_MEM      (-8)  /* P3 is a pointer to a Mem*    structure */
 #define P3_TRANSIENT (-9) /* P3 is a pointer to a transient string */
+#define P3_VTAB     (-10) /* P3 is a pointer to an sqlite3_vtab structure */
 
 /* When adding a P3 argument using P3_KEYINFO, a copy of the KeyInfo structure
 ** is made.  That copy is freed when the Vdbe is finalized.  But if the
index cab259f05f77df8054ad1c0d9860b188f9d4d2eb..8b5f66c62435228f64b77d840e3a1fde1a11cd92 100644 (file)
@@ -558,15 +558,18 @@ static char *displayP3(Op *pOp, char *zTemp, int nTemp){
     }
     case P3_FUNCDEF: {
       FuncDef *pDef = (FuncDef*)pOp->p3;
-      char zNum[30];
-      sprintf(zTemp, "%.*s", nTemp, pDef->zName);
-      sprintf(zNum,"(%d)", pDef->nArg);
-      if( strlen(zTemp)+strlen(zNum)+1<=nTemp ){
-        strcat(zTemp, zNum);
-      }
+      sqlite3_snprintf(nTemp, zTemp, "%s(%d)", pDef->zName, pDef->nArg);
+      zP3 = zTemp;
+      break;
+    }
+#ifndef SQLITE_OMIT_VIRTUALTABLE
+    case P3_VTAB: {
+      sqlite3_vtab *pVtab = (sqlite3_vtab*)pOp->p3;
+      sqlite3_snprintf(nTemp, zTemp, "%p:%s", pVtab, pVtab->pModule->zName);
       zP3 = zTemp;
       break;
     }
+#endif
     default: {
       zP3 = pOp->p3;
       if( zP3==0 || pOp->opcode==OP_Noop ){
index ac806208791e8991d5ba9bf50dabdf82d3ae04ef..764b32a98de3c87fb9103d23a2134c24b1481796 100644 (file)
@@ -16,7 +16,7 @@
 ** so is applicable.  Because this module is responsible for selecting
 ** indices, you might also think of this module as the "query optimizer".
 **
-** $Id: where.c,v 1.211 2006/06/12 21:59:14 drh Exp $
+** $Id: where.c,v 1.212 2006/06/13 01:04:53 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -1010,10 +1010,10 @@ static double bestVirtualIndex(
   pIdxInfo->estimatedCost = SQLITE_BIG_DBL;
   nOrderBy = pIdxInfo->nOrderBy;
   if( pIdxInfo->nOrderBy && !orderByUsable ){
-    *(int*)pIdxInfo->nOrderBy = 0;
+    *(int*)&pIdxInfo->nOrderBy = 0;
   }
   pTab->pVtab->pModule->xBestIndex(pTab->pVtab, pIdxInfo);
-  *(int*)pIdxInfo->nOrderBy = nOrderBy;
+  *(int*)&pIdxInfo->nOrderBy = nOrderBy;
   return pIdxInfo->estimatedCost;
 }
 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -1770,7 +1770,7 @@ WhereInfo *sqlite3WhereBegin(
     if( pTab->isEphem || pTab->pSelect ) continue;
 #ifndef SQLITE_OMIT_VIRTUALTABLE
     if( pLevel->pIdxInfo ){
-      sqlite3VdbeAddOp(v, OP_VOpen, 0, 0);  /***** Fix Me *****/
+      sqlite3VdbeOp3(v, OP_VOpen, 0, 0, (const char*)pTab->pVtab, P3_VTAB);
     }else
 #endif
     if( (pLevel->flags & WHERE_IDX_ONLY)==0 ){
@@ -1855,16 +1855,17 @@ WhereInfo *sqlite3WhereBegin(
         }
         if( j==pIdxInfo->nConstraint ) break;
       }
-      sqlite3VdbeAddOp(v, OP_VFilter, iCur, pIdxInfo->idxNum);
-      if( i>1 ){
-        sqlite3VdbeAddOp(v, OP_Pop, i-1, 0);
-      }
+      sqlite3VdbeAddOp(v, OP_Integer, i-1, 0);
+      sqlite3VdbeAddOp(v, OP_Integer, pIdxInfo->idxNum, 0);
+      sqlite3VdbeAddOp(v, OP_VFilter, iCur, brk);
       for(i=0; i<pIdxInfo->nConstraint; i++){
         if( pIdxInfo->aConstraintUsage[i].omit ){
           disableTerm(pLevel, &wc.a[i]);
         }
       }
       pLevel->op = OP_VNext;
+      pLevel->p1 = iCur;
+      pLevel->p2 = sqlite3VdbeCurrentAddr(v);
     }else
 #endif /* SQLITE_OMIT_VIRTUALTABLE */