1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-03 16:53:36 +03:00

Add the ".trace" option to the command-line shell.

FossilOrigin-Name: b9ac3d7e340eb616fd23cc7dbdef6fdd66a79fe4
This commit is contained in:
drh
2012-04-04 16:56:23 +00:00
parent 689453dbf0
commit 42f64e52ee
3 changed files with 71 additions and 36 deletions

View File

@@ -1,5 +1,5 @@
C Fix\sthe\smultiplexor\slogging\sso\sthat\sit\sworks\swith\sSQLITE_ENABLE_8_3_NAMES. C Add\sthe\s".trace"\soption\sto\sthe\scommand-line\sshell.
D 2012-04-04T13:58:19.112 D 2012-04-04T16:56:23.330
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 2f37e468503dbe79d35c9f6dffcf3fae1ae9ec20 F Makefile.in 2f37e468503dbe79d35c9f6dffcf3fae1ae9ec20
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -182,7 +182,7 @@ F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50
F src/resolve.c 3d3e80a98f203ac6b9329e9621e29eda85ddfd40 F src/resolve.c 3d3e80a98f203ac6b9329e9621e29eda85ddfd40
F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697 F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697
F src/select.c 5e0e481c7d215d3c7ca8ccae1e688aa30163c6c1 F src/select.c 5e0e481c7d215d3c7ca8ccae1e688aa30163c6c1
F src/shell.c abf18d6ee54f2631860a98fdd7ab1327f470db67 F src/shell.c ce4d41582182b8fad3be364e2fa295b70bc342ab
F src/sqlite.h.in 11a883919b0baf4ffaa7550cfeef99be613ec2bf F src/sqlite.h.in 11a883919b0baf4ffaa7550cfeef99be613ec2bf
F src/sqlite3ext.h 6904f4aadf976f95241311fbffb00823075d9477 F src/sqlite3ext.h 6904f4aadf976f95241311fbffb00823075d9477
F src/sqliteInt.h d701123ab4c8774ee2837cd4ade84e370d665f87 F src/sqliteInt.h d701123ab4c8774ee2837cd4ade84e370d665f87
@@ -1000,7 +1000,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
P 781453c686656a7bd4a274a3b3204ceb6ecae8df P 9e1e2fe2950bb96784413eae934314d95bce08e7
R c73cb9ac19cc77c57d2e11c87f4932e5 R 7ce64940a4af6b82ea18cf10b0da61e8
U drh U drh
Z d5193cf8e689933624e4e4454cffd3d6 Z 783b4beff01e2d5037d4d8570a1550e1

View File

@@ -1 +1 @@
9e1e2fe2950bb96784413eae934314d95bce08e7 b9ac3d7e340eb616fd23cc7dbdef6fdd66a79fe4

View File

@@ -421,6 +421,7 @@ struct callback_data {
int statsOn; /* True to display memory stats before each finalize */ int statsOn; /* True to display memory stats before each finalize */
int cnt; /* Number of records displayed so far */ int cnt; /* Number of records displayed so far */
FILE *out; /* Write results here */ FILE *out; /* Write results here */
FILE *traceOut; /* Output for sqlite3_trace() */
int nErr; /* Number of errors seen */ int nErr; /* Number of errors seen */
int mode; /* An output mode setting */ int mode; /* An output mode setting */
int writableSchema; /* True if PRAGMA writable_schema=ON */ int writableSchema; /* True if PRAGMA writable_schema=ON */
@@ -1433,6 +1434,7 @@ static char zHelp[] =
" If TABLE specified, only list tables matching\n" " If TABLE specified, only list tables matching\n"
" LIKE pattern TABLE.\n" " LIKE pattern TABLE.\n"
".timeout MS Try opening locked tables for MS milliseconds\n" ".timeout MS Try opening locked tables for MS milliseconds\n"
".trace FILE|off Output each SQL statement as it is run\n"
".vfsname ?AUX? Print the name of the VFS stack\n" ".vfsname ?AUX? Print the name of the VFS stack\n"
".width NUM1 NUM2 ... Set column widths for \"column\" mode\n" ".width NUM1 NUM2 ... Set column widths for \"column\" mode\n"
; ;
@@ -1522,6 +1524,43 @@ static int booleanValue(char *zArg){
return val; return val;
} }
/*
** Close an output file, assuming it is not stderr or stdout
*/
static void output_file_close(FILE *f){
if( f && f!=stdout && f!=stderr ) fclose(f);
}
/*
** Try to open an output file. The names "stdout" and "stderr" are
** recognized and do the right thing. NULL is returned if the output
** filename is "off".
*/
static FILE *output_file_open(const char *zFile){
FILE *f;
if( strcmp(zFile,"stdout")==0 ){
f = stdout;
}else if( strcmp(zFile, "stderr")==0 ){
f = stderr;
}else if( strcmp(zFile, "off")==0 ){
f = 0;
}else{
f = fopen(zFile, "wb");
if( f==0 ){
fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
}
}
return f;
}
/*
** A routine for handling output from sqlite3_trace().
*/
static void sql_trace_callback(void *pArg, const char *z){
FILE *f = (FILE*)pArg;
if( f ) fprintf(f, "%s\n", z);
}
/* /*
** If an input line begins with "." then invoke this routine to ** If an input line begins with "." then invoke this routine to
** process that line. ** process that line.
@@ -1932,22 +1971,8 @@ static int do_meta_command(char *zLine, struct callback_data *p){
if( c=='l' && strncmp(azArg[0], "log", n)==0 && nArg>=2 ){ if( c=='l' && strncmp(azArg[0], "log", n)==0 && nArg>=2 ){
const char *zFile = azArg[1]; const char *zFile = azArg[1];
if( p->pLog && p->pLog!=stdout && p->pLog!=stderr ){ output_file_close(p->pLog);
fclose(p->pLog); p->pLog = output_file_open(zFile);
p->pLog = 0;
}
if( strcmp(zFile,"stdout")==0 ){
p->pLog = stdout;
}else if( strcmp(zFile, "stderr")==0 ){
p->pLog = stderr;
}else if( strcmp(zFile, "off")==0 ){
p->pLog = 0;
}else{
p->pLog = fopen(zFile, "w");
if( p->pLog==0 ){
fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
}
}
}else }else
if( c=='m' && strncmp(azArg[0], "mode", n)==0 && nArg==2 ){ if( c=='m' && strncmp(azArg[0], "mode", n)==0 && nArg==2 ){
@@ -2000,17 +2025,13 @@ static int do_meta_command(char *zLine, struct callback_data *p){
}else }else
if( c=='o' && strncmp(azArg[0], "output", n)==0 && nArg==2 ){ if( c=='o' && strncmp(azArg[0], "output", n)==0 && nArg==2 ){
if( p->out!=stdout ){
if( p->outfile[0]=='|' ){ if( p->outfile[0]=='|' ){
pclose(p->out); pclose(p->out);
}else{ }else{
fclose(p->out); output_file_close(p->out);
} }
} p->outfile[0] = 0;
if( strcmp(azArg[1],"stdout")==0 ){ if( azArg[1][0]=='|' ){
p->out = stdout;
sqlite3_snprintf(sizeof(p->outfile), p->outfile, "stdout");
}else if( azArg[1][0]=='|' ){
p->out = popen(&azArg[1][1], "w"); p->out = popen(&azArg[1][1], "w");
if( p->out==0 ){ if( p->out==0 ){
fprintf(stderr,"Error: cannot open pipe \"%s\"\n", &azArg[1][1]); fprintf(stderr,"Error: cannot open pipe \"%s\"\n", &azArg[1][1]);
@@ -2020,9 +2041,11 @@ static int do_meta_command(char *zLine, struct callback_data *p){
sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", azArg[1]); sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", azArg[1]);
} }
}else{ }else{
p->out = fopen(azArg[1], "wb"); p->out = output_file_open(azArg[1]);
if( p->out==0 ){ if( p->out==0 ){
if( strcmp(azArg[1],"off")!=0 ){
fprintf(stderr,"Error: cannot write to \"%s\"\n", azArg[1]); fprintf(stderr,"Error: cannot write to \"%s\"\n", azArg[1]);
}
p->out = stdout; p->out = stdout;
rc = 1; rc = 1;
} else { } else {
@@ -2396,6 +2419,18 @@ static int do_meta_command(char *zLine, struct callback_data *p){
enableTimer = booleanValue(azArg[1]); enableTimer = booleanValue(azArg[1]);
}else }else
if( c=='t' && strncmp(azArg[0], "trace", n)==0 && nArg>1 ){
output_file_close(p->traceOut);
p->traceOut = output_file_open(azArg[1]);
#ifndef SQLITE_OMIT_TRACE
if( p->traceOut==0 ){
sqlite3_trace(p->db, 0, 0);
}else{
sqlite3_trace(p->db, sql_trace_callback, p->traceOut);
}
#endif
}else
if( c=='v' && strncmp(azArg[0], "version", n)==0 ){ if( c=='v' && strncmp(azArg[0], "version", n)==0 ){
printf("SQLite %s %s\n" /*extra-version-info*/, printf("SQLite %s %s\n" /*extra-version-info*/,
sqlite3_libversion(), sqlite3_sourceid()); sqlite3_libversion(), sqlite3_sourceid());