diff options
author | drh <drh@noemail.net> | 2018-01-03 01:28:46 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2018-01-03 01:28:46 +0000 |
commit | ac442f41c134b1242baf488cd53ff57e64deb448 (patch) | |
tree | a0f40b5e3db9f39da427662f7170559944518fb1 /src/tclsqlite.c | |
parent | d9620b8555f1bd62847400b8c9d8d3c2adf60ccb (diff) | |
download | sqlite-ac442f41c134b1242baf488cd53ff57e64deb448.tar.gz sqlite-ac442f41c134b1242baf488cd53ff57e64deb448.zip |
Add support for the "memdb" VFS and the sqlite3_memdb_ptr() and
sqlite3_memdb_config() interfaces, to enable an SQLite database to be
manipulated as an in-memory object.
FossilOrigin-Name: fb2ac2d2fa6374084f3325b41b257c7a3ace43aade4b666ec4be93b6b70dc39a
Diffstat (limited to 'src/tclsqlite.c')
-rw-r--r-- | src/tclsqlite.c | 77 |
1 files changed, 62 insertions, 15 deletions
diff --git a/src/tclsqlite.c b/src/tclsqlite.c index eed86eee3..0e86d727b 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -1852,14 +1852,13 @@ static int SQLITE_TCLAPI DbObjCmd( "complete", "copy", "enable_load_extension", "errorcode", "eval", "exists", "function", "incrblob", "interrupt", - "last_insert_rowid", "nullvalue", "onecolumn", - "preupdate", "profile", "progress", - "rekey", "restore", "rollback_hook", - "status", "timeout", "total_changes", - "trace", "trace_v2", "transaction", - "unlock_notify", "update_hook", "version", - "wal_hook", - 0 + "last_insert_rowid", "memdb", "nullvalue", + "onecolumn", "preupdate", "profile", + "progress", "rekey", "restore", + "rollback_hook", "status", "timeout", + "total_changes", "trace", "trace_v", + "transaction", "unlock_notify", "update_hook", + "version", "wal_hook", 0 }; enum DB_enum { DB_AUTHORIZER, DB_BACKUP, DB_BUSY, @@ -1868,13 +1867,13 @@ static int SQLITE_TCLAPI DbObjCmd( DB_COMPLETE, DB_COPY, DB_ENABLE_LOAD_EXTENSION, DB_ERRORCODE, DB_EVAL, DB_EXISTS, DB_FUNCTION, DB_INCRBLOB, DB_INTERRUPT, - DB_LAST_INSERT_ROWID, DB_NULLVALUE, DB_ONECOLUMN, - DB_PREUPDATE, DB_PROFILE, DB_PROGRESS, - DB_REKEY, DB_RESTORE, DB_ROLLBACK_HOOK, - DB_STATUS, DB_TIMEOUT, DB_TOTAL_CHANGES, - DB_TRACE, DB_TRACE_V2, DB_TRANSACTION, - DB_UNLOCK_NOTIFY, DB_UPDATE_HOOK, DB_VERSION, - DB_WAL_HOOK, + DB_LAST_INSERT_ROWID, DB_MEMDB, DB_NULLVALUE, + DB_ONECOLUMN, DB_PREUPDATE, DB_PROFILE, + DB_PROGRESS, DB_REKEY, DB_RESTORE, + DB_ROLLBACK_HOOK, DB_STATUS, DB_TIMEOUT, + DB_TOTAL_CHANGES, DB_TRACE, DB_TRACE_V2, + DB_TRANSACTION, DB_UNLOCK_NOTIFY, DB_UPDATE_HOOK, + DB_VERSION, DB_WAL_HOOK }; /* don't leave trailing commas on DB_enum, it confuses the AIX xlc compiler */ @@ -2668,6 +2667,54 @@ static int SQLITE_TCLAPI DbObjCmd( } /* + ** $db memdb DATABASE ?BLOB? + ** + ** Set or query the content of a MEMDB database. + ** + */ + case DB_MEMDB: { +#ifndef SQLITE_ENABLE_MEMDB + Tcl_AppendResult(interp, "MEMDB not available in this build", + (char*)0); + rc = TCL_ERROR; +#else + const char *zSchema = Tcl_GetString(objv[2]); + sqlite3_int64 sz = 0; + unsigned char *pData; + if( objc==3 ){ + pData = sqlite3_memdb_ptr(pDb->db, zSchema, &sz); + if( pData==0 ){ + Tcl_AppendResult(interp, "not a MEMDB database", (char*)0); + rc = TCL_ERROR; + }else{ + Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(pData,sz)); + } + }else if( objc==4 ){ + int len = 0, xrc; + unsigned char *pBA = Tcl_GetByteArrayFromObj(objv[3], &len); + pData = sqlite3_malloc64( len ); + if( pData==0 ){ + Tcl_AppendResult(interp, "out of memory", (char*)0); + rc = TCL_ERROR; + }else{ + memcpy(pData, pBA, len); + xrc = sqlite3_memdb_config(pDb->db, zSchema, pData, len, len, + SQLITE_MEMDB_FREEONCLOSE|SQLITE_MEMDB_RESIZEABLE); + if( xrc ){ + sqlite3_free(pData); + Tcl_AppendResult(interp, "unable to set MEMDB content", (char*)0); + rc = TCL_ERROR; + } + } + }else{ + Tcl_WrongNumArgs(interp, 2, objv, "?SCRIPT?"); + rc = TCL_ERROR; + } +#endif + break; + } + + /* ** $db nullvalue ?STRING? ** ** Change text used when a NULL comes back from the database. If ?STRING? |