#define isatty(x) 1
#endif
+/* True if the timer is enabled */
+static int enableTimer = 0;
+
#if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) && !defined(__RTP__) && !defined(_WRS_KERNEL)
#include <sys/time.h>
#include <sys/resource.h>
/* Saved resource information for the beginning of an operation */
static struct rusage sBegin;
-/* True if the timer is enabled */
-static int enableTimer = 0;
-
/*
** Begin timing an operation
*/
typedef BOOL (WINAPI *GETPROCTIMES)(HANDLE, LPFILETIME, LPFILETIME, LPFILETIME, LPFILETIME);
static GETPROCTIMES getProcessTimesAddr = NULL;
-/* True if the timer is enabled */
-static int enableTimer = 0;
-
/*
** Check to see if we have timer support. Return 1 if necessary
** support found (or found previously).
** .explain ON */
char outfile[FILENAME_MAX]; /* Filename for *out */
const char *zDbFilename; /* name of the database file */
+ const char *zVfs; /* Name of VFS to use */
sqlite3_stmt *pStmt; /* Current statement if any. */
FILE *pLog; /* Write log output here */
};
}else
#endif
- if( c=='l' && strncmp(azArg[0], "log", n)==0 && nArg>=1 ){
+ if( c=='l' && strncmp(azArg[0], "log", n)==0 && nArg>=2 ){
const char *zFile = azArg[1];
if( p->pLog && p->pLog!=stdout && p->pLog!=stderr ){
fclose(p->pLog);
sqlite3_free_table(azResult);
}else
+ if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 && nArg>=2 ){
+ static const struct {
+ const char *zCtrlName; /* Name of a test-control option */
+ int ctrlCode; /* Integer code for that option */
+ } aCtrl[] = {
+ { "prng_save", SQLITE_TESTCTRL_PRNG_SAVE },
+ { "prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE },
+ { "prng_reset", SQLITE_TESTCTRL_PRNG_RESET },
+ { "bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST },
+ { "fault_install", SQLITE_TESTCTRL_FAULT_INSTALL },
+ { "benign_malloc_hooks", SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS },
+ { "pending_byte", SQLITE_TESTCTRL_PENDING_BYTE },
+ { "assert", SQLITE_TESTCTRL_ASSERT },
+ { "always", SQLITE_TESTCTRL_ALWAYS },
+ { "reserve", SQLITE_TESTCTRL_RESERVE },
+ { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS },
+ { "iskeyword", SQLITE_TESTCTRL_ISKEYWORD },
+ { "pghdrsz", SQLITE_TESTCTRL_PGHDRSZ },
+ { "scratchmalloc", SQLITE_TESTCTRL_SCRATCHMALLOC },
+ };
+ int testctrl = -1;
+ int rc = 0;
+ int i, n;
+ open_db(p);
+
+ /* convert testctrl text option to value. allow any unique prefix
+ ** of the option name, or a numerical value. */
+ n = strlen30(azArg[1]);
+ for(i=0; i<(int)(sizeof(aCtrl)/sizeof(aCtrl[0])); i++){
+ if( strncmp(azArg[1], aCtrl[i].zCtrlName, n)==0 ){
+ if( testctrl<0 ){
+ testctrl = aCtrl[i].ctrlCode;
+ }else{
+ fprintf(stderr, "ambiguous option name: \"%s\"\n", azArg[i]);
+ testctrl = -1;
+ break;
+ }
+ }
+ }
+ if( testctrl<0 ) testctrl = atoi(azArg[1]);
+ if( (testctrl<SQLITE_TESTCTRL_FIRST) || (testctrl>SQLITE_TESTCTRL_LAST) ){
+ fprintf(stderr,"Error: invalid testctrl option: %s\n", azArg[1]);
+ }else{
+ switch(testctrl){
+
+ /* sqlite3_test_control(int, db, int) */
+ case SQLITE_TESTCTRL_OPTIMIZATIONS:
+ case SQLITE_TESTCTRL_RESERVE:
+ if( nArg==3 ){
+ int opt = (int)strtol(azArg[2], 0, 0);
+ rc = sqlite3_test_control(testctrl, p->db, opt);
+ printf("%d (0x%08x)\n", rc, rc);
+ } else {
+ fprintf(stderr,"Error: testctrl %s takes a single int option\n",
+ azArg[1]);
+ }
+ break;
+
+ /* sqlite3_test_control(int) */
+ case SQLITE_TESTCTRL_PRNG_SAVE:
+ case SQLITE_TESTCTRL_PRNG_RESTORE:
+ case SQLITE_TESTCTRL_PRNG_RESET:
+ case SQLITE_TESTCTRL_PGHDRSZ:
+ if( nArg==2 ){
+ rc = sqlite3_test_control(testctrl);
+ printf("%d (0x%08x)\n", rc, rc);
+ } else {
+ fprintf(stderr,"Error: testctrl %s takes no options\n", azArg[1]);
+ }
+ break;
+
+ /* sqlite3_test_control(int, uint) */
+ case SQLITE_TESTCTRL_PENDING_BYTE:
+ if( nArg==3 ){
+ unsigned int opt = (unsigned int)atoi(azArg[2]);
+ rc = sqlite3_test_control(testctrl, opt);
+ printf("%d (0x%08x)\n", rc, rc);
+ } else {
+ fprintf(stderr,"Error: testctrl %s takes a single unsigned"
+ " int option\n", azArg[1]);
+ }
+ break;
+
+ /* sqlite3_test_control(int, int) */
+ case SQLITE_TESTCTRL_ASSERT:
+ case SQLITE_TESTCTRL_ALWAYS:
+ if( nArg==3 ){
+ int opt = atoi(azArg[2]);
+ rc = sqlite3_test_control(testctrl, opt);
+ printf("%d (0x%08x)\n", rc, rc);
+ } else {
+ fprintf(stderr,"Error: testctrl %s takes a single int option\n",
+ azArg[1]);
+ }
+ break;
+
+ /* sqlite3_test_control(int, char *) */
+#ifdef SQLITE_N_KEYWORD
+ case SQLITE_TESTCTRL_ISKEYWORD:
+ if( nArg==3 ){
+ const char *opt = azArg[2];
+ rc = sqlite3_test_control(testctrl, opt);
+ printf("%d (0x%08x)\n", rc, rc);
+ } else {
+ fprintf(stderr,"Error: testctrl %s takes a single char * option\n",
+ azArg[1]);
+ }
+ break;
+#endif
+
+ case SQLITE_TESTCTRL_BITVEC_TEST:
+ case SQLITE_TESTCTRL_FAULT_INSTALL:
+ case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS:
+ case SQLITE_TESTCTRL_SCRATCHMALLOC:
+ default:
+ fprintf(stderr,"Error: CLI support for testctrl %s not implemented\n",
+ azArg[1]);
+ break;
+ }
+ }
+ }else
+
if( c=='t' && n>4 && strncmp(azArg[0], "timeout", n)==0 && nArg==2 ){
open_db(p);
sqlite3_busy_timeout(p->db, atoi(azArg[1]));
}else
- if( HAS_TIMER && c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0 && nArg==2 ){
+ if( HAS_TIMER && c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0
+ && nArg==2
+ ){
enableTimer = booleanValue(azArg[1]);
}else
}
}
if( zSql ){
- if( !_all_whitespace(zSql) ) fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
+ if( !_all_whitespace(zSql) ){
+ fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
+ }
free(zSql);
}
free(zLine);
" -stats print memory stats before each finalize\n"
" -nullvalue 'text' set text string for NULL values\n"
" -version show SQLite version\n"
+ " -vfs NAME use NAME as the default VFS\n"
+#ifdef SQLITE_ENABLE_VFSTRACE
+ " -vfstrace enable tracing of all VFS calls\n"
+#endif
;
static void usage(int showDetail){
fprintf(stderr,
#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
sqlite3_config(SQLITE_CONFIG_HEAP, malloc((int)szHeap), (int)szHeap, 64);
#endif
+#ifdef SQLITE_ENABLE_VFSTRACE
+ }else if( strcmp(argv[i],"-vfstrace")==0 ){
+ extern int vfstrace_register(
+ const char *zTraceName,
+ const char *zOldVfsName,
+ int (*xOut)(const char*,void*),
+ void *pOutArg,
+ int makeDefault
+ );
+ vfstrace_register("trace",0,(int(*)(const char*,void*))fputs,stderr,1);
+#endif
+ }else if( strcmp(argv[i],"-vfs")==0 ){
+ sqlite3_vfs *pVfs = sqlite3_vfs_find(argv[++i]);
+ if( pVfs ){
+ sqlite3_vfs_register(pVfs, 1);
+ }else{
+ fprintf(stderr, "no such VFS: \"%s\"\n", argv[i]);
+ exit(1);
+ }
}
}
if( i<argc ){
stdin_is_interactive = 0;
}else if( strcmp(z,"-heap")==0 ){
i++;
+ }else if( strcmp(z,"-vfs")==0 ){
+ i++;
+ }else if( strcmp(z,"-vfstrace")==0 ){
+ i++;
}else if( strcmp(z,"-help")==0 || strcmp(z, "--help")==0 ){
usage(1);
}else{