/ Check-in [e3dd3651]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add a module-destructor to the echo module (test8.c) to improve code coverage. (CVS 4372)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e3dd3651421ee723f9b7550fc333a308a83b276d
User & Date: danielk1977 2007-09-03 11:51:50
Context
2007-09-03
12:34
Document the fact that xRandomness is only called once from the default VFS. Ticket #2614. (CVS 4373) check-in: e89d4131 user: drh tags: trunk
11:51
Add a module-destructor to the echo module (test8.c) to improve code coverage. (CVS 4372) check-in: e3dd3651 user: danielk1977 tags: trunk
11:04
Handle transient malloc() failures in sqlite3CreateFunc(). (CVS 4371) check-in: c0ce6319 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/test8.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Code for testing the virtual table interfaces.  This code
    13     13   ** is not included in the SQLite library.  It is used for automated
    14     14   ** testing of the SQLite library.
    15     15   **
    16         -** $Id: test8.c,v 1.55 2007/08/29 12:31:28 danielk1977 Exp $
           16  +** $Id: test8.c,v 1.56 2007/09/03 11:51:50 danielk1977 Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include "tcl.h"
    20     20   #include <stdlib.h>
    21     21   #include <string.h>
    22     22   
    23     23   #ifndef SQLITE_OMIT_VIRTUALTABLE
................................................................................
   345    345     sqlite3_free(p->zThis);
   346    346     sqlite3_free(p->zTableName);
   347    347     sqlite3_free(p->zLogName);
   348    348     sqlite3_free(p);
   349    349     return 0;
   350    350   }
   351    351   
          352  +typedef struct EchoModule EchoModule;
          353  +struct EchoModule {
          354  +  Tcl_Interp *interp;
          355  +};
          356  +
   352    357   /*
   353    358   ** This function is called to do the work of the xConnect() method -
   354    359   ** to allocate the required in-memory structures for a newly connected
   355    360   ** virtual table.
   356    361   */
   357    362   static int echoConstructor(
   358    363     sqlite3 *db,
................................................................................
   366    371     echo_vtab *pVtab;
   367    372   
   368    373     /* Allocate the sqlite3_vtab/echo_vtab structure itself */
   369    374     pVtab = sqlite3MallocZero( sizeof(*pVtab) );
   370    375     if( !pVtab ){
   371    376       return SQLITE_NOMEM;
   372    377     }
   373         -  pVtab->interp = (Tcl_Interp *)pAux;
          378  +  pVtab->interp = ((EchoModule *)pAux)->interp;
   374    379     pVtab->db = db;
   375    380   
   376    381     /* Allocate echo_vtab.zThis */
   377    382     pVtab->zThis = sqlite3MPrintf(0, "%s", argv[2]);
   378    383     if( !pVtab->zThis ){
   379    384       echoDestructor((sqlite3_vtab *)pVtab);
   380    385       return SQLITE_NOMEM;
................................................................................
   423    428     sqlite3 *db,
   424    429     void *pAux,
   425    430     int argc, const char *const*argv,
   426    431     sqlite3_vtab **ppVtab,
   427    432     char **pzErr
   428    433   ){
   429    434     int rc = SQLITE_OK;
   430         -  appendToEchoModule((Tcl_Interp *)(pAux), "xCreate");
          435  +  appendToEchoModule(((EchoModule *)pAux)->interp, "xCreate");
   431    436     rc = echoConstructor(db, pAux, argc, argv, ppVtab, pzErr);
   432    437   
   433    438     /* If there were two arguments passed to the module at the SQL level 
   434    439     ** (i.e. "CREATE VIRTUAL TABLE tbl USING echo(arg1, arg2)"), then 
   435    440     ** the second argument is used as a table name. Attempt to create
   436    441     ** such a table with a single column, "logmsg". This table will
   437    442     ** be used to log calls to the xUpdate method. It will be deleted
................................................................................
   458    463   static int echoConnect(
   459    464     sqlite3 *db,
   460    465     void *pAux,
   461    466     int argc, const char *const*argv,
   462    467     sqlite3_vtab **ppVtab,
   463    468     char **pzErr
   464    469   ){
   465         -  appendToEchoModule((Tcl_Interp *)(pAux), "xConnect");
          470  +  appendToEchoModule(((EchoModule *)pAux)->interp, "xConnect");
   466    471     return echoConstructor(db, pAux, argc, argv, ppVtab, pzErr);
   467    472   }
   468    473   
   469    474   /* 
   470    475   ** Echo virtual table module xDisconnect method.
   471    476   */
   472    477   static int echoDisconnect(sqlite3_vtab *pVtab){
................................................................................
  1120   1125   /*
  1121   1126   ** Decode a pointer to an sqlite3 object.
  1122   1127   */
  1123   1128   static int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb){
  1124   1129     *ppDb = (sqlite3*)sqlite3TextToPtr(zA);
  1125   1130     return TCL_OK;
  1126   1131   }
         1132  +
         1133  +static void moduleDestroy(void *p){
         1134  +  sqlite3_free(p);
         1135  +}
  1127   1136   
  1128   1137   /*
  1129   1138   ** Register the echo virtual table module.
  1130   1139   */
  1131   1140   static int register_echo_module(
  1132   1141     ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
  1133   1142     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
  1134   1143     int objc,              /* Number of arguments */
  1135   1144     Tcl_Obj *CONST objv[]  /* Command arguments */
  1136   1145   ){
  1137   1146     sqlite3 *db;
         1147  +  EchoModule *pMod;
  1138   1148     if( objc!=2 ){
  1139   1149       Tcl_WrongNumArgs(interp, 1, objv, "DB");
  1140   1150       return TCL_ERROR;
  1141   1151     }
  1142   1152     if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
  1143         -  sqlite3_create_module(db, "echo", &echoModule, (void *)interp);
         1153  +  pMod = sqlite3_malloc(sizeof(EchoModule));
         1154  +  pMod->interp = interp;
         1155  +  sqlite3_create_module_v2(db, "echo", &echoModule, (void*)pMod, moduleDestroy);
  1144   1156     return TCL_OK;
  1145   1157   }
  1146   1158   
  1147   1159   /*
  1148   1160   ** Tcl interface to sqlite3_declare_vtab, invoked as follows from Tcl:
  1149   1161   **
  1150   1162   ** sqlite3_declare_vtab DB SQL