/ Check-in [fc6504aa]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Include the "dbstat" virtual table in the amalgamation.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dbstat-in-amalgamation
Files: files | file ages | folders
SHA1: fc6504aa8ca19b3737f72c1e20db8df6b7608dd2
User & Date: drh 2015-05-04 17:06:39
Context
2015-05-04
18:31
Rename the test_stat.c source file to dbstat.c and rework the makefiles to make dbstat.c a first-class source module. Closed-Leaf check-in: a24480a4 user: drh tags: dbstat-in-amalgamation
17:06
Include the "dbstat" virtual table in the amalgamation. check-in: fc6504aa user: drh tags: dbstat-in-amalgamation
16:09
Fix a faulty assert() in the SELECT code generator and add a test case to prevent regression. check-in: 1421c8ff user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.in.

   571    571   	mkdir tsrc
   572    572   	cp -f $(SRC) tsrc
   573    573   	rm tsrc/sqlite.h.in tsrc/parse.y
   574    574   	$(TCLSH_CMD) $(TOP)/tool/vdbe-compress.tcl $(OPTS) <tsrc/vdbe.c >vdbe.new
   575    575   	mv vdbe.new tsrc/vdbe.c
   576    576   	touch .target_source
   577    577   
   578         -sqlite3.c:	.target_source $(TOP)/tool/mksqlite3c.tcl
   579         -	$(TCLSH_CMD) $(TOP)/tool/mksqlite3c.tcl
          578  +sqlite3.c:	.target_source $(TOP)/src/test_stat.c $(TOP)/tool/mksqlite3c.tcl
          579  +	$(TCLSH_CMD) $(TOP)/tool/mksqlite3c.tcl --srcdir $(TOP)/src
   580    580   	cp tsrc/shell.c tsrc/sqlite3ext.h .
   581    581   
   582    582   tclsqlite3.c:	sqlite3.c
   583    583   	echo '#ifndef USE_SYSTEM_SQLITE' >tclsqlite3.c
   584    584   	cat sqlite3.c >>tclsqlite3.c
   585    585   	echo '#endif /* USE_SYSTEM_SQLITE */' >>tclsqlite3.c
   586    586   	cat $(TOP)/src/tclsqlite.c >>tclsqlite3.c
................................................................................
   987    987   # comes out."
   988    988   #
   989    989   smoketest:	testfixture$(TEXE) fuzzershell$(TEXE)
   990    990   	./testfixture$(TEXE) $(TOP)/test/main.test
   991    991   
   992    992   sqlite3_analyzer.c: sqlite3.c $(TOP)/src/test_stat.c $(TOP)/src/tclsqlite.c $(TOP)/tool/spaceanal.tcl
   993    993   	echo "#define TCLSH 2" > $@
   994         -	cat sqlite3.c $(TOP)/src/test_stat.c $(TOP)/src/tclsqlite.c >> $@
          994  +	echo "#define SQLITE_ENABLE_DBSTAT_VTAB" >> $@
          995  +	cat sqlite3.c $(TOP)/src/tclsqlite.c >> $@
   995    996   	echo "static const char *tclsh_main_loop(void){" >> $@
   996    997   	echo "static const char *zMainloop = " >> $@
   997    998   	$(NAWK) -f $(TOP)/tool/tostr.awk $(TOP)/tool/spaceanal.tcl >> $@
   998    999   	echo "; return zMainloop; }" >> $@
   999   1000   
  1000   1001   sqlite3_analyzer$(TEXE): sqlite3_analyzer.c
  1001   1002   	$(LTLINK) sqlite3_analyzer.c -o $@ $(LIBTCL) $(TLIBS)

Changes to Makefile.msc.

  1225   1225   	for %i in ($(SRC4)) do copy /Y %i tsrc
  1226   1226   	for %i in ($(SRC5)) do copy /Y %i tsrc
  1227   1227   	del /Q tsrc\sqlite.h.in tsrc\parse.y 2>NUL
  1228   1228   	$(TCLSH_CMD) $(TOP)\tool\vdbe-compress.tcl $(OPTS) < tsrc\vdbe.c > vdbe.new
  1229   1229   	move vdbe.new tsrc\vdbe.c
  1230   1230   	echo > .target_source
  1231   1231   
  1232         -sqlite3.c:	.target_source $(TOP)\tool\mksqlite3c.tcl
  1233         -	$(TCLSH_CMD) $(TOP)\tool\mksqlite3c.tcl $(MKSQLITE3C_ARGS)
         1232  +sqlite3.c:	.target_source $(TOP)\tool\mksqlite3c.tcl $(TOP)\src\test_stat.c
         1233  +	$(TCLSH_CMD) $(TOP)\tool\mksqlite3c.tcl $(MKSQLITE3C_ARGS) --srcdir $(TOP)/src
  1234   1234   	copy tsrc\shell.c .
  1235   1235   	copy tsrc\sqlite3ext.h .
  1236   1236   
  1237   1237   sqlite3-all.c:	sqlite3.c $(TOP)\tool\split-sqlite3c.tcl
  1238   1238   	$(TCLSH_CMD) $(TOP)\tool\split-sqlite3c.tcl
  1239   1239   
  1240   1240   # Set the source code file to be used by executables and libraries when
................................................................................
  1652   1652   test:	testfixture.exe sqlite3.exe fuzztest
  1653   1653   	.\testfixture.exe $(TOP)\test\veryquick.test
  1654   1654   
  1655   1655   smoketest:	testfixture.exe
  1656   1656   	.\testfixture.exe $(TOP)\test\main.test
  1657   1657   
  1658   1658   sqlite3_analyzer.c: $(SQLITE3C) $(TOP)\src\test_stat.c $(TOP)\src\tclsqlite.c $(TOP)\tool\spaceanal.tcl
  1659         -	copy $(SQLITE3C) + $(TOP)\src\test_stat.c + $(TOP)\src\tclsqlite.c $@
         1659  +	copy $(SQLITE3C) + $(TOP)\src\tclsqlite.c $@
  1660   1660   	echo static const char *tclsh_main_loop(void){ >> $@
  1661   1661   	echo static const char *zMainloop = >> $@
  1662   1662   	$(NAWK) -f $(TOP)\tool\tostr.awk $(TOP)\tool\spaceanal.tcl >> $@
  1663   1663   	echo ; return zMainloop; } >> $@
  1664   1664   
  1665   1665   sqlite3_analyzer.exe:	sqlite3_analyzer.c $(LIBRESOBJS)
  1666         -	$(LTLINK) $(NO_WARN) -DBUILD_sqlite -DTCLSH=2 -I$(TCLINCDIR) sqlite3_analyzer.c \
         1666  +	$(LTLINK) $(NO_WARN) -DBUILD_sqlite -DSQLITE_ENABLE_DBSTAT_VTAB -DTCLSH=2 -I$(TCLINCDIR) sqlite3_analyzer.c \
  1667   1667   		/link $(LTLINKOPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LTLIBS) $(TLIBS)
  1668   1668   
  1669   1669   testloadext.lo:	$(TOP)\src\test_loadext.c
  1670   1670   	$(LTCOMPILE) $(NO_WARN) -c $(TOP)\src\test_loadext.c
  1671   1671   
  1672   1672   testloadext.dll: testloadext.lo
  1673   1673   	$(LD) $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /DLL /OUT:$@ testloadext.lo

Changes to main.mk.

   443    443   	mkdir tsrc
   444    444   	cp -f $(SRC) tsrc
   445    445   	rm tsrc/sqlite.h.in tsrc/parse.y
   446    446   	tclsh $(TOP)/tool/vdbe-compress.tcl $(OPTS) <tsrc/vdbe.c >vdbe.new
   447    447   	mv vdbe.new tsrc/vdbe.c
   448    448   	touch target_source
   449    449   
   450         -sqlite3.c:	target_source $(TOP)/tool/mksqlite3c.tcl
   451         -	tclsh $(TOP)/tool/mksqlite3c.tcl
          450  +sqlite3.c:	target_source $(TOP)/src/test_stat.c $(TOP)/tool/mksqlite3c.tcl
          451  +	tclsh $(TOP)/tool/mksqlite3c.tcl --srcdir $(TOP)/src
   452    452   	cp tsrc/shell.c tsrc/sqlite3ext.h .
   453    453   	echo '#ifndef USE_SYSTEM_SQLITE' >tclsqlite3.c
   454    454   	cat sqlite3.c >>tclsqlite3.c
   455    455   	echo '#endif /* USE_SYSTEM_SQLITE */' >>tclsqlite3.c
   456    456   	cat $(TOP)/src/tclsqlite.c >>tclsqlite3.c
   457    457   
   458    458   sqlite3.c-debug:	target_source $(TOP)/tool/mksqlite3c.tcl
................................................................................
   599    599   #
   600    600   tclsqlite3:	$(TOP)/src/tclsqlite.c libsqlite3.a
   601    601   	$(TCCX) $(TCL_FLAGS) -DTCLSH=1 -o tclsqlite3 \
   602    602   		$(TOP)/src/tclsqlite.c libsqlite3.a $(LIBTCL) $(THREADLIB)
   603    603   
   604    604   sqlite3_analyzer.c: sqlite3.c $(TOP)/src/test_stat.c $(TOP)/src/tclsqlite.c $(TOP)/tool/spaceanal.tcl
   605    605   	echo "#define TCLSH 2" > $@
   606         -	cat sqlite3.c $(TOP)/src/test_stat.c $(TOP)/src/tclsqlite.c >> $@
          606  +	echo "#define SQLITE_ENABLE_DBSTAT_VTAB 1" >> $@
          607  +	cat sqlite3.c $(TOP)/src/tclsqlite.c >> $@
   607    608   	echo "static const char *tclsh_main_loop(void){" >> $@
   608    609   	echo "static const char *zMainloop = " >> $@
   609    610   	$(NAWK) -f $(TOP)/tool/tostr.awk $(TOP)/tool/spaceanal.tcl >> $@
   610    611   	echo "; return zMainloop; }" >> $@
   611    612   
   612    613   sqlite3_analyzer$(EXE): sqlite3_analyzer.c
   613    614   	$(TCCX) $(TCL_FLAGS) sqlite3_analyzer.c -o $@ $(LIBTCL) $(THREADLIB) 

Changes to src/shell.c.

  1906   1906   ** Make sure the database is open.  If it is not, then open it.  If
  1907   1907   ** the database fails to open, print an error message and exit.
  1908   1908   */
  1909   1909   static void open_db(ShellState *p, int keepAlive){
  1910   1910     if( p->db==0 ){
  1911   1911       sqlite3_initialize();
  1912   1912       sqlite3_open(p->zDbFilename, &p->db);
  1913         -#ifdef SQLITE_ENABLE_STAT_VTAB
         1913  +#ifdef SQLITE_ENABLE_DBSTAT_VTAB
  1914   1914       if( p->db ){
  1915   1915         int sqlite3_dbstat_register(sqlite3*);
  1916   1916         sqlite3_dbstat_register(p->db);
  1917   1917       }
  1918   1918   #endif
  1919   1919       globalDb = p->db;
  1920   1920       if( p->db && sqlite3_errcode(p->db)==SQLITE_OK ){

Changes to src/test_stat.c.

    14     14   **
    15     15   ** The dbstat virtual table is used to extract low-level formatting
    16     16   ** information from an SQLite database in order to implement the
    17     17   ** "sqlite3_analyzer" utility.  See the ../tool/spaceanal.tcl script
    18     18   ** for an example implementation.
    19     19   */
    20     20   
           21  +/* Only compile this module if there is evidence that the programmer
           22  +** deliberately wants to include it.  Evidence can be:
           23  +**    (1) Tt is compiled and linked separately from the amalgamation.
           24  +**    (2) The SQLITE_ENABLE_DBSTAT_VTAB compile-time option is used
           25  +**    (3) The SQLITE_TEST compile-time option is used
           26  +*/
           27  +#if !defined(SQLITE_AMALGAMATION) \
           28  +     || defined(SQLITE_ENABLE_DBSTAT_VTAB) \
           29  +     || defined(SQLITE_TEST)
           30  +
    21     31   #ifndef SQLITE_AMALGAMATION
    22         -# include "sqliteInt.h"
           32  +# include "sqliteInt.h"   /* Requires access to internal data structures */
    23     33   #endif
    24     34   
    25     35   #ifndef SQLITE_OMIT_VIRTUALTABLE
    26     36   
    27     37   /*
    28     38   ** Page paths:
    29     39   ** 
................................................................................
   621    631       0,                            /* xRename */
   622    632     };
   623    633     return sqlite3_create_module(db, "dbstat", &dbstat_module, 0);
   624    634   }
   625    635   
   626    636   #endif
   627    637   
          638  +/*
          639  +** This is the TCL interface
          640  +*/
   628    641   #if defined(SQLITE_TEST) || TCLSH==2
   629         -#include <tcl.h>
          642  +#include <tcl.h> /* amalgamator: keep */
   630    643   
          644  +/*
          645  +** tclcmd:   register_dbstat_vtab DB
          646  +**
          647  +** Cause the dbstat virtual table to be available on the connection DB
          648  +*/
   631    649   static int test_dbstat(
   632    650     void *clientData,
   633    651     Tcl_Interp *interp,
   634    652     int objc,
   635    653     Tcl_Obj *CONST objv[]
   636    654   ){
   637    655   #ifdef SQLITE_OMIT_VIRTUALTABLE
................................................................................
   652    670     if( Tcl_GetCommandInfo(interp, zDb, &cmdInfo) ){
   653    671       sqlite3* db = ((struct SqliteDb*)cmdInfo.objClientData)->db;
   654    672       sqlite3_dbstat_register(db);
   655    673     }
   656    674     return TCL_OK;
   657    675   #endif
   658    676   }
   659         -
   660    677   int SqlitetestStat_Init(Tcl_Interp *interp){
   661    678     Tcl_CreateObjCommand(interp, "register_dbstat_vtab", test_dbstat, 0, 0);
   662    679     return TCL_OK;
   663    680   }
   664    681   #endif /* if defined(SQLITE_TEST) || TCLSH==2 */
          682  +
          683  +#endif /* !SQLITE_AMALGAMATION || SQLITE_ENABLE_DBSTAT_VTAB || SQLITE_TEST */

Changes to tool/mksqlite3c.tcl.

    13     13   # For example, the "parse.c" and "parse.h" files to implement the
    14     14   # the parser are derived from "parse.y" using lemon.  And the 
    15     15   # "keywordhash.h" files is generated by a program named "mkkeywordhash".
    16     16   #
    17     17   # After the "tsrc" directory has been created and populated, run
    18     18   # this script:
    19     19   #
    20         -#      tclsh mksqlite3c.tcl
           20  +#      tclsh mksqlite3c.tcl --srcdir $SRC
    21     21   #
    22     22   # The amalgamated SQLite code will be written into sqlite3.c
    23     23   #
    24     24   
    25     25   # Begin by reading the "sqlite3.h" header file.  Extract the version number
    26     26   # from in this file.  The version number is needed to generate the header
    27     27   # comment of the amalgamation.
    28     28   #
    29         -if {[lsearch $argv --nostatic]>=0} {
    30         -  set addstatic 0
    31         -} else {
    32         -  set addstatic 1
    33         -}
    34         -if {[lsearch $argv --linemacros]>=0} {
    35         -  set linemacros 1
    36         -} else {
    37         -  set linemacros 0
           29  +set addstatic 1
           30  +set linemacros 0
           31  +set srcdir {}
           32  +for {set i 0} {$i<[llength $argv]} {incr i} {
           33  +  set x [lindex $argv $i]
           34  +  if {[regexp {^-+nostatic$} $x]} {
           35  +    set addstatic 0
           36  +  } elseif {[regexp {^-+linemacros} $x]} {
           37  +    set linemacros 1
           38  +  } elseif {[regexp {^-+srcdir} $x]} {
           39  +    incr i
           40  +    set srcdir [lindex $argv $i]
           41  +  } else {
           42  +    error "unknown command-line option: $x"
           43  +  }
    38     44   }
    39     45   set in [open tsrc/sqlite3.h]
    40     46   set cnt 0
    41     47   set VERSION ?????
    42     48   while {![eof $in]} {
    43     49     set line [gets $in]
    44     50     if {$line=="" && [eof $in]} break
................................................................................
   365    371   
   366    372      rtree.c
   367    373      icu.c
   368    374      fts3_icu.c
   369    375   } {
   370    376     copy_file tsrc/$file
   371    377   }
          378  +if {$srcdir!=""} {
          379  +  copy_file $srcdir/test_stat.c
          380  +}
   372    381   
   373    382   close $out