Add the sqlite_trace() hook for tracing the SQL that an application executes.
The plan is to leave this API undocumented for the time being, in case we
want to make changes to it later. (CVS 836)
FossilOrigin-Name: f67bff8ff3db9694f87daf1a549d24ea9612da6b
diff --git a/src/main.c b/src/main.c
index 2c60210..0985c88 100644
--- a/src/main.c
+++ b/src/main.c
@@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
-** $Id: main.c,v 1.106 2003/01/12 18:02:18 drh Exp $
+** $Id: main.c,v 1.107 2003/01/16 16:28:54 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -602,6 +602,9 @@
){
Parse sParse;
+#ifndef SQLITE_OMIT_TRACE
+ if( db->xTrace ) db->xTrace(db->pTraceArg, zSql);
+#endif
if( pzErrMsg ) *pzErrMsg = 0;
if( sqliteSafetyOn(db) ) goto exec_misuse;
if( (db->flags & SQLITE_Initialized)==0 ){
@@ -859,6 +862,26 @@
}
/*
+** Register a trace function. The pArg from the previously registered trace
+** is returned.
+**
+** A NULL trace function means that no tracing is executes. A non-NULL
+** trace is a pointer to a function that is invoked at the start of each
+** sqlite_exec().
+*/
+void *sqlite_trace(sqlite *db, void (*xTrace)(void*,const char*), void *pArg){
+#ifndef SQLITE_OMIT_TRACE
+ void *pOld = db->pTraceArg;
+ db->xTrace = xTrace;
+ db->pTraceArg = pArg;
+ return pOld;
+#else
+ return 0;
+#endif
+}
+
+
+/*
** Attempt to open the file named in the argument as the auxiliary database
** file. The auxiliary database file is used to store TEMP tables. But
** by using this API, it is possible to trick SQLite into opening two
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index 410691b..0f5dde8 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -12,7 +12,7 @@
** This header file defines the interface that the SQLite library
** presents to client programs.
**
-** @(#) $Id: sqlite.h.in,v 1.38 2003/01/14 02:49:28 drh Exp $
+** @(#) $Id: sqlite.h.in,v 1.39 2003/01/16 16:28:54 drh Exp $
*/
#ifndef _SQLITE_H_
#define _SQLITE_H_
@@ -555,6 +555,13 @@
#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
/*
+** Register a function that is called at every invocation of sqlite_exec().
+** This function can be used (for example) to generate a log file of all
+** SQL executed against a database.
+*/
+void *sqlite_trace(sqlite*, void(*xTrace)(void*,const char*), void*);
+
+/*
** Attempt to open the file named in the argument as the auxiliary database
** file. The auxiliary database file is used to store TEMP tables. But
** by using this API, it is possible to trick SQLite into opening two
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 38ae75c..bec619c 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
-** @(#) $Id: sqliteInt.h,v 1.154 2003/01/13 23:27:33 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.155 2003/01/16 16:28:54 drh Exp $
*/
#include "config.h"
#include "sqlite.h"
@@ -225,6 +225,10 @@
int magic; /* Magic number for detect library misuse */
int nChange; /* Number of rows changed */
int recursionDepth; /* Number of nested calls to sqlite_exec() */
+#ifndef SQLITE_OMIT_TRACE
+ void (*xTrace)(void*,const char*); /* Trace function */
+ void *pTraceArg; /* Argument to the trace function */
+#endif
#ifndef SQLITE_OMIT_AUTHORIZATION
int (*xAuth)(void*,int,const char*,const char*); /* Access Auth function */
void *pAuthArg; /* 1st argument to the access auth function */