1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-06 15:49:35 +03:00

Add the undocumented and experimental I/O tracing interface. This

interface is likely to change and may be completely abandoned in the
near future. (CVS 3665)

FossilOrigin-Name: 007ca283892a66dd8b9e0dfece4f75d0d08a4300
This commit is contained in:
drh
2007-02-28 04:47:26 +00:00
parent 15d00c4e7b
commit b0603416dc
6 changed files with 93 additions and 14 deletions

View File

@@ -12,7 +12,7 @@
** This file contains code to implement the "sqlite" command line
** utility for accessing SQLite databases.
**
** $Id: shell.c,v 1.158 2007/01/08 14:31:36 drh Exp $
** $Id: shell.c,v 1.159 2007/02/28 04:47:27 drh Exp $
*/
#include <stdlib.h>
#include <string.h>
@@ -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,25 @@ 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;
if( iotrace==0 ) return;
va_start(ap, zFormat);
vfprintf(iotrace, zFormat, ap);
va_end(ap);
}
/*
** Determines if a string is a number of not.
@@ -1219,6 +1239,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;