aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dbstat.c (renamed from src/test_stat.c)71
-rw-r--r--src/tclsqlite.c44
2 files changed, 46 insertions, 69 deletions
diff --git a/src/test_stat.c b/src/dbstat.c
index 35304b3fd..a53bc07e4 100644
--- a/src/test_stat.c
+++ b/src/dbstat.c
@@ -18,21 +18,9 @@
** for an example implementation.
*/
-/* Only compile this module if there is evidence that the programmer
-** deliberately wants to include it. Evidence can be:
-** (1) Tt is compiled and linked separately from the amalgamation.
-** (2) The SQLITE_ENABLE_DBSTAT_VTAB compile-time option is used
-** (3) The SQLITE_TEST compile-time option is used
-*/
-#if !defined(SQLITE_AMALGAMATION) \
- || defined(SQLITE_ENABLE_DBSTAT_VTAB) \
- || defined(SQLITE_TEST)
-
-#ifndef SQLITE_AMALGAMATION
-# include "sqliteInt.h" /* Requires access to internal data structures */
-#endif
-
-#ifndef SQLITE_OMIT_VIRTUALTABLE
+#if (defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)) \
+ && !defined(SQLITE_OMIT_VIRTUAL_TABLE)
+#include "sqliteInt.h" /* Requires access to internal data structures */
/*
** Page paths:
@@ -607,6 +595,9 @@ static int statRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
return SQLITE_OK;
}
+/*
+** Invoke this routine to register the "dbstat" virtual table module
+*/
int sqlite3_dbstat_register(sqlite3 *db){
static sqlite3_module dbstat_module = {
0, /* iVersion */
@@ -632,52 +623,4 @@ int sqlite3_dbstat_register(sqlite3 *db){
};
return sqlite3_create_module(db, "dbstat", &dbstat_module, 0);
}
-
-#endif
-
-/*
-** This is the TCL interface
-*/
-#if defined(SQLITE_TEST) || TCLSH==2
-#include <tcl.h> /* amalgamator: keep */
-
-/*
-** tclcmd: register_dbstat_vtab DB
-**
-** Cause the dbstat virtual table to be available on the connection DB
-*/
-static int test_dbstat(
- void *clientData,
- Tcl_Interp *interp,
- int objc,
- Tcl_Obj *CONST objv[]
-){
-#ifdef SQLITE_OMIT_VIRTUALTABLE
- Tcl_AppendResult(interp, "dbstat not available because of "
- "SQLITE_OMIT_VIRTUALTABLE", (void*)0);
- return TCL_ERROR;
-#else
- struct SqliteDb { sqlite3 *db; };
- char *zDb;
- Tcl_CmdInfo cmdInfo;
-
- if( objc!=2 ){
- Tcl_WrongNumArgs(interp, 1, objv, "DB");
- return TCL_ERROR;
- }
-
- zDb = Tcl_GetString(objv[1]);
- if( Tcl_GetCommandInfo(interp, zDb, &cmdInfo) ){
- sqlite3* db = ((struct SqliteDb*)cmdInfo.objClientData)->db;
- sqlite3_dbstat_register(db);
- }
- return TCL_OK;
-#endif
-}
-int SqlitetestStat_Init(Tcl_Interp *interp){
- Tcl_CreateObjCommand(interp, "register_dbstat_vtab", test_dbstat, 0, 0);
- return TCL_OK;
-}
-#endif /* if defined(SQLITE_TEST) || TCLSH==2 */
-
-#endif /* !SQLITE_AMALGAMATION || SQLITE_ENABLE_DBSTAT_VTAB || SQLITE_TEST */
+#endif /* SQLITE_ENABLE_DBSTAT_VTAB */
diff --git a/src/tclsqlite.c b/src/tclsqlite.c
index e38c1dd08..6556e5ad6 100644
--- a/src/tclsqlite.c
+++ b/src/tclsqlite.c
@@ -3704,7 +3704,42 @@ static int db_last_stmt_ptr(
return TCL_OK;
}
-#endif
+#endif /* SQLITE_TEST */
+
+/*
+** tclcmd: register_dbstat_vtab DB
+**
+** Cause the dbstat virtual table to be available on the connection DB
+*/
+static int sqlite3RegisterDbstatCmd(
+ void *clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *CONST objv[]
+){
+#ifdef SQLITE_OMIT_VIRTUALTABLE
+ Tcl_AppendResult(interp, "dbstat not available because of "
+ "SQLITE_OMIT_VIRTUALTABLE", (void*)0);
+ return TCL_ERROR;
+#else
+ struct SqliteDb { sqlite3 *db; };
+ char *zDb;
+ Tcl_CmdInfo cmdInfo;
+
+ if( objc!=2 ){
+ Tcl_WrongNumArgs(interp, 1, objv, "DB");
+ return TCL_ERROR;
+ }
+
+ zDb = Tcl_GetString(objv[1]);
+ if( Tcl_GetCommandInfo(interp, zDb, &cmdInfo) ){
+ int sqlite3_dbstat_register(sqlite3*);
+ sqlite3* db = ((struct SqliteDb*)cmdInfo.objClientData)->db;
+ sqlite3_dbstat_register(db);
+ }
+ return TCL_OK;
+#endif /* SQLITE_OMIT_VIRTUALTABLE */
+}
/*
** Configure the interpreter passed as the first argument to have access
@@ -3729,10 +3764,9 @@ static void init_all(Tcl_Interp *interp){
** required for testfixture and sqlite3_analyzer, but not by the production
** Tcl extension. */
#if defined(SQLITE_TEST) || TCLSH==2
- {
- extern int SqlitetestStat_Init(Tcl_Interp*);
- SqlitetestStat_Init(interp);
- }
+ Tcl_CreateObjCommand(
+ interp, "register_dbstat_vtab", sqlite3RegisterDbstatCmd, 0, 0
+ );
#endif
#ifdef SQLITE_TEST