Skip to content

Commit de16a89

Browse files
author
D. Richard Hipp
committed
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]
1 parent a856780 commit de16a89

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

src/shell.c.in

+34-25
Original file line numberDiff line numberDiff line change
@@ -1243,30 +1243,6 @@ static void shellDtostr(
12431243
sqlite3_result_text(pCtx, z, -1, SQLITE_TRANSIENT);
12441244
}
12451245

1246-
1247-
/*
1248-
** SQL function: shell_module_schema(X)
1249-
**
1250-
** Return a fake schema for the table-valued function or eponymous virtual
1251-
** table X.
1252-
*/
1253-
static void shellModuleSchema(
1254-
sqlite3_context *pCtx,
1255-
int nVal,
1256-
sqlite3_value **apVal
1257-
){
1258-
const char *zName;
1259-
char *zFake;
1260-
UNUSED_PARAMETER(nVal);
1261-
zName = (const char*)sqlite3_value_text(apVal[0]);
1262-
zFake = zName? shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName) : 0;
1263-
if( zFake ){
1264-
sqlite3_result_text(pCtx, sqlite3_mprintf("/* %s */", zFake),
1265-
-1, sqlite3_free);
1266-
free(zFake);
1267-
}
1268-
}
1269-
12701246
/*
12711247
** SQL function: shell_add_schema(S,X)
12721248
**
@@ -5710,6 +5686,39 @@ static void shellUSleepFunc(
57105686
sqlite3_result_int(context, sleep);
57115687
}
57125688

5689+
/*
5690+
** SQL function: shell_module_schema(X)
5691+
**
5692+
** Return a fake schema for the table-valued function or eponymous virtual
5693+
** table X.
5694+
*/
5695+
static void shellModuleSchema(
5696+
sqlite3_context *pCtx,
5697+
int nVal,
5698+
sqlite3_value **apVal
5699+
){
5700+
const char *zName;
5701+
char *zFake;
5702+
ShellState *p = (ShellState*)sqlite3_user_data(pCtx);
5703+
FILE *pSavedLog = p->pLog;
5704+
UNUSED_PARAMETER(nVal);
5705+
zName = (const char*)sqlite3_value_text(apVal[0]);
5706+
5707+
/* Temporarily disable the ".log" when calling shellFakeSchema() because
5708+
** shellFakeSchema() might generate failures for some ephemeral virtual
5709+
** tables due to missing arguments. Example: fts4aux.
5710+
** https://sqlite.org/forum/forumpost/42fe6520b803be51 */
5711+
p->pLog = 0;
5712+
zFake = zName? shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName) : 0;
5713+
p->pLog = pSavedLog;
5714+
5715+
if( zFake ){
5716+
sqlite3_result_text(pCtx, sqlite3_mprintf("/* %s */", zFake),
5717+
-1, sqlite3_free);
5718+
free(zFake);
5719+
}
5720+
}
5721+
57135722
/* Flags for open_db().
57145723
**
57155724
** 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){
58535862
shellDtostr, 0, 0);
58545863
sqlite3_create_function(p->db, "shell_add_schema", 3, SQLITE_UTF8, 0,
58555864
shellAddSchemaName, 0, 0);
5856-
sqlite3_create_function(p->db, "shell_module_schema", 1, SQLITE_UTF8, 0,
5865+
sqlite3_create_function(p->db, "shell_module_schema", 1, SQLITE_UTF8, p,
58575866
shellModuleSchema, 0, 0);
58585867
sqlite3_create_function(p->db, "shell_putsnl", 1, SQLITE_UTF8, p,
58595868
shellPutsFunc, 0, 0);

0 commit comments

Comments
 (0)