Compare commits

...

3 Commits

Author SHA1 Message Date
drh c87242aeec Add a prototype of the sqlite3_kv_reset() interface.
FossilOrigin-Name: 088c590379f844c1443b0ccdf8695f1506584451
2017-01-19 12:07:08 +00:00
drh 42345c1e4a Begin fleshing out the key/value accessor implementation. This is an
incremental check-in.

FossilOrigin-Name: 02d60e196fe2a07ef90a5cfad0daa46020bfd06e
2017-01-18 19:54:07 +00:00
drh c109d88fa2 Baseline interface definition for the experimental sqlite3_kv accessor object.
FossilOrigin-Name: a435841e71deecb374c7b667f8d52e82603177ae
2017-01-18 17:20:33 +00:00
9 changed files with 269 additions and 16 deletions
+5 -1
View File
@@ -174,7 +174,7 @@ LIBOBJS0 = alter.lo analyze.lo attach.lo auth.lo \
fts3_unicode.lo fts3_unicode2.lo fts3_write.lo \
fts5.lo \
func.lo global.lo hash.lo \
icu.lo insert.lo json1.lo legacy.lo loadext.lo \
icu.lo insert.lo json1.lo kvapi.o legacy.lo loadext.lo \
main.lo malloc.lo mem0.lo mem1.lo mem2.lo mem3.lo mem5.lo \
memjournal.lo \
mutex.lo mutex_noop.lo mutex_unix.lo mutex_w32.lo \
@@ -226,6 +226,7 @@ SRC = \
$(TOP)/src/hash.h \
$(TOP)/src/hwtime.h \
$(TOP)/src/insert.c \
$(TOP)/src/kvapi.c \
$(TOP)/src/legacy.c \
$(TOP)/src/loadext.c \
$(TOP)/src/main.c \
@@ -767,6 +768,9 @@ hash.lo: $(TOP)/src/hash.c $(HDR)
insert.lo: $(TOP)/src/insert.c $(HDR)
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/insert.c
kvapi.lo: $(TOP)/src/kvapi.c $(HDR)
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/kvapi.c
legacy.lo: $(TOP)/src/legacy.c $(HDR)
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/legacy.c
+5 -1
View File
@@ -1081,7 +1081,7 @@ LIBOBJS0 = vdbe.lo parse.lo alter.lo analyze.lo attach.lo auth.lo \
fts3_tokenize_vtab.lo fts3_unicode.lo fts3_unicode2.lo fts3_write.lo \
fts5.lo \
func.lo global.lo hash.lo \
icu.lo insert.lo legacy.lo loadext.lo \
icu.lo insert.lo kvapi.lo legacy.lo loadext.lo \
main.lo malloc.lo mem0.lo mem1.lo mem2.lo mem3.lo mem5.lo \
memjournal.lo \
mutex.lo mutex_noop.lo mutex_unix.lo mutex_w32.lo \
@@ -1146,6 +1146,7 @@ SRC00 = \
$(TOP)\src\global.c \
$(TOP)\src\hash.c \
$(TOP)\src\insert.c \
$(TOP)\src\kvapi.c \
$(TOP)\src\legacy.c \
$(TOP)\src\loadext.c \
$(TOP)\src\main.c \
@@ -1741,6 +1742,9 @@ hash.lo: $(TOP)\src\hash.c $(HDR)
insert.lo: $(TOP)\src\insert.c $(HDR)
$(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\insert.c
kvapi.lo: $(TOP)\src\kvapi.c $(HDR)
$(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\kvapi.c
legacy.lo: $(TOP)\src\legacy.c $(HDR)
$(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\legacy.c
+2 -1
View File
@@ -62,7 +62,7 @@ LIBOBJ+= vdbe.o parse.o \
fts3_tokenize_vtab.o \
fts3_unicode.o fts3_unicode2.o \
fts3_write.o fts5.o func.o global.o hash.o \
icu.o insert.o json1.o legacy.o loadext.o \
icu.o insert.o json1.o kvapi.o legacy.o loadext.o \
main.o malloc.o mem0.o mem1.o mem2.o mem3.o mem5.o \
memjournal.o \
mutex.o mutex_noop.o mutex_unix.o mutex_w32.o \
@@ -106,6 +106,7 @@ SRC = \
$(TOP)/src/hash.h \
$(TOP)/src/hwtime.h \
$(TOP)/src/insert.c \
$(TOP)/src/kvapi.c \
$(TOP)/src/legacy.c \
$(TOP)/src/loadext.c \
$(TOP)/src/main.c \
+13 -12
View File
@@ -1,8 +1,8 @@
C Fix\sa\sproblem\sthat\scould\scause\sa\sspurious\sSQLITE_NOMEM\serror\swhen\sattempting\nto\sresume\san\sRBU\soperation\sif\sthe\sprevious\sclient\sfailed\sright\safter\ncompleting\sthe\sincremental\scheckpoint.\sAlso\sa\s"cannot\svacuum\swal\sdb"\serror\nthat\scould\soccur\swhen\sresuming\san\sRBU\svacuum\sif\san\serror\s(OOM\sor\sIO\serror)\noccurs\sduring\sthe\sincremental\scheckpoint.
D 2017-01-17T10:41:42.780
F Makefile.in 41bd4cad981487345c4a84081074bcdb876e4b2e
C Add\sa\sprototype\sof\sthe\ssqlite3_kv_reset()\sinterface.
D 2017-01-19T12:07:08.814
F Makefile.in 78688a52015911e4b841b265c5fef09fbf81e655
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc b8ca53350ae545e3562403d5da2a69cec79308da
F Makefile.msc 836dde6df991bd855e93db1721f9347678cb9cda
F README.md 8ecc12493ff9f820cdea6520a9016001cb2e59b7
F VERSION cddd8d88dc8202afa0ebc96da61fc4acbd1e96a5
F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50
@@ -314,7 +314,7 @@ F ext/userauth/userauth.c 5fa3bdb492f481bbc1709fc83c91ebd13460c69e
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8
F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60
F main.mk 2cf5f0362c5687fd8e912c3a327b49a2e8ba0f9b
F main.mk c909362c60f2cb7b0a804605e4ccb43ac4ce79e9
F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83
F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271
F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504
@@ -353,6 +353,7 @@ F src/hash.h ab34c5c54a9e9de2e790b24349ba5aab3dbb4fd4
F src/hwtime.h 747c1bbe9df21a92e9c50f3bbec1de841dc5e5da
F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
F src/insert.c 05e47e2de7b712a3a4148cd469e5f60873f5ef13
F src/kvapi.c 3b20d8f7d7e69f17f81e7917e0f3a5ceca559d20
F src/legacy.c 75d3023be8f0d2b99d60f905090341a03358c58e
F src/loadext.c 5d6642d141c07d366e43d359e94ec9de47add41d
F src/main.c e207b81542d13b9f13d61e78ca441f9781f055b0
@@ -392,7 +393,7 @@ F src/resolve.c bb070cf5f23611c44ab7e4788803684e385fc3fb
F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
F src/select.c 3856db523b942062bca8722ba03b61c324ff94d6
F src/shell.c 6095531aa900decdaa765e0f3993fba7153c92c1
F src/sqlite.h.in e71655293c9bde26939496f3aac9d1821d2c07a2
F src/sqlite.h.in ff59423b65e5573b3abdf65c8a437ceaef93eb69
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae
F src/sqliteInt.h ce3e07c720b0cebc8887ea86b3b128da0913c5d3
@@ -1487,8 +1488,8 @@ F tool/mkopcodeh.tcl a01d2c1d8a6205b03fc635adf3735b4c523befd3
F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e
F tool/mkpragmatab.tcl ebb4bfcd2f8010e0a3934b6118db4b5f2f5edf5c
F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97
F tool/mksqlite3c-noext.tcl fef88397668ae83166735c41af99d79f56afaabb
F tool/mksqlite3c.tcl 06b2e6a0f21cc0a5d70fbbd136b3e0a96470645e
F tool/mksqlite3c-noext.tcl 12c48e8b822ed989e606450b372ee215aa6750ab
F tool/mksqlite3c.tcl 062485c4c907c5fdc824b4ccdf2c405f40fdf3fe
F tool/mksqlite3h.tcl c006c4e5da57c649b24b689511dcd270dd7b0249
F tool/mksqlite3internalh.tcl eb994013e833359137eb53a55acdad0b5ae1049b
F tool/mkvsix.tcl b9e0777a213c23156b6542842c238479e496ebf5
@@ -1547,7 +1548,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 7fd560c6d2ff470b755ad118287a0a8825b3009e
R 3b5f909693e02732236a5ff9d24ebb43
U dan
Z 623656530433c4c90deab7fe9f3d0d79
P 02d60e196fe2a07ef90a5cfad0daa46020bfd06e
R a9d74517ea3f75ec81817c95ce60d493
U drh
Z 706252d4c96233de5edfe4f55ad55c0d
+1 -1
View File
@@ -1 +1 @@
681d96eb822e606da53700867191d4738bda20c8
088c590379f844c1443b0ccdf8695f1506584451
+129
View File
@@ -0,0 +1,129 @@
/*
** 2017-01-18
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains code used to implement key/value access interface.
*/
#include "sqliteInt.h"
#ifndef SQLITE_OMIT_KEYVALUE_ACCESSOR
/*
** An sqlite3_kv object is an accessor for key/value pairs.
**
** This is an opaque object. The public interface sees pointers to this
** object, but not the internals. So the internal composition of this
** object is free to change from one release to the next without breaking
** compatibility.
*/
struct sqlite3_kv {
sqlite3 *db; /* The database holding the table to be accessed */
u32 iRoot; /* Root page of the table */
int iGen; /* Schema generation number */
int iCookie; /* Schema cookie number from the database file */
Schema *pSchema; /* Schema holding the table */
sqlite3_int64 iRowid; /* Current rowid */
};
/*
** Create a new sqlite3_kv object open on zDb.zTable and return
** a pointer to that object.
*/
int sqlite3_kv_open(
sqlite3 *db, /* The database connection */
const char *zDb, /* Schema containing zTable. NULL for "main" */
const char *zTable, /* Name of table the key/value table */
unsigned int flags, /* Must be zero. Reserved for future expansion. */
sqlite3_kv **ppKvOut /* Store the new sqlite3_kv object here */
){
sqlite3_kv *pKv;
Table *pTab;
int rc = SQLITE_ERROR;
#ifdef SQLITE_ENABLE_API_ARMOR
if( ppKvOut==0 ){
return SQLITE_MISUSE_BKPT;
}
#endif
*ppKvOut = 0;
#ifdef SQLITE_ENABLE_API_ARMOR
if( !sqlite3SafetyCheckOk(db) || zTable==0 ){
return SQLITE_MISUSE_BKPT;
}
#endif
sqlite3_mutex_enter(db->mutex);
sqlite3BtreeEnterAll(db);
pTab = sqlite3FindTable(db, zTable, zDb);
if( pTab==0 ){
goto kv_open_done;
}
if( !((pTab->nCol==1 && pTab->iPKey<0)
|| (pTab->nCol==2 && pTab->iPKey==0))
){
/* Must be an single-column table without an INTEGER PRIMARY KEY,
** or a two-column table where the first column is the INTEGER PRIMARY KEY
*/
goto kv_open_done;
}
if( pTab->pIndex!=0 || pTab->pFKey!=0 || pTab->pCheck!=0 ){
/* Do not allow secondary indexes, foreign keys, or CHECK constraints */
goto kv_open_done;
}
if( pTab->tabFlags & (TF_Autoincrement|TF_Virtual|TF_WithoutRowid) ){
/* Must not have autoincrement. Must not be a virtual table or a
** without rowid table */
goto kv_open_done;
}
*ppKvOut = pKv = sqlite3_malloc(sizeof(*pKv));
if( pKv==0 ){
rc = SQLITE_NOMEM;
goto kv_open_done;
}
pKv->db = db;
pKv->iGen = pTab->pSchema->iGeneration;
pKv->iCookie = pTab->pSchema->schema_cookie;
pKv->pSchema = pTab->pSchema;
pKv->iRoot = pTab->tnum;
rc = SQLITE_OK;
kv_open_done:
sqlite3BtreeLeaveAll(db);
sqlite3_mutex_leave(db->mutex);
return rc;
}
/*
** Free the key/value accessor at pKv
*/
int sqlite3_kv_close(sqlite3_kv *pKv){
sqlite3_free(pKv);
return SQLITE_OK;
}
int sqlite3_kv_seek(sqlite3_kv *pKv, sqlite3_int64 rowid){
return SQLITE_MISUSE;
}
int sqlite3_kv_reset(sqlite3_kv *pKv){
return SQLITE_MISUSE;
}
int sqlite3_kv_bytes(sqlite3_kv *pKv){
return -1;
}
int sqlite3_kv_read(sqlite3_kv *pKv, void *pBuf, int amt, int offset){
return SQLITE_MISUSE;
}
int sqlite3_kv_insert(sqlite3_kv *pKv, sqlite3_int64 rid, int sz, void *pBuf){
return SQLITE_MISUSE;
}
#endif /* #ifndef SQLITE_OMIT_KEYVALU_ACCESSOR */
+112
View File
@@ -497,6 +497,8 @@ int sqlite3_exec(
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
#define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
#define SQLITE_KV_BEFORE (SQLITE_NOTFOUND | (1<<8))
#define SQLITE_KV_AFTER (SQLITE_NOTFOUND | (2<<8))
#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
#define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
@@ -8448,6 +8450,116 @@ SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp(
*/
SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
/*
** CAPI3REF: Key/Value Access
** EXPERIMENTAL
**
** The sqlite3_kv object is used to access database tables using
** the key/value interface.
*/
typedef struct sqlite3_kv sqlite3_kv;
/*
** CAPI3REF: Open a key/value accessor object
** CONSTRUCTOR: sqlite3_kv
** EXPERIMENTAL
**
** This interface attempts create a new [sqlite3_kv] object and
** return a pointer to that object in the 5th parameter.
** SQLITE_OK is returned on success or an error code if something
** goes wrong.
*/
int sqlite3_kv_open(
sqlite3 *db,
const char *zDb,
const char *zTable,
unsigned int flags, /* Must be zero. Reserved for future expansion. */
sqlite3_kv **ppKvOut
);
/*
** CAPI3REF: Close a key/value accessor object
** DESTRUCTOR: sqlite3_kv
** EXPERIMENTAL
**
** The sqlite3_kv_close(P) interface closes a key/value accessor P.
** The argument to sqlite3_kv_close(P) may be NULL, resulting in a harmless
** no-op.
*/
int sqlite3_kv_close(sqlite3_kv*);
/*
** CAPI3REF: Reposition a key/value accessor object
** METHOD: sqlite3_kv
** EXPERIMENTAL
**
** The sqlite3_kv_seek(P,I) interface attempts to reposition
** the key/value accessor object P so that it is pointing to a table
** entry with rowid I. The sqlite3_kv_seek(P,I) interface returns
** SQLITE_OK on success or an error code if it is unable to complete
** the operation. If no record exists with rowid I, then sqlite3_kv_seek(P,I)
** attempts to position itself at another nearby record and returns
** either SQLITE_KV_BEFORE or SQLITE_KV_AFTER depending on whether the
** record the accessor is left pointing to is less than or greater than I,
** respectively. If the table is empty, sqlite3_kv_seek(P,I) returns
** SQLITE_EMPTY.
**
** A successful sqlite3_kv_seek(P,I) call leave the key/value accessor
** P holding a read transaction open on the database. Use sqlite3_kv_reset(P)
** or sqlite3_kv_close(P) to release this transaction.
*/
int sqlite3_kv_seek(sqlite3_kv*, sqlite3_int64 rowid);
/*
** CAPI3REF: Reset a key/value accessor object
** METHOD: sqlite3_kv
** EXPERIMENTAL
**
** The sqlite3_kv_reset(P) interface restores the key/value accessor P
** back to its original state, releasing any transactions held.
*/
int sqlite3_kv_reset(sqlite3_kv*);
/*
** CAPI3REF: Find the size of the value for a key/value pair
** METHOD: sqlite3_kv
** EXPERIMENTAL
**
** The sqlite3_kv_bytes(P) interface returns the size of the value
** in the key/value pair that the key/value accessor object P is currently
** pointing to. The sqlite3_kv_bytes(P) interface returns a negative
** number if the key/value accessor object P is not currently pointing
** to a valid entry in the table.
*/
int sqlite3_kv_bytes(sqlite3_kv*);
/*
** CAPI3REF: Read the value for a key/value pair
** METHOD: sqlite3_kv
** EXPERIMENTAL
**
** The sqlite3_kv_read(P,B,A,O) interface attempts to read A bytes of
** content beginning at offset O from the value that the key/value accessor P
** is currently pointing at, storing the results in buffer B.
** The caller must ensure that the buffer B is at least A bytes in length.
*/
int sqlite3_kv_read(sqlite3_kv*, void *pBuf, int amt, int offset);
/*
** CAPI3REF: Insert a new key/value pair
** METHOD: sqlite3_kv
** EXPERIMENTAL
**
** The sqlite3_kv_insert(P,I,N,B) interface inserts a key/value pair
** having key I and a value that is an N-byte BLOB pointed to by B.
** In a call to sqlite3_kv_insert(P,I,N,B), if a previous row with key I
** already exists in the table, then that previous row is replaced by
** the new row.
*/
int sqlite3_kv_insert(sqlite3_kv*, sqlite3_int64 rowid, int size, void *pBuf);
/*
** Undo the hack that converts floating point types to integer for
** builds on processors without floating point support.
+1
View File
@@ -338,6 +338,7 @@ foreach file {
func.c
fkey.c
insert.c
kvapi.c
legacy.c
loadext.c
pragma.c
+1
View File
@@ -346,6 +346,7 @@ foreach file {
func.c
fkey.c
insert.c
kvapi.c
legacy.c
loadext.c
pragma.c