Add the sqlite3_drop_modules() interface.

FossilOrigin-Name: e2c6fed8f84929ed51a4e876bb09c85ac4b86a2e4cf0832a7da724bb9f4df5bf
This commit is contained in:
drh 2019-08-19 20:44:07 +00:00
commit b6e0286c49
6 changed files with 97 additions and 16 deletions

View File

@ -1,5 +1,5 @@
C Add\ssome\sextra\stests\sfor\sthe\slsm\svirtual\stable\smodule.
D 2019-08-17T19:58:26.438
C Add\sthe\ssqlite3_drop_modules()\sinterface.
D 2019-08-19T20:44:07.937
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -524,8 +524,8 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
F src/resolve.c b2733d39a22f5023ab489b8535ca6854b51ff8667ca975815d004bb7388b0e41
F src/rowset.c d977b011993aaea002cab3e0bb2ce50cf346000dff94e944d547b989f4b1fe93
F src/select.c 80b8b4c857db2f20d98f80b71ef3bb0d70cdd17bd6b00217dcff803e9b989bd8
F src/shell.c.in 48f7a9ee4bfc95aaea09f45c37f0cc305f56d4840c988565cdb92df2db689c32
F src/sqlite.h.in 5445ee2844c15bf277ebb64e910b56b0e6fb9377f184a81cd9bd78f0946be8c8
F src/shell.c.in e0f0758b6ab506d8ab12502fd2b8c55546bb9e4bb772374344a5a1b73f5bc2b9
F src/sqlite.h.in 50fc0914ccd347437db9a0278a47d7541df3a45eb6e641e9680750c6f98dad27
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 9ecc93b8493bd20c0c07d52e2ac0ed8bab9b549c7f7955b59869597b650dd8b5
F src/sqliteInt.h b7d612d9c63abc8a8a7dcf7fbec5326b1770f40c81502c56f508e272154e7615
@ -533,7 +533,7 @@ F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6
F src/status.c 46e7aec11f79dad50965a5ca5fa9de009f7d6bde08be2156f1538a0a296d4d0e
F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34
F src/tclsqlite.c 50c93be3e1c03b4e6cf6756e5197afcfe7f5cd0497d83a7ac317cde09e19b290
F src/test1.c 87059457fb90b73a74044b379fe2cb0aefbb53c010c646ecaff23179a423638c
F src/test1.c af2f21f9aee617582129bdef3934734d88c0d53de0c71019453bb72185430389
F src/test2.c 3efb99ab7f1fc8d154933e02ae1378bac9637da5
F src/test3.c 61798bb0d38b915067a8c8e03f5a534b431181f802659a6616f9b4ff7d872644
F src/test4.c 405834f6a93ec395cc4c9bb8ecebf7c3d8079e7ca16ae65e82d01afd229694bb
@ -604,7 +604,7 @@ F src/vdbeblob.c 253ed82894924c362a7fa3079551d3554cd1cdace39aa833da77d3bc67e7c1b
F src/vdbemem.c 920285c3b7f5c64369e02da437dab71e9e91862df9c486541c14633739f91d75
F src/vdbesort.c 3531ae3a431ad6b98b67bd891fb42ec9d66867157188a2b1a9e58c55da6151b2
F src/vdbetrace.c fa3bf238002f0bbbdfb66cc8afb0cea284ff9f148d6439bc1f6f2b4c3b7143f0
F src/vtab.c 994a4686197c00cee75f4ade8645e7336d8bb612c80ed61f4b8b7ceecf0a32ea
F src/vtab.c 6b36944fdf05a33150787236e3506e878dca027a239e39eaf408f09c4821170c
F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
F src/wal.c bbd6838bd79c0a32144d482fb0b6a9d2d1a252fb3b16d5005ec30f2f80413b0d
F src/wal.h 606292549f5a7be50b6227bd685fa76e3a4affad71bb8ac5ce4cb5c79f6a176a
@ -1836,7 +1836,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 7496e872a1a50ac65ad04709365a43038fb015ac9c690196de3cb02ce54c2e57
R 7c52be13cef9eee33da71a3e3a70b980
U dan
Z 775a473efffe71d8a3fe393281372f17
P 4cb009b0f724f72eaea90e45488122f7c2a7d0caf31a8422da4060469507e921 e5ba47c2d8eb9f48a0e0d325e57d0092d536f85983819634c871ebd51829f1d1
R 9f3cd232033726d002a567b7aed22f3d
T +closed e5ba47c2d8eb9f48a0e0d325e57d0092d536f85983819634c871ebd51829f1d1
U drh
Z ea1a16d1273af50410789215c7a1a587

View File

@ -1 +1 @@
4cb009b0f724f72eaea90e45488122f7c2a7d0caf31a8422da4060469507e921
e2c6fed8f84929ed51a4e876bb09c85ac4b86a2e4cf0832a7da724bb9f4df5bf

View File

@ -3651,6 +3651,7 @@ static const char *(azHelp[]) = {
#endif /* SQLITE_OMIT_TRACE */
#ifdef SQLITE_DEBUG
".unmodule NAME ... Unregister virtual table modules",
" --allexcept Unregister everything except those named",
#endif
".vfsinfo ?AUX? Information about the top-level VFS",
".vfslist List all available VFSes",
@ -6892,7 +6893,7 @@ static int do_meta_command(char *zLine, ShellState *p){
int nArg = 0;
int n, c;
int rc = 0;
char *azArg[50];
char *azArg[52];
#ifndef SQLITE_OMIT_VIRTUALTABLE
if( p->expert.pExpert ){
@ -6902,7 +6903,7 @@ static int do_meta_command(char *zLine, ShellState *p){
/* Parse the input line into tokens.
*/
while( zLine[h] && nArg<ArraySize(azArg) ){
while( zLine[h] && nArg<ArraySize(azArg)-1 ){
while( IsSpace(zLine[h]) ){ h++; }
if( zLine[h]==0 ) break;
if( zLine[h]=='\'' || zLine[h]=='"' ){
@ -6923,6 +6924,7 @@ static int do_meta_command(char *zLine, ShellState *p){
resolve_backslashes(azArg[nArg-1]);
}
}
azArg[nArg] = 0;
/* Process the input line.
*/
@ -9407,14 +9409,24 @@ static int do_meta_command(char *zLine, ShellState *p){
#ifdef SQLITE_DEBUG
if( c=='u' && strncmp(azArg[0], "unmodule", n)==0 ){
int ii;
int lenOpt;
char *zOpt;
if( nArg<2 ){
raw_printf(stderr, "Usage: .unmodule NAME ...\n");
raw_printf(stderr, "Usage: .unmodule [--allexcept] NAME ...\n");
rc = 1;
goto meta_command_exit;
}
open_db(p, 0);
for(ii=1; ii<nArg; ii++){
sqlite3_create_module(p->db, azArg[ii], 0, 0);
zOpt = azArg[1];
if( zOpt[0]=='-' && zOpt[1]=='-' && zOpt[2]!=0 ) zOpt++;
lenOpt = (int)strlen(zOpt);
if( lenOpt>=3 && strncmp(zOpt, "-allexcept",lenOpt)==0 ){
assert( azArg[nArg]==0 );
sqlite3_drop_modules(p->db, nArg>2 ? (const char**)(azArg+2) : 0);
}else{
for(ii=1; ii<nArg; ii++){
sqlite3_create_module(p->db, azArg[ii], 0, 0);
}
}
}else
#endif

View File

@ -6639,6 +6639,8 @@ struct sqlite3_index_info {
** ^If the third parameter (the pointer to the sqlite3_module object) is
** NULL then no new module is create and any existing modules with the
** same name are dropped.
**
** See also: [sqlite3_drop_modules()]
*/
int sqlite3_create_module(
sqlite3 *db, /* SQLite connection to register module with */
@ -6654,6 +6656,23 @@ int sqlite3_create_module_v2(
void(*xDestroy)(void*) /* Module destructor function */
);
/*
** CAPI3REF: Remove Unnecessary Virtual Table Implementations
** METHOD: sqlite3
**
** ^The sqlite3_drop_modules(D,L) interface removes all virtual
** table modules from database connection D except those named on list L.
** The L parameter must be either NULL or a pointer to an array of pointers
** to strings where the array is terminated by a single NULL pointer.
** ^If the L parameter is NULL, then all virtual table modules are removed.
**
** See also: [sqlite3_create_module()]
*/
int sqlite3_drop_modules(
sqlite3 *db, /* Remove modules from this connection */
const char **azKeep /* Except, do not remove the ones named here */
);
/*
** CAPI3REF: Virtual Table Instance Object
** KEYWORDS: sqlite3_vtab

View File

@ -1110,6 +1110,32 @@ static int SQLITE_TCLAPI test_create_function(
return TCL_OK;
}
/*
** Usage: sqlite3_drop_modules DB ?NAME ...?
**
** Invoke the sqlite3_drop_modules(D,L) interface on database
** connection DB, in order to drop all modules except those named in
** the argument.
*/
static int SQLITE_TCLAPI test_drop_modules(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
char **argv /* Text of each argument */
){
int rc;
sqlite3 *db;
if( argc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" DB\"", 0);
return TCL_ERROR;
}
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
sqlite3_drop_modules(db, argc>2 ? (const char**)(argv+2) : 0);
return TCL_OK;
}
/*
** Routines to implement the x_count() aggregate function.
**
@ -7860,6 +7886,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
{ "sqlite3_close_v2", (Tcl_CmdProc*)sqlite_test_close_v2 },
{ "sqlite3_create_function", (Tcl_CmdProc*)test_create_function },
{ "sqlite3_create_aggregate", (Tcl_CmdProc*)test_create_aggregate },
{ "sqlite3_drop_modules", (Tcl_CmdProc*)test_drop_modules },
{ "sqlite_register_test_function", (Tcl_CmdProc*)test_register_func },
{ "sqlite_abort", (Tcl_CmdProc*)sqlite_abort },
{ "sqlite_bind", (Tcl_CmdProc*)test_bind },

View File

@ -133,6 +133,28 @@ int sqlite3_create_module_v2(
return createModule(db, zName, pModule, pAux, xDestroy);
}
/*
** External API to drop all virtual-table modules, except those named
** on the azNames list.
*/
int sqlite3_drop_modules(sqlite3 *db, const char** azNames){
HashElem *pThis, *pNext;
#ifdef SQLITE_ENABLE_API_ARMOR
if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
#endif
for(pThis=sqliteHashFirst(&db->aModule); pThis; pThis=pNext){
Module *pMod = (Module*)sqliteHashData(pThis);
pNext = sqliteHashNext(pThis);
if( azNames ){
int ii;
for(ii=0; azNames[ii]!=0 && strcmp(azNames[ii],pMod->zName)!=0; ii++){}
if( azNames[ii]!=0 ) continue;
}
createModule(db, pMod->zName, 0, 0, 0);
}
return SQLITE_OK;
}
/*
** Decrement the reference count on a Module object. Destroy the
** module when the reference count reaches zero.