From 2b24d8957e196be6a1fa5a2b0dc3441706df7832 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 25 Oct 2025 19:36:12 +0000 Subject: [PATCH] New --normal option for the ".open" command in the CLI. Also, when opening the database for deduceDatabaseType(), use the same open-flags that will be used subsequently for the official open, to avoid creating unusable file descriptors that need to be held until all database instances close. FossilOrigin-Name: 5e20a0435b1bd84d90c9a419219afe794fdf8ea73213f4c7ae5612c0375bed55 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c.in | 11 +++++++---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 5770a2b411..49abbb856a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sadditional\sinformation\sabout\sunix\sfile\sdescriptors\sto\sthe\ssame\sdatabase\sfile\nin\sthe\ssqlite_file_info()\soutput. -D 2025-10-25T19:26:16.953 +C New\s--normal\soption\sfor\sthe\s".open"\scommand\sin\sthe\sCLI.\s\sAlso,\swhen\sopening\nthe\sdatabase\sfor\sdeduceDatabaseType(),\suse\sthe\ssame\sopen-flags\sthat\swill\nbe\sused\ssubsequently\sfor\sthe\sofficial\sopen,\sto\savoid\screating\sunusable\nfile\sdescriptors\sthat\sneed\sto\sbe\sheld\suntil\sall\sdatabase\sinstances\sclose. +D 2025-10-25T19:36:12.834 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -736,7 +736,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c f8d1d011aba0964ff1bdccd049d4d2c2fec217efd90d202a4bb775e926b2c25d F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c b95181711d59c36d9789e67f76c4cfec64b99f9629a50be5e6566e117b87d957 -F src/shell.c.in a1cf350fa00e75eecf21d76e64a3bd2daaf90a5d31c1a2597e59edd7e3e2ee1a +F src/shell.c.in e58b0cecf2579c0115253e9c02a44b54fbadf77f4f33b43cfaa48a8274c9aa01 F src/sqlite.h.in 3285114481f84812b9d8c1dc41a2dcd48ce4e79f610b8392ae398b56d1800e1e F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479 F src/sqlite3ext.h 7f236ca1b175ffe03316d974ef57df79b3938466c28d2f95caef5e08c57f3a52 @@ -2171,8 +2171,8 @@ F tool/version-info.c 33d0390ef484b3b1cb685d59362be891ea162123cea181cb8e6d2cf6dd F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7 F tool/warnings.sh 1ad0169b022b280bcaaf94a7fa231591be96b514230ab5c98fbf15cd7df842dd F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P eafe88b782875cd839fc27da509830e3e1d95781c686e27242a2844910203a42 -R 7022e3a791fb52de409c6fc91d6ad96f +P 64045f0a4d71ef068d64f2f25799cf1ae79c3cdb94039c73f1066290e3dbc943 +R 8dad99d3cc73b12fe09f0f44e32c4e63 U drh -Z 4dfb0e7c66571c44833f2e4abaab7a73 +Z 87cde9cae3dbd3e703e8129f211fb4d4 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index bae7e1baa3..fc771bed96 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -64045f0a4d71ef068d64f2f25799cf1ae79c3cdb94039c73f1066290e3dbc943 +5e20a0435b1bd84d90c9a419219afe794fdf8ea73213f4c7ae5612c0375bed55 diff --git a/src/shell.c.in b/src/shell.c.in index 9fb0d5f5df..c74681e643 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -5308,6 +5308,7 @@ static const char *(azHelp[]) = { " --maxsize N Maximum size for --hexdb or --deserialized database", #endif " --new Initialize FILE to an empty database", + " --normal FILE is an ordinary SQLite database", " --nofollow Do not follow symbolic links", " --readonly Open FILE readonly", " --zip FILE is a ZIP archive", @@ -5649,7 +5650,7 @@ static int session_filter(void *pCtx, const char *zTab){ ** Otherwise, assume an ordinary database regardless of the filename if ** the type cannot be determined from content. */ -int deduceDatabaseType(const char *zName, int dfltZip){ +int deduceDatabaseType(const char *zName, int dfltZip, int openFlags){ FILE *f; size_t n; sqlite3 *db = 0; @@ -5657,7 +5658,7 @@ int deduceDatabaseType(const char *zName, int dfltZip){ int rc = SHELL_OPEN_UNSPEC; char zBuf[100]; if( access(zName,0)!=0 ) goto database_type_by_name; - if( sqlite3_open_v2(zName, &db, SQLITE_OPEN_READONLY, 0)==SQLITE_OK + if( sqlite3_open_v2(zName, &db, openFlags, 0)==SQLITE_OK && sqlite3_prepare_v2(db,"SELECT count(*) FROM sqlite_schema",-1,&pStmt,0) ==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW @@ -5866,7 +5867,7 @@ static void open_db(ShellState *p, int openFlags){ p->openMode = SHELL_OPEN_NORMAL; }else{ p->openMode = (u8)deduceDatabaseType(zDbFilename, - (openFlags & OPEN_DB_ZIPFILE)!=0); + (openFlags & OPEN_DB_ZIPFILE)!=0, p->openFlags); } } if( (p->openFlags & (SQLITE_OPEN_READONLY|SQLITE_OPEN_READWRITE))==0 ){ @@ -8247,7 +8248,7 @@ static int arDotCommand( cmd.out = pState->out; cmd.db = pState->db; if( cmd.zFile ){ - eDbType = deduceDatabaseType(cmd.zFile, 1); + eDbType = deduceDatabaseType(cmd.zFile, 1, 0); }else{ eDbType = pState->openMode; } @@ -10349,6 +10350,8 @@ static int do_meta_command(char *zLine, ShellState *p){ openMode = SHELL_OPEN_DESERIALIZE; }else if( optionMatch(z, "hexdb") ){ openMode = SHELL_OPEN_HEXDB; + }else if( optionMatch(z, "normal") ){ + openMode = SHELL_OPEN_NORMAL; }else if( optionMatch(z, "maxsize") && iName+1szMax = integerValue(azArg[++iName]); #endif /* SQLITE_OMIT_DESERIALIZE */ -- 2.47.3