From: drh Date: Wed, 18 Jan 2017 17:20:33 +0000 (+0000) Subject: Baseline interface definition for the experimental sqlite3_kv accessor object. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c109d88fa2eac79080c30cf352a1e7720a9d1fe4;p=thirdparty%2Fsqlite.git Baseline interface definition for the experimental sqlite3_kv accessor object. FossilOrigin-Name: a435841e71deecb374c7b667f8d52e82603177ae --- diff --git a/Makefile.in b/Makefile.in index b961070c23..bbc2b3e619 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 diff --git a/Makefile.msc b/Makefile.msc index d4aba301fb..9e8bafbddb 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -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 diff --git a/main.mk b/main.mk index e07b964d67..3b2d334d95 100644 --- a/main.mk +++ b/main.mk @@ -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 \ diff --git a/manifest b/manifest index e888f901e2..b88e69407a 100644 --- a/manifest +++ b/manifest @@ -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 Baseline\sinterface\sdefinition\sfor\sthe\sexperimental\ssqlite3_kv\saccessor\sobject. +D 2017-01-18T17:20:33.979 +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 3562e46e834d5b4f4aeb00f00c37d63eeea4af3e 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 ba4a6ea9c93071e24579805bd8a2218a939a36da 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,10 @@ 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 681d96eb822e606da53700867191d4738bda20c8 +R 6e440b2267c2c9d7235eb3ac1bb470a2 +T *branch * sqlite3_kv +T *sym-sqlite3_kv * +T -sym-trunk * +U drh +Z 1d83426f401ae270d7359f563a790e16 diff --git a/manifest.uuid b/manifest.uuid index 4ce4080714..b7881d193f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -681d96eb822e606da53700867191d4738bda20c8 \ No newline at end of file +a435841e71deecb374c7b667f8d52e82603177ae \ No newline at end of file diff --git a/src/kvapi.c b/src/kvapi.c new file mode 100644 index 0000000000..671ac6c937 --- /dev/null +++ b/src/kvapi.c @@ -0,0 +1,62 @@ +/* +** 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 */ + u8 iDb; /* Database containing the table to access */ + u32 iRoot; /* Root page of the table */ + sqlite3_int64 iRowid; /* Current rowid */ +}; + +int sqlite3_kv_open( + sqlite3 *db, + const char *zDb, + const char *zTable, + unsigned int flags, /* Must be zero. Reserved for future expansion. */ + sqlite3_kv *pKvOut +){ + return SQLITE_MISUSE; +} + +int sqlite3_kv_close(sqlite3_kv *pKv){ + return SQLITE_OK; +} + +int sqlite3_kv_seek(sqlite3_kv *pKv, sqlite3_int64 rowid){ + 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 */ diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 7d7e70f901..f8e67ec635 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -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,102 @@ 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 *pKvOut +); + +/* +** 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. +*/ +int sqlite3_kv_seek(sqlite3_kv*, sqlite3_int64 rowid); + +/* +** 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. diff --git a/tool/mksqlite3c-noext.tcl b/tool/mksqlite3c-noext.tcl index a16b0591eb..e75e391c14 100644 --- a/tool/mksqlite3c-noext.tcl +++ b/tool/mksqlite3c-noext.tcl @@ -338,6 +338,7 @@ foreach file { func.c fkey.c insert.c + kvapi.c legacy.c loadext.c pragma.c diff --git a/tool/mksqlite3c.tcl b/tool/mksqlite3c.tcl index 55179c4b80..0131d033b9 100644 --- a/tool/mksqlite3c.tcl +++ b/tool/mksqlite3c.tcl @@ -346,6 +346,7 @@ foreach file { func.c fkey.c insert.c + kvapi.c legacy.c loadext.c pragma.c