/ Check-in [088c5903]
Login

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

Overview
Comment:Add a prototype of the sqlite3_kv_reset() interface.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | sqlite3_kv
Files: files | file ages | folders
SHA1: 088c590379f844c1443b0ccdf8695f1506584451
User & Date: drh 2017-01-19 12:07:08
Context
2017-01-19
12:07
Add a prototype of the sqlite3_kv_reset() interface. Leaf check-in: 088c5903 user: drh tags: sqlite3_kv
2017-01-18
19:54
Begin fleshing out the key/value accessor implementation. This is an incremental check-in. check-in: 02d60e19 user: drh tags: sqlite3_kv
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/kvapi.c.

    23     23   ** This is an opaque object.  The public interface sees pointers to this
    24     24   ** object, but not the internals.  So the internal composition of this
    25     25   ** object is free to change from one release to the next without breaking
    26     26   ** compatibility.
    27     27   */
    28     28   struct sqlite3_kv {
    29     29     sqlite3 *db;            /* The database holding the table to be accessed */
    30         -  u8 iDb;                 /* Database containing the table to access */
    31     30     u32 iRoot;              /* Root page of the table */
           31  +  int iGen;               /* Schema generation number */
           32  +  int iCookie;            /* Schema cookie number from the database file */
           33  +  Schema *pSchema;        /* Schema holding the table */
    32     34     sqlite3_int64 iRowid;   /* Current rowid */
    33     35   };
    34     36   
    35     37   /*
    36     38   ** Create a new sqlite3_kv object open on zDb.zTable and return
    37     39   ** a pointer to that object.
    38     40   */
................................................................................
    84     86     }
    85     87     *ppKvOut = pKv = sqlite3_malloc(sizeof(*pKv));
    86     88     if( pKv==0 ){
    87     89       rc = SQLITE_NOMEM;
    88     90       goto kv_open_done;
    89     91     }
    90     92     pKv->db = db;
           93  +  pKv->iGen = pTab->pSchema->iGeneration;
           94  +  pKv->iCookie = pTab->pSchema->schema_cookie;
           95  +  pKv->pSchema = pTab->pSchema;
           96  +  pKv->iRoot = pTab->tnum;
    91     97     rc = SQLITE_OK;
    92     98   
    93     99   kv_open_done:
    94    100     sqlite3BtreeLeaveAll(db);
    95    101     sqlite3_mutex_leave(db->mutex);
    96    102     return rc;
    97    103   }
................................................................................
   102    108   int sqlite3_kv_close(sqlite3_kv *pKv){
   103    109     sqlite3_free(pKv);
   104    110     return SQLITE_OK;
   105    111   }
   106    112   
   107    113   int sqlite3_kv_seek(sqlite3_kv *pKv, sqlite3_int64 rowid){
   108    114     return SQLITE_MISUSE;
          115  +}
          116  +int sqlite3_kv_reset(sqlite3_kv *pKv){
          117  +  return SQLITE_MISUSE;
   109    118   }
   110    119   int sqlite3_kv_bytes(sqlite3_kv *pKv){
   111    120     return -1;
   112    121   }
   113    122   int sqlite3_kv_read(sqlite3_kv *pKv, void *pBuf, int amt, int offset){
   114    123     return SQLITE_MISUSE;
   115    124   }
   116    125   int sqlite3_kv_insert(sqlite3_kv *pKv, sqlite3_int64 rid, int sz, void *pBuf){
   117    126     return SQLITE_MISUSE;
   118    127   }
   119    128   
   120    129   #endif /* #ifndef SQLITE_OMIT_KEYVALU_ACCESSOR */

Changes to src/sqlite.h.in.

  8501   8501   ** SQLITE_OK on success or an error code if it is unable to complete
  8502   8502   ** the operation.  If no record exists with rowid I, then sqlite3_kv_seek(P,I)
  8503   8503   ** attempts to position itself at another nearby record and returns
  8504   8504   ** either SQLITE_KV_BEFORE or SQLITE_KV_AFTER depending on whether the
  8505   8505   ** record the accessor is left pointing to is less than or greater than I,
  8506   8506   ** respectively.  If the table is empty, sqlite3_kv_seek(P,I) returns
  8507   8507   ** SQLITE_EMPTY.
         8508  +**
         8509  +** A successful sqlite3_kv_seek(P,I) call leave the key/value accessor
         8510  +** P holding a read transaction open on the database.  Use sqlite3_kv_reset(P)
         8511  +** or sqlite3_kv_close(P) to release this transaction.
  8508   8512   */
  8509   8513   int sqlite3_kv_seek(sqlite3_kv*, sqlite3_int64 rowid);
  8510   8514   
         8515  +/*
         8516  +** CAPI3REF: Reset a key/value accessor object
         8517  +** METHOD: sqlite3_kv
         8518  +** EXPERIMENTAL
         8519  +**
         8520  +** The sqlite3_kv_reset(P) interface restores the key/value accessor P
         8521  +** back to its original state, releasing any transactions held.
         8522  +*/
         8523  +int sqlite3_kv_reset(sqlite3_kv*);
         8524  +
  8511   8525   /*
  8512   8526   ** CAPI3REF: Find the size of the value for a key/value pair
  8513   8527   ** METHOD: sqlite3_kv
  8514   8528   ** EXPERIMENTAL
  8515   8529   **
  8516   8530   ** The sqlite3_kv_bytes(P) interface returns the size of the value
  8517   8531   ** in the key/value pair that the key/value accessor object P is currently