]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Enhanced documentation for the SQLITE_CONFIG_SQLLOG mechanism and the
authordrh <drh@noemail.net>
Mon, 22 Apr 2013 13:51:09 +0000 (13:51 +0000)
committerdrh <drh@noemail.net>
Mon, 22 Apr 2013 13:51:09 +0000 (13:51 +0000)
test_sqllog.c demonstration file.  No changes to code.

FossilOrigin-Name: 206caf21f6f6963aa38a9aa0f6ea11c7230bb726

manifest
manifest.uuid
src/sqlite.h.in
src/test_sqllog.c

index 9cf2da3aad9765ae8f03e5ae269cd0cb64633386..68a8c4093845f459eca5ebd09f377b82e28ca7e9 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Use\stransitivity\sto\smove\sconstraints\sinto\sthe\souter\sloops\sof\sa\sjoin\swhenever\npossible,\sthereby\sreducing\sthe\samount\sof\swork\sthat\sneeds\sto\soccur\sin\ninner\sloops.
-D 2013-04-22T02:39:10.341
+C Enhanced\sdocumentation\sfor\sthe\sSQLITE_CONFIG_SQLLOG\smechanism\sand\sthe\ntest_sqllog.c\sdemonstration\sfile.\s\sNo\schanges\sto\scode.
+D 2013-04-22T13:51:09.759
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 3dd3fcb87b70c78d99b2c8a03e44ec86d6ca9ce2
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -182,7 +182,7 @@ F src/resolve.c 10a1b332e3eb36e5d561085e18c58a8578cd7d73
 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0
 F src/select.c 01540bcd3df3c8f1187158e77986028b1c667258
 F src/shell.c aca9d94653decd4496846dee0c7ba83eaf96a46d
-F src/sqlite.h.in a291a999d28ebc16cd1fe7fdd010dfe5266ef767
+F src/sqlite.h.in ec279b782bea05db63b8b29481f9642b406004af
 F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0
 F src/sqlite3ext.h d936f797812c28b81b26ed18345baf8db28a21a5
 F src/sqliteInt.h 2a83cfec9963372b636b0cabd4b200c1f1074a99
@@ -229,7 +229,7 @@ F src/test_rtree.c aba603c949766c4193f1068b91c787f57274e0d9
 F src/test_schema.c 8c06ef9ddb240c7a0fcd31bc221a6a2aade58bf0
 F src/test_server.c 2f99eb2837dfa06a4aacf24af24c6affdf66a84f
 F src/test_spellfix.c 56dfa6d583ac34f61af0834d7b58d674e7e18e13
-F src/test_sqllog.c bc50e5afeb7fb50e77b4594e42302df9d05446aa
+F src/test_sqllog.c c1c1bbedbcaf82b93d83e4f9dd990e62476a680e
 F src/test_stat.c d1569c7a4839f13e80187e2c26b2ab4da2d03935
 F src/test_superlock.c 2b97936ca127d13962c3605dbc9a4ef269c424cd
 F src/test_syscall.c 7e8293e4e6971b0f44c7f7f37b1315a8cc9f6018
@@ -1051,7 +1051,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
-P 514adbbd8cf3e296f55e8f803bddaac8ad8b2c96
-R a81fa97db156009318d49bf4c6dae35e
+P 5f4907e1c6230e3dd904bd99e1c48c576c669f63
+R 3f851c92fc64d9ebdb6dc226b2109b9c
 U drh
-Z 1c3c5b72018db605301d161eada3f156
+Z 928e878ceb923ac2280cddfe9d967aac
index bd39d463766ba3d8cd237099888de5bce10d88d7..77c2db74deb658b6ba08e3d7892d6cc877386a29 100644 (file)
@@ -1 +1 @@
-5f4907e1c6230e3dd904bd99e1c48c576c669f63
\ No newline at end of file
+206caf21f6f6963aa38a9aa0f6ea11c7230bb726
\ No newline at end of file
index 3c6291eebeb6d3bd6a40263c07f9abb046072a66..3265b3196bfe551ac0c797c7f6ffbfe93f65cfb8 100644 (file)
@@ -1633,12 +1633,12 @@ struct sqlite3_mem_methods {
 ** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE
 ** <dd> These options are obsolete and should not be used by new code.
 ** They are retained for backwards compatibility but are now no-ops.
-** </dl>
+** </dd>
 **
 ** [[SQLITE_CONFIG_SQLLOG]]
 ** <dt>SQLITE_CONFIG_SQLLOG
 ** <dd>This option is only available if sqlite is compiled with the
-** SQLITE_ENABLE_SQLLOG pre-processor macro defined. The first argument should
+** [SQLITE_ENABLE_SQLLOG] pre-processor macro defined. The first argument should
 ** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int).
 ** The second should be of type (void*). The callback is invoked by the library
 ** in three separate circumstances, identified by the value passed as the
@@ -1648,7 +1648,9 @@ struct sqlite3_mem_methods {
 ** fourth parameter is 1, then the SQL statement that the third parameter
 ** points to has just been executed. Or, if the fourth parameter is 2, then
 ** the connection being passed as the second parameter is being closed. The
-** third parameter is passed NULL In this case.
+** third parameter is passed NULL In this case.  An example of using this
+** configuration option can be seen in the "test_sqllog.c" source file in
+** the canonical SQLite source tree.</dd>
 **
 ** [[SQLITE_CONFIG_MMAP_SIZE]]
 ** <dt>SQLITE_CONFIG_MMAP_SIZE
index 24c675b5e9e6d3fc4226c9dadf45f4c4f6d54982..4aa68b7c429323b8eebe6c9c2d07fc660d8d47c9 100644 (file)
 ** OVERVIEW
 **
 **   This file contains experimental code used to record data from live
-**   SQLite applications that may be useful for offline analysis. Specifically:
+**   SQLite applications that may be useful for offline analysis. 
+**   Specifically, this module can be used to capture the following
+**   information:
 **
 **     1) The initial contents of all database files opened by the 
 **        application, and
 **
 **     2) All SQL statements executed by the application.
 **
+**   The captured information can then be used to run (for example)
+**   performance analysis looking for slow queries or to look for
+**   optimization opportunities in either the application or in SQLite
+**   itself.
+**
 ** USAGE
 **
 **   To use this module, SQLite must be compiled with the SQLITE_ENABLE_SQLLOG
-**   pre-processor symbol defined and this file linked into the application
-**   somehow.
+**   pre-processor symbol defined and this file linked into the application.
+**   One way to link this file into the application is to append the content
+**   of this file onto the end of the "sqlite3.c" amalgamation and then 
+**   recompile the application as normal except with the addition  of the
+**   -DSQLITE_ENABLE_SQLLOG option.
 **
 **   At runtime, logging is enabled by setting environment variable
 **   SQLITE_SQLLOG_DIR to the name of a directory in which to store logged 
-**   data. The directory must already exist.
+**   data. The logging directory must already exist.
 **
 **   Usually, if the application opens the same database file more than once
 **   (either by attaching it or by using more than one database handle), only
 **   logging proceeds as expected. Errors are logged by calling sqlite3_log().
 */
 
+#ifndef _SQLITE3_H_
 #include "sqlite3.h"
-#include "stdio.h"
-#include "stdlib.h"
-#include "string.h"
-#include "assert.h"
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
 
-#include "sys/types.h"
-#include "unistd.h"
+#include <sys/types.h>
+#include <unistd.h>
 static int getProcessId(void){
 #if SQLITE_OS_WIN
   return (int)_getpid();
@@ -73,7 +85,7 @@ static int getProcessId(void){
 #endif
 }
 
-
+/* Names of environment variables to be used */
 #define ENVIRONMENT_VARIABLE1_NAME "SQLITE_SQLLOG_DIR"
 #define ENVIRONMENT_VARIABLE2_NAME "SQLITE_SQLLOG_REUSE_FILES"
 
@@ -86,6 +98,9 @@ static int getProcessId(void){
 */
 #define MAX_CONNECTIONS 256
 
+/* There is one instance of this object for each SQLite database connection
+** that is being logged.
+*/
 struct SLConn {
   int isErr;                      /* True if an error has occurred */
   sqlite3 *db;                    /* Connection handle */
@@ -93,7 +108,9 @@ struct SLConn {
   FILE *fd;                       /* File descriptor for log file */
 };
 
-struct SLGlobal {
+/* This object is a singleton that keeps track of all data loggers.
+*/
+static struct SLGlobal {
   /* Protected by MUTEX_STATIC_MASTER */
   sqlite3_mutex *mutex;           /* Recursive mutex */
   int nConn;                      /* Size of aConn[] array */
@@ -388,6 +405,24 @@ static void testSqllogStmt(struct SLConn *p, const char *zSql){
 
 /*
 ** The SQLITE_CONFIG_SQLLOG callback registered by sqlite3_init_sqllog().
+**
+** The eType parameter has the following values:
+**
+**    0:  Opening a new database connection.  zSql is the name of the
+**        file being opened.  db is a pointer to the newly created database
+**        connection.
+**
+**    1:  An SQL statement has run to completion.  zSql is the text of the
+**        SQL statement with all parameters expanded to their actual values.
+**
+**    2:  Closing a database connection.  zSql is NULL.  The db pointer to
+**        the database connection being closed has already been shut down
+**        and cannot be used for any further SQL.
+**
+** The pCtx parameter is a copy of the pointer that was originally passed
+** into the sqlite3_config(SQLITE_CONFIG_SQLLOG) statement.  In this
+** particular implementation, pCtx is always a pointer to the 
+** sqllogglobal global variable define above.
 */
 static void testSqllog(void *pCtx, sqlite3 *db, const char *zSql, int eType){
   struct SLConn *p = 0;