2017-10-13 20:58:55 +02:00
|
|
|
/*
|
|
|
|
** Read an SQLite database file and analyze its space utilization. Generate
|
|
|
|
** text on standard output.
|
|
|
|
*/
|
2017-10-13 22:14:06 +02:00
|
|
|
#define TCLSH_INIT_PROC sqlite3_analyzer_init_proc
|
2017-10-13 20:58:55 +02:00
|
|
|
#define SQLITE_ENABLE_DBSTAT_VTAB 1
|
|
|
|
#undef SQLITE_THREADSAFE
|
|
|
|
#define SQLITE_THREADSAFE 0
|
|
|
|
#undef SQLITE_ENABLE_COLUMN_METADATA
|
|
|
|
#define SQLITE_OMIT_DECLTYPE 1
|
|
|
|
#define SQLITE_OMIT_DEPRECATED 1
|
|
|
|
#define SQLITE_OMIT_PROGRESS_CALLBACK 1
|
|
|
|
#define SQLITE_OMIT_SHARED_CACHE 1
|
|
|
|
#define SQLITE_DEFAULT_MEMSTATUS 0
|
|
|
|
#define SQLITE_MAX_EXPR_DEPTH 0
|
|
|
|
#define SQLITE_OMIT_LOAD_EXTENSION 1
|
2021-11-18 21:56:59 +01:00
|
|
|
#if !defined(SQLITE_AMALGAMATION) && !defined(USE_EXTERNAL_SQLITE)
|
2017-10-13 20:58:55 +02:00
|
|
|
INCLUDE sqlite3.c
|
2017-10-31 15:56:44 +01:00
|
|
|
#endif
|
2017-10-13 20:58:55 +02:00
|
|
|
INCLUDE $ROOT/src/tclsqlite.c
|
|
|
|
|
2024-01-03 15:13:27 +01:00
|
|
|
#if defined(_WIN32)
|
2024-09-24 19:49:06 +02:00
|
|
|
INCLUDE $ROOT/ext/misc/sqlite3_stdio.h
|
|
|
|
INCLUDE $ROOT/ext/misc/sqlite3_stdio.c
|
2024-01-03 15:13:27 +01:00
|
|
|
|
|
|
|
/* Substitute "puts" command. Only these forms recognized:
|
|
|
|
**
|
|
|
|
** puts STRING
|
|
|
|
** puts stderr STRING
|
|
|
|
** puts -nonewline STRING
|
|
|
|
*/
|
|
|
|
static int subst_puts(
|
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *const*objv
|
|
|
|
){
|
|
|
|
FILE *pOut = stdout;
|
|
|
|
const char *zOut;
|
|
|
|
int addNewLine = 1;
|
|
|
|
if( objc==2 ){
|
|
|
|
zOut = Tcl_GetString(objv[1]);
|
|
|
|
}else if( objc!=3 ){
|
|
|
|
Tcl_WrongNumArgs(interp, 1, objv, "?stderr|-nonewline? STRING");
|
|
|
|
return TCL_ERROR;
|
|
|
|
}else{
|
|
|
|
const char *zArg = Tcl_GetString(objv[1]);
|
|
|
|
if( zArg==0 ) return TCL_ERROR;
|
|
|
|
zOut = Tcl_GetString(objv[2]);
|
|
|
|
if( strcmp(zArg, "stderr")==0 ){
|
|
|
|
pOut = stderr;
|
|
|
|
}else if( strcmp(zArg, "-nonewline")==0 ){
|
|
|
|
addNewLine = 0;
|
|
|
|
}else{
|
|
|
|
Tcl_AppendResult(interp, "bad argument: ", zArg, 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2024-09-24 19:49:06 +02:00
|
|
|
sqlite3_fputs(zOut, pOut);
|
|
|
|
if( addNewLine ) sqlite3_fputs("\n", pOut);
|
2024-01-03 15:13:27 +01:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
#endif /* defined(_WIN32) */
|
|
|
|
|
2017-10-13 22:14:06 +02:00
|
|
|
const char *sqlite3_analyzer_init_proc(Tcl_Interp *interp){
|
2024-01-03 15:13:27 +01:00
|
|
|
#if defined(_WIN32)
|
|
|
|
Tcl_CreateObjCommand(interp, "puts", subst_puts, 0, 0);
|
|
|
|
#else
|
2017-10-13 22:14:06 +02:00
|
|
|
(void)interp;
|
2024-01-03 15:13:27 +01:00
|
|
|
#endif
|
2017-10-13 22:14:06 +02:00
|
|
|
return
|
2017-10-13 20:58:55 +02:00
|
|
|
BEGIN_STRING
|
2017-10-13 22:14:06 +02:00
|
|
|
INCLUDE $ROOT/tool/spaceanal.tcl
|
2017-10-13 20:58:55 +02:00
|
|
|
END_STRING
|
|
|
|
;
|
|
|
|
}
|