/ Check-in [b9c4aa52]
Login

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

Overview
Comment:Add extra debugging function to test_rbu.c. Enhance the documentation for sqlite3rbu_db() to define the validity of the returned database handles.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b9c4aa521156d8ca09151a82a7e80aa8d1d7a313
User & Date: dan 2015-10-21 08:26:01
Context
2015-10-21
20:07
Minor optimization for fts5 queries. check-in: 363b36d5 user: dan tags: trunk
08:26
Add extra debugging function to test_rbu.c. Enhance the documentation for sqlite3rbu_db() to define the validity of the returned database handles. check-in: b9c4aa52 user: dan tags: trunk
2015-10-20
23:27
Fix harmless compiler warnings in FTS5. check-in: 0a903ec2 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/rbu/sqlite3rbu.h.

   337    337   **   * If the application uses the "rbu_delta()" feature described above,
   338    338   **     it must use sqlite3_create_function() or similar to register the
   339    339   **     rbu_delta() implementation with the target database handle.
   340    340   **
   341    341   ** If an error has occurred, either while opening or stepping the RBU object,
   342    342   ** this function may return NULL. The error code and message may be collected
   343    343   ** when sqlite3rbu_close() is called.
          344  +**
          345  +** Database handles returned by this function remain valid until the next
          346  +** call to any sqlite3rbu_xxx() function other than sqlite3rbu_db().
   344    347   */
   345    348   sqlite3 *sqlite3rbu_db(sqlite3rbu*, int bRbu);
   346    349   
   347    350   /*
   348    351   ** Do some work towards applying the RBU update to the target db. 
   349    352   **
   350    353   ** Return SQLITE_DONE if the update has been completely applied, or 

Changes to ext/rbu/test_rbu.c.

    52     52     ClientData clientData,
    53     53     Tcl_Interp *interp,
    54     54     int objc,
    55     55     Tcl_Obj *CONST objv[]
    56     56   ){
    57     57     int ret = TCL_OK;
    58     58     sqlite3rbu *pRbu = (sqlite3rbu*)clientData;
    59         -  const char *azMethod[] = { 
    60         -    "step", "close", "create_rbu_delta", "savestate", 0 
           59  +  struct RbuCmd {
           60  +    const char *zName;
           61  +    int nArg;
           62  +    const char *zUsage;
           63  +  } aCmd[] = {
           64  +    {"step", 2, ""},              /* 0 */
           65  +    {"close", 2, ""},             /* 1 */
           66  +    {"create_rbu_delta", 2, ""},  /* 2 */
           67  +    {"savestate", 2, ""},         /* 3 */
           68  +    {"dbMain_eval", 3, "SQL"},    /* 4 */
           69  +    {0,0,0}
    61     70     };
    62         -  int iMethod;
           71  +  int iCmd;
    63     72   
    64         -  if( objc!=2 ){
           73  +  if( objc<2 ){
    65     74       Tcl_WrongNumArgs(interp, 1, objv, "METHOD");
    66     75       return TCL_ERROR;
    67     76     }
    68         -  if( Tcl_GetIndexFromObj(interp, objv[1], azMethod, "method", 0, &iMethod) ){
           77  +  ret = Tcl_GetIndexFromObjStruct(
           78  +      interp, objv[1], aCmd, sizeof(aCmd[0]), "method", 0, &iCmd
           79  +  );
           80  +  if( ret ) return TCL_ERROR;
           81  +  if( objc!=aCmd[iCmd].nArg ){
           82  +    Tcl_WrongNumArgs(interp, 1, objv, aCmd[iCmd].zUsage);
    69     83       return TCL_ERROR;
    70     84     }
    71     85   
    72         -  switch( iMethod ){
           86  +  switch( iCmd ){
    73     87       case 0: /* step */ {
    74     88         int rc = sqlite3rbu_step(pRbu);
    75     89         Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1));
    76     90         break;
    77     91       }
    78     92   
    79     93       case 1: /* close */ {
................................................................................
   107    121   
   108    122       case 3: /* savestate */ {
   109    123         int rc = sqlite3rbu_savestate(pRbu);
   110    124         Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1));
   111    125         ret = (rc==SQLITE_OK ? TCL_OK : TCL_ERROR);
   112    126         break;
   113    127       }
          128  +
          129  +    case 4: /* dbMain_eval */ {
          130  +      sqlite3 *db = sqlite3rbu_db(pRbu, 0);
          131  +      int rc = sqlite3_exec(db, Tcl_GetString(objv[2]), 0, 0, 0);
          132  +      if( rc!=SQLITE_OK ){
          133  +        Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3_errmsg(db), -1));
          134  +        ret = TCL_ERROR;
          135  +      }
          136  +      break;
          137  +    }
   114    138   
   115    139       default: /* seems unlikely */
   116    140         assert( !"cannot happen" );
   117    141         break;
   118    142     }
   119    143   
   120    144     return ret;