diff options
author | drh <> | 2025-04-30 14:37:00 +0000 |
---|---|---|
committer | drh <> | 2025-04-30 14:37:00 +0000 |
commit | f23a61258bf9f9e346fe33ad6f740834455ade56 (patch) | |
tree | e49799090c98c15cbbbe51bbab19a77fc287d55f /src | |
parent | 88ed1806a4dae310ea08a9c2e6c5631e87c4fabb (diff) | |
download | sqlite-f23a61258bf9f9e346fe33ad6f740834455ade56.tar.gz sqlite-f23a61258bf9f9e346fe33ad6f740834455ade56.zip |
Fix a harmless problem in the CLI in which SQL errors that occur during
the ".schema" command are properly ignored, yes still appear in the ".log"
output. [forum:/forumpost/42fe6520b803be51|Forum post 42fe6520b8]
FossilOrigin-Name: 20abf1ec107f942e4527901685d61283c9c2fe7bcefad63dbf5c6cbf050da849
Diffstat (limited to 'src')
-rw-r--r-- | src/shell.c.in | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/src/shell.c.in b/src/shell.c.in index ca76e4a6e..7af8f79b8 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -1243,30 +1243,6 @@ static void shellDtostr( sqlite3_result_text(pCtx, z, -1, SQLITE_TRANSIENT); } - -/* -** SQL function: shell_module_schema(X) -** -** Return a fake schema for the table-valued function or eponymous virtual -** table X. -*/ -static void shellModuleSchema( - sqlite3_context *pCtx, - int nVal, - sqlite3_value **apVal -){ - const char *zName; - char *zFake; - UNUSED_PARAMETER(nVal); - zName = (const char*)sqlite3_value_text(apVal[0]); - zFake = zName? shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName) : 0; - if( zFake ){ - sqlite3_result_text(pCtx, sqlite3_mprintf("/* %s */", zFake), - -1, sqlite3_free); - free(zFake); - } -} - /* ** SQL function: shell_add_schema(S,X) ** @@ -5710,6 +5686,39 @@ static void shellUSleepFunc( sqlite3_result_int(context, sleep); } +/* +** SQL function: shell_module_schema(X) +** +** Return a fake schema for the table-valued function or eponymous virtual +** table X. +*/ +static void shellModuleSchema( + sqlite3_context *pCtx, + int nVal, + sqlite3_value **apVal +){ + const char *zName; + char *zFake; + ShellState *p = (ShellState*)sqlite3_user_data(pCtx); + FILE *pSavedLog = p->pLog; + UNUSED_PARAMETER(nVal); + zName = (const char*)sqlite3_value_text(apVal[0]); + + /* Temporarily disable the ".log" when calling shellFakeSchema() because + ** shellFakeSchema() might generate failures for some ephemeral virtual + ** tables due to missing arguments. Example: fts4aux. + ** https://sqlite.org/forum/forumpost/42fe6520b803be51 */ + p->pLog = 0; + zFake = zName? shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName) : 0; + p->pLog = pSavedLog; + + if( zFake ){ + sqlite3_result_text(pCtx, sqlite3_mprintf("/* %s */", zFake), + -1, sqlite3_free); + free(zFake); + } +} + /* Flags for open_db(). ** ** The default behavior of open_db() is to exit(1) if the database fails to @@ -5853,7 +5862,7 @@ static void open_db(ShellState *p, int openFlags){ shellDtostr, 0, 0); sqlite3_create_function(p->db, "shell_add_schema", 3, SQLITE_UTF8, 0, shellAddSchemaName, 0, 0); - sqlite3_create_function(p->db, "shell_module_schema", 1, SQLITE_UTF8, 0, + sqlite3_create_function(p->db, "shell_module_schema", 1, SQLITE_UTF8, p, shellModuleSchema, 0, 0); sqlite3_create_function(p->db, "shell_putsnl", 1, SQLITE_UTF8, p, shellPutsFunc, 0, 0); |