From a90046780411e6f42760bf68b3fbd4e50cd0417e Mon Sep 17 00:00:00 2001 From: larrybr Date: Sat, 2 Sep 2023 22:00:48 +0000 Subject: [PATCH] Issue NK_DbAboutToClose notifications for any shell DB about to be closed, whether presently visible in ShellExState or not. FossilOrigin-Name: 8e6e54e48c1739c76db3e7979669cf17f7cee471b1d37836adbf72f42e8b8972 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c.in | 28 ++++++++++++++-------------- src/shext_linkage.h | 4 ++-- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/manifest b/manifest index 69a2ecc342..415a8251ea 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Sync\sw/trunk -D 2023-06-29T17:58:51.696 +C Issue\sNK_DbAboutToClose\snotifications\sfor\sany\sshell\sDB\sabout\sto\sbe\sclosed,\swhether\spresently\svisible\sin\sShellExState\sor\snot. +D 2023-09-02T22:00:48.464 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -645,8 +645,8 @@ F src/resmanage.h eb63130e49d7b696a33c6d39d1c437a050bbef42b4f6f4405a15fc563c7dd6 F src/resolve.c 37953a5f36c60bea413c3c04efcd433b6177009f508ef2ace0494728912fe2e9 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 x F src/select.c 383b9dba12493c365ee2036bcadd73013b7c0f7d2afcda0c378317c335d60ac2 x -F src/shell.c.in 3d9053cee4ccb6744e4b18f1f980d037bfebc8a01c162fbc6f35e194858a4ab1 -F src/shext_linkage.h 4a686427844d5d2b71f2095cb032280fb262490795f0710487ebbedb3732f1cb x +F src/shell.c.in 4528d910b082e4cf251de767cd04bda10f3795d1e2d7f28eb14d5267a6ba969a +F src/shext_linkage.h f7c8331f6e3c4a53a7bd70d2aa3d28fec9b206638140d804d35fdaaade54496c x F src/sqlite.h.in 3076d78836b6dac53b3ab0875fc8fd15bca8077aad4d33c85336e05af6aef8c7 x F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h da473ce2b3d0ae407a6300c4a164589b9a6bfdbec9462688a8593ff16f3bb6e4 @@ -2053,8 +2053,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 a61f9377014ee582ec469f1066196e07b745295724c6d3ff4baffcaed22ae5a1 24927c1377314a10177da4a57191593440aa97fd0c5949fdf25a22df1d947600 2f9d4444aa503102a00d6e6769dadc57d4b26a2c07f145f23f2f28e0c161246d -R bd3140ab1e0bb2a93e6d3c105e3f3689 +P fe9aa2e9c17f33a8f6045e9cf755f8251d261c34f89a59d658b72f7c99a6a12c +R d5f163c7f28125775ba39d501d65bd13 U larrybr -Z 497f78a875664dfe4baa50f499afe15b +Z 2b8a61033c96da67076a31e0f7c46650 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4b532a727a..13d30a8ceb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fe9aa2e9c17f33a8f6045e9cf755f8251d261c34f89a59d658b72f7c99a6a12c \ No newline at end of file +8e6e54e48c1739c76db3e7979669cf17f7cee471b1d37836adbf72f42e8b8972 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 802a2cb57b..8a8fa79c8b 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -6014,8 +6014,11 @@ static void shellUSleepFunc( ** Attempt to close the database connection. Report errors. ** The close is done under mutex protection for globalDb. */ -static void close_db(sqlite3 *db){ +static void close_db(ShellInState *psi, sqlite3 *db){ int rc; +#if SHELL_DYNAMIC_EXTENSION + if( db!=0 ) notify_subscribers(psi, NK_DbAboutToClose, db); +#endif if( db==globalDb ){ /* This should only block for the time needed to handle ^C interrupt. */ sqlite3_mutex_enter(pGlobalDbLock); @@ -6095,7 +6098,7 @@ static sqlite3 * open_db(ShellExState *psx, int openFlags){ const char *zWhy = (DBX(psx)==0)? "(?)" : sqlite3_errmsg(DBX(psx)); utf8_printf(STD_ERR,"Error: unable to open database \"%s\": %s\n", zDbFilename, zWhy); - close_db(DBX(psx)); + close_db(psi,DBX(psx)); if( bail_on_error && !stdin_is_interactive ){ shell_terminate("-bail used in batch mode."); } @@ -6904,7 +6907,7 @@ static void tryToClone(ShellExState *psx, const char *zNewDb){ sqlite3_exec(newDb, "COMMIT;", 0, 0, 0); // sqlite3_exec(DBX(psx), "PRAGMA writable_schema=OFF;", 0, 0, 0); } - close_db(newDb); + close_db(ISS(psx),newDb); } /* @@ -8180,7 +8183,7 @@ static DotCmdRC arDotCommand( } end_ar_command: if( cmd.db!=DBX(pState) ){ - close_db(cmd.db); + close_db(ISS(pState),cmd.db); } sqlite3_free(cmd.zSrcTable); @@ -8243,7 +8246,7 @@ writeDb( char *azArg[], int nArg, ShellExState *psx, char **pzErr ){ SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, zVfs); if( rc!=SQLITE_OK ){ *pzErr = smprintf("cannot open \"%s\"\n", zDestFile); - close_db(pDest); + close_db(ISS(psx),pDest); return DCR_Error; } if( bAsync ){ @@ -8254,7 +8257,7 @@ writeDb( char *azArg[], int nArg, ShellExState *psx, char **pzErr ){ pBackup = sqlite3_backup_init(pDest, "main", DBX(psx), zDb); if( pBackup==0 ){ *pzErr = smprintf("%s failed, %s\n", azArg[0], sqlite3_errmsg(pDest)); - close_db(pDest); + close_db(ISS(psx),pDest); return DCR_Error; } while( (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK ){} @@ -8265,7 +8268,7 @@ writeDb( char *azArg[], int nArg, ShellExState *psx, char **pzErr ){ *pzErr = smprintf("%s\n", sqlite3_errmsg(pDest)); rc = 1; } - close_db(pDest); + close_db(ISS(psx),pDest); return DCR_Ok|rc; } #endif /* !defined(SQLITE_SHELL_FIDDLE) */ @@ -9808,7 +9811,7 @@ DISPATCHABLE_COMMAND( connection ? 1 4 ){ return DCR_Error; }else if( psi->aAuxDb[i].db ){ session_close_all(psi, i); - close_db(psi->aAuxDb[i].db); + close_db(psi,psi->aAuxDb[i].db); psi->aAuxDb[i].db = 0; } }else{ @@ -11692,10 +11695,7 @@ DISPATCHABLE_COMMAND( open 3 1 0 ){ /* Close the existing database */ session_close_all(psi, -1); -#if SHELL_DYNAMIC_EXTENSION - if( DBX(p)!=0 ) notify_subscribers(psi, NK_DbAboutToClose, DBX(p)); -#endif - close_db(DBX(p)); + close_db(psi,DBX(p)); DBX(p) = 0; psi->pAuxDb->zDbFilename = 0; sqlite3_free(psi->pAuxDb->zFreeOnClose); @@ -16596,13 +16596,13 @@ static void main_cleanup(ShellInState *psi, ShellExState *psx) { #if SHELL_DYNAMIC_EXTENSION notify_subscribers(psi, NK_DbAboutToClose, psx->dbUser); #endif - close_db(psx->dbUser); + close_db(psi,psx->dbUser); } for(i=0; iaAuxDb); i++){ sqlite3_free(psi->aAuxDb[i].zFreeOnClose); if( psi->aAuxDb[i].db ){ session_close_all(psi, i); - close_db(psi->aAuxDb[i].db); + close_db(psi,psi->aAuxDb[i].db); } } find_home_dir(1); diff --git a/src/shext_linkage.h b/src/shext_linkage.h index d59d4b347e..eec96b0e22 100755 --- a/src/shext_linkage.h +++ b/src/shext_linkage.h @@ -338,8 +338,8 @@ typedef enum { * pvSubject is the newly set .dbUser value. */ NK_DbUserVanishing, /* Current ShellExState .dbUser will soon vanish, * pvSubject is the vanishing .dbUser value. */ - NK_DbAboutToClose, /* A possibly ShellExState-visible DB will soon be - * closed, pvSubject is the DB's sqlite3 pointer. */ + NK_DbAboutToClose, /* Possibly (or not) ShellExState-visible DB will soon + * be closed, pvSubject is the DB's sqlite3 pointer. */ NK_ExtensionUnload, /* The ShellExState .dbShell DB will soon be closed, * soon to be followed by unloading of all dynamic * extensions; pvSubject is the DB's sqlite3 pointer. */ -- 2.47.2