From: drh <> Date: Tue, 10 Mar 2026 21:01:59 +0000 (+0000) Subject: Fix the behavior dot-commands that appear as command line arguments to the X-Git-Tag: major-release~87 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=3bd23b0d78a790e0d82222f1dfa8c204ba4d6955;p=thirdparty%2Fsqlite.git Fix the behavior dot-commands that appear as command line arguments to the CLI so that their effect persists into subsequent commands on the command line. This fix also improves error messages caused by command line arguments. [forum:/forumpost/2026-03-10T19:26:06z|Forum post 2026-03-10T19:26:06z]. FossilOrigin-Name: ff084ae341eab5c4ce9403defee03adc448c05f77648a954f0942a38f640080b --- diff --git a/manifest b/manifest index 70f6b3490a..da2a162e0d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Revamp\sthe\sQRF\sinsert-mode\soptimization\sof\s[659ff6ab55802507].\s\sThe\ncontrol\svalue\sis\snow\snMultiInsert.\s\sMultiple\srows\sare\sadded\sto\seach\sINSERT\nstatement\suntil\sthe\snumber\sof\sbytes\sin\sthat\sstatement\sexceeds\sthe\nnMultiInsert\svalue.\s\sThe\sCLI\suses\sa\sdefault\svalue\sof\s3000,\swhich\sprovides\na\sgood\sbalance\sbetween\sspeed\sand\sprepare-statement\ssize.\s\sThe\soutput\nfrom\s".dump"\snow\sloads\snearly\s2x\sfaster\sin\ssome\scases. -D 2026-03-10T18:13:13.382 +C Fix\sthe\sbehavior\sdot-commands\sthat\sappear\sas\scommand\sline\sarguments\sto\sthe\nCLI\sso\sthat\stheir\seffect\spersists\sinto\ssubsequent\scommands\son\sthe\scommand\nline.\s\sThis\sfix\salso\simproves\serror\smessages\scaused\sby\scommand\sline\narguments.\s\n[forum:/forumpost/2026-03-10T19:26:06z|Forum\spost\s2026-03-10T19:26:06z]. +D 2026-03-10T21:01:59.339 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -733,7 +733,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 928ff887f2a7c64275182060d94d06fdddbe32226c569781cf7e7edc6f58d7fd F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c ffe199f025a0dd74670d2a77232bdea364a4d7b36f32c64a6572d39ba6a11576 -F src/shell.c.in dc19fd2fddbfec60f52852edbb4a4e3723e23e00c63b2ea289800fa4d37b7a6e +F src/shell.c.in 5bfc926b756d5816fcaf56a30c3a363ba09ac09a9f6a5a7eef1b27c8bac8f6c4 F src/sqlite.h.in 4d657846d68a58b028f0c4c331b9d3b4a79306f25c3b0d04fb56060343f73d85 F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479 F src/sqlite3ext.h 1b7a0ee438bb5c2896d0609c537e917d8057b3340f6ad004d2de44f03e3d3cca @@ -1534,7 +1534,7 @@ F test/rbu.test 168573d353cd0fd10196b87b0caa322c144ef736 F test/rdonly.test 64e2696c322e3538df0b1ed624e21f9a23ed9ff8 F test/readonly.test 0d307c335b3421898cfe64a783a376138aa003849b6bff61ee2d21e805bc0051 F test/recover.test 643139b911ac880a1e881d7621f02cfb546b608b8f2494d7d26fd5ed103b1ceb -F test/regexp1.sql de2b5b33b16b664d655b41e780f2efca38de3e5559fc254b4c9783ff0bea96b0 +F test/regexp1.sql fd15d317973dd0c9cd9ee7b8bda45ef1c0a5e126223fc53c86d71b5d407e6fb4 F test/regexp1.test 0023eae4073265641b826a70d81ba34d4dd66ad71871a5b4a1b7cf500d5c0c51 F test/regexp2.test 64f9726b2ddc71aea06725fcad53231833d038d58b936d49083ace658b370a13 F test/reindex.test cd9d6021729910ece82267b4f5e1b5ac2911a7566c43b43c176a6a4732e2118d @@ -1615,15 +1615,15 @@ F test/sharedA.test 64bdd21216dda2c6a3bd3475348ccdc108160f34682c97f2f51c19fc0e21 F test/sharedB.test 1a84863d7a2204e0d42f2e1606577c5e92e4473fa37ea0f5bdf829e4bf8ee707 F test/shared_err.test 32634e404a3317eeb94abc7a099c556a346fdb8fb3858dbe222a4cbb8926a939 F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304 -F test/shell1.test 2d658ceee13d9e4361d04d0ea16340ad17784ddf378fb6e9ca6d49c682cb4bae +F test/shell1.test d714be78c063cfb5f0933dcf2b5d9df62ef57f8eaf8848bbd0026a9d252d4db5 F test/shell2.test dc541d2681503e55466a24d35a4cbf8ca5b90b8fcdef37fc4db07373a67d31d3 -F test/shell3.test 603b448e917537cf77be0f265c05c6f63bc677c63a533c8e96aae923b56f4a0e +F test/shell3.test 91efdd545097a61a1f72cf79c9ad5b49da080f3f10282eaf4c3c272cd1012db2 F test/shell4.test e25580a792b7b54560c3a76b6968bd8189261f38979fe28e6bc6312c5db280db F test/shell5.test a9cd2c8b62e125049ef500937674f47dd6787f0157ac0515aa554044a4dc3ea9 F test/shell6.test e3b883b61d4916b6906678a35f9d19054861123ad91b856461e0a456273bdbb8 F test/shell7.test 43fd8e511c533bab5232e95c7b4be93b243451709e89582600d4b6e67693d5c3 F test/shell8.test 38c9e4d7e85d2a3ecfacaa9f6cda4f7a81bf4fffb5f3f37f9cd76827c6883192 -F test/shell9.test 8742a5b390cdcef6369f5aa223e415aa4255a4129ef249b177887dc635a87209 +F test/shell9.test c0e8871061a92151450b3332279a893b516fa73a6c46d4f51a0998407cbf8c89 F test/shellA.test 05cdaafa1f79913654487ce3aefa038d4106245d58f52e02faf506140a76d480 F test/shellB.test 7123d231158588401f332bf278754687b83ba5fc5b352ec8679fb19edfb4cc0a F test/shmlock.test 9f1f729a7fe2c46c88b156af819ac9b72c0714ac6f7246638a73c5752b5fd13c @@ -2192,8 +2192,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c -P f6787e4b50af50663d8fa00ebe0694440354a7ad0509837a6b249e090e6cffca -R d860bc66dd6bb7267fd1bfd3a3708814 +P 55b0ce9f93d68b17a18423f0f751b778573127743a2bac67abfea074ac32d41a +R 21539a759b0a7022400859ae71a2ff6b U drh -Z d618cb096ff3c243141ddcd38eae46e6 +Z b14a9c81759ec24063349a7bdc6c3b5d # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ceeffaa003..d1c036ca92 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -55b0ce9f93d68b17a18423f0f751b778573127743a2bac67abfea074ac32d41a +ff084ae341eab5c4ce9403defee03adc448c05f77648a954f0942a38f640080b diff --git a/src/shell.c.in b/src/shell.c.in index c007856b2b..1aa6e442de 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -12227,7 +12227,12 @@ static int doAutoDetectRestore(ShellState *p, const char *zSql){ /* ** Run a single line of SQL. Return the number of errors. */ -static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){ +static int runOneSqlLine( + ShellState *p, /* Execution context */ + char *zSql, /* SQL to be run */ + const char *zFilename, /* Source file of the sql */ + int startline /* linenumber */ +){ int rc; char *zErrMsg = 0; @@ -12254,9 +12259,17 @@ static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){ zErrorType = "Error"; zErrorTail = zErrMsg; } - if( in!=0 || !stdin_is_interactive ){ - sqlite3_snprintf(sizeof(zPrefix), zPrefix, - "%s near line %d:", zErrorType, startline); + if( zFilename || !stdin_is_interactive ){ + if( cli_strcmp(zFilename,"cmdline")==0 ){ + sqlite3_snprintf(sizeof(zPrefix), zPrefix, + "%s in %r command line argument:", zErrorType, startline); + }else if( cli_strcmp(zFilename,"")==0 ){ + sqlite3_snprintf(sizeof(zPrefix), zPrefix, + "%s near line %d:", zErrorType, startline); + }else{ + sqlite3_snprintf(sizeof(zPrefix), zPrefix, + "%s near line %d of %s:", zErrorType, startline, zFilename); + } }else{ sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%s:", zErrorType); } @@ -12419,7 +12432,7 @@ static int process_input(ShellState *p, const char *zSrc){ break; }else if( nSql && QSS_SEMITERM(qss) && sqlite3_complete(zSql) ){ echo_group_input(p, zSql); - errCnt += runOneSqlLine(p, zSql, p->in, startline); + errCnt += runOneSqlLine(p, zSql, p->zInFile, startline); CONTINUE_PROMPT_RESET; nSql = 0; if( p->nPopOutput ){ @@ -12443,7 +12456,7 @@ static int process_input(ShellState *p, const char *zSrc){ if( nSql ){ /* This may be incomplete. Let the SQL parser deal with that. */ echo_group_input(p, zSql); - errCnt += runOneSqlLine(p, zSql, p->in, startline); + errCnt += runOneSqlLine(p, zSql, p->zInFile, startline); CONTINUE_PROMPT_RESET; } free(zSql); @@ -12840,7 +12853,6 @@ int SQLITE_CDECL main(int argc, char **argv){ #ifdef SQLITE_DEBUG sqlite3_int64 mem_main_enter = 0; #endif - char *zErrMsg = 0; #ifdef SQLITE_SHELL_FIDDLE # define data shellState #else @@ -13379,15 +13391,7 @@ int SQLITE_CDECL main(int argc, char **argv){ goto shell_main_exit; } }else{ - open_db(&data, 0); - rc = shell_exec(&data, z, &zErrMsg); - if( zErrMsg!=0 ){ - shellEmitError(zErrMsg); - sqlite3_free(zErrMsg); - if( !rc ) rc = 1; - }else if( rc!=0 ){ - cli_printf(stderr,"Error: unable to process SQL \"%s\"\n", z); - } + rc = runOneSqlLine(&data, z, "cmdline", i); if( bail_on_error ) goto shell_main_exit; } #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) @@ -13453,25 +13457,13 @@ int SQLITE_CDECL main(int argc, char **argv){ goto shell_main_exit; } }else{ - open_db(&data, 0); - rc = shell_exec(&data, azCmd[i], &zErrMsg); - if( zErrMsg || rc ){ - if( zErrMsg!=0 ){ - shellEmitError(zErrMsg); - }else{ - cli_printf(stderr, - "Error: unable to process SQL: %s\n", azCmd[i]); - } - sqlite3_free(zErrMsg); - if( rc==0 ) rc = 1; - goto shell_main_exit; - } + rc = runOneSqlLine(&data, azCmd[i], "cmdline", aiCmd[i]); if( data.nPopMode ){ modePop(&data); data.nPopMode = 0; } } - if( data.nPopOutput ){ + if( data.nPopOutput && azCmd[i][0]!='.' ){ output_reset(&data); data.nPopOutput = 0; }else{ diff --git a/test/regexp1.sql b/test/regexp1.sql index c1938885a6..00bf2b41a3 100644 --- a/test/regexp1.sql +++ b/test/regexp1.sql @@ -24,7 +24,7 @@ SELECT 'abcdefg' REGEXP '((((((((((((((((((abcdefg))))))))))))))))))'; .testcase 110 .limit like_pattern_length 42 SELECT 'abcdefg' REGEXP '((((((((((((((((((abcdefg))))))))))))))))))'; -.check -glob "Error near line #: REGEXP pattern too big*" +.check -glob "Error near line *: REGEXP pattern too big*" .testcase 120 .limit like_pattern_length 43 diff --git a/test/shell1.test b/test/shell1.test index 1d111d6161..162f5f3e86 100644 --- a/test/shell1.test +++ b/test/shell1.test @@ -54,7 +54,7 @@ do_test shell1-1.1.2 { # error on extra options do_test shell1-1.1.3 { catchcmd "test.db FOO test.db BAD" ".quit" -} {/1 .Error: in prepare, near "FOO": syntax error*/} +} {/1 .Parse error in 2nd command line argument: near "FOO": syntax error*/} # -help do_test shell1-1.2.1 { @@ -79,7 +79,7 @@ do_test shell1-1.3.2 { } {0 {}} do_test shell1-1.3.3 { catchcmd "-init FOO test.db BAD .quit" "" -} {/1 .Error: in prepare, near "BAD": syntax error*/} +} {/1 .Parse error in 4th command line argument: near "BAD": syntax error*/} # -echo print commands before execution do_test shell1-1.4.1 { diff --git a/test/shell3.test b/test/shell3.test index 6bb49f5c3d..3b1246dfe8 100644 --- a/test/shell3.test +++ b/test/shell3.test @@ -69,7 +69,7 @@ do_test shell3-1.6 { } {0 {}} do_test shell3-1.7 { catchcmd "foo.db \"CREATE TABLE\"" -} {1 {Error: in prepare, incomplete input}} +} {1 {Parse error in 2nd command line argument: incomplete input}} #---------------------------------------------------------------------------- # shell3-2.*: Basic tests for running SQL file from command line. diff --git a/test/shell9.test b/test/shell9.test index 869cb075da..173de3b068 100644 --- a/test/shell9.test +++ b/test/shell9.test @@ -74,7 +74,7 @@ do_execsql_test 1.2.1 { db close do_test 1.2.2 { catchcmd test.db ".read testdump.txt" -} {1 {Parse error near line 5: table sqlite_master may not be modified}} +} {1 {Parse error near line 5 of testdump.txt: table sqlite_master may not be modified}} # Check testdump.txt cannot be processed if the db is in safe mode #