@@ -1243,30 +1243,6 @@ static void shellDtostr(
1243
1243
sqlite3_result_text(pCtx, z, -1, SQLITE_TRANSIENT);
1244
1244
}
1245
1245
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
-
1270
1246
/*
1271
1247
** SQL function: shell_add_schema(S,X)
1272
1248
**
@@ -5710,6 +5686,39 @@ static void shellUSleepFunc(
5710
5686
sqlite3_result_int(context, sleep);
5711
5687
}
5712
5688
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
+
5713
5722
/* Flags for open_db().
5714
5723
**
5715
5724
** 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){
5853
5862
shellDtostr, 0, 0);
5854
5863
sqlite3_create_function(p->db, "shell_add_schema", 3, SQLITE_UTF8, 0,
5855
5864
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 ,
5857
5866
shellModuleSchema, 0, 0);
5858
5867
sqlite3_create_function(p->db, "shell_putsnl", 1, SQLITE_UTF8, p,
5859
5868
shellPutsFunc, 0, 0);
0 commit comments