diff options
Diffstat (limited to 'ext/pdo_sqlite/sqlite/src/shell.c')
| -rw-r--r-- | ext/pdo_sqlite/sqlite/src/shell.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/ext/pdo_sqlite/sqlite/src/shell.c b/ext/pdo_sqlite/sqlite/src/shell.c index 0cf75e2046..0e4cc4e230 100644 --- a/ext/pdo_sqlite/sqlite/src/shell.c +++ b/ext/pdo_sqlite/sqlite/src/shell.c @@ -20,6 +20,7 @@ #include <assert.h> #include "sqlite3.h" #include <ctype.h> +#include <stdarg.h> #if !defined(_WIN32) && !defined(WIN32) && !defined(__MACOS__) && !defined(__OS2__) # include <signal.h> @@ -97,6 +98,28 @@ static char *Argv0; static char mainPrompt[20]; /* First line prompt. default: "sqlite> "*/ static char continuePrompt[20]; /* Continuation prompt. default: " ...> " */ +/* +** Write I/O traces to the following stream. +*/ +static FILE *iotrace = 0; + +/* +** This routine works like printf in that its first argument is a +** format string and subsequent arguments are values to be substituted +** in place of % fields. The result of formatting this string +** is written to iotrace. +*/ +static void iotracePrintf(const char *zFormat, ...){ + va_list ap; + char *z; + if( iotrace==0 ) return; + va_start(ap, zFormat); + z = sqlite3_vmprintf(zFormat, ap); + va_end(ap); + fprintf(iotrace, "%s", z); + sqlite3_free(z); +} + /* ** Determines if a string is a number of not. @@ -1219,6 +1242,26 @@ static int do_meta_command(char *zLine, struct callback_data *p){ } }else + if( c=='i' && strncmp(azArg[0], "iotrace", n)==0 ){ + extern void (*sqlite3_io_trace)(const char*, ...); + if( iotrace && iotrace!=stdout ) fclose(iotrace); + iotrace = 0; + if( nArg<2 ){ + sqlite3_io_trace = 0; + }else if( strcmp(azArg[1], "-")==0 ){ + sqlite3_io_trace = iotracePrintf; + iotrace = stdout; + }else{ + iotrace = fopen(azArg[1], "w"); + if( iotrace==0 ){ + fprintf(stderr, "cannot open \"%s\"\n", azArg[1]); + sqlite3_io_trace = 0; + }else{ + sqlite3_io_trace = iotracePrintf; + } + } + }else + #ifndef SQLITE_OMIT_LOAD_EXTENSION if( c=='l' && strncmp(azArg[0], "load", n)==0 && nArg>=2 ){ const char *zFile, *zProc; |
