Compare commits
38 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4ebf07fafe | |||
| cef4deecd7 | |||
| d164fd3483 | |||
| c7b7f1ae1d | |||
| 10ec0fa557 | |||
| 1e9db16c55 | |||
| 6468ad04e4 | |||
| 1feb7dd391 | |||
| f3d3c27a0c | |||
| a03396aafb | |||
| c70dfc477f | |||
| 1aa690c87c | |||
| 397d65f641 | |||
| 1ceedd3736 | |||
| 62c14b3487 | |||
| b232c23297 | |||
| 4c6517848f | |||
| 50128aea6a | |||
| 1d2988554c | |||
| 2161474f62 | |||
| cdcfe95cec | |||
| 00e136135e | |||
| 234329761a | |||
| 64202cfec6 | |||
| 89d4004f03 | |||
| 971854898a | |||
| d92db531c8 | |||
| 44cd45c85d | |||
| 032c0c14f9 | |||
| 777da0848d | |||
| dcc50b74e6 | |||
| 84ca3837c2 | |||
| ec21707dd7 | |||
| 093e0f6ffe | |||
| ac8d7b35fa | |||
| d17e71c95c | |||
| bc2ca9eb39 | |||
| 0d0654119f |
+8
-2
@@ -167,8 +167,8 @@ OBJS0 = alter.lo analyze.lo attach.lo auth.lo bitvec.lo btmutex.lo \
|
||||
memjournal.lo \
|
||||
mutex.lo mutex_noop.lo mutex_os2.lo mutex_unix.lo mutex_w32.lo \
|
||||
opcodes.lo os.lo os_unix.lo os_win.lo os_os2.lo \
|
||||
pager.lo parse.lo pcache.lo pragma.lo prepare.lo printf.lo random.lo \
|
||||
resolve.lo select.lo status.lo \
|
||||
pager.lo parse.lo pcache.lo pcache1.lo pragma.lo prepare.lo printf.lo \
|
||||
random.lo resolve.lo select.lo status.lo \
|
||||
table.lo tokenize.lo trigger.lo update.lo \
|
||||
util.lo vacuum.lo \
|
||||
vdbe.lo vdbeapi.lo vdbeaux.lo vdbeblob.lo vdbefifo.lo vdbemem.lo \
|
||||
@@ -237,6 +237,7 @@ SRC = \
|
||||
$(TOP)/src/parse.y \
|
||||
$(TOP)/src/pcache.c \
|
||||
$(TOP)/src/pcache.h \
|
||||
$(TOP)/src/pcache1.c \
|
||||
$(TOP)/src/pragma.c \
|
||||
$(TOP)/src/prepare.c \
|
||||
$(TOP)/src/printf.c \
|
||||
@@ -335,6 +336,7 @@ TESTSRC2 = \
|
||||
$(TOP)/src/os_win.c \
|
||||
$(TOP)/src/pager.c \
|
||||
$(TOP)/src/pcache.c \
|
||||
$(TOP)/src/pcache1.c \
|
||||
$(TOP)/src/pragma.c \
|
||||
$(TOP)/src/prepare.c \
|
||||
$(TOP)/src/printf.c \
|
||||
@@ -374,6 +376,7 @@ TESTSRC = \
|
||||
$(TOP)/src/test_mutex.c \
|
||||
$(TOP)/src/test_onefile.c \
|
||||
$(TOP)/src/test_osinst.c \
|
||||
$(TOP)/src/test_pcache.c \
|
||||
$(TOP)/src/test_schema.c \
|
||||
$(TOP)/src/test_server.c \
|
||||
$(TOP)/src/test_tclvar.c \
|
||||
@@ -596,6 +599,9 @@ pager.lo: $(TOP)/src/pager.c $(HDR) $(TOP)/src/pager.h
|
||||
pcache.lo: $(TOP)/src/pcache.c $(HDR) $(TOP)/src/pcache.h
|
||||
$(LTCOMPILE) -c $(TOP)/src/pcache.c
|
||||
|
||||
pcache1.lo: $(TOP)/src/pcache1.c $(HDR) $(TOP)/src/pcache.h
|
||||
$(LTCOMPILE) -c $(TOP)/src/pcache1.c
|
||||
|
||||
opcodes.lo: opcodes.c
|
||||
$(LTCOMPILE) -c opcodes.c
|
||||
|
||||
|
||||
+635
@@ -0,0 +1,635 @@
|
||||
#!/usr/make
|
||||
#
|
||||
# Makefile for SQLITE on VxWorks
|
||||
|
||||
ifeq ($(FORCPU),)
|
||||
FORCPU = SH32gnule
|
||||
endif
|
||||
|
||||
TOOL_FAMILY = gnu
|
||||
|
||||
include $(WIND_USR)/tool/gnu/make.$(FORCPU)
|
||||
|
||||
#### The toplevel directory of the source tree. This is the directory
|
||||
# that contains this "Makefile.in" and the "configure.in" script.
|
||||
#
|
||||
TOP = ../sqlite-3.6.5
|
||||
|
||||
#### C Compiler and options for use in building executables that
|
||||
# will run on the platform that is doing the build.
|
||||
#
|
||||
BCC = gcc -g -O2
|
||||
#BCC = /opt/ancic/bin/c89 -0
|
||||
|
||||
#### If the target operating system supports the "usleep()" system
|
||||
# call, then define the HAVE_USLEEP macro for all C modules.
|
||||
#
|
||||
USLEEP =
|
||||
#USLEEP = -DHAVE_USLEEP=1
|
||||
|
||||
#### If you want the SQLite library to be safe for use within a
|
||||
# multi-threaded program, then define the following macro
|
||||
# appropriately:
|
||||
#
|
||||
THREADSAFE = -DSQLITE_THREADSAFE=1
|
||||
#THREADSAFE = -DSQLITE_THREADSAFE=0
|
||||
|
||||
#### Specify any extra linker options needed to make the library
|
||||
# thread safe
|
||||
#
|
||||
#THREADLIB = -lpthread
|
||||
THREADLIB =
|
||||
|
||||
#### Specify any extra libraries needed to access required functions.
|
||||
#
|
||||
#TLIBS = -lrt # fdatasync on Solaris 8
|
||||
#for x86 vxWorks
|
||||
#TLIBS += TLIBS = $(LD_LINK_PATH_ATEND) $(LD_PARTIAL_LAST_FLAGS)
|
||||
#for SH4 shared library
|
||||
TLIBS_SHARED += -L$(WIND_USR)/lib/sh/SH32/commonle/PIC
|
||||
#TLIBS_SHARED += $(LD_LINK_PATH_ATEND) $(LD_PARTIAL_LAST_FLAGS)
|
||||
#for SH4 static
|
||||
TLIBS += $(LD_LINK_PATH_ATEND) $(LD_PARTIAL_LAST_FLAGS)
|
||||
|
||||
#### Leave SQLITE_DEBUG undefined for maximum speed. Use SQLITE_DEBUG=1
|
||||
# to check for memory leaks. Use SQLITE_DEBUG=2 to print a log of all
|
||||
# malloc()s and free()s in order to track down memory leaks.
|
||||
#
|
||||
# SQLite uses some expensive assert() statements in the inner loop.
|
||||
# You can make the library go almost twice as fast if you compile
|
||||
# with -DNDEBUG=1
|
||||
#
|
||||
#OPTS = -DSQLITE_DEBUG=2
|
||||
#OPTS = -DSQLITE_DEBUG=1
|
||||
#OPTS =
|
||||
OPTS = -DNDEBUG=1 -DSQLITE_OS_UNIX=1 $(THREADSAFE)
|
||||
OPTS += -DSQLITE_OMIT_LOAD_EXTENSION=1
|
||||
OPTS += -DSQLITE_ENABLE_LOCKING_STYLE=1
|
||||
OPTS += -DSQLITE_THREAD_OVERRIDE_LOCK=0
|
||||
OPTS += -DSQLITE_ENABLE_COLUMN_METADATA=1
|
||||
OPTS += -DHAVE_FDATASYNC=1
|
||||
|
||||
#### The suffix to add to executable files. ".exe" for windows.
|
||||
# Nothing for unix.
|
||||
#
|
||||
EXE = .vxe
|
||||
#EXE =
|
||||
|
||||
#### C Compile and options for use in building executables that
|
||||
# will run on the target platform. This is usually the same
|
||||
# as BCC, unless you are cross-compiling.
|
||||
#
|
||||
#TCC = gcc -O6
|
||||
#TCC = gcc -g -O0 -Wall
|
||||
#TCC = gcc -g -O0 -Wall -fprofile-arcs -ftest-coverage
|
||||
#TCC = /opt/mingw/bin/i386-mingw32-gcc -O6
|
||||
TCC = $(CC) $(DEFINE_CC) -O2 -g -mrtp $(CC_ARCH_SPEC) -D_REENTRANT=1 -D_VX_CPU=_VX_$(CPU) -D_VX_TOOL_FAMILY=$(TOOL_FAMILY) -D_VX_TOOL=$(TOOL)
|
||||
TCC += -I$(WIND_USR)/h -I$(WIND_USR)/h/wrn/coreip
|
||||
#TCC = /opt/ansic/bin/c89 -O +z -Wl,-a,archive
|
||||
|
||||
#TCC_SHARED = $(TCC) -fPIC
|
||||
TCC_SHARED = $(TCC)
|
||||
|
||||
#### Tools used to build a static library.
|
||||
#
|
||||
#ARX = ar cr
|
||||
#ARX = /opt/mingw/bin/i386-mingw32-ar cr
|
||||
AR += cr
|
||||
#RANLIB = ranlib
|
||||
#RANLIB = /opt/mingw/bin/i386-mingw32-ranlib
|
||||
|
||||
#MKSHLIB = gcc -shared
|
||||
#SO = so
|
||||
#SHPREFIX = lib
|
||||
MKSHLIB = $(CC) $(DEFINE_CC) -mrtp -shared $(CC_ARCH_SPEC) -D_VX_CPU=_VX_$(CPU) -D_VX_TOOL_FAMILY=$(TOOL_FAMILY) -D_VX_TOOL=$(TOOL)
|
||||
SO = so
|
||||
SHPREFIX = lib
|
||||
|
||||
#### Extra compiler options needed for programs that use the TCL library.
|
||||
#
|
||||
#TCL_FLAGS =
|
||||
#TCL_FLAGS = -DSTATIC_BUILD=1
|
||||
TCL_FLAGS = -I/home/drh/tcltk/8.4linux
|
||||
#TCL_FLAGS = -I/home/drh/tcltk/8.4win -DSTATIC_BUILD=1
|
||||
#TCL_FLAGS = -I/home/drh/tcltk/8.3hpux
|
||||
|
||||
#### Linker options needed to link against the TCL library.
|
||||
#
|
||||
#LIBTCL = -ltcl -lm -ldl
|
||||
LIBTCL = /home/drh/tcltk/8.4linux/libtcl8.4g.a -lm -ldl
|
||||
#LIBTCL = /home/drh/tcltk/8.4win/libtcl84s.a -lmsvcrt
|
||||
#LIBTCL = /home/drh/tcltk/8.3hpux/libtcl8.3.a -ldld -lm -lc
|
||||
|
||||
#### Additional objects for SQLite library when TCL support is enabled.
|
||||
TCLOBJ =
|
||||
#TCLOBJ = tclsqlite.o
|
||||
|
||||
#### Compiler options needed for programs that use the readline() library.
|
||||
#
|
||||
READLINE_FLAGS =
|
||||
#READLINE_FLAGS = -DHAVE_READLINE=1 -I/usr/include/readline
|
||||
|
||||
#### Linker options needed by programs using readline() must link against.
|
||||
#
|
||||
LIBREADLINE =
|
||||
#LIBREADLINE = -static -lreadline -ltermcap
|
||||
|
||||
#### Which "awk" program provides nawk compatibilty
|
||||
#
|
||||
# NAWK = nawk
|
||||
NAWK = awk
|
||||
|
||||
|
||||
#### Pasted and adapted main.mk file
|
||||
###############################################################################
|
||||
# The following macros should be defined before this script is
|
||||
# invoked:
|
||||
#
|
||||
# TOP The toplevel directory of the source tree. This is the
|
||||
# directory that contains this "Makefile.in" and the
|
||||
# "configure.in" script.
|
||||
#
|
||||
# BCC C Compiler and options for use in building executables that
|
||||
# will run on the platform that is doing the build.
|
||||
#
|
||||
# THREADLIB Specify any extra linker options needed to make the library
|
||||
# thread safe
|
||||
#
|
||||
# OPTS Extra compiler command-line options.
|
||||
#
|
||||
# EXE The suffix to add to executable files. ".exe" for windows
|
||||
# and "" for Unix.
|
||||
#
|
||||
# TCC C Compiler and options for use in building executables that
|
||||
# will run on the target platform. This is usually the same
|
||||
# as BCC, unless you are cross-compiling.
|
||||
#
|
||||
# AR Tools used to build a static library.
|
||||
# RANLIB
|
||||
#
|
||||
# TCL_FLAGS Extra compiler options needed for programs that use the
|
||||
# TCL library.
|
||||
#
|
||||
# LIBTCL Linker options needed to link against the TCL library.
|
||||
#
|
||||
# READLINE_FLAGS Compiler options needed for programs that use the
|
||||
# readline() library.
|
||||
#
|
||||
# LIBREADLINE Linker options needed by programs using readline() must
|
||||
# link against.
|
||||
#
|
||||
# NAWK Nawk compatible awk program. Older (obsolete?) solaris
|
||||
# systems need this to avoid using the original AT&T AWK.
|
||||
#
|
||||
# Once the macros above are defined, the rest of this make script will
|
||||
# build the SQLite library and testing tools.
|
||||
################################################################################
|
||||
|
||||
# This is how we compile
|
||||
#
|
||||
TCCX = $(TCC) $(OPTS) -I. -I$(TOP)/src -I$(TOP) -I$(TOP)/ext/rtree
|
||||
TCCX_SHARED = $(TCC_SHARED) $(OPTS) -I. -I$(TOP)/src -I$(TOP) -I$(TOP)/ext/rtree
|
||||
|
||||
# Object files for the SQLite library.
|
||||
#
|
||||
LIBOBJ+= alter.o analyze.o attach.o auth.o \
|
||||
bitvec.o btmutex.o btree.o build.o \
|
||||
callback.o complete.o date.o delete.o \
|
||||
expr.o fault.o func.o global.o hash.o \
|
||||
icu.o insert.o journal.o legacy.o loadext.o \
|
||||
main.o malloc.o mem0.o mem1.o mem2.o mem3.o mem5.o memjournal.o \
|
||||
mutex.o mutex_os2.o mutex_unix.o mutex_w32.o mutex_noop.o \
|
||||
opcodes.o os.o os_os2.o os_unix.o os_win.o \
|
||||
pager.o parse.o pcache.o pragma.o prepare.o printf.o \
|
||||
random.o resolve.o rtree.o select.o status.o \
|
||||
table.o tokenize.o trigger.o \
|
||||
update.o util.o vacuum.o \
|
||||
vdbe.o vdbeapi.o vdbeaux.o vdbeblob.o vdbefifo.o vdbemem.o \
|
||||
walker.o where.o utf.o vtab.o
|
||||
|
||||
|
||||
# All of the source code files.
|
||||
#
|
||||
SRC = \
|
||||
$(TOP)/src/alter.c \
|
||||
$(TOP)/src/analyze.c \
|
||||
$(TOP)/src/attach.c \
|
||||
$(TOP)/src/auth.c \
|
||||
$(TOP)/src/bitvec.c \
|
||||
$(TOP)/src/btmutex.c \
|
||||
$(TOP)/src/btree.c \
|
||||
$(TOP)/src/btree.h \
|
||||
$(TOP)/src/btreeInt.h \
|
||||
$(TOP)/src/build.c \
|
||||
$(TOP)/src/callback.c \
|
||||
$(TOP)/src/complete.c \
|
||||
$(TOP)/src/date.c \
|
||||
$(TOP)/src/delete.c \
|
||||
$(TOP)/src/expr.c \
|
||||
$(TOP)/src/fault.c \
|
||||
$(TOP)/src/func.c \
|
||||
$(TOP)/src/global.c \
|
||||
$(TOP)/src/hash.c \
|
||||
$(TOP)/src/hash.h \
|
||||
$(TOP)/src/hwtime.h \
|
||||
$(TOP)/src/insert.c \
|
||||
$(TOP)/src/journal.c \
|
||||
$(TOP)/src/legacy.c \
|
||||
$(TOP)/src/loadext.c \
|
||||
$(TOP)/src/main.c \
|
||||
$(TOP)/src/malloc.c \
|
||||
$(TOP)/src/mem0.c \
|
||||
$(TOP)/src/mem1.c \
|
||||
$(TOP)/src/mem2.c \
|
||||
$(TOP)/src/mem3.c \
|
||||
$(TOP)/src/mem5.c \
|
||||
$(TOP)/src/memjournal.c \
|
||||
$(TOP)/src/mutex.c \
|
||||
$(TOP)/src/mutex.h \
|
||||
$(TOP)/src/mutex_os2.c \
|
||||
$(TOP)/src/mutex_unix.c \
|
||||
$(TOP)/src/mutex_w32.c \
|
||||
$(TOP)/src/mutex_noop.c \
|
||||
$(TOP)/src/os.c \
|
||||
$(TOP)/src/os.h \
|
||||
$(TOP)/src/os_common.h \
|
||||
$(TOP)/src/os_os2.c \
|
||||
$(TOP)/src/os_unix.c \
|
||||
$(TOP)/src/os_win.c \
|
||||
$(TOP)/src/pager.c \
|
||||
$(TOP)/src/pager.h \
|
||||
$(TOP)/src/parse.y \
|
||||
$(TOP)/src/pcache.c \
|
||||
$(TOP)/src/pcache.h \
|
||||
$(TOP)/src/pragma.c \
|
||||
$(TOP)/src/prepare.c \
|
||||
$(TOP)/src/printf.c \
|
||||
$(TOP)/src/random.c \
|
||||
$(TOP)/src/resolve.c \
|
||||
$(TOP)/src/select.c \
|
||||
$(TOP)/src/status.c \
|
||||
$(TOP)/src/shell.c \
|
||||
$(TOP)/src/sqlite.h.in \
|
||||
$(TOP)/src/sqlite3ext.h \
|
||||
$(TOP)/src/sqliteInt.h \
|
||||
$(TOP)/src/sqliteLimit.h \
|
||||
$(TOP)/src/table.c \
|
||||
$(TOP)/src/tclsqlite.c \
|
||||
$(TOP)/src/tokenize.c \
|
||||
$(TOP)/src/trigger.c \
|
||||
$(TOP)/src/utf.c \
|
||||
$(TOP)/src/update.c \
|
||||
$(TOP)/src/util.c \
|
||||
$(TOP)/src/vacuum.c \
|
||||
$(TOP)/src/vdbe.c \
|
||||
$(TOP)/src/vdbe.h \
|
||||
$(TOP)/src/vdbeapi.c \
|
||||
$(TOP)/src/vdbeaux.c \
|
||||
$(TOP)/src/vdbeblob.c \
|
||||
$(TOP)/src/vdbefifo.c \
|
||||
$(TOP)/src/vdbemem.c \
|
||||
$(TOP)/src/vdbeInt.h \
|
||||
$(TOP)/src/vtab.c \
|
||||
$(TOP)/src/walker.c \
|
||||
$(TOP)/src/where.c
|
||||
|
||||
# Source code for extensions
|
||||
#
|
||||
SRC += \
|
||||
$(TOP)/ext/fts1/fts1.c \
|
||||
$(TOP)/ext/fts1/fts1.h \
|
||||
$(TOP)/ext/fts1/fts1_hash.c \
|
||||
$(TOP)/ext/fts1/fts1_hash.h \
|
||||
$(TOP)/ext/fts1/fts1_porter.c \
|
||||
$(TOP)/ext/fts1/fts1_tokenizer.h \
|
||||
$(TOP)/ext/fts1/fts1_tokenizer1.c
|
||||
SRC += \
|
||||
$(TOP)/ext/fts2/fts2.c \
|
||||
$(TOP)/ext/fts2/fts2.h \
|
||||
$(TOP)/ext/fts2/fts2_hash.c \
|
||||
$(TOP)/ext/fts2/fts2_hash.h \
|
||||
$(TOP)/ext/fts2/fts2_icu.c \
|
||||
$(TOP)/ext/fts2/fts2_porter.c \
|
||||
$(TOP)/ext/fts2/fts2_tokenizer.h \
|
||||
$(TOP)/ext/fts2/fts2_tokenizer.c \
|
||||
$(TOP)/ext/fts2/fts2_tokenizer1.c
|
||||
SRC += \
|
||||
$(TOP)/ext/fts3/fts3.c \
|
||||
$(TOP)/ext/fts3/fts3.h \
|
||||
$(TOP)/ext/fts3/fts3_hash.c \
|
||||
$(TOP)/ext/fts3/fts3_hash.h \
|
||||
$(TOP)/ext/fts3/fts3_icu.c \
|
||||
$(TOP)/ext/fts3/fts3_porter.c \
|
||||
$(TOP)/ext/fts3/fts3_tokenizer.h \
|
||||
$(TOP)/ext/fts3/fts3_tokenizer.c \
|
||||
$(TOP)/ext/fts3/fts3_tokenizer1.c
|
||||
SRC += \
|
||||
$(TOP)/ext/icu/icu.c \
|
||||
$(TOP)/ext/icu/sqliteicu.h
|
||||
SRC += \
|
||||
$(TOP)/ext/rtree/rtree.h \
|
||||
$(TOP)/ext/rtree/rtree.c
|
||||
|
||||
|
||||
# Generated source code files
|
||||
#
|
||||
SRC += \
|
||||
keywordhash.h \
|
||||
opcodes.c \
|
||||
opcodes.h \
|
||||
parse.c \
|
||||
parse.h \
|
||||
sqlite3.h
|
||||
|
||||
|
||||
# Source code to the test files.
|
||||
#
|
||||
TESTSRC = \
|
||||
$(TOP)/src/test1.c \
|
||||
$(TOP)/src/test2.c \
|
||||
$(TOP)/src/test3.c \
|
||||
$(TOP)/src/test4.c \
|
||||
$(TOP)/src/test5.c \
|
||||
$(TOP)/src/test6.c \
|
||||
$(TOP)/src/test7.c \
|
||||
$(TOP)/src/test8.c \
|
||||
$(TOP)/src/test9.c \
|
||||
$(TOP)/src/test_autoext.c \
|
||||
$(TOP)/src/test_async.c \
|
||||
$(TOP)/src/test_btree.c \
|
||||
$(TOP)/src/test_config.c \
|
||||
$(TOP)/src/test_devsym.c \
|
||||
$(TOP)/src/test_func.c \
|
||||
$(TOP)/src/test_hexio.c \
|
||||
$(TOP)/src/test_malloc.c \
|
||||
$(TOP)/src/test_md5.c \
|
||||
$(TOP)/src/test_mutex.c \
|
||||
$(TOP)/src/test_onefile.c \
|
||||
$(TOP)/src/test_osinst.c \
|
||||
$(TOP)/src/test_schema.c \
|
||||
$(TOP)/src/test_server.c \
|
||||
$(TOP)/src/test_tclvar.c \
|
||||
$(TOP)/src/test_thread.c \
|
||||
|
||||
#TESTSRC += $(TOP)/ext/fts2/fts2_tokenizer.c
|
||||
#TESTSRC += $(TOP)/ext/fts3/fts3_tokenizer.c
|
||||
|
||||
TESTSRC2 = \
|
||||
$(TOP)/src/attach.c $(TOP)/src/btree.c $(TOP)/src/build.c $(TOP)/src/date.c \
|
||||
$(TOP)/src/expr.c $(TOP)/src/func.c $(TOP)/src/insert.c $(TOP)/src/os.c \
|
||||
$(TOP)/src/os_os2.c $(TOP)/src/os_unix.c $(TOP)/src/os_win.c \
|
||||
$(TOP)/src/pager.c $(TOP)/src/pragma.c $(TOP)/src/prepare.c \
|
||||
$(TOP)/src/printf.c $(TOP)/src/random.c $(TOP)/src/pcache.c \
|
||||
$(TOP)/src/select.c $(TOP)/src/tokenize.c \
|
||||
$(TOP)/src/utf.c $(TOP)/src/util.c $(TOP)/src/vdbeapi.c $(TOP)/src/vdbeaux.c \
|
||||
$(TOP)/src/vdbe.c $(TOP)/src/vdbemem.c $(TOP)/src/where.c parse.c
|
||||
|
||||
# Header files used by all library source files.
|
||||
#
|
||||
HDR = \
|
||||
$(TOP)/src/btree.h \
|
||||
$(TOP)/src/btreeInt.h \
|
||||
$(TOP)/src/hash.h \
|
||||
$(TOP)/src/hwtime.h \
|
||||
keywordhash.h \
|
||||
$(TOP)/src/mutex.h \
|
||||
opcodes.h \
|
||||
$(TOP)/src/os.h \
|
||||
$(TOP)/src/os_common.h \
|
||||
$(TOP)/src/pager.h \
|
||||
$(TOP)/src/pcache.h \
|
||||
parse.h \
|
||||
sqlite3.h \
|
||||
$(TOP)/src/sqlite3ext.h \
|
||||
$(TOP)/src/sqliteInt.h \
|
||||
$(TOP)/src/sqliteLimit.h \
|
||||
$(TOP)/src/vdbe.h \
|
||||
$(TOP)/src/vdbeInt.h
|
||||
|
||||
# Header files used by extensions
|
||||
#
|
||||
EXTHDR += \
|
||||
$(TOP)/ext/fts1/fts1.h \
|
||||
$(TOP)/ext/fts1/fts1_hash.h \
|
||||
$(TOP)/ext/fts1/fts1_tokenizer.h
|
||||
EXTHDR += \
|
||||
$(TOP)/ext/fts2/fts2.h \
|
||||
$(TOP)/ext/fts2/fts2_hash.h \
|
||||
$(TOP)/ext/fts2/fts2_tokenizer.h
|
||||
EXTHDR += \
|
||||
$(TOP)/ext/fts3/fts3.h \
|
||||
$(TOP)/ext/fts3/fts3_hash.h \
|
||||
$(TOP)/ext/fts3/fts3_tokenizer.h
|
||||
EXTHDR += \
|
||||
$(TOP)/ext/rtree/rtree.h
|
||||
|
||||
# This is the default Makefile target. The objects listed here
|
||||
# are what get build when you type just "make" with no arguments.
|
||||
#
|
||||
all: sqlite3.h libsqlite3.a sqlite3$(EXE)
|
||||
|
||||
libsqlite3.a: $(LIBOBJ)
|
||||
$(AR) libsqlite3.a $(LIBOBJ)
|
||||
$(RANLIB) libsqlite3.a
|
||||
|
||||
$(SHPREFIX)sqlite3.$(SO): $(LIBOBJ)
|
||||
$(MKSHLIB) -o $(SHPREFIX)sqlite3.$(SO) $(LIBOBJ) $(TLIBS_SHARED)
|
||||
|
||||
sqlite3$(EXE): $(TOP)/src/shell.c libsqlite3.a sqlite3.h
|
||||
$(TCCX) $(READLINE_FLAGS) -o sqlite3$(EXE) \
|
||||
$(TOP)/src/shell.c \
|
||||
$(LIBREADLINE) $(TLIBS) $(THREADLIB) -L. -lsqlite3
|
||||
|
||||
# This target creates a directory named "tsrc" and fills it with
|
||||
# copies of all of the C source code and header files needed to
|
||||
# build on the target system. Some of the C source code and header
|
||||
# files are automatically generated. This target takes care of
|
||||
# all that automatic generation.
|
||||
#
|
||||
target_source: $(SRC)
|
||||
rm -rf tsrc
|
||||
mkdir tsrc
|
||||
cp -f $(SRC) tsrc
|
||||
rm tsrc/sqlite.h.in tsrc/parse.y
|
||||
touch target_source
|
||||
|
||||
sqlite3.c: target_source $(TOP)/tool/mksqlite3c.tcl
|
||||
tclsh $(TOP)/tool/mksqlite3c.tcl
|
||||
cp sqlite3.c tclsqlite3.c
|
||||
cat $(TOP)/src/tclsqlite.c >>tclsqlite3.c
|
||||
|
||||
fts2amal.c: target_source $(TOP)/ext/fts2/mkfts2amal.tcl
|
||||
tclsh $(TOP)/ext/fts2/mkfts2amal.tcl
|
||||
|
||||
fts3amal.c: target_source $(TOP)/ext/fts3/mkfts3amal.tcl
|
||||
tclsh $(TOP)/ext/fts3/mkfts3amal.tcl
|
||||
|
||||
# Rules to build the LEMON compiler generator
|
||||
#
|
||||
lemon: $(TOP)/tool/lemon.c $(TOP)/tool/lempar.c
|
||||
$(BCC) -o lemon $(TOP)/tool/lemon.c
|
||||
cp $(TOP)/tool/lempar.c .
|
||||
|
||||
# Rules to build individual *.o files from generated *.c files. This
|
||||
# applies to:
|
||||
#
|
||||
# parse.o
|
||||
# opcodes.o
|
||||
#
|
||||
%.o: %.c $(HDR)
|
||||
$(TCCX_SHARED) -c $<
|
||||
|
||||
# Rules to build individual *.o files from files in the src directory.
|
||||
#
|
||||
%.o: $(TOP)/src/%.c $(HDR)
|
||||
$(TCCX_SHARED) -c $<
|
||||
|
||||
tclsqlite.o: $(TOP)/src/tclsqlite.c $(HDR)
|
||||
$(TCCX_SHARED) $(TCL_FLAGS) -c $(TOP)/src/tclsqlite.c
|
||||
|
||||
|
||||
|
||||
# Rules to build opcodes.c and opcodes.h
|
||||
#
|
||||
opcodes.c: opcodes.h $(TOP)/mkopcodec.awk
|
||||
sort -n -b -k 3 opcodes.h | $(NAWK) -f $(TOP)/mkopcodec.awk >opcodes.c
|
||||
|
||||
opcodes.h: parse.h $(TOP)/src/vdbe.c $(TOP)/mkopcodeh.awk
|
||||
cat parse.h $(TOP)/src/vdbe.c | \
|
||||
$(NAWK) -f $(TOP)/mkopcodeh.awk >opcodes.h
|
||||
|
||||
# Rules to build parse.c and parse.h - the outputs of lemon.
|
||||
#
|
||||
parse.h: parse.c
|
||||
|
||||
parse.c: $(TOP)/src/parse.y lemon $(TOP)/addopcodes.awk
|
||||
cp $(TOP)/src/parse.y .
|
||||
rm -f parse.h
|
||||
./lemon $(OPTS) parse.y
|
||||
mv parse.h parse.h.temp
|
||||
awk -f $(TOP)/addopcodes.awk parse.h.temp >parse.h
|
||||
|
||||
sqlite3.h: $(TOP)/src/sqlite.h.in
|
||||
sed -e s/--VERS--/`cat ${TOP}/VERSION`/ \
|
||||
-e s/--VERSION-NUMBER--/`cat ${TOP}/VERSION | sed 's/[^0-9]/ /g' | $(NAWK) '{printf "%d%03d%03d",$$1,$$2,$$3}'`/ \
|
||||
$(TOP)/src/sqlite.h.in >sqlite3.h
|
||||
|
||||
keywordhash.h: $(TOP)/tool/mkkeywordhash.c
|
||||
$(BCC) -o mkkeywordhash $(OPTS) $(TOP)/tool/mkkeywordhash.c
|
||||
./mkkeywordhash >keywordhash.h
|
||||
|
||||
|
||||
|
||||
# Rules to build the extension objects.
|
||||
#
|
||||
icu.o: $(TOP)/ext/icu/icu.c $(HDR) $(EXTHDR)
|
||||
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/icu/icu.c
|
||||
|
||||
fts2.o: $(TOP)/ext/fts2/fts2.c $(HDR) $(EXTHDR)
|
||||
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts2/fts2.c
|
||||
|
||||
fts2_hash.o: $(TOP)/ext/fts2/fts2_hash.c $(HDR) $(EXTHDR)
|
||||
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts2/fts2_hash.c
|
||||
|
||||
fts2_icu.o: $(TOP)/ext/fts2/fts2_icu.c $(HDR) $(EXTHDR)
|
||||
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts2/fts2_icu.c
|
||||
|
||||
fts2_porter.o: $(TOP)/ext/fts2/fts2_porter.c $(HDR) $(EXTHDR)
|
||||
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts2/fts2_porter.c
|
||||
|
||||
fts2_tokenizer.o: $(TOP)/ext/fts2/fts2_tokenizer.c $(HDR) $(EXTHDR)
|
||||
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts2/fts2_tokenizer.c
|
||||
|
||||
fts2_tokenizer1.o: $(TOP)/ext/fts2/fts2_tokenizer1.c $(HDR) $(EXTHDR)
|
||||
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts2/fts2_tokenizer1.c
|
||||
|
||||
fts3.o: $(TOP)/ext/fts3/fts3.c $(HDR) $(EXTHDR)
|
||||
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3.c
|
||||
|
||||
fts3_hash.o: $(TOP)/ext/fts3/fts3_hash.c $(HDR) $(EXTHDR)
|
||||
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_hash.c
|
||||
|
||||
fts3_icu.o: $(TOP)/ext/fts3/fts3_icu.c $(HDR) $(EXTHDR)
|
||||
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_icu.c
|
||||
|
||||
fts3_porter.o: $(TOP)/ext/fts3/fts3_porter.c $(HDR) $(EXTHDR)
|
||||
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_porter.c
|
||||
|
||||
fts3_tokenizer.o: $(TOP)/ext/fts3/fts3_tokenizer.c $(HDR) $(EXTHDR)
|
||||
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_tokenizer.c
|
||||
|
||||
fts3_tokenizer1.o: $(TOP)/ext/fts3/fts3_tokenizer1.c $(HDR) $(EXTHDR)
|
||||
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_tokenizer1.c
|
||||
|
||||
rtree.o: $(TOP)/ext/rtree/rtree.c $(HDR) $(EXTHDR)
|
||||
$(TCCX_SHARED) -DSQLITE_CORE -c $(TOP)/ext/rtree/rtree.c
|
||||
|
||||
|
||||
# Rules for building test programs and for running tests
|
||||
#
|
||||
tclsqlite3: $(TOP)/src/tclsqlite.c libsqlite3.a
|
||||
$(TCCX_SHARED) $(TCL_FLAGS) -DTCLSH=1 -o tclsqlite3 \
|
||||
$(TOP)/src/tclsqlite.c libsqlite3.a $(LIBTCL) $(THREADLIB)
|
||||
|
||||
|
||||
# Rules to build the 'testfixture' application.
|
||||
#
|
||||
TESTFIXTURE_FLAGS = -DTCLSH=1 -DSQLITE_TEST=1 -DSQLITE_CRASH_TEST=1
|
||||
TESTFIXTURE_FLAGS += -DSQLITE_SERVER=1 -DSQLITE_PRIVATE="" -DSQLITE_CORE
|
||||
|
||||
testfixture$(EXE): $(TESTSRC2) libsqlite3.a $(TESTSRC) $(TOP)/src/tclsqlite.c
|
||||
$(TCCX) $(TCL_FLAGS) $(TESTFIXTURE_FLAGS) \
|
||||
$(TESTSRC) $(TESTSRC2) $(TOP)/src/tclsqlite.c \
|
||||
-o testfixture$(EXE) $(LIBTCL) $(THREADLIB) libsqlite3.a
|
||||
|
||||
amalgamation-testfixture$(EXE): sqlite3.c $(TESTSRC) $(TOP)/src/tclsqlite.c
|
||||
$(TCCX) $(TCL_FLAGS) $(TESTFIXTURE_FLAGS) \
|
||||
$(TESTSRC) $(TOP)/src/tclsqlite.c sqlite3.c \
|
||||
-o testfixture$(EXE) $(LIBTCL) $(THREADLIB)
|
||||
|
||||
fts3-testfixture$(EXE): sqlite3.c fts3amal.c $(TESTSRC) $(TOP)/src/tclsqlite.c
|
||||
$(TCCX) $(TCL_FLAGS) $(TESTFIXTURE_FLAGS) \
|
||||
-DSQLITE_ENABLE_FTS3=1 \
|
||||
$(TESTSRC) $(TOP)/src/tclsqlite.c sqlite3.c fts3amal.c \
|
||||
-o testfixture$(EXE) $(LIBTCL) $(THREADLIB)
|
||||
|
||||
fulltest: testfixture$(EXE) sqlite3$(EXE)
|
||||
./testfixture$(EXE) $(TOP)/test/all.test
|
||||
|
||||
soaktest: testfixture$(EXE) sqlite3$(EXE)
|
||||
./testfixture$(EXE) $(TOP)/test/all.test -soak 1
|
||||
|
||||
test: testfixture$(EXE) sqlite3$(EXE)
|
||||
./testfixture$(EXE) $(TOP)/test/veryquick.test
|
||||
|
||||
sqlite3_analyzer$(EXE): $(TOP)/src/tclsqlite.c sqlite3.c $(TESTSRC) \
|
||||
$(TOP)/tool/spaceanal.tcl
|
||||
sed \
|
||||
-e '/^#/d' \
|
||||
-e 's,\\,\\\\,g' \
|
||||
-e 's,",\\",g' \
|
||||
-e 's,^,",' \
|
||||
-e 's,$$,\\n",' \
|
||||
$(TOP)/tool/spaceanal.tcl >spaceanal_tcl.h
|
||||
$(TCCX) $(TCL_FLAGS) $(TESTFIXTURE_FLAGS) \
|
||||
-DTCLSH=2 -DSQLITE_TEST=1 -DSQLITE_DEBUG=1 -DSQLITE_PRIVATE="" \
|
||||
$(TESTSRC) $(TOP)/src/tclsqlite.c sqlite3.c \
|
||||
-o sqlite3_analyzer$(EXE) \
|
||||
$(LIBTCL) $(THREADLIB)
|
||||
|
||||
TEST_EXTENSION = $(SHPREFIX)testloadext.$(SO)
|
||||
$(TEST_EXTENSION): $(TOP)/src/test_loadext.c
|
||||
$(MKSHLIB) $(TOP)/src/test_loadext.c -o $(TEST_EXTENSION)
|
||||
|
||||
extensiontest: testfixture$(EXE) $(TEST_EXTENSION)
|
||||
./testfixture$(EXE) $(TOP)/test/loadext.test
|
||||
|
||||
clean:
|
||||
rm -f *.o sqlite3$(EXE) libsqlite3.a sqlite3.h opcodes.*
|
||||
rm -f lemon lempar.c parse.* sqlite*.tar.gz mkkeywordhash keywordhash.h
|
||||
rm -f $(PUBLISH)
|
||||
rm -f *.da *.bb *.bbg gmon.out
|
||||
rm -rf tsrc target_source
|
||||
rm -f testloadext.dll libtestloadext.so
|
||||
rm -f sqlite3.c fts?amal.c tclsqlite3.c
|
||||
rm -f $(SHPREFIX)sqlite3.$(SO)
|
||||
@@ -338,6 +338,13 @@ void *sqlite3Fts3HashInsert(
|
||||
return old_data;
|
||||
}
|
||||
if( data==0 ) return 0;
|
||||
if( pH->htsize==0 ){
|
||||
fts3Rehash(pH,8);
|
||||
if( pH->htsize==0 ){
|
||||
pH->count = 0;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
new_elem = (fts3HashElem*)fts3HashMalloc( sizeof(fts3HashElem) );
|
||||
if( new_elem==0 ) return data;
|
||||
if( pH->copyKey && pKey!=0 ){
|
||||
@@ -352,14 +359,6 @@ void *sqlite3Fts3HashInsert(
|
||||
}
|
||||
new_elem->nKey = nKey;
|
||||
pH->count++;
|
||||
if( pH->htsize==0 ){
|
||||
fts3Rehash(pH,8);
|
||||
if( pH->htsize==0 ){
|
||||
pH->count = 0;
|
||||
fts3HashFree(new_elem);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
if( pH->count > pH->htsize ){
|
||||
fts3Rehash(pH,pH->htsize*2);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ LIBOBJ+= alter.o analyze.o attach.o auth.o \
|
||||
memjournal.o \
|
||||
mutex.o mutex_noop.o mutex_os2.o mutex_unix.o mutex_w32.o \
|
||||
opcodes.o os.o os_os2.o os_unix.o os_win.o \
|
||||
pager.o parse.o pcache.o pragma.o prepare.o printf.o \
|
||||
pager.o parse.o pcache.o pcache1.o pragma.o prepare.o printf.o \
|
||||
random.o resolve.o rtree.o select.o status.o \
|
||||
table.o tokenize.o trigger.o \
|
||||
update.o util.o vacuum.o \
|
||||
@@ -122,6 +122,7 @@ SRC = \
|
||||
$(TOP)/src/parse.y \
|
||||
$(TOP)/src/pcache.c \
|
||||
$(TOP)/src/pcache.h \
|
||||
$(TOP)/src/pcache1.c \
|
||||
$(TOP)/src/pragma.c \
|
||||
$(TOP)/src/prepare.c \
|
||||
$(TOP)/src/printf.c \
|
||||
@@ -227,6 +228,7 @@ TESTSRC = \
|
||||
$(TOP)/src/test_mutex.c \
|
||||
$(TOP)/src/test_onefile.c \
|
||||
$(TOP)/src/test_osinst.c \
|
||||
$(TOP)/src/test_pcache.c \
|
||||
$(TOP)/src/test_schema.c \
|
||||
$(TOP)/src/test_server.c \
|
||||
$(TOP)/src/test_tclvar.c \
|
||||
@@ -242,7 +244,7 @@ TESTSRC2 = \
|
||||
$(TOP)/src/os_os2.c $(TOP)/src/os_unix.c $(TOP)/src/os_win.c \
|
||||
$(TOP)/src/pager.c $(TOP)/src/pragma.c $(TOP)/src/prepare.c \
|
||||
$(TOP)/src/printf.c $(TOP)/src/random.c $(TOP)/src/pcache.c \
|
||||
$(TOP)/src/select.c $(TOP)/src/tokenize.c \
|
||||
$(TOP)/src/pcache1.c $(TOP)/src/select.c $(TOP)/src/tokenize.c \
|
||||
$(TOP)/src/utf.c $(TOP)/src/util.c $(TOP)/src/vdbeapi.c $(TOP)/src/vdbeaux.c \
|
||||
$(TOP)/src/vdbe.c $(TOP)/src/vdbemem.c $(TOP)/src/where.c parse.c \
|
||||
$(TOP)/ext/fts3/fts3.c $(TOP)/ext/fts3/fts3_tokenizer.c
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
C Version\s3.6.5\s(CVS\s5897)
|
||||
D 2008-11-12T15:38:53
|
||||
C Version\s3.6.6.1\s(CVS\s5948)
|
||||
D 2008-11-22T15:51:28
|
||||
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
||||
F Makefile.in 48172b58e444a9725ec482e0c022a564749acab4
|
||||
F Makefile.in 0aa7bbe3be6acc4045706e3bb3fd0b8f38f4a3b5
|
||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||
F Makefile.vxwSH4 d53b4be86491060d498b22148951b6d765884cab
|
||||
F README b974cdc3f9f12b87e851b04e75996d720ebf81ac
|
||||
F VERSION 4eb06187e9b9f72fdf3ba27c407e24665d0bb513
|
||||
F VERSION 0fb8ff48a435ea7ea0f720a79cb3c4911a7ab06c
|
||||
F aclocal.m4 7d02b11fed45174e11156144227278deb6236eea
|
||||
F addopcodes.awk 215333be9d99c260e076c3080a81dba3ae928c45
|
||||
F art/2005osaward.gif 0d1851b2a7c1c9d0ccce545f3e14bca42d7fd248
|
||||
@@ -53,7 +54,7 @@ F ext/fts3/README.tokenizers 226644a0eab97724e8de83061912e8bb248461b6
|
||||
F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d
|
||||
F ext/fts3/fts3.c e67453b6ac421b79e600385491ed7f038b3bb271
|
||||
F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe
|
||||
F ext/fts3/fts3_hash.c 83e7bb4042106b32811681dd2859b4577a7a6b35
|
||||
F ext/fts3/fts3_hash.c e15e84d18f8df149ab290029872d4559c4c7c15a
|
||||
F ext/fts3/fts3_hash.h 004b759e1602ff16dfa02fea3ca1c77336ad6798
|
||||
F ext/fts3/fts3_icu.c ac494aed69835008185299315403044664bda295
|
||||
F ext/fts3/fts3_porter.c 3063da945fb0a935781c135f7575f39166173eca
|
||||
@@ -79,7 +80,7 @@ F ext/rtree/tkt3363.test 6662237ea75bb431cd5d262dfc9535e1023315fc
|
||||
F ext/rtree/viewrtree.tcl 09526398dae87a5a87c5aac2b3854dbaf8376869
|
||||
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
|
||||
F ltmain.sh 09fe5815427dc7d0abb188bbcdf0e34896577210
|
||||
F main.mk 187bbff650073ffad5e8313795665ea64f36c0d5
|
||||
F main.mk 87a73e91a3d0827dc796a249260866335e38a36e
|
||||
F mkdll.sh 7d09b23c05d56532e9d44a50868eb4b12ff4f74a
|
||||
F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f
|
||||
F mkextw.sh 4123480947681d9b434a5e7b1ee08135abe409ac
|
||||
@@ -93,66 +94,67 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
|
||||
F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
|
||||
F sqlite3.def a1be7b9a4b8b51ac41c6ff6e8e44a14ef66b338b
|
||||
F sqlite3.pc.in ae6f59a76e862f5c561eb32a380228a02afc3cad
|
||||
F src/alter.c a03c9236476f0469eb830bcd16ac30b695e09b83
|
||||
F src/analyze.c 91b958435cbb423721ef2a841dbc459c1959bb3a
|
||||
F src/attach.c 208881c87160d9e2c73a46cf86116c5a6d66f9d7
|
||||
F src/alter.c 0a00c184052b7fd20271e783f65fec4efec6fe30
|
||||
F src/analyze.c 301a1358f4f4d84d96608927d8ddcf471c53ad9a
|
||||
F src/attach.c 85c6a3d0daf11965b47604190d7cf5597dc88382
|
||||
F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
|
||||
F src/bitvec.c 9e922b2577b7e46d8f95349bca6a52f7674d7582
|
||||
F src/btmutex.c 3a90096c3080b9057dc570b8e16e46511e1c788a
|
||||
F src/btree.c 7505a73bd9b7c36a816543c4a71437d8c2f7539a
|
||||
F src/bitvec.c 4300d311b17fb3c1476623fd895a8feac02a0b08
|
||||
F src/btmutex.c 63c5cc4ad5715690767ffcb741e185d7bc35ec1a
|
||||
F src/btree.c adfb7974429f79f188fabcdb26145fca3a7d04ed
|
||||
F src/btree.h 179c3ea813780df78a289a8f5130db18e6d4616e
|
||||
F src/btreeInt.h e38e9b2b285f40f5bc0a6664f630d4a141622f16
|
||||
F src/build.c 98a6884d47c3cc12faeb2e9a926018d3a7382133
|
||||
F src/btreeInt.h 8d21590c97b6a2c00cce1f78ed5dc5756e835108
|
||||
F src/build.c a89e901ea24d8ec845286f9a1fbfd14572a7777e
|
||||
F src/callback.c e970e5beddbdb23f89a6d05cb1a6419d9f755624
|
||||
F src/complete.c cb14e06dbe79dee031031f0d9e686ff306afe07c
|
||||
F src/date.c 6f4277fa56d8c1b8e70c0bde838c9e99609f5ec0
|
||||
F src/delete.c 3b156e1d396942fe50664af4e45e14e7de08c312
|
||||
F src/expr.c 0a23a7f58084a40c38e1fc3afcd8adbbc8950b45
|
||||
F src/date.c 88898ae96a0d7f66711caffa40b2cf30e623a387
|
||||
F src/delete.c 2f85d6d00333343a76824a899e15f241ca383c7c
|
||||
F src/expr.c 01b1cf0783a6d0093d72b799fcb22c86146362ef
|
||||
F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff
|
||||
F src/func.c d8eb180e4f454d480894522d8ed11de771a14c7e
|
||||
F src/func.c b4570eb73d873041b8e68f5cdbb4556ff13a94c3
|
||||
F src/global.c 20a3fe46c8287a01ba3a7442558f0eb70c66b19a
|
||||
F src/hash.c 582c00618efe2051785e66ba1b6430d5a129de3f
|
||||
F src/hash.h 28f38ebb1006a5beedcb013bcdfe31befe7437ae
|
||||
F src/hwtime.h 4a1d45f4cae1f402ea19686acf24acf4f0cb53cb
|
||||
F src/insert.c d61998cb8d934bd42b77bd362f94cc3368c5d5f7
|
||||
F src/insert.c 73c4b33767d9540f8ead5d903504ed93f48ad147
|
||||
F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e
|
||||
F src/legacy.c aac57bd984e666059011ea01ec4383892a253be3
|
||||
F src/loadext.c 3872457afdf25bb174fd383cb4e3e0d2a9e60552
|
||||
F src/main.c cdc0fa9b11254d7e9f15c67b22a3981cb5090119
|
||||
F src/malloc.c a213fb461b8df08aed7606f6a1e1d3452e089000
|
||||
F src/main.c d67d2eee7a643a4a894e5de91231a99ad88400b9
|
||||
F src/malloc.c 4e7bf5a3fcfd848a09f7ce7abb00f7b358128161
|
||||
F src/mem0.c f2f84062d1f35814d6535c9f9e33de3bfb3b132c
|
||||
F src/mem1.c 2091081d1c6bcd4516738f37cd84d42e814cf9a2
|
||||
F src/mem1.c bb8e26adde7d463270e961f045802c61dbabc8f1
|
||||
F src/mem2.c 5d9968f576ba1babc787adbfb613cf428ab484ec
|
||||
F src/mem3.c 1594f117fde4cf11a6c16521f3f30af8d04bbe68
|
||||
F src/mem5.c 8cb9dfacf7e11a7822b4935757ae0c1749278b4e
|
||||
F src/memjournal.c e2551e89243b39a972a1fbefeedaf4f74438a0cf
|
||||
F src/mem3.c 67153ec933e08b70714055e872efb58a6b287939
|
||||
F src/mem5.c 838309b521c96a2a34507f74a5a739d28de4aac6
|
||||
F src/memjournal.c bd536c4d6d701b4fa7428545128c5684d2adf779
|
||||
F src/mutex.c e9cb5fbe94afb4328869afaf3ac49bd1327559eb
|
||||
F src/mutex.h 9e686e83a88838dac8b9c51271c651e833060f1e
|
||||
F src/mutex_noop.c 0004efdbc2fd48d261d5b3416fe537e888c79a54
|
||||
F src/mutex_os2.c 9c5637aa4c307c552566d0f0b3bd206245b54a97
|
||||
F src/mutex_unix.c 29049a61755cccddb2ee53904e6906bb7674223c
|
||||
F src/mutex_unix.c 3b1c895a044d45812ea1eae9019daeff8cfb27ce
|
||||
F src/mutex_w32.c 017b522f63ef09b834fefc9daa876c9ec167e7b5
|
||||
F src/os.c 0b411644b87ad689d7250bbfd1834d99b81a3df4
|
||||
F src/os.h ef8abeb9afc694b82dbd169a91c9b7e26db3c892
|
||||
F src/os_common.h 24525d8b7bce66c374dfc1810a6c9043f3359b60
|
||||
F src/os_os2.c 63be0987dbeb42e9b08c831863d2a315953b86e1
|
||||
F src/os_unix.c af390f03ebe339e63911aec2d4ccd1e53fde581e
|
||||
F src/os_win.c e208cbbceac63c1dd881d0909de5a4679a2c6992
|
||||
F src/pager.c 6b6f8eb4938d184d6612ea89631185dbace246b3
|
||||
F src/pager.h 4a57b219c0765fe1870238064e3f46e4eb2cf5af
|
||||
F src/os_os2.c d12285d66df674c42f6f544a6f7c21bf1a954ee1
|
||||
F src/os_unix.c 03c76b5269361adcd68cf9d6713181922535ac6e
|
||||
F src/os_win.c 3dff41670fb9798a869c636626bb7d6d8b6a45bb
|
||||
F src/pager.c db12a8333e54e7bbf62dc621ada5507adb3a6493
|
||||
F src/pager.h a02ef8e6cc7e78b54874166e5ce786c9d4c489bf
|
||||
F src/parse.y 2c4758b4c5ead6de8cf7112f5a7cce7561d313fe
|
||||
F src/pcache.c 3d547c392145113336d44b901e048b86ee6a4774
|
||||
F src/pcache.h 2caf2deb6cbaa75c423b8b96fc1411069ee77c75
|
||||
F src/pragma.c 5d4333a27ef4f770fc69ca4f138419d3b462c554
|
||||
F src/prepare.c ae49b8298eca79acdbc964679962e089b943ec94
|
||||
F src/printf.c 785f87120589c1db672e37c6eb1087c456e6f84d
|
||||
F src/pcache.c f3121a531745b20f5b824201eb63949a7e2959ac
|
||||
F src/pcache.h f20c3e82dd6da622c3fe296170cb1801f9a2d75a
|
||||
F src/pcache1.c 2453a3e925841fdb610f39bba24def8b2ad4a908
|
||||
F src/pragma.c 0a5051029c5b687e2f2669d91aa3281ebcbe4fdb
|
||||
F src/prepare.c fcadb25d2ad722d87103517333c825b56b79a770
|
||||
F src/printf.c ce86aed93a704938ca4d0344aaa763271842a4b0
|
||||
F src/random.c a87afbd598aa877e23ac676ee92fd8ee5c786a51
|
||||
F src/resolve.c 266bb03d2b456fe68f5df2dd5687e7e88ff8088d
|
||||
F src/select.c b03c6fe474ded7bd110ca7b551bf0236133c12da
|
||||
F src/shell.c 01835f435d2e42be95480f7d7cce48e9b255652e
|
||||
F src/sqlite.h.in b73e17f40b0dcfc4b17f5ef18ba90bca8d1e8bc5
|
||||
F src/resolve.c 4af5391d2b4c1d6c583a6805ac6660181de4545b
|
||||
F src/select.c e01537d4d8b8b81a6507e07ebb17fc232dacdda7
|
||||
F src/shell.c 650d1a87408682280d0e9d014d0d328c59c84b38
|
||||
F src/sqlite.h.in e9a0aa2502dfe01bf166956051528f28871474c3
|
||||
F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17
|
||||
F src/sqliteInt.h f2b50cd40d847ccf2d9baf5a622e744a05f136e3
|
||||
F src/sqliteInt.h beacd5768e55285097fbb419bcd741721b455003
|
||||
F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8
|
||||
F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76
|
||||
F src/table.c 22744786199c9195720c15a7a42cb97b2e2728d8
|
||||
@@ -174,33 +176,34 @@ F src/test_devsym.c 802d10e65b4217208cb47059b84adf46318bcdf4
|
||||
F src/test_func.c a55c4d5479ff2eb5c0a22d4d88e9528ab59c953b
|
||||
F src/test_hexio.c 2f1122aa3f012fa0142ee3c36ce5c902a70cd12f
|
||||
F src/test_loadext.c 97dc8800e46a46ed002c2968572656f37e9c0dd9
|
||||
F src/test_malloc.c e2f6e6774308f531a3d12475dd2a5211dd31b7eb
|
||||
F src/test_malloc.c 5127337c9fb4c851a7f604c0170e0e5ca1fbfe33
|
||||
F src/test_md5.c 28209a4e2068711b5443c33104fe41f21d160071
|
||||
F src/test_mutex.c 66c4ab4e0396a440ddb17cd9b58a05305144f05d
|
||||
F src/test_onefile.c 243157b10275251c5dc2d6619aee2ff9ae22379c
|
||||
F src/test_osinst.c ae29e9c09485622a157849508302dd9ffe44f21f
|
||||
F src/test_pcache.c 0008968cc36558c8253585e5d321eccba44edb80
|
||||
F src/test_schema.c 4b4bf7bb329326458c491b0e6facd4c8c4c5b479
|
||||
F src/test_server.c f0a403b5f699c09bd2b1236b6f69830fd6221f6b
|
||||
F src/test_tclvar.c 9e42fa59d3d2f064b7ab8628e7ab2dc8a9fe93d4
|
||||
F src/test_thread.c d74fc445e0dba0e00806117eb449b307c0b146bf
|
||||
F src/test_wsd.c c297d7d6b8a990239e1bd25935e81d612d8ae31d
|
||||
F src/tokenize.c aaa5fa6a4536a9dd7c855a3f66f32508f1612138
|
||||
F src/trigger.c 649940b5bf5838a33721fb72372e7c9d1faf56a9
|
||||
F src/update.c f22a6f4507f9a0ef082418919382f83b90fd2e63
|
||||
F src/trigger.c b86eb6d216c0014138f858a04185113cb54518e4
|
||||
F src/update.c 37d03659f4d2186ffb8d0ab1df9c3038273fb488
|
||||
F src/utf.c 86dc0f8076f606432a01f1498ae054c32de1f9d2
|
||||
F src/util.c afe659ccc05d1f8af9e8631dabfec3ee3a7144af
|
||||
F src/vacuum.c fd77433d0c26d3ff1eb96eab017a1787ac5aa642
|
||||
F src/vdbe.c b6b989bbd0e306581695f8914c4246905a5c0d14
|
||||
F src/util.c b9a5d1c4c1a433e17d5828f9717fac763016a2cb
|
||||
F src/vacuum.c 383d6297bddc011ab04a9eed110db6eaf523e8e9
|
||||
F src/vdbe.c c5270245fcb5368634a9301481ab94a22e7a21b2
|
||||
F src/vdbe.h 03516f28bf5aca00a53c4dccd6c313f96adb94f6
|
||||
F src/vdbeInt.h c9400778d6f801c2cb8ebe6151c909e19dd2d793
|
||||
F src/vdbeapi.c ea22e171704906632cd971668359b8c0c5053001
|
||||
F src/vdbeaux.c 75258853624ec5fba72039f87397b3d88c586fa1
|
||||
F src/vdbeInt.h 6b1082480832d406c57a7f469a1c61f1a8759aca
|
||||
F src/vdbeapi.c 20722164e7701a0747eaea03cddbbe0de5cb37bf
|
||||
F src/vdbeaux.c 18dea7bbaf3657d77331b03a3ec34363348ea5b0
|
||||
F src/vdbeblob.c b0dcebfafedcf9c0addc7901ad98f6f986c08935
|
||||
F src/vdbefifo.c 20fda2a7c4c0bcee1b90eb7e545fefcdbf2e1de7
|
||||
F src/vdbefifo.c e6326ad6d16ccd8c2ef659046e3a509c0ae4990a
|
||||
F src/vdbemem.c 223e03281855515e9474dbf66f157452093a77c2
|
||||
F src/vtab.c 527c180e9c5fca417c9167d02af4b5039f892b4b
|
||||
F src/vtab.c 02c51eac45dbff1a1d6e73f58febf92ecb563f7f
|
||||
F src/walker.c 488c2660e13224ff70c0c82761118efb547f8f0d
|
||||
F src/where.c 171c9b2583944f66484c8552daa85373ce9e949f
|
||||
F src/where.c 96f7c2bd9e83c252d90ee2794f7a902fc5ba505b
|
||||
F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
|
||||
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
|
||||
F test/alias.test 597662c5d777a122f9a3df0047ea5c5bd383a911
|
||||
@@ -230,7 +233,7 @@ F test/bigfile.test 9a6a8346e4042d9c781ed6cb6553ac871ae30618
|
||||
F test/bigrow.test f0aeb7573dcb8caaafea76454be3ade29b7fc747
|
||||
F test/bind.test 1134441f1ea47abd1c740090435a6ecbe9ceb263
|
||||
F test/bindxfer.test d4f573750e06c34ef2309acb95ad57da1d3c983f
|
||||
F test/bitvec.test 62a512c3f7041d1df12558eb25990e5a19820571
|
||||
F test/bitvec.test ecea9aa315f36991e56e326701279b7775cb2bef
|
||||
F test/blob.test 2a38d867bdf08f9ce081776acec1ac8d4bca66be
|
||||
F test/busy.test 76b4887f8b9160ba903c1ac22e8ff406ad6ae2f0
|
||||
F test/cache.test 3ff445c445742a7b6b9ba6e1d62a25263f9424b9
|
||||
@@ -265,7 +268,7 @@ F test/corrupt8.test 9992ef7f67cefc576b92373f6bf5ab8775280f51
|
||||
F test/corrupt9.test 794d284109c65c8f10a2b275479045e02d163bae
|
||||
F test/corruptA.test 99e95620b980161cb3e79f06a884a4bb8ae265ff
|
||||
F test/corruptB.test 505331779fe7a96fe38ecbb817f19c63bc27d171
|
||||
F test/corruptC.test d73d70aa2919fae2e0032043e85d00949e1d556a
|
||||
F test/corruptC.test c798aa395a8d052fba88bd1be8e1945309e3f94a
|
||||
F test/crash.test 1b6ac8410689ff78028887f445062dc897c9ac89
|
||||
F test/crash2.test 5b14d4eb58b880e231361d3b609b216acda86651
|
||||
F test/crash3.test 776f9363554c029fcce71d9e6600fa0ba6359ce7
|
||||
@@ -458,8 +461,8 @@ F test/pager3.test 2323bf27fd5bd887b580247e5bce500ceee994b4
|
||||
F test/pageropt.test 3ee6578891baaca967f0bd349e4abfa736229e1a
|
||||
F test/pagesize.test 0d9ff3fedfce6e5ffe8fa7aca9b6d3433a2e843b
|
||||
F test/pcache.test 515b4c26e9f57660357dfff5b6b697acac1abc5f
|
||||
F test/pcache2.test e2260293e892190be65de89526dbc4f92c8b5a7c
|
||||
F test/permutations.test b1b15770940d954dbd874f3e6296ec321b81b5c6
|
||||
F test/pcache2.test 46efd980a89f737847b99327bda19e08fe11e402
|
||||
F test/permutations.test 5308a94878efc81a8e8ce133926dfb2c53d19133
|
||||
F test/pragma.test 165372b62391d233715cde82d99f34d306f9257f
|
||||
F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47
|
||||
F test/printf.test 262a5acd3158f788e9bdf7f18d718f3af32ff6ef
|
||||
@@ -495,7 +498,7 @@ F test/shared4.test d0fadacb50bb6981b2fb9dc6d1da30fa1edddf83
|
||||
F test/shared_err.test 91e26ec4f3fbe07951967955585137e2f18993de
|
||||
F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3
|
||||
F test/sidedelete.test f0ad71abe6233e3b153100f3b8d679b19a488329
|
||||
F test/soak.test 3c317b3e55e1160731030c8e865d1858fab66fea
|
||||
F test/soak.test d9d0a5e5c0157115c9a17f526f12691fe146768d
|
||||
F test/softheap1.test 73ebd6e020d2954d965da2072baba5922fc8fb6a
|
||||
F test/sort.test 0e4456e729e5a92a625907c63dcdedfbe72c5dc5
|
||||
F test/speed1.test c74564fea46e094d6b518bf464c355991905eea2
|
||||
@@ -575,7 +578,7 @@ F test/tkt3424.test 3171193ce340cff6b7ea81c03b8fa1cbc34ec36e
|
||||
F test/tkt3442.test 33722a3fa4bdc0614448044eb5e28765aea28eb7
|
||||
F test/tkt3457.test e9ca2b90f0eb1fb8be73a30d29aacb2e3abedeb9
|
||||
F test/tkt3461.test 5a63e8d8ee5ce00f076b1e2f82aba5480a0f14ed
|
||||
F test/tkt3472.test 33bec8e3b6d990b3926b3c91fb1ebd5cf8519d87
|
||||
F test/tkt3472.test e689a687631e59c7a47d9438148115fee23b16c3
|
||||
F test/tkt3493.test 8472b3464e49a27ff7271308eec46154209e667b
|
||||
F test/tokenize.test ce430a7aed48fc98301611429595883fdfcab5d7
|
||||
F test/trace.test 951cd0f5f571e7f36bf7bfe04be70f90fb16fb00
|
||||
@@ -630,18 +633,18 @@ F test/wherelimit.test 5e9fd41e79bb2b2d588ed999d641d9c965619b31
|
||||
F test/zeroblob.test 792124852ec61458a2eb527b5091791215e0be95
|
||||
F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b
|
||||
F tool/fragck.tcl 5265a95126abcf6ab357f7efa544787e5963f439
|
||||
F tool/genfkey.README d94b4423eef29e662898948f04a7dbe210c35e7a
|
||||
F tool/genfkey.README 080ca2269f727fcf14c8e76d52e85d157e3a8e9a
|
||||
F tool/genfkey.c e1b9c93da828db10c1109c7b4fa611aec8adc407
|
||||
F tool/genfkey.test 182829596fb15785b94b2493c5f735b847d91076
|
||||
F tool/lemon.c 6cb39632ef3bfec2cea8f81b4d7f63c09fe12802
|
||||
F tool/lempar.c 770dc64b74429daf9611676f43bfbd7c1bed0152
|
||||
F tool/lempar.c 9ef6809804f9066fa94a0bdc02224ce015951843
|
||||
F tool/memleak.awk 4e7690a51bf3ed757e611273d43fe3f65b510133
|
||||
F tool/memleak2.awk 9cc20c8e8f3c675efac71ea0721ee6874a1566e8
|
||||
F tool/memleak3.tcl 7707006ee908cffff210c98158788d85bb3fcdbf
|
||||
F tool/mkkeywordhash.c c219ee2b8b5b8e7011cccfa1caec62d9812e82e7
|
||||
F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e x
|
||||
F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97
|
||||
F tool/mksqlite3c.tcl f27bd970d5963cc4c6fb421d8553a2c439e61b9b
|
||||
F tool/mksqlite3c.tcl 619c0629ac51f670f1f522cd0ab1fbb62ca97d45
|
||||
F tool/mksqlite3internalh.tcl 7b43894e21bcb1bb39e11547ce7e38a063357e87
|
||||
F tool/omittest.tcl 27d6f6e3b1e95aeb26a1c140e6eb57771c6d794a
|
||||
F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c
|
||||
@@ -656,7 +659,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
|
||||
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
P f41dd2053c8a297a05b47d0ef631b4d9a7db2fff
|
||||
R 217eb8bceae810089ca0de92c63eed2e
|
||||
P 15d88edf7671822c57238c3f85adf0b40b13e3e2
|
||||
R d2ce2d5b91c1f6ae4cf2c6a18038f9fd
|
||||
U drh
|
||||
Z d3949478ddaafe6e3d8afbf1d2a260a7
|
||||
Z d6e85c23f6cca1b4a3eb502f6411e7b2
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
369f74983bb1b6a6426260148018cdc084fc2b49
|
||||
c2266aa094411346a73ab704c03ec919d6e5f46d
|
||||
+7
-4
@@ -12,7 +12,7 @@
|
||||
** This file contains C code routines that used to generate VDBE code
|
||||
** that implements the ALTER TABLE command.
|
||||
**
|
||||
** $Id: alter.c,v 1.49 2008/10/30 17:21:13 danielk1977 Exp $
|
||||
** $Id: alter.c,v 1.50 2008/11/19 09:05:27 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@@ -39,7 +39,7 @@
|
||||
*/
|
||||
static void renameTableFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
int NotUsed,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
unsigned char const *zSql = sqlite3_value_text(argv[0]);
|
||||
@@ -53,6 +53,8 @@ static void renameTableFunc(
|
||||
|
||||
sqlite3 *db = sqlite3_context_db_handle(context);
|
||||
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
|
||||
/* The principle used to locate the table name in the CREATE TABLE
|
||||
** statement is that the table name is the first non-space token that
|
||||
** is immediately followed by a TK_LP or TK_USING token.
|
||||
@@ -94,7 +96,7 @@ static void renameTableFunc(
|
||||
*/
|
||||
static void renameTriggerFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
int NotUsed,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
unsigned char const *zSql = sqlite3_value_text(argv[0]);
|
||||
@@ -106,9 +108,10 @@ static void renameTriggerFunc(
|
||||
unsigned char const *zCsr = zSql;
|
||||
int len = 0;
|
||||
char *zRet;
|
||||
|
||||
sqlite3 *db = sqlite3_context_db_handle(context);
|
||||
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
|
||||
/* The principle used to locate the table name in the CREATE TRIGGER
|
||||
** statement is that the table name is the first token that is immediatedly
|
||||
** preceded by either TK_ON or TK_DOT and immediatedly followed by one
|
||||
|
||||
+4
-2
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** This file contains code associated with the ANALYZE command.
|
||||
**
|
||||
** @(#) $Id: analyze.c,v 1.44 2008/11/03 20:55:07 drh Exp $
|
||||
** @(#) $Id: analyze.c,v 1.46 2008/11/19 16:52:44 danielk1977 Exp $
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_ANALYZE
|
||||
#include "sqliteInt.h"
|
||||
@@ -356,7 +356,7 @@ struct analysisInfo {
|
||||
** argv[0] = name of the index
|
||||
** argv[1] = results of analysis - on integer for each column
|
||||
*/
|
||||
static int analysisLoader(void *pData, int argc, char **argv, char **azNotUsed){
|
||||
static int analysisLoader(void *pData, int argc, char **argv, char **NotUsed){
|
||||
analysisInfo *pInfo = (analysisInfo*)pData;
|
||||
Index *pIndex;
|
||||
int i, c;
|
||||
@@ -364,6 +364,8 @@ static int analysisLoader(void *pData, int argc, char **argv, char **azNotUsed){
|
||||
const char *z;
|
||||
|
||||
assert( argc==2 );
|
||||
UNUSED_PARAMETER2(NotUsed, argc);
|
||||
|
||||
if( argv==0 || argv[0]==0 || argv[1]==0 ){
|
||||
return 0;
|
||||
}
|
||||
|
||||
+7
-3
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the ATTACH and DETACH commands.
|
||||
**
|
||||
** $Id: attach.c,v 1.79 2008/10/28 17:52:39 danielk1977 Exp $
|
||||
** $Id: attach.c,v 1.80 2008/11/19 09:05:27 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -64,7 +64,7 @@ static int resolveAttachExpr(NameContext *pName, Expr *pExpr)
|
||||
*/
|
||||
static void attachFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
int NotUsed,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
int i;
|
||||
@@ -76,6 +76,8 @@ static void attachFunc(
|
||||
char *zErrDyn = 0;
|
||||
char zErr[128];
|
||||
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
|
||||
zFile = (const char *)sqlite3_value_text(argv[0]);
|
||||
zName = (const char *)sqlite3_value_text(argv[1]);
|
||||
if( zFile==0 ) zFile = "";
|
||||
@@ -232,7 +234,7 @@ attach_error:
|
||||
*/
|
||||
static void detachFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
int NotUsed,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
const char *zName = (const char *)sqlite3_value_text(argv[0]);
|
||||
@@ -241,6 +243,8 @@ static void detachFunc(
|
||||
Db *pDb = 0;
|
||||
char zErr[128];
|
||||
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
|
||||
if( zName==0 ) zName = "";
|
||||
for(i=0; i<db->nDb; i++){
|
||||
pDb = &db->aDb[i];
|
||||
|
||||
+99
-47
@@ -34,21 +34,42 @@
|
||||
** start of a transaction, and is thus usually less than a few thousand,
|
||||
** but can be as large as 2 billion for a really big database.
|
||||
**
|
||||
** @(#) $Id: bitvec.c,v 1.8 2008/11/11 15:48:48 drh Exp $
|
||||
** @(#) $Id: bitvec.c,v 1.9 2008/11/19 18:30:35 shane Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/* Size of the Bitvec structure in bytes. */
|
||||
#define BITVEC_SZ 512
|
||||
|
||||
/* Round the union size down to the nearest pointer boundary, since that's how
|
||||
** it will be aligned within the Bitvec struct. */
|
||||
#define BITVEC_USIZE (((BITVEC_SZ-12)/sizeof(Bitvec*))*sizeof(Bitvec*))
|
||||
#define BITVEC_NCHAR BITVEC_USIZE
|
||||
#define BITVEC_NBIT (BITVEC_NCHAR*8)
|
||||
#define BITVEC_NINT (BITVEC_USIZE/4)
|
||||
#define BITVEC_USIZE (((BITVEC_SZ-(3*sizeof(u32)))/sizeof(Bitvec*))*sizeof(Bitvec*))
|
||||
|
||||
/* Type of the array "element" for the bitmap representation.
|
||||
** Should be a power of 2, and ideally, evenly divide into BITVEC_USIZE.
|
||||
** Setting this to the "natural word" size of your CPU may improve
|
||||
** performance. */
|
||||
#define BITVEC_TELEM u8
|
||||
/* Size, in bits, of the bitmap element. */
|
||||
#define BITVEC_SZELEM 8
|
||||
/* Number of elements in a bitmap array. */
|
||||
#define BITVEC_NELEM (BITVEC_USIZE/sizeof(BITVEC_TELEM))
|
||||
/* Number of bits in the bitmap array. */
|
||||
#define BITVEC_NBIT (BITVEC_NELEM*BITVEC_SZELEM)
|
||||
|
||||
/* Number of u32 values in hash table. */
|
||||
#define BITVEC_NINT (BITVEC_USIZE/sizeof(u32))
|
||||
/* Maximum number of entries in hash table before
|
||||
** sub-dividing and re-hashing. */
|
||||
#define BITVEC_MXHASH (BITVEC_NINT/2)
|
||||
/* Hashing function for the aHash representation.
|
||||
** Empirical testing showed that the *37 multiplier
|
||||
** (an arbitrary prime)in the hash function provided
|
||||
** no fewer collisions than the no-op *1. */
|
||||
#define BITVEC_HASH(X) (((X)*1)%BITVEC_NINT)
|
||||
|
||||
#define BITVEC_NPTR (BITVEC_USIZE/sizeof(Bitvec *))
|
||||
|
||||
#define BITVEC_HASH(X) (((X)*37)%BITVEC_NINT)
|
||||
|
||||
/*
|
||||
** A bitmap is an instance of the following structure.
|
||||
@@ -72,11 +93,15 @@
|
||||
** to hold deal with values between 1 and iDivisor.
|
||||
*/
|
||||
struct Bitvec {
|
||||
u32 iSize; /* Maximum bit index */
|
||||
u32 nSet; /* Number of bits that are set */
|
||||
u32 iDivisor; /* Number of bits handled by each apSub[] entry */
|
||||
u32 iSize; /* Maximum bit index. Max iSize is 4,294,967,296. */
|
||||
u32 nSet; /* Number of bits that are set - only valid for aHash element */
|
||||
/* Max nSet is BITVEC_NINT. For BITVEC_SZ of 512, this would be 125. */
|
||||
u32 iDivisor; /* Number of bits handled by each apSub[] entry. */
|
||||
/* Should >=0 for apSub element. */
|
||||
/* Max iDivisor is max(u32) / BITVEC_NPTR + 1. */
|
||||
/* For a BITVEC_SZ of 512, this would be 34,359,739. */
|
||||
union {
|
||||
u8 aBitmap[BITVEC_NCHAR]; /* Bitmap representation */
|
||||
BITVEC_TELEM aBitmap[BITVEC_NELEM]; /* Bitmap representation */
|
||||
u32 aHash[BITVEC_NINT]; /* Hash table representation */
|
||||
Bitvec *apSub[BITVEC_NPTR]; /* Recursive representation */
|
||||
} u;
|
||||
@@ -105,16 +130,19 @@ Bitvec *sqlite3BitvecCreate(u32 iSize){
|
||||
int sqlite3BitvecTest(Bitvec *p, u32 i){
|
||||
if( p==0 ) return 0;
|
||||
if( i>p->iSize || i==0 ) return 0;
|
||||
if( p->iSize<=BITVEC_NBIT ){
|
||||
i--;
|
||||
return (p->u.aBitmap[i/8] & (1<<(i&7)))!=0;
|
||||
i--;
|
||||
while( p->iDivisor ){
|
||||
u32 bin = i/p->iDivisor;
|
||||
i = i%p->iDivisor;
|
||||
p = p->u.apSub[bin];
|
||||
if (!p) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if( p->iDivisor>0 ){
|
||||
u32 bin = (i-1)/p->iDivisor;
|
||||
i = (i-1)%p->iDivisor + 1;
|
||||
return sqlite3BitvecTest(p->u.apSub[bin], i);
|
||||
}else{
|
||||
u32 h = BITVEC_HASH(i);
|
||||
if( p->iSize<=BITVEC_NBIT ){
|
||||
return (p->u.aBitmap[i/BITVEC_SZELEM] & (1<<(i&(BITVEC_SZELEM-1))))!=0;
|
||||
} else{
|
||||
u32 h = BITVEC_HASH(i++);
|
||||
while( p->u.aHash[h] ){
|
||||
if( p->u.aHash[h]==i ) return 1;
|
||||
h++;
|
||||
@@ -141,35 +169,50 @@ int sqlite3BitvecSet(Bitvec *p, u32 i){
|
||||
assert( p!=0 );
|
||||
assert( i>0 );
|
||||
assert( i<=p->iSize );
|
||||
if( p->iSize<=BITVEC_NBIT ){
|
||||
i--;
|
||||
p->u.aBitmap[i/8] |= 1 << (i&7);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
if( p->iDivisor ){
|
||||
u32 bin = (i-1)/p->iDivisor;
|
||||
i = (i-1)%p->iDivisor + 1;
|
||||
i--;
|
||||
while((p->iSize > BITVEC_NBIT) && p->iDivisor) {
|
||||
u32 bin = i/p->iDivisor;
|
||||
i = i%p->iDivisor;
|
||||
if( p->u.apSub[bin]==0 ){
|
||||
sqlite3BeginBenignMalloc();
|
||||
p->u.apSub[bin] = sqlite3BitvecCreate( p->iDivisor );
|
||||
sqlite3EndBenignMalloc();
|
||||
if( p->u.apSub[bin]==0 ) return SQLITE_NOMEM;
|
||||
}
|
||||
return sqlite3BitvecSet(p->u.apSub[bin], i);
|
||||
p = p->u.apSub[bin];
|
||||
}
|
||||
h = BITVEC_HASH(i);
|
||||
while( p->u.aHash[h] ){
|
||||
if( p->iSize<=BITVEC_NBIT ){
|
||||
p->u.aBitmap[i/BITVEC_SZELEM] |= 1 << (i&(BITVEC_SZELEM-1));
|
||||
return SQLITE_OK;
|
||||
}
|
||||
h = BITVEC_HASH(i++);
|
||||
/* if there wasn't a hash collision, and this doesn't */
|
||||
/* completely fill the hash, then just add it without */
|
||||
/* worring about sub-dividing and re-hashing. */
|
||||
if( !p->u.aHash[h] ){
|
||||
if (p->nSet<(BITVEC_NINT-1)) {
|
||||
goto bitvec_set_end;
|
||||
} else {
|
||||
goto bitvec_set_rehash;
|
||||
}
|
||||
}
|
||||
/* there was a collision, check to see if it's already */
|
||||
/* in hash, if not, try to find a spot for it */
|
||||
do {
|
||||
if( p->u.aHash[h]==i ) return SQLITE_OK;
|
||||
h++;
|
||||
if( h==BITVEC_NINT ) h = 0;
|
||||
}
|
||||
p->nSet++;
|
||||
if( h>=BITVEC_NINT ) h = 0;
|
||||
} while( p->u.aHash[h] );
|
||||
/* we didn't find it in the hash. h points to the first */
|
||||
/* available free spot. check to see if this is going to */
|
||||
/* make our hash too "full". */
|
||||
bitvec_set_rehash:
|
||||
if( p->nSet>=BITVEC_MXHASH ){
|
||||
unsigned int j;
|
||||
int rc;
|
||||
u32 aiValues[BITVEC_NINT];
|
||||
memcpy(aiValues, p->u.aHash, sizeof(aiValues));
|
||||
memset(p->u.apSub, 0, sizeof(p->u.apSub[0])*BITVEC_NPTR);
|
||||
memset(p->u.apSub, 0, sizeof(aiValues));
|
||||
p->iDivisor = (p->iSize + BITVEC_NPTR - 1)/BITVEC_NPTR;
|
||||
rc = sqlite3BitvecSet(p, i);
|
||||
for(j=0; j<BITVEC_NINT; j++){
|
||||
@@ -177,35 +220,44 @@ int sqlite3BitvecSet(Bitvec *p, u32 i){
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
bitvec_set_end:
|
||||
p->nSet++;
|
||||
p->u.aHash[h] = i;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Clear the i-th bit. Return 0 on success and an error code if
|
||||
** anything goes wrong.
|
||||
** Clear the i-th bit.
|
||||
*/
|
||||
void sqlite3BitvecClear(Bitvec *p, u32 i){
|
||||
assert( p!=0 );
|
||||
assert( i>0 );
|
||||
if( p->iSize<=BITVEC_NBIT ){
|
||||
i--;
|
||||
p->u.aBitmap[i/8] &= ~(1 << (i&7));
|
||||
}else if( p->iDivisor ){
|
||||
u32 bin = (i-1)/p->iDivisor;
|
||||
i = (i-1)%p->iDivisor + 1;
|
||||
if( p->u.apSub[bin] ){
|
||||
sqlite3BitvecClear(p->u.apSub[bin], i);
|
||||
i--;
|
||||
while( p->iDivisor ){
|
||||
u32 bin = i/p->iDivisor;
|
||||
i = i%p->iDivisor;
|
||||
p = p->u.apSub[bin];
|
||||
if (!p) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if( p->iSize<=BITVEC_NBIT ){
|
||||
p->u.aBitmap[i/BITVEC_SZELEM] &= ~(1 << (i&(BITVEC_SZELEM-1)));
|
||||
}else{
|
||||
unsigned int j;
|
||||
u32 aiValues[BITVEC_NINT];
|
||||
memcpy(aiValues, p->u.aHash, sizeof(aiValues));
|
||||
memset(p->u.aHash, 0, sizeof(p->u.aHash[0])*BITVEC_NINT);
|
||||
memset(p->u.aHash, 0, sizeof(aiValues));
|
||||
p->nSet = 0;
|
||||
for(j=0; j<BITVEC_NINT; j++){
|
||||
if( aiValues[j] && aiValues[j]!=i ){
|
||||
sqlite3BitvecSet(p, aiValues[j]);
|
||||
if( aiValues[j] && aiValues[j]!=(i+1) ){
|
||||
u32 h = BITVEC_HASH(aiValues[j]-1);
|
||||
p->nSet++;
|
||||
while( p->u.aHash[h] ){
|
||||
h++;
|
||||
if( h>=BITVEC_NINT ) h = 0;
|
||||
}
|
||||
p->u.aHash[h] = aiValues[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -10,7 +10,7 @@
|
||||
**
|
||||
*************************************************************************
|
||||
**
|
||||
** $Id: btmutex.c,v 1.11 2008/10/07 15:25:48 drh Exp $
|
||||
** $Id: btmutex.c,v 1.12 2008/11/17 19:18:55 danielk1977 Exp $
|
||||
**
|
||||
** This file contains code used to implement mutexes on Btree objects.
|
||||
** This code really belongs in btree.c. But btree.c is getting too
|
||||
@@ -248,7 +248,7 @@ void sqlite3BtreeMutexArrayInsert(BtreeMutexArray *pArray, Btree *pBtree){
|
||||
}
|
||||
#endif
|
||||
assert( pArray->nMutex>=0 );
|
||||
assert( pArray->nMutex<sizeof(pArray->aBtree)/sizeof(pArray->aBtree[0])-1 );
|
||||
assert( pArray->nMutex<ArraySize(pArray->aBtree)-1 );
|
||||
pBt = pBtree->pBt;
|
||||
for(i=0; i<pArray->nMutex; i++){
|
||||
assert( pArray->aBtree[i]!=pBtree );
|
||||
|
||||
+93
-66
@@ -9,7 +9,7 @@
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** $Id: btree.c,v 1.533 2008/11/12 08:49:52 danielk1977 Exp $
|
||||
** $Id: btree.c,v 1.539.2.1 2008/11/22 14:07:49 drh Exp $
|
||||
**
|
||||
** This file implements a external (disk-based) database using BTrees.
|
||||
** See the header comment on "btreeInt.h" for additional information.
|
||||
@@ -435,7 +435,8 @@ int sqlite3BtreeCursorHasMoved(BtCursor *pCur, int *pHasMoved){
|
||||
** input page number.
|
||||
*/
|
||||
static Pgno ptrmapPageno(BtShared *pBt, Pgno pgno){
|
||||
int nPagesPerMapPage, iPtrMap, ret;
|
||||
int nPagesPerMapPage;
|
||||
Pgno iPtrMap, ret;
|
||||
assert( sqlite3_mutex_held(pBt->mutex) );
|
||||
nPagesPerMapPage = (pBt->usableSize/5)+1;
|
||||
iPtrMap = (pgno-2)/nPagesPerMapPage;
|
||||
@@ -734,14 +735,15 @@ static int defragmentPage(MemPage *pPage){
|
||||
u8 *pAddr; /* The i-th cell pointer */
|
||||
pAddr = &data[cellOffset + i*2];
|
||||
pc = get2byte(pAddr);
|
||||
if (pc >= pPage->pBt->usableSize) {
|
||||
if( pc>=usableSize ){
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
size = cellSizePtr(pPage, &temp[pc]);
|
||||
cbrk -= size;
|
||||
if ((cbrk < cellOffset+2*nCell) || (cbrk+size>pPage->pBt->usableSize)) {
|
||||
if( cbrk<cellOffset+2*nCell || pc+size>usableSize ){
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
assert( cbrk+size<=usableSize && cbrk>=0 );
|
||||
memcpy(&data[cbrk], &temp[pc], size);
|
||||
put2byte(pAddr, cbrk);
|
||||
}
|
||||
@@ -834,7 +836,7 @@ static int allocateSpace(MemPage *pPage, int nByte){
|
||||
** Most of the effort here is involved in coalesing adjacent
|
||||
** free blocks into a single big free block.
|
||||
*/
|
||||
static void freeSpace(MemPage *pPage, int start, int size){
|
||||
static int freeSpace(MemPage *pPage, int start, int size){
|
||||
int addr, pbegin, hdr;
|
||||
unsigned char *data = pPage->aData;
|
||||
|
||||
@@ -856,10 +858,14 @@ static void freeSpace(MemPage *pPage, int start, int size){
|
||||
addr = hdr + 1;
|
||||
while( (pbegin = get2byte(&data[addr]))<start && pbegin>0 ){
|
||||
assert( pbegin<=pPage->pBt->usableSize-4 );
|
||||
assert( pbegin>addr );
|
||||
if( pbegin<=addr ) {
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
addr = pbegin;
|
||||
}
|
||||
assert( pbegin<=pPage->pBt->usableSize-4 );
|
||||
if ( pbegin>pPage->pBt->usableSize-4 ) {
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
assert( pbegin>addr || pbegin==0 );
|
||||
put2byte(&data[addr], start);
|
||||
put2byte(&data[start], pbegin);
|
||||
@@ -876,7 +882,9 @@ static void freeSpace(MemPage *pPage, int start, int size){
|
||||
psize = get2byte(&data[pbegin+2]);
|
||||
if( pbegin + psize + 3 >= pnext && pnext>0 ){
|
||||
int frag = pnext - (pbegin+psize);
|
||||
assert( frag<=data[pPage->hdrOffset+7] );
|
||||
if( (frag<0) || (frag>data[pPage->hdrOffset+7]) ){
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
data[pPage->hdrOffset+7] -= frag;
|
||||
put2byte(&data[pbegin], get2byte(&data[pnext]));
|
||||
put2byte(&data[pbegin+2], pnext+get2byte(&data[pnext+2])-pbegin);
|
||||
@@ -893,6 +901,7 @@ static void freeSpace(MemPage *pPage, int start, int size){
|
||||
top = get2byte(&data[hdr+5]);
|
||||
put2byte(&data[hdr+5], top + get2byte(&data[pbegin+2]));
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1100,14 +1109,16 @@ int sqlite3BtreeGetPage(
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the size of the database file in pages. Or return -1 if
|
||||
** there is any kind of error.
|
||||
** Return the size of the database file in pages. If there is any kind of
|
||||
** error, return ((unsigned int)-1).
|
||||
*/
|
||||
static int pagerPagecount(Pager *pPager){
|
||||
static Pgno pagerPagecount(BtShared *pBt){
|
||||
int nPage = -1;
|
||||
int rc;
|
||||
int nPage;
|
||||
rc = sqlite3PagerPagecount(pPager, &nPage);
|
||||
return (rc==SQLITE_OK?nPage:-1);
|
||||
assert( pBt->pPage1 );
|
||||
rc = sqlite3PagerPagecount(pBt->pPager, &nPage);
|
||||
assert( rc==SQLITE_OK || nPage==-1 );
|
||||
return (Pgno)nPage;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1141,7 +1152,7 @@ static int getAndInitPage(
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
/* Page not in cache. Acquire it. */
|
||||
if( pgno>pagerPagecount(pBt->pPager) ){
|
||||
if( pgno>pagerPagecount(pBt) ){
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
rc = sqlite3BtreeGetPage(pBt, pgno, ppPage, 0);
|
||||
@@ -1196,7 +1207,7 @@ static void pageReinit(DbPage *pData){
|
||||
/*
|
||||
** Invoke the busy handler for a btree.
|
||||
*/
|
||||
static int sqlite3BtreeInvokeBusyHandler(void *pArg, int n){
|
||||
static int btreeInvokeBusyHandler(void *pArg){
|
||||
BtShared *pBt = (BtShared*)pArg;
|
||||
assert( pBt->db );
|
||||
assert( sqlite3_mutex_held(pBt->db->mutex) );
|
||||
@@ -1313,8 +1324,6 @@ int sqlite3BtreeOpen(
|
||||
rc = SQLITE_NOMEM;
|
||||
goto btree_open_out;
|
||||
}
|
||||
pBt->busyHdr.xFunc = sqlite3BtreeInvokeBusyHandler;
|
||||
pBt->busyHdr.pArg = pBt;
|
||||
rc = sqlite3PagerOpen(pVfs, &pBt->pPager, zFilename,
|
||||
EXTRA_SIZE, flags, vfsFlags);
|
||||
if( rc==SQLITE_OK ){
|
||||
@@ -1323,7 +1332,7 @@ int sqlite3BtreeOpen(
|
||||
if( rc!=SQLITE_OK ){
|
||||
goto btree_open_out;
|
||||
}
|
||||
sqlite3PagerSetBusyhandler(pBt->pPager, &pBt->busyHdr);
|
||||
sqlite3PagerSetBusyhandler(pBt->pPager, btreeInvokeBusyHandler, pBt);
|
||||
p->pBt = pBt;
|
||||
|
||||
sqlite3PagerSetReiniter(pBt->pPager, pageReinit);
|
||||
@@ -2021,7 +2030,7 @@ int sqlite3BtreeBeginTrans(Btree *p, int wrflag){
|
||||
unlockBtreeIfUnused(pBt);
|
||||
}
|
||||
}while( rc==SQLITE_BUSY && pBt->inTransaction==TRANS_NONE &&
|
||||
sqlite3BtreeInvokeBusyHandler(pBt, 0) );
|
||||
btreeInvokeBusyHandler(pBt) );
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
if( p->inTrans==TRANS_NONE ){
|
||||
@@ -2259,7 +2268,7 @@ static int incrVacuumStep(BtShared *pBt, Pgno nFin){
|
||||
assert( sqlite3_mutex_held(pBt->mutex) );
|
||||
iLastPg = pBt->nTrunc;
|
||||
if( iLastPg==0 ){
|
||||
iLastPg = pagerPagecount(pBt->pPager);
|
||||
iLastPg = pagerPagecount(pBt);
|
||||
}
|
||||
|
||||
if( !PTRMAP_ISPAGE(pBt, iLastPg) && iLastPg!=PENDING_BYTE_PAGE(pBt) ){
|
||||
@@ -2390,7 +2399,7 @@ static int autoVacuumCommit(BtShared *pBt, Pgno *pnTrunc){
|
||||
Pgno nFree;
|
||||
Pgno nPtrmap;
|
||||
const int pgsz = pBt->pageSize;
|
||||
int nOrig = pagerPagecount(pBt->pPager);
|
||||
Pgno nOrig = pagerPagecount(pBt);
|
||||
|
||||
if( PTRMAP_ISPAGE(pBt, nOrig) ){
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
@@ -2602,9 +2611,14 @@ void sqlite3BtreeTripAllCursors(Btree *pBtree, int errCode){
|
||||
BtCursor *p;
|
||||
sqlite3BtreeEnter(pBtree);
|
||||
for(p=pBtree->pBt->pCursor; p; p=p->pNext){
|
||||
int i;
|
||||
sqlite3BtreeClearCursor(p);
|
||||
p->eState = CURSOR_FAULT;
|
||||
p->skip = errCode;
|
||||
for(i=0; i<=p->iPage; i++){
|
||||
releasePage(p->apPage[i]);
|
||||
p->apPage[i] = 0;
|
||||
}
|
||||
}
|
||||
sqlite3BtreeLeave(pBtree);
|
||||
}
|
||||
@@ -2791,6 +2805,7 @@ static int btreeCursor(
|
||||
BtCursor *pCur /* Space for new cursor */
|
||||
){
|
||||
int rc;
|
||||
Pgno nPage;
|
||||
BtShared *pBt = p->pBt;
|
||||
|
||||
assert( sqlite3BtreeHoldsMutex(p) );
|
||||
@@ -2813,7 +2828,11 @@ static int btreeCursor(
|
||||
}
|
||||
}
|
||||
pCur->pgnoRoot = (Pgno)iTable;
|
||||
if( iTable==1 && pagerPagecount(pBt->pPager)==0 ){
|
||||
rc = sqlite3PagerPagecount(pBt->pPager, (int *)&nPage);
|
||||
if( rc!=SQLITE_OK ){
|
||||
return rc;
|
||||
}
|
||||
if( iTable==1 && nPage==0 ){
|
||||
rc = SQLITE_EMPTY;
|
||||
goto create_cursor_exception;
|
||||
}
|
||||
@@ -3074,7 +3093,7 @@ static int getOverflowPage(
|
||||
iGuess++;
|
||||
}
|
||||
|
||||
if( iGuess<=pagerPagecount(pBt->pPager) ){
|
||||
if( iGuess<=pagerPagecount(pBt) ){
|
||||
rc = ptrmapGet(pBt, iGuess, &eType, &pgno);
|
||||
if( rc!=SQLITE_OK ){
|
||||
return rc;
|
||||
@@ -3170,8 +3189,8 @@ static int copyPayload(
|
||||
*/
|
||||
static int accessPayload(
|
||||
BtCursor *pCur, /* Cursor pointing to entry to read from */
|
||||
int offset, /* Begin reading this far into payload */
|
||||
int amt, /* Read this many bytes */
|
||||
u32 offset, /* Begin reading this far into payload */
|
||||
u32 amt, /* Read this many bytes */
|
||||
unsigned char *pBuf, /* Write the bytes into this buffer */
|
||||
int skipKey, /* offset begins at data if this is true */
|
||||
int eOp /* zero to read. non-zero to write. */
|
||||
@@ -3181,12 +3200,11 @@ static int accessPayload(
|
||||
u32 nKey;
|
||||
int iIdx = 0;
|
||||
MemPage *pPage = pCur->apPage[pCur->iPage]; /* Btree page of current entry */
|
||||
BtShared *pBt; /* Btree this cursor belongs to */
|
||||
BtShared *pBt = pCur->pBt; /* Btree this cursor belongs to */
|
||||
|
||||
assert( pPage );
|
||||
assert( pCur->eState==CURSOR_VALID );
|
||||
assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
|
||||
assert( offset>=0 );
|
||||
assert( cursorHoldsMutex(pCur) );
|
||||
|
||||
getCellInfo(pCur);
|
||||
@@ -3196,7 +3214,9 @@ static int accessPayload(
|
||||
if( skipKey ){
|
||||
offset += nKey;
|
||||
}
|
||||
if( offset+amt > nKey+pCur->info.nData ){
|
||||
if( offset+amt > nKey+pCur->info.nData
|
||||
|| &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize]
|
||||
){
|
||||
/* Trying to read or write past the end of the data is an error */
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
@@ -3215,9 +3235,8 @@ static int accessPayload(
|
||||
offset -= pCur->info.nLocal;
|
||||
}
|
||||
|
||||
pBt = pCur->pBt;
|
||||
if( rc==SQLITE_OK && amt>0 ){
|
||||
const int ovflSize = pBt->usableSize - 4; /* Bytes content per ovfl page */
|
||||
const u32 ovflSize = pBt->usableSize - 4; /* Bytes content per ovfl page */
|
||||
Pgno nextPage;
|
||||
|
||||
nextPage = get4byte(&aPayload[pCur->info.nLocal]);
|
||||
@@ -3384,7 +3403,7 @@ static const unsigned char *fetchPayload(
|
||||
unsigned char *aPayload;
|
||||
MemPage *pPage;
|
||||
u32 nKey;
|
||||
int nLocal;
|
||||
u32 nLocal;
|
||||
|
||||
assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
|
||||
assert( pCur->eState==CURSOR_VALID );
|
||||
@@ -4074,7 +4093,7 @@ static int allocateBtreePage(
|
||||
** the entire-list will be searched for that page.
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_AUTOVACUUM
|
||||
if( exact && nearby<=pagerPagecount(pBt->pPager) ){
|
||||
if( exact && nearby<=pagerPagecount(pBt) ){
|
||||
u8 eType;
|
||||
assert( nearby>0 );
|
||||
assert( pBt->autoVacuum );
|
||||
@@ -4209,9 +4228,9 @@ static int allocateBtreePage(
|
||||
|
||||
iPage = get4byte(&aData[8+closest*4]);
|
||||
if( !searchList || iPage==nearby ){
|
||||
int nPage;
|
||||
Pgno nPage;
|
||||
*pPgno = iPage;
|
||||
nPage = pagerPagecount(pBt->pPager);
|
||||
nPage = pagerPagecount(pBt);
|
||||
if( *pPgno>nPage ){
|
||||
/* Free page off the end of the file */
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
@@ -4241,7 +4260,7 @@ static int allocateBtreePage(
|
||||
}else{
|
||||
/* There are no pages on the freelist, so create a new page at the
|
||||
** end of the file */
|
||||
int nPage = pagerPagecount(pBt->pPager);
|
||||
int nPage = pagerPagecount(pBt);
|
||||
*pPgno = nPage + 1;
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTOVACUUM
|
||||
@@ -4285,9 +4304,12 @@ static int allocateBtreePage(
|
||||
end_allocate_page:
|
||||
releasePage(pTrunk);
|
||||
releasePage(pPrevTrunk);
|
||||
if( rc==SQLITE_OK && sqlite3PagerPageRefcount((*ppPage)->pDbPage)>1 ){
|
||||
releasePage(*ppPage);
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
if( rc==SQLITE_OK ){
|
||||
if( sqlite3PagerPageRefcount((*ppPage)->pDbPage)>1 ){
|
||||
releasePage(*ppPage);
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
(*ppPage)->isInit = 0;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@@ -4408,7 +4430,7 @@ static int clearCell(MemPage *pPage, unsigned char *pCell){
|
||||
assert( ovflPgno==0 || nOvfl>0 );
|
||||
while( nOvfl-- ){
|
||||
MemPage *pOvfl;
|
||||
if( ovflPgno==0 || ovflPgno>pagerPagecount(pBt->pPager) ){
|
||||
if( ovflPgno==0 || ovflPgno>pagerPagecount(pBt) ){
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
|
||||
@@ -4470,7 +4492,7 @@ static int fillInCell(
|
||||
sqlite3BtreeParseCellPtr(pPage, pCell, &info);
|
||||
assert( info.nHeader==nHeader );
|
||||
assert( info.nKey==nKey );
|
||||
assert( info.nData==nData+nZero );
|
||||
assert( info.nData==(u32)(nData+nZero) );
|
||||
|
||||
/* Fill in the payload */
|
||||
nPayload = nData + nZero;
|
||||
@@ -4572,6 +4594,7 @@ static int dropCell(MemPage *pPage, int idx, int sz){
|
||||
int pc; /* Offset to cell content of cell being deleted */
|
||||
u8 *data; /* pPage->aData */
|
||||
u8 *ptr; /* Used to move bytes around within data[] */
|
||||
int rc; /* The return code */
|
||||
|
||||
assert( idx>=0 && idx<pPage->nCell );
|
||||
assert( sz==cellSize(pPage, idx) );
|
||||
@@ -4580,10 +4603,13 @@ static int dropCell(MemPage *pPage, int idx, int sz){
|
||||
data = pPage->aData;
|
||||
ptr = &data[pPage->cellOffset + 2*idx];
|
||||
pc = get2byte(ptr);
|
||||
if ( pc<=10 || pc+sz>pPage->pBt->usableSize ) {
|
||||
if ( (pc<pPage->hdrOffset+6+(pPage->leaf?0:4)) || (pc+sz>pPage->pBt->usableSize) ) {
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
freeSpace(pPage, pc, sz);
|
||||
rc = freeSpace(pPage, pc, sz);
|
||||
if( rc!=SQLITE_OK ){
|
||||
return rc;
|
||||
}
|
||||
for(i=idx+1; i<pPage->nCell; i++, ptr+=2){
|
||||
ptr[0] = ptr[2];
|
||||
ptr[1] = ptr[3];
|
||||
@@ -4638,7 +4664,7 @@ static int insertCell(
|
||||
pCell = pTemp;
|
||||
}
|
||||
j = pPage->nOverflow++;
|
||||
assert( j<sizeof(pPage->aOvfl)/sizeof(pPage->aOvfl[0]) );
|
||||
assert( j<(int)(sizeof(pPage->aOvfl)/sizeof(pPage->aOvfl[0])) );
|
||||
pPage->aOvfl[j].pCell = pCell;
|
||||
pPage->aOvfl[j].idx = i;
|
||||
pPage->nFree = 0;
|
||||
@@ -5525,7 +5551,7 @@ static int balance_shallower(BtCursor *pCur){
|
||||
VVA_ONLY( pCur->pagesShuffled = 1 );
|
||||
pgnoChild = get4byte(&pPage->aData[pPage->hdrOffset+8]);
|
||||
assert( pgnoChild>0 );
|
||||
assert( pgnoChild<=pagerPagecount(pPage->pBt->pPager) );
|
||||
assert( pgnoChild<=pagerPagecount(pPage->pBt) );
|
||||
rc = sqlite3BtreeGetPage(pPage->pBt, pgnoChild, &pChild, 0);
|
||||
if( rc ) goto end_shallow_balance;
|
||||
if( pPage->pgno==1 ){
|
||||
@@ -5613,7 +5639,8 @@ static int balance_deeper(BtCursor *pCur){
|
||||
cdata = pChild->aData;
|
||||
memcpy(cdata, &data[hdr], pPage->cellOffset+2*pPage->nCell-hdr);
|
||||
memcpy(&cdata[cbrk], &data[cbrk], usableSize-cbrk);
|
||||
|
||||
|
||||
assert( pChild->isInit==0 );
|
||||
rc = sqlite3BtreeInitPage(pChild);
|
||||
if( rc==SQLITE_OK ){
|
||||
int nCopy = pPage->nOverflow*sizeof(pPage->aOvfl[0]);
|
||||
@@ -6043,8 +6070,10 @@ int sqlite3BtreeDelete(BtCursor *pCur){
|
||||
}else{
|
||||
TRACE(("DELETE: table=%d delete from leaf %d\n",
|
||||
pCur->pgnoRoot, pPage->pgno));
|
||||
dropCell(pPage, idx, cellSizePtr(pPage, pCell));
|
||||
rc = balance(pCur, 0);
|
||||
rc = dropCell(pPage, idx, cellSizePtr(pPage, pCell));
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = balance(pCur, 0);
|
||||
}
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
moveToRoot(pCur);
|
||||
@@ -6210,7 +6239,6 @@ int sqlite3BtreeCreateTable(Btree *p, int *piTable, int flags){
|
||||
static int clearDatabasePage(
|
||||
BtShared *pBt, /* The BTree that contains the table */
|
||||
Pgno pgno, /* Page number to clear */
|
||||
MemPage *pParent, /* Parent page. NULL for the root */
|
||||
int freePageFlag, /* Deallocate page if true */
|
||||
int *pnChange
|
||||
){
|
||||
@@ -6220,7 +6248,7 @@ static int clearDatabasePage(
|
||||
int i;
|
||||
|
||||
assert( sqlite3_mutex_held(pBt->mutex) );
|
||||
if( pgno>pagerPagecount(pBt->pPager) ){
|
||||
if( pgno>pagerPagecount(pBt) ){
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
|
||||
@@ -6229,14 +6257,14 @@ static int clearDatabasePage(
|
||||
for(i=0; i<pPage->nCell; i++){
|
||||
pCell = findCell(pPage, i);
|
||||
if( !pPage->leaf ){
|
||||
rc = clearDatabasePage(pBt, get4byte(pCell), pPage, 1, pnChange);
|
||||
rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
|
||||
if( rc ) goto cleardatabasepage_out;
|
||||
}
|
||||
rc = clearCell(pPage, pCell);
|
||||
if( rc ) goto cleardatabasepage_out;
|
||||
}
|
||||
if( !pPage->leaf ){
|
||||
rc = clearDatabasePage(pBt, get4byte(&pPage->aData[8]), pPage, 1, pnChange);
|
||||
rc = clearDatabasePage(pBt, get4byte(&pPage->aData[8]), 1, pnChange);
|
||||
if( rc ) goto cleardatabasepage_out;
|
||||
}else if( pnChange ){
|
||||
assert( pPage->intKey );
|
||||
@@ -6278,7 +6306,7 @@ int sqlite3BtreeClearTable(Btree *p, int iTable, int *pnChange){
|
||||
}else if( SQLITE_OK!=(rc = saveAllCursors(pBt, iTable, 0)) ){
|
||||
/* nothing to do */
|
||||
}else{
|
||||
rc = clearDatabasePage(pBt, (Pgno)iTable, 0, 0, pnChange);
|
||||
rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange);
|
||||
}
|
||||
sqlite3BtreeLeave(p);
|
||||
return rc;
|
||||
@@ -6304,7 +6332,7 @@ int sqlite3BtreeClearTable(Btree *p, int iTable, int *pnChange){
|
||||
** The last root page is recorded in meta[3] and the value of
|
||||
** meta[3] is updated by this procedure.
|
||||
*/
|
||||
static int btreeDropTable(Btree *p, int iTable, int *piMoved){
|
||||
static int btreeDropTable(Btree *p, Pgno iTable, int *piMoved){
|
||||
int rc;
|
||||
MemPage *pPage = 0;
|
||||
BtShared *pBt = p->pBt;
|
||||
@@ -6587,9 +6615,9 @@ static void checkAppendMsg(
|
||||
**
|
||||
** Also check that the page number is in bounds.
|
||||
*/
|
||||
static int checkRef(IntegrityCk *pCheck, int iPage, char *zContext){
|
||||
static int checkRef(IntegrityCk *pCheck, Pgno iPage, char *zContext){
|
||||
if( iPage==0 ) return 1;
|
||||
if( iPage>pCheck->nPage || iPage<0 ){
|
||||
if( iPage>pCheck->nPage ){
|
||||
checkAppendMsg(pCheck, zContext, "invalid page number %d", iPage);
|
||||
return 1;
|
||||
}
|
||||
@@ -6724,7 +6752,6 @@ static void checkList(
|
||||
static int checkTreePage(
|
||||
IntegrityCk *pCheck, /* Context for the sanity check */
|
||||
int iPage, /* Page number of the page to check */
|
||||
MemPage *pParent, /* Parent page */
|
||||
char *zParentContext /* Parent context */
|
||||
){
|
||||
MemPage *pPage;
|
||||
@@ -6762,7 +6789,7 @@ static int checkTreePage(
|
||||
depth = 0;
|
||||
for(i=0; i<pPage->nCell && pCheck->mxErr; i++){
|
||||
u8 *pCell;
|
||||
int sz;
|
||||
u32 sz;
|
||||
CellInfo info;
|
||||
|
||||
/* Check payload overflow pages
|
||||
@@ -6794,7 +6821,7 @@ static int checkTreePage(
|
||||
checkPtrmap(pCheck, pgno, PTRMAP_BTREE, iPage, zContext);
|
||||
}
|
||||
#endif
|
||||
d2 = checkTreePage(pCheck,pgno,pPage,zContext);
|
||||
d2 = checkTreePage(pCheck, pgno, zContext);
|
||||
if( i>0 && d2!=depth ){
|
||||
checkAppendMsg(pCheck, zContext, "Child page depth differs");
|
||||
}
|
||||
@@ -6810,7 +6837,7 @@ static int checkTreePage(
|
||||
checkPtrmap(pCheck, pgno, PTRMAP_BTREE, iPage, 0);
|
||||
}
|
||||
#endif
|
||||
checkTreePage(pCheck, pgno, pPage, zContext);
|
||||
checkTreePage(pCheck, pgno, zContext);
|
||||
}
|
||||
|
||||
/* Check for complete coverage of the page
|
||||
@@ -6898,7 +6925,7 @@ char *sqlite3BtreeIntegrityCheck(
|
||||
int mxErr, /* Stop reporting errors after this many */
|
||||
int *pnErr /* Write number of errors seen to this variable */
|
||||
){
|
||||
int i;
|
||||
Pgno i;
|
||||
int nRef;
|
||||
IntegrityCk sCheck;
|
||||
BtShared *pBt = p->pBt;
|
||||
@@ -6914,7 +6941,7 @@ char *sqlite3BtreeIntegrityCheck(
|
||||
}
|
||||
sCheck.pBt = pBt;
|
||||
sCheck.pPager = pBt->pPager;
|
||||
sCheck.nPage = pagerPagecount(sCheck.pPager);
|
||||
sCheck.nPage = pagerPagecount(sCheck.pBt);
|
||||
sCheck.mxErr = mxErr;
|
||||
sCheck.nErr = 0;
|
||||
sCheck.mallocFailed = 0;
|
||||
@@ -6950,14 +6977,14 @@ char *sqlite3BtreeIntegrityCheck(
|
||||
|
||||
/* Check all the tables.
|
||||
*/
|
||||
for(i=0; i<nRoot && sCheck.mxErr; i++){
|
||||
for(i=0; (int)i<nRoot && sCheck.mxErr; i++){
|
||||
if( aRoot[i]==0 ) continue;
|
||||
#ifndef SQLITE_OMIT_AUTOVACUUM
|
||||
if( pBt->autoVacuum && aRoot[i]>1 ){
|
||||
checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0, 0);
|
||||
}
|
||||
#endif
|
||||
checkTreePage(&sCheck, aRoot[i], 0, "List of tree roots: ");
|
||||
checkTreePage(&sCheck, aRoot[i], "List of tree roots: ");
|
||||
}
|
||||
|
||||
/* Make sure every page in the file is referenced
|
||||
@@ -7081,8 +7108,8 @@ static int btreeCopyFile(Btree *pTo, Btree *pFrom){
|
||||
return SQLITE_BUSY;
|
||||
}
|
||||
|
||||
nToPage = pagerPagecount(pBtTo->pPager);
|
||||
nFromPage = pagerPagecount(pBtFrom->pPager);
|
||||
nToPage = pagerPagecount(pBtTo);
|
||||
nFromPage = pagerPagecount(pBtFrom);
|
||||
iSkip = PENDING_BYTE_PAGE(pBtTo);
|
||||
|
||||
/* Variable nNewPage is the number of pages required to store the
|
||||
|
||||
+3
-4
@@ -9,7 +9,7 @@
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** $Id: btreeInt.h,v 1.34 2008/09/30 17:18:17 drh Exp $
|
||||
** $Id: btreeInt.h,v 1.36 2008/11/19 10:22:33 danielk1977 Exp $
|
||||
**
|
||||
** This file implements a external (disk-based) database using BTrees.
|
||||
** For a detailed discussion of BTrees, refer to
|
||||
@@ -384,7 +384,6 @@ struct BtShared {
|
||||
void *pSchema; /* Pointer to space allocated by sqlite3BtreeSchema() */
|
||||
void (*xFreeSchema)(void*); /* Destructor for BtShared.pSchema */
|
||||
sqlite3_mutex *mutex; /* Non-recursive mutex required to access this struct */
|
||||
BusyHandler busyHdr; /* The busy handler for this btree */
|
||||
#ifndef SQLITE_OMIT_SHARED_CACHE
|
||||
int nRef; /* Number of references to this structure */
|
||||
BtShared *pNext; /* Next on a list of sharable BtShared structs */
|
||||
@@ -502,7 +501,7 @@ struct BtCursor {
|
||||
#ifdef SQLITE_OMIT_DISKIO
|
||||
# define PENDING_BYTE_PAGE(pBt) 0x7fffffff
|
||||
#else
|
||||
# define PENDING_BYTE_PAGE(pBt) ((PENDING_BYTE/(pBt)->pageSize)+1)
|
||||
# define PENDING_BYTE_PAGE(pBt) ((Pgno)((PENDING_BYTE/(pBt)->pageSize)+1))
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -609,7 +608,7 @@ typedef struct IntegrityCk IntegrityCk;
|
||||
struct IntegrityCk {
|
||||
BtShared *pBt; /* The tree being checked out */
|
||||
Pager *pPager; /* The associated pager. Also accessible by pBt->pPager */
|
||||
int nPage; /* Number of pages in the database */
|
||||
Pgno nPage; /* Number of pages in the database */
|
||||
int *anRef; /* Number of times each page is referenced */
|
||||
int mxErr; /* Stop accumulating errors when this reaches zero */
|
||||
int nErr; /* Number of messages written to zErrMsg so far */
|
||||
|
||||
+8
-4
@@ -22,7 +22,7 @@
|
||||
** COMMIT
|
||||
** ROLLBACK
|
||||
**
|
||||
** $Id: build.c,v 1.501 2008/11/11 18:28:59 drh Exp $
|
||||
** $Id: build.c,v 1.503 2008/11/17 19:18:55 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@@ -626,7 +626,7 @@ void sqlite3OpenMasterTable(Parse *p, int iDb){
|
||||
*/
|
||||
int sqlite3FindDb(sqlite3 *db, Token *pName){
|
||||
int i = -1; /* Database number */
|
||||
int n; /* Number of characters in the name */
|
||||
size_t n; /* Number of characters in the name */
|
||||
Db *pDb; /* A database whose name space is being searched */
|
||||
char *zName; /* Name we are searching for */
|
||||
|
||||
@@ -670,7 +670,11 @@ int sqlite3TwoPartName(
|
||||
sqlite3 *db = pParse->db;
|
||||
|
||||
if( pName2 && pName2->n>0 ){
|
||||
assert( !db->init.busy );
|
||||
if( db->init.busy ) {
|
||||
sqlite3ErrorMsg(pParse, "corrupt database");
|
||||
pParse->nErr++;
|
||||
return -1;
|
||||
}
|
||||
*pUnqual = pName2;
|
||||
iDb = sqlite3FindDb(db, pName1);
|
||||
if( iDb<0 ){
|
||||
@@ -1392,7 +1396,7 @@ static char *createTableStmt(sqlite3 *db, Table *p, int isTemp){
|
||||
identPut(zStmt, &k, pCol->zName);
|
||||
if( (z = pCol->zType)!=0 ){
|
||||
zStmt[k++] = ' ';
|
||||
assert( strlen(z)+k+1<=n );
|
||||
assert( (int)(strlen(z)+k+1)<=n );
|
||||
sqlite3_snprintf(n-k, &zStmt[k], "%s", z);
|
||||
k += strlen(z);
|
||||
}
|
||||
|
||||
+12
-9
@@ -16,7 +16,7 @@
|
||||
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
|
||||
** All other code has file scope.
|
||||
**
|
||||
** $Id: date.c,v 1.92 2008/10/13 15:35:09 drh Exp $
|
||||
** $Id: date.c,v 1.94 2008/11/19 09:05:27 danielk1977 Exp $
|
||||
**
|
||||
** SQLite processes all times and dates as Julian Day numbers. The
|
||||
** dates and times are stored as the number of days since noon
|
||||
@@ -521,7 +521,7 @@ static int parseModifier(const char *zMod, DateTime *p){
|
||||
double r;
|
||||
char *z, zBuf[30];
|
||||
z = zBuf;
|
||||
for(n=0; n<sizeof(zBuf)-1 && zMod[n]; n++){
|
||||
for(n=0; n<ArraySize(zBuf)-1 && zMod[n]; n++){
|
||||
z[n] = tolower(zMod[n]);
|
||||
}
|
||||
z[n] = 0;
|
||||
@@ -889,7 +889,7 @@ static void strftimeFunc(
|
||||
}
|
||||
if( n<sizeof(zBuf) ){
|
||||
z = zBuf;
|
||||
}else if( n>db->aLimit[SQLITE_LIMIT_LENGTH] ){
|
||||
}else if( n>(u64)db->aLimit[SQLITE_LIMIT_LENGTH] ){
|
||||
sqlite3_result_error_toobig(context);
|
||||
return;
|
||||
}else{
|
||||
@@ -968,9 +968,10 @@ static void strftimeFunc(
|
||||
*/
|
||||
static void ctimeFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
int NotUsed,
|
||||
sqlite3_value **NotUsed2
|
||||
){
|
||||
UNUSED_PARAMETER2(NotUsed, NotUsed2);
|
||||
timeFunc(context, 0, 0);
|
||||
}
|
||||
|
||||
@@ -981,9 +982,10 @@ static void ctimeFunc(
|
||||
*/
|
||||
static void cdateFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
int NotUsed,
|
||||
sqlite3_value **NotUsed2
|
||||
){
|
||||
UNUSED_PARAMETER2(NotUsed, NotUsed2);
|
||||
dateFunc(context, 0, 0);
|
||||
}
|
||||
|
||||
@@ -994,9 +996,10 @@ static void cdateFunc(
|
||||
*/
|
||||
static void ctimestampFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
int NotUsed,
|
||||
sqlite3_value **NotUsed2
|
||||
){
|
||||
UNUSED_PARAMETER2(NotUsed, NotUsed2);
|
||||
datetimeFunc(context, 0, 0);
|
||||
}
|
||||
#endif /* !defined(SQLITE_OMIT_DATETIME_FUNCS) */
|
||||
|
||||
+2
-2
@@ -12,7 +12,7 @@
|
||||
** This file contains C code routines that are called by the parser
|
||||
** in order to generate code for DELETE FROM statements.
|
||||
**
|
||||
** $Id: delete.c,v 1.186 2008/10/31 10:53:23 danielk1977 Exp $
|
||||
** $Id: delete.c,v 1.187 2008/11/19 09:05:27 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -265,7 +265,7 @@ void sqlite3DeleteFrom(
|
||||
** deleted from is a view
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
triggers_exist = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0);
|
||||
triggers_exist = sqlite3TriggersExist(pTab, TK_DELETE, 0);
|
||||
isView = pTab->pSelect!=0;
|
||||
#else
|
||||
# define triggers_exist 0
|
||||
|
||||
+5
-3
@@ -12,7 +12,7 @@
|
||||
** This file contains routines used for analyzing expressions and
|
||||
** for generating VDBE code that evaluates expressions in SQLite.
|
||||
**
|
||||
** $Id: expr.c,v 1.402 2008/11/12 08:07:12 danielk1977 Exp $
|
||||
** $Id: expr.c,v 1.404 2008/11/19 16:52:44 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@@ -939,7 +939,8 @@ static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
|
||||
return WRC_Continue;
|
||||
}
|
||||
}
|
||||
static int selectNodeIsConstant(Walker *pWalker, Select *pSelect){
|
||||
static int selectNodeIsConstant(Walker *pWalker, Select *NotUsed){
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
pWalker->u.i = 0;
|
||||
return WRC_Abort;
|
||||
}
|
||||
@@ -1459,10 +1460,11 @@ static char *dup8bytes(Vdbe *v, const char *in){
|
||||
*/
|
||||
static void codeReal(Vdbe *v, const char *z, int n, int negateFlag, int iMem){
|
||||
assert( z || v==0 || sqlite3VdbeDb(v)->mallocFailed );
|
||||
assert( !z || !isdigit(z[n]) );
|
||||
UNUSED_PARAMETER(n);
|
||||
if( z ){
|
||||
double value;
|
||||
char *zV;
|
||||
assert( !isdigit(z[n]) );
|
||||
sqlite3AtoF(z, &value);
|
||||
if( sqlite3IsNaN(value) ){
|
||||
sqlite3VdbeAddOp2(v, OP_Null, 0, iMem);
|
||||
|
||||
+33
-14
@@ -16,7 +16,7 @@
|
||||
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
|
||||
** All other code has file scope.
|
||||
**
|
||||
** $Id: func.c,v 1.204 2008/10/28 17:52:39 danielk1977 Exp $
|
||||
** $Id: func.c,v 1.206 2008/11/19 16:52:44 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@@ -65,10 +65,11 @@ static void minmaxFunc(
|
||||
*/
|
||||
static void typeofFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
int NotUsed,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
const char *z = 0;
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
switch( sqlite3_value_type(argv[0]) ){
|
||||
case SQLITE_NULL: z = "null"; break;
|
||||
case SQLITE_INTEGER: z = "integer"; break;
|
||||
@@ -91,6 +92,7 @@ static void lengthFunc(
|
||||
int len;
|
||||
|
||||
assert( argc==1 );
|
||||
UNUSED_PARAMETER(argc);
|
||||
switch( sqlite3_value_type(argv[0]) ){
|
||||
case SQLITE_BLOB:
|
||||
case SQLITE_INTEGER:
|
||||
@@ -121,6 +123,7 @@ static void lengthFunc(
|
||||
*/
|
||||
static void absFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
assert( argc==1 );
|
||||
UNUSED_PARAMETER(argc);
|
||||
switch( sqlite3_value_type(argv[0]) ){
|
||||
case SQLITE_INTEGER: {
|
||||
i64 iVal = sqlite3_value_int64(argv[0]);
|
||||
@@ -324,10 +327,11 @@ static void ifnullFunc(
|
||||
*/
|
||||
static void randomFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
int NotUsed,
|
||||
sqlite3_value **NotUsed2
|
||||
){
|
||||
sqlite_int64 r;
|
||||
UNUSED_PARAMETER2(NotUsed, NotUsed2);
|
||||
sqlite3_randomness(sizeof(r), &r);
|
||||
if( (r<<1)==0 ) r = 0; /* Prevent 0x8000.... as the result so that we */
|
||||
/* can always do abs() of the result */
|
||||
@@ -346,6 +350,7 @@ static void randomBlob(
|
||||
int n;
|
||||
unsigned char *p;
|
||||
assert( argc==1 );
|
||||
UNUSED_PARAMETER(argc);
|
||||
n = sqlite3_value_int(argv[0]);
|
||||
if( n<1 ){
|
||||
n = 1;
|
||||
@@ -363,10 +368,11 @@ static void randomBlob(
|
||||
*/
|
||||
static void last_insert_rowid(
|
||||
sqlite3_context *context,
|
||||
int arg,
|
||||
sqlite3_value **argv
|
||||
int NotUsed,
|
||||
sqlite3_value **NotUsed2
|
||||
){
|
||||
sqlite3 *db = sqlite3_context_db_handle(context);
|
||||
UNUSED_PARAMETER2(NotUsed, NotUsed2);
|
||||
sqlite3_result_int64(context, sqlite3_last_insert_rowid(db));
|
||||
}
|
||||
|
||||
@@ -376,10 +382,11 @@ static void last_insert_rowid(
|
||||
*/
|
||||
static void changes(
|
||||
sqlite3_context *context,
|
||||
int arg,
|
||||
sqlite3_value **argv
|
||||
int NotUsed,
|
||||
sqlite3_value **NotUsed2
|
||||
){
|
||||
sqlite3 *db = sqlite3_context_db_handle(context);
|
||||
UNUSED_PARAMETER2(NotUsed, NotUsed2);
|
||||
sqlite3_result_int(context, sqlite3_changes(db));
|
||||
}
|
||||
|
||||
@@ -389,10 +396,11 @@ static void changes(
|
||||
*/
|
||||
static void total_changes(
|
||||
sqlite3_context *context,
|
||||
int arg,
|
||||
sqlite3_value **argv
|
||||
int NotUsed,
|
||||
sqlite3_value **NotUsed2
|
||||
){
|
||||
sqlite3 *db = sqlite3_context_db_handle(context);
|
||||
UNUSED_PARAMETER2(NotUsed, NotUsed2);
|
||||
sqlite3_result_int(context, sqlite3_total_changes(db));
|
||||
}
|
||||
|
||||
@@ -637,10 +645,11 @@ static void likeFunc(
|
||||
*/
|
||||
static void nullifFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
int NotUsed,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
CollSeq *pColl = sqlite3GetFuncCollSeq(context);
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
if( sqlite3MemCompare(argv[0], argv[1], pColl)!=0 ){
|
||||
sqlite3_result_value(context, argv[0]);
|
||||
}
|
||||
@@ -652,9 +661,10 @@ static void nullifFunc(
|
||||
*/
|
||||
static void versionFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
int NotUsed,
|
||||
sqlite3_value **NotUsed2
|
||||
){
|
||||
UNUSED_PARAMETER2(NotUsed, NotUsed2);
|
||||
sqlite3_result_text(context, sqlite3_version, -1, SQLITE_STATIC);
|
||||
}
|
||||
|
||||
@@ -747,6 +757,7 @@ static void hexFunc(
|
||||
const unsigned char *pBlob;
|
||||
char *zHex, *z;
|
||||
assert( argc==1 );
|
||||
UNUSED_PARAMETER(argc);
|
||||
pBlob = sqlite3_value_blob(argv[0]);
|
||||
n = sqlite3_value_bytes(argv[0]);
|
||||
assert( pBlob==sqlite3_value_blob(argv[0]) ); /* No encoding change */
|
||||
@@ -772,6 +783,7 @@ static void zeroblobFunc(
|
||||
){
|
||||
i64 n;
|
||||
assert( argc==1 );
|
||||
UNUSED_PARAMETER(argc);
|
||||
n = sqlite3_value_int64(argv[0]);
|
||||
if( n>SQLITE_MAX_LENGTH ){
|
||||
sqlite3_result_error_toobig(context);
|
||||
@@ -803,6 +815,7 @@ static void replaceFunc(
|
||||
int i, j; /* Loop counters */
|
||||
|
||||
assert( argc==3 );
|
||||
UNUSED_PARAMETER(argc);
|
||||
zStr = sqlite3_value_text(argv[0]);
|
||||
if( zStr==0 ) return;
|
||||
nStr = sqlite3_value_bytes(argv[0]);
|
||||
@@ -1040,6 +1053,7 @@ static void sumStep(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
SumCtx *p;
|
||||
int type;
|
||||
assert( argc==1 );
|
||||
UNUSED_PARAMETER(argc);
|
||||
p = sqlite3_aggregate_context(context, sizeof(*p));
|
||||
type = sqlite3_value_numeric_type(argv[0]);
|
||||
if( p && type!=SQLITE_NULL ){
|
||||
@@ -1115,9 +1129,14 @@ static void countFinalize(sqlite3_context *context){
|
||||
/*
|
||||
** Routines to implement min() and max() aggregate functions.
|
||||
*/
|
||||
static void minmaxStep(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
static void minmaxStep(
|
||||
sqlite3_context *context,
|
||||
int NotUsed,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
Mem *pArg = (Mem *)argv[0];
|
||||
Mem *pBest;
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
|
||||
if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
|
||||
pBest = (Mem *)sqlite3_aggregate_context(context, sizeof(*pBest));
|
||||
|
||||
+9
-11
@@ -12,7 +12,7 @@
|
||||
** This file contains C code routines that are called by the parser
|
||||
** to handle INSERT statements in SQLite.
|
||||
**
|
||||
** $Id: insert.c,v 1.251 2008/11/03 20:55:07 drh Exp $
|
||||
** $Id: insert.c,v 1.253 2008/11/19 09:05:27 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -430,7 +430,7 @@ void sqlite3Insert(
|
||||
** inserted into is a view
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
triggers_exist = sqlite3TriggersExist(pParse, pTab, TK_INSERT, 0);
|
||||
triggers_exist = sqlite3TriggersExist(pTab, TK_INSERT, 0);
|
||||
isView = pTab->pSelect!=0;
|
||||
#else
|
||||
# define triggers_exist 0
|
||||
@@ -936,7 +936,6 @@ void sqlite3Insert(
|
||||
regIns,
|
||||
aRegIdx,
|
||||
0,
|
||||
0,
|
||||
(triggers_exist & TRIGGER_AFTER)!=0 ? newIdx : -1,
|
||||
appendFlag
|
||||
);
|
||||
@@ -1272,26 +1271,26 @@ void sqlite3GenerateConstraintChecks(
|
||||
case OE_Fail: {
|
||||
int j, n1, n2;
|
||||
char zErrMsg[200];
|
||||
sqlite3_snprintf(sizeof(zErrMsg), zErrMsg,
|
||||
sqlite3_snprintf(ArraySize(zErrMsg), zErrMsg,
|
||||
pIdx->nColumn>1 ? "columns " : "column ");
|
||||
n1 = strlen(zErrMsg);
|
||||
for(j=0; j<pIdx->nColumn && n1<sizeof(zErrMsg)-30; j++){
|
||||
for(j=0; j<pIdx->nColumn && n1<ArraySize(zErrMsg)-30; j++){
|
||||
char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
|
||||
n2 = strlen(zCol);
|
||||
if( j>0 ){
|
||||
sqlite3_snprintf(sizeof(zErrMsg)-n1, &zErrMsg[n1], ", ");
|
||||
sqlite3_snprintf(ArraySize(zErrMsg)-n1, &zErrMsg[n1], ", ");
|
||||
n1 += 2;
|
||||
}
|
||||
if( n1+n2>sizeof(zErrMsg)-30 ){
|
||||
sqlite3_snprintf(sizeof(zErrMsg)-n1, &zErrMsg[n1], "...");
|
||||
if( n1+n2>ArraySize(zErrMsg)-30 ){
|
||||
sqlite3_snprintf(ArraySize(zErrMsg)-n1, &zErrMsg[n1], "...");
|
||||
n1 += 3;
|
||||
break;
|
||||
}else{
|
||||
sqlite3_snprintf(sizeof(zErrMsg)-n1, &zErrMsg[n1], "%s", zCol);
|
||||
sqlite3_snprintf(ArraySize(zErrMsg)-n1, &zErrMsg[n1], "%s", zCol);
|
||||
n1 += n2;
|
||||
}
|
||||
}
|
||||
sqlite3_snprintf(sizeof(zErrMsg)-n1, &zErrMsg[n1],
|
||||
sqlite3_snprintf(ArraySize(zErrMsg)-n1, &zErrMsg[n1],
|
||||
pIdx->nColumn>1 ? " are not unique" : " is not unique");
|
||||
sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_CONSTRAINT, onError, 0, zErrMsg,0);
|
||||
break;
|
||||
@@ -1328,7 +1327,6 @@ void sqlite3CompleteInsertion(
|
||||
int baseCur, /* Index of a read/write cursor pointing at pTab */
|
||||
int regRowid, /* Range of content */
|
||||
int *aRegIdx, /* Register used by each index. 0 for unused indices */
|
||||
int rowidChng, /* True if the record number will change */
|
||||
int isUpdate, /* True for UPDATE, False for INSERT */
|
||||
int newIdx, /* Index of NEW table for triggers. -1 if none */
|
||||
int appendBias /* True if this is likely to be an append */
|
||||
|
||||
+16
-1
@@ -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.511 2008/11/10 18:05:36 shane Exp $
|
||||
** $Id: main.c,v 1.514 2008/11/19 09:05:27 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@@ -309,6 +309,20 @@ int sqlite3_config(int op, ...){
|
||||
break;
|
||||
}
|
||||
|
||||
case SQLITE_CONFIG_PCACHE: {
|
||||
/* Specify an alternative malloc implementation */
|
||||
sqlite3GlobalConfig.pcache = *va_arg(ap, sqlite3_pcache_methods*);
|
||||
break;
|
||||
}
|
||||
|
||||
case SQLITE_CONFIG_GETPCACHE: {
|
||||
if( sqlite3GlobalConfig.pcache.xInit==0 ){
|
||||
sqlite3PCacheSetDefault();
|
||||
}
|
||||
*va_arg(ap, sqlite3_pcache_methods*) = sqlite3GlobalConfig.pcache;
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
|
||||
case SQLITE_CONFIG_HEAP: {
|
||||
/* Designate a buffer for heap memory space */
|
||||
@@ -501,6 +515,7 @@ static int nocaseCollatingFunc(
|
||||
){
|
||||
int r = sqlite3StrNICmp(
|
||||
(const char *)pKey1, (const char *)pKey2, (nKey1<nKey2)?nKey1:nKey2);
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
if( 0==r ){
|
||||
r = nKey1-nKey2;
|
||||
}
|
||||
|
||||
+6
-4
@@ -12,7 +12,7 @@
|
||||
**
|
||||
** Memory allocation functions used throughout sqlite.
|
||||
**
|
||||
** $Id: malloc.c,v 1.45 2008/10/12 00:27:53 shane Exp $
|
||||
** $Id: malloc.c,v 1.48 2008/11/19 09:05:27 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <stdarg.h>
|
||||
@@ -25,9 +25,10 @@
|
||||
*/
|
||||
static void softHeapLimitEnforcer(
|
||||
void *NotUsed,
|
||||
sqlite3_int64 inUse,
|
||||
sqlite3_int64 NotUsed2,
|
||||
int allocSize
|
||||
){
|
||||
UNUSED_PARAMETER2(NotUsed, NotUsed2);
|
||||
sqlite3_release_memory(allocSize);
|
||||
}
|
||||
|
||||
@@ -69,6 +70,7 @@ int sqlite3_release_memory(int n){
|
||||
nRet += sqlite3PcacheReleaseMemory(n-nRet);
|
||||
return nRet;
|
||||
#else
|
||||
UNUSED_PARAMETER(n);
|
||||
return SQLITE_OK;
|
||||
#endif
|
||||
}
|
||||
@@ -102,7 +104,7 @@ static SQLITE_WSD struct Mem0Global {
|
||||
*/
|
||||
u32 *aScratchFree;
|
||||
u32 *aPageFree;
|
||||
} mem0 = { 62560955 };
|
||||
} mem0 = { 62560955, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
#define mem0 GLOBAL(struct Mem0Global, mem0)
|
||||
|
||||
@@ -387,7 +389,7 @@ void sqlite3ScratchFree(void *p){
|
||||
i /= sqlite3GlobalConfig.szScratch;
|
||||
assert( i>=0 && i<sqlite3GlobalConfig.nScratch );
|
||||
sqlite3_mutex_enter(mem0.mutex);
|
||||
assert( mem0.nScratchFree<sqlite3GlobalConfig.nScratch );
|
||||
assert( mem0.nScratchFree<(u32)sqlite3GlobalConfig.nScratch );
|
||||
mem0.aScratchFree[mem0.nScratchFree++] = i;
|
||||
sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, -1);
|
||||
sqlite3_mutex_leave(mem0.mutex);
|
||||
|
||||
+3
-1
@@ -17,7 +17,7 @@
|
||||
** This file contains implementations of the low-level memory allocation
|
||||
** routines specified in the sqlite3_mem_methods object.
|
||||
**
|
||||
** $Id: mem1.c,v 1.27 2008/10/28 18:58:20 drh Exp $
|
||||
** $Id: mem1.c,v 1.28 2008/11/19 09:05:27 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -110,6 +110,7 @@ static int sqlite3MemRoundup(int n){
|
||||
** Initialize this module.
|
||||
*/
|
||||
static int sqlite3MemInit(void *NotUsed){
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -117,6 +118,7 @@ static int sqlite3MemInit(void *NotUsed){
|
||||
** Deinitialize this module.
|
||||
*/
|
||||
static void sqlite3MemShutdown(void *NotUsed){
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+10
-6
@@ -23,7 +23,7 @@
|
||||
** This version of the memory allocation subsystem is included
|
||||
** in the build only if SQLITE_ENABLE_MEMSYS3 is defined.
|
||||
**
|
||||
** $Id: mem3.c,v 1.23 2008/09/02 17:52:52 danielk1977 Exp $
|
||||
** $Id: mem3.c,v 1.25 2008/11/19 16:52:44 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -251,7 +251,7 @@ static void memsys3OutOfMemory(int nByte){
|
||||
** size parameters for check-out and return a pointer to the
|
||||
** user portion of the chunk.
|
||||
*/
|
||||
static void *memsys3Checkout(u32 i, int nBlock){
|
||||
static void *memsys3Checkout(u32 i, u32 nBlock){
|
||||
u32 x;
|
||||
assert( sqlite3_mutex_held(mem3.mutex) );
|
||||
assert( i>=1 );
|
||||
@@ -269,7 +269,7 @@ static void *memsys3Checkout(u32 i, int nBlock){
|
||||
** Return a pointer to the new allocation. Or, if the master chunk
|
||||
** is not large enough, return 0.
|
||||
*/
|
||||
static void *memsys3FromMaster(int nBlock){
|
||||
static void *memsys3FromMaster(u32 nBlock){
|
||||
assert( sqlite3_mutex_held(mem3.mutex) );
|
||||
assert( mem3.szMaster>=nBlock );
|
||||
if( nBlock>=mem3.szMaster-1 ){
|
||||
@@ -355,8 +355,8 @@ static void memsys3Merge(u32 *pRoot){
|
||||
*/
|
||||
static void *memsys3MallocUnsafe(int nByte){
|
||||
u32 i;
|
||||
int nBlock;
|
||||
int toFree;
|
||||
u32 nBlock;
|
||||
u32 toFree;
|
||||
|
||||
assert( sqlite3_mutex_held(mem3.mutex) );
|
||||
assert( sizeof(Mem3Block)==8 );
|
||||
@@ -552,6 +552,7 @@ void *memsys3Realloc(void *pPrior, int nBytes){
|
||||
** Initialize this module.
|
||||
*/
|
||||
static int memsys3Init(void *NotUsed){
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
if( !sqlite3GlobalConfig.pHeap ){
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
@@ -576,6 +577,7 @@ static int memsys3Init(void *NotUsed){
|
||||
** Deinitialize this module.
|
||||
*/
|
||||
static void memsys3Shutdown(void *NotUsed){
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -588,7 +590,7 @@ static void memsys3Shutdown(void *NotUsed){
|
||||
void sqlite3Memsys3Dump(const char *zFilename){
|
||||
#ifdef SQLITE_DEBUG
|
||||
FILE *out;
|
||||
int i, j;
|
||||
u32 i, j;
|
||||
u32 size;
|
||||
if( zFilename==0 || zFilename[0]==0 ){
|
||||
out = stdout;
|
||||
@@ -653,6 +655,8 @@ void sqlite3Memsys3Dump(const char *zFilename){
|
||||
}else{
|
||||
fclose(out);
|
||||
}
|
||||
#else
|
||||
UNUSED_PARAMETER(zFilename);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
+10
-6
@@ -23,7 +23,7 @@
|
||||
** This version of the memory allocation subsystem is included
|
||||
** in the build only if SQLITE_ENABLE_MEMSYS5 is defined.
|
||||
**
|
||||
** $Id: mem5.c,v 1.15 2008/10/28 18:58:20 drh Exp $
|
||||
** $Id: mem5.c,v 1.19 2008/11/19 16:52:44 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -208,12 +208,11 @@ static void *memsys5MallocUnsafe(int nByte){
|
||||
|
||||
/* Keep track of the maximum allocation request. Even unfulfilled
|
||||
** requests are counted */
|
||||
if( nByte>mem5.maxRequest ){
|
||||
if( (u32)nByte>mem5.maxRequest ){
|
||||
mem5.maxRequest = nByte;
|
||||
}
|
||||
|
||||
/* Round nByte up to the next valid power of two */
|
||||
if( nByte>POW2_MAX ) return 0;
|
||||
for(iFullSz=mem5.nAtom, iLogsize=0; iFullSz<nByte; iFullSz *= 2, iLogsize++){}
|
||||
|
||||
/* Make sure mem5.aiFreelist[iLogsize] contains at least one free
|
||||
@@ -265,12 +264,12 @@ static void memsys5FreeUnsafe(void *pOld){
|
||||
|
||||
iLogsize = mem5.aCtrl[iBlock] & CTRL_LOGSIZE;
|
||||
size = 1<<iLogsize;
|
||||
assert( iBlock+size-1<mem5.nBlock );
|
||||
assert( iBlock+size-1<(u32)mem5.nBlock );
|
||||
|
||||
mem5.aCtrl[iBlock] |= CTRL_FREE;
|
||||
mem5.aCtrl[iBlock+size-1] |= CTRL_FREE;
|
||||
assert( mem5.currentCount>0 );
|
||||
assert( mem5.currentOut>=0 );
|
||||
assert( mem5.currentOut>=(size*mem5.nAtom) );
|
||||
mem5.currentCount--;
|
||||
mem5.currentOut -= size*mem5.nAtom;
|
||||
assert( mem5.currentOut>0 || mem5.currentCount==0 );
|
||||
@@ -380,13 +379,15 @@ static int memsys5Init(void *NotUsed){
|
||||
int nMinLog; /* Log of minimum allocation size in bytes*/
|
||||
int iOffset;
|
||||
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
|
||||
if( !zByte ){
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
|
||||
nMinLog = memsys5Log(sqlite3GlobalConfig.mnReq);
|
||||
mem5.nAtom = (1<<nMinLog);
|
||||
while( sizeof(Mem5Link)>mem5.nAtom ){
|
||||
while( (int)sizeof(Mem5Link)>mem5.nAtom ){
|
||||
mem5.nAtom = mem5.nAtom << 1;
|
||||
}
|
||||
|
||||
@@ -416,6 +417,7 @@ static int memsys5Init(void *NotUsed){
|
||||
** Deinitialize this module.
|
||||
*/
|
||||
static void memsys5Shutdown(void *NotUsed){
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -459,6 +461,8 @@ void sqlite3Memsys5Dump(const char *zFilename){
|
||||
}else{
|
||||
fclose(out);
|
||||
}
|
||||
#else
|
||||
UNUSED_PARAMETER(zFilename);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -14,7 +14,7 @@
|
||||
** The in-memory rollback journal is used to journal transactions for
|
||||
** ":memory:" databases and when the journal_mode=MEMORY pragma is used.
|
||||
**
|
||||
** @(#) $Id: memjournal.c,v 1.3 2008/11/12 15:24:28 drh Exp $
|
||||
** @(#) $Id: memjournal.c,v 1.5 2008/11/19 16:52:44 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -123,6 +123,7 @@ static int memjrnlWrite(
|
||||
** access writes are not required by sqlite.
|
||||
*/
|
||||
assert(iOfst==p->endpoint.iOffset);
|
||||
UNUSED_PARAMETER(iOfst);
|
||||
|
||||
while( nWrite>0 ){
|
||||
FileChunk *pChunk = p->endpoint.pChunk;
|
||||
@@ -162,6 +163,7 @@ static int memjrnlTruncate(sqlite3_file *pJfd, sqlite_int64 size){
|
||||
MemJournal *p = (MemJournal *)pJfd;
|
||||
FileChunk *pChunk;
|
||||
assert(size==0);
|
||||
UNUSED_PARAMETER(size);
|
||||
pChunk = p->pFirst;
|
||||
while( pChunk ){
|
||||
FileChunk *pTmp = pChunk;
|
||||
@@ -184,7 +186,8 @@ static int memjrnlClose(sqlite3_file *pJfd){
|
||||
/*
|
||||
** Sync the file.
|
||||
*/
|
||||
static int memjrnlSync(sqlite3_file *pJfd, int flags){
|
||||
static int memjrnlSync(sqlite3_file *NotUsed, int NotUsed2){
|
||||
UNUSED_PARAMETER2(NotUsed, NotUsed2);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** This file contains the C functions that implement mutexes for pthreads
|
||||
**
|
||||
** $Id: mutex_unix.c,v 1.13 2008/07/16 12:33:24 drh Exp $
|
||||
** $Id: mutex_unix.c,v 1.15 2008/11/17 19:18:55 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -61,7 +61,7 @@ struct sqlite3_mutex {
|
||||
** make sure no assert() statements are evaluated and hence these
|
||||
** routines are never called.
|
||||
*/
|
||||
#ifndef NDEBUG
|
||||
#if !defined(NDEBUG) || defined(SQLITE_DEBUG)
|
||||
static int pthreadMutexHeld(sqlite3_mutex *p){
|
||||
return (p->nRef!=0 && pthread_equal(p->owner, pthread_self()));
|
||||
}
|
||||
@@ -157,7 +157,7 @@ static sqlite3_mutex *pthreadMutexAlloc(int iType){
|
||||
}
|
||||
default: {
|
||||
assert( iType-2 >= 0 );
|
||||
assert( iType-2 < sizeof(staticMutexes)/sizeof(staticMutexes[0]) );
|
||||
assert( iType-2 < ArraySize(staticMutexes) );
|
||||
p = &staticMutexes[iType-2];
|
||||
p->id = iType;
|
||||
break;
|
||||
|
||||
+8
-1
@@ -12,7 +12,7 @@
|
||||
**
|
||||
** This file contains code that is specific to OS/2.
|
||||
**
|
||||
** $Id: os_os2.c,v 1.58 2008/11/07 00:06:18 drh Exp $
|
||||
** $Id: os_os2.c,v 1.59 2008/11/18 23:03:40 pweilbacher Exp $
|
||||
*/
|
||||
|
||||
#include "sqliteInt.h"
|
||||
@@ -196,7 +196,14 @@ static int os2Sync( sqlite3_file *id, int flags ){
|
||||
}
|
||||
sqlite3_sync_count++;
|
||||
#endif
|
||||
/* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
|
||||
** no-op
|
||||
*/
|
||||
#ifdef SQLITE_NO_SYNC
|
||||
return SQLITE_OK;
|
||||
#else
|
||||
return DosResetBuffer( pFile->h ) == NO_ERROR ? SQLITE_OK : SQLITE_IOERR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+542
-46
File diff suppressed because it is too large
Load Diff
+17
-4
@@ -12,7 +12,7 @@
|
||||
**
|
||||
** This file contains code that is specific to windows.
|
||||
**
|
||||
** $Id: os_win.c,v 1.137 2008/11/07 00:06:18 drh Exp $
|
||||
** $Id: os_win.c,v 1.140 2008/11/19 21:35:47 shane Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#if SQLITE_OS_WIN /* This file is used for windows only */
|
||||
@@ -252,7 +252,7 @@ static char *unicodeToMbcs(const WCHAR *zWideFilename){
|
||||
** Convert multibyte character string to UTF-8. Space to hold the
|
||||
** returned string is obtained from malloc().
|
||||
*/
|
||||
static char *mbcsToUtf8(const char *zFilename){
|
||||
char *sqlite3_win32_mbcs_to_utf8(const char *zFilename){
|
||||
char *zFilenameUtf8;
|
||||
WCHAR *zTmpWide;
|
||||
|
||||
@@ -751,11 +751,18 @@ static int winSync(sqlite3_file *id, int flags){
|
||||
}
|
||||
sqlite3_sync_count++;
|
||||
#endif
|
||||
/* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
|
||||
** no-op
|
||||
*/
|
||||
#ifdef SQLITE_NO_SYNC
|
||||
return SQLITE_OK;
|
||||
#else
|
||||
if( FlushFileBuffers(pFile->h) ){
|
||||
return SQLITE_OK;
|
||||
}else{
|
||||
return SQLITE_IOERR;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1133,7 +1140,7 @@ static int getTempname(int nBuf, char *zBuf){
|
||||
char *zUtf8;
|
||||
char zMbcsPath[MAX_PATH];
|
||||
GetTempPathA(MAX_PATH-30, zMbcsPath);
|
||||
zUtf8 = mbcsToUtf8(zMbcsPath);
|
||||
zUtf8 = sqlite3_win32_mbcs_to_utf8(zMbcsPath);
|
||||
if( zUtf8 ){
|
||||
sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zUtf8);
|
||||
free(zUtf8);
|
||||
@@ -1474,7 +1481,7 @@ static int winFullPathname(
|
||||
}
|
||||
GetFullPathNameA((char*)zConverted, nByte, zTemp, 0);
|
||||
free(zConverted);
|
||||
zOut = mbcsToUtf8(zTemp);
|
||||
zOut = sqlite3_win32_mbcs_to_utf8(zTemp);
|
||||
free(zTemp);
|
||||
#endif
|
||||
}
|
||||
@@ -1546,6 +1553,11 @@ void winDlClose(sqlite3_vfs *pVfs, void *pHandle){
|
||||
*/
|
||||
static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
|
||||
int n = 0;
|
||||
UNUSED_PARAMETER(pVfs);
|
||||
#if defined(SQLITE_TEST)
|
||||
n = nBuf;
|
||||
memset(zBuf, 0, nBuf);
|
||||
#else
|
||||
if( sizeof(SYSTEMTIME)<=nBuf-n ){
|
||||
SYSTEMTIME x;
|
||||
GetSystemTime(&x);
|
||||
@@ -1568,6 +1580,7 @@ static int winRandomness(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
|
||||
memcpy(&zBuf[n], &i, sizeof(i));
|
||||
n += sizeof(i);
|
||||
}
|
||||
#endif
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
+57
-70
@@ -18,7 +18,7 @@
|
||||
** file simultaneously, or one process from reading the database while
|
||||
** another is writing.
|
||||
**
|
||||
** @(#) $Id: pager.c,v 1.502 2008/11/07 00:24:54 drh Exp $
|
||||
** @(#) $Id: pager.c,v 1.506 2008/11/19 18:30:29 drh Exp $
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_DISKIO
|
||||
#include "sqliteInt.h"
|
||||
@@ -176,11 +176,12 @@ struct Pager {
|
||||
u8 journalMode; /* On of the PAGER_JOURNALMODE_* values */
|
||||
u8 dbModified; /* True if there are any changes to the Db */
|
||||
u8 changeCountDone; /* Set after incrementing the change-counter */
|
||||
u8 dbSizeValid; /* Set when dbSize is correct */
|
||||
u32 vfsFlags; /* Flags for sqlite3_vfs.xOpen() */
|
||||
int errCode; /* One of several kinds of errors */
|
||||
int dbSize; /* Number of pages in the file */
|
||||
int origDbSize; /* dbSize before the current change */
|
||||
int stmtSize; /* Size of database (in pages) at stmt_begin() */
|
||||
Pgno dbSize; /* Number of pages in the file */
|
||||
Pgno origDbSize; /* dbSize before the current change */
|
||||
Pgno stmtSize; /* Size of database (in pages) at stmt_begin() */
|
||||
int nRec; /* Number of pages written to the journal */
|
||||
u32 cksumInit; /* Quasi-random value added to every checksum */
|
||||
int stmtNRec; /* Number of records in stmt subjournal */
|
||||
@@ -197,7 +198,8 @@ struct Pager {
|
||||
char *zDirectory; /* Directory hold database and journal files */
|
||||
sqlite3_file *fd, *jfd; /* File descriptors for database and journal */
|
||||
sqlite3_file *stfd; /* File descriptor for the statement subjournal*/
|
||||
BusyHandler *pBusyHandler; /* Pointer to sqlite.busyHandler */
|
||||
int (*xBusyHandler)(void*); /* Function to call when busy */
|
||||
void *pBusyHandlerArg; /* Context argument for xBusyHandler */
|
||||
i64 journalOff; /* Current byte offset in the journal file */
|
||||
i64 journalHdr; /* Byte offset to previous journal header */
|
||||
i64 stmtHdrOff; /* First journal header written this statement */
|
||||
@@ -295,7 +297,7 @@ static const unsigned char aJournalMagic[] = {
|
||||
** roll back. See comments for function writeMasterJournal() for details.
|
||||
*/
|
||||
/* #define PAGER_MJ_PGNO(x) (PENDING_BYTE/((x)->pageSize)) */
|
||||
#define PAGER_MJ_PGNO(x) ((PENDING_BYTE/((x)->pageSize))+1)
|
||||
#define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1))
|
||||
|
||||
/*
|
||||
** The maximum legal page number is (2^31 - 1).
|
||||
@@ -312,6 +314,10 @@ static int pageInStatement(PgHdr *pPg){
|
||||
return sqlite3BitvecTest(pPager->pInStmt, pPg->pgno);
|
||||
}
|
||||
|
||||
static int pageInJournal(PgHdr *pPg){
|
||||
return sqlite3BitvecTest(pPg->pPager->pInJournal, pPg->pgno);
|
||||
}
|
||||
|
||||
/*
|
||||
** Read a 32-bit integer from the given file descriptor. Store the integer
|
||||
** that is read in *pRes. Return SQLITE_OK if everything worked, or an
|
||||
@@ -454,7 +460,7 @@ static u32 pager_datahash(int nByte, unsigned char *pData){
|
||||
static u32 pager_pagehash(PgHdr *pPage){
|
||||
return pager_datahash(pPage->pPager->pageSize, (unsigned char *)pPage->pData);
|
||||
}
|
||||
static u32 pager_set_pagehash(PgHdr *pPage){
|
||||
static void pager_set_pagehash(PgHdr *pPage){
|
||||
pPage->pageHash = pager_pagehash(pPage);
|
||||
}
|
||||
|
||||
@@ -491,7 +497,7 @@ static void checkPage(PgHdr *pPg){
|
||||
** If no master journal file name is present zMaster[0] is set to 0 and
|
||||
** SQLITE_OK returned.
|
||||
*/
|
||||
static int readMasterJournal(sqlite3_file *pJrnl, char *zMaster, int nMaster){
|
||||
static int readMasterJournal(sqlite3_file *pJrnl, char *zMaster, u32 nMaster){
|
||||
int rc;
|
||||
u32 len;
|
||||
i64 szJ;
|
||||
@@ -623,8 +629,8 @@ static int zeroJournalHdr(Pager *pPager, int doTruncate){
|
||||
static int writeJournalHdr(Pager *pPager){
|
||||
int rc = SQLITE_OK;
|
||||
char *zHeader = pPager->pTmpSpace;
|
||||
int nHeader = pPager->pageSize;
|
||||
int nWrite;
|
||||
u32 nHeader = pPager->pageSize;
|
||||
u32 nWrite;
|
||||
|
||||
if( nHeader>JOURNAL_HDR_SZ(pPager) ){
|
||||
nHeader = JOURNAL_HDR_SZ(pPager);
|
||||
@@ -883,7 +889,7 @@ static void pager_unlock(Pager *pPager){
|
||||
if( !pPager->exclusiveMode ){
|
||||
int rc = osUnlock(pPager->fd, NO_LOCK);
|
||||
if( rc ) pPager->errCode = rc;
|
||||
pPager->dbSize = -1;
|
||||
pPager->dbSizeValid = 0;
|
||||
IOTRACE(("UNLOCK %p\n", pPager))
|
||||
|
||||
/* Always close the journal file when dropping the database lock.
|
||||
@@ -997,13 +1003,10 @@ static int pager_end_transaction(Pager *pPager, int hasMaster){
|
||||
pPager->pInJournal = 0;
|
||||
sqlite3BitvecDestroy(pPager->pAlwaysRollback);
|
||||
pPager->pAlwaysRollback = 0;
|
||||
sqlite3PcacheCleanAll(pPager->pPCache);
|
||||
#ifdef SQLITE_CHECK_PAGES
|
||||
sqlite3PcacheIterate(pPager->pPCache, pager_set_pagehash);
|
||||
sqlite3PcacheIterateDirty(pPager->pPCache, pager_set_pagehash);
|
||||
#endif
|
||||
sqlite3PcacheClearFlags(pPager->pPCache,
|
||||
PGHDR_IN_JOURNAL | PGHDR_NEED_SYNC
|
||||
);
|
||||
sqlite3PcacheCleanAll(pPager->pPCache);
|
||||
pPager->dirtyCache = 0;
|
||||
pPager->nRec = 0;
|
||||
}else{
|
||||
@@ -1021,7 +1024,7 @@ static int pager_end_transaction(Pager *pPager, int hasMaster){
|
||||
pPager->needSync = 0;
|
||||
/* lruListSetFirstSynced(pPager); */
|
||||
if( !MEMDB ){
|
||||
pPager->dbSize = -1;
|
||||
pPager->dbSizeValid = 0;
|
||||
}
|
||||
pPager->dbModified = 0;
|
||||
|
||||
@@ -1309,7 +1312,7 @@ static void pager_truncate_cache(Pager *pPager);
|
||||
** so detect this case and write a single zero byte to the end of the new
|
||||
** file instead.
|
||||
*/
|
||||
static int pager_truncate(Pager *pPager, int nPage){
|
||||
static int pager_truncate(Pager *pPager, Pgno nPage){
|
||||
int rc = SQLITE_OK;
|
||||
if( pPager->state>=PAGER_EXCLUSIVE && pPager->fd->pMethods ){
|
||||
i64 currentSize, newSize;
|
||||
@@ -1818,7 +1821,7 @@ int sqlite3PagerOpen(
|
||||
/* Open the pager file.
|
||||
*/
|
||||
if( zFilename && zFilename[0] && !memDb ){
|
||||
if( nPathname>(pVfs->mxPathname - sizeof("-journal")) ){
|
||||
if( nPathname>(pVfs->mxPathname - (int)sizeof("-journal")) ){
|
||||
rc = SQLITE_CANTOPEN;
|
||||
}else{
|
||||
int fout = 0;
|
||||
@@ -1909,7 +1912,7 @@ int sqlite3PagerOpen(
|
||||
/* pPager->stmtOpen = 0; */
|
||||
/* pPager->stmtInUse = 0; */
|
||||
/* pPager->nRef = 0; */
|
||||
pPager->dbSize = memDb-1;
|
||||
pPager->dbSizeValid = memDb;
|
||||
pPager->pageSize = szPageDflt;
|
||||
/* pPager->stmtSize = 0; */
|
||||
/* pPager->stmtJSize = 0; */
|
||||
@@ -1940,7 +1943,8 @@ int sqlite3PagerOpen(
|
||||
if( memDb ){
|
||||
pPager->journalMode = PAGER_JOURNALMODE_MEMORY;
|
||||
}
|
||||
/* pPager->pBusyHandler = 0; */
|
||||
/* pPager->xBusyHandler = 0; */
|
||||
/* pPager->pBusyHandlerArg = 0; */
|
||||
/* memset(pPager->aHash, 0, sizeof(pPager->aHash)); */
|
||||
*ppPager = pPager;
|
||||
return SQLITE_OK;
|
||||
@@ -1949,8 +1953,13 @@ int sqlite3PagerOpen(
|
||||
/*
|
||||
** Set the busy handler function.
|
||||
*/
|
||||
void sqlite3PagerSetBusyhandler(Pager *pPager, BusyHandler *pBusyHandler){
|
||||
pPager->pBusyHandler = pBusyHandler;
|
||||
void sqlite3PagerSetBusyhandler(
|
||||
Pager *pPager,
|
||||
int (*xBusyHandler)(void *),
|
||||
void *pBusyHandlerArg
|
||||
){
|
||||
pPager->xBusyHandler = xBusyHandler;
|
||||
pPager->pBusyHandlerArg = pBusyHandlerArg;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2087,7 +2096,7 @@ int sqlite3PagerPagecount(Pager *pPager, int *pnPage){
|
||||
rc = pPager->errCode;
|
||||
return rc;
|
||||
}
|
||||
if( pPager->dbSize>=0 ){
|
||||
if( pPager->dbSizeValid ){
|
||||
n = pPager->dbSize;
|
||||
} else {
|
||||
assert(pPager->fd->pMethods||pPager->tempFile);
|
||||
@@ -2103,6 +2112,7 @@ int sqlite3PagerPagecount(Pager *pPager, int *pnPage){
|
||||
}
|
||||
if( pPager->state!=PAGER_UNLOCK ){
|
||||
pPager->dbSize = n;
|
||||
pPager->dbSizeValid = 1;
|
||||
}
|
||||
}
|
||||
if( n==(PENDING_BYTE/pPager->pageSize) ){
|
||||
@@ -2155,15 +2165,14 @@ static int pager_wait_on_lock(Pager *pPager, int locktype){
|
||||
assert( PAGER_EXCLUSIVE==EXCLUSIVE_LOCK );
|
||||
|
||||
/* If the file is currently unlocked then the size must be unknown */
|
||||
assert( pPager->state>=PAGER_SHARED || pPager->dbSize<0 );
|
||||
assert( pPager->state>=PAGER_SHARED || pPager->dbSizeValid==0 );
|
||||
|
||||
if( pPager->state>=locktype ){
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
if( pPager->pBusyHandler ) pPager->pBusyHandler->nBusy = 0;
|
||||
do {
|
||||
rc = sqlite3OsLock(pPager->fd, locktype);
|
||||
}while( rc==SQLITE_BUSY && sqlite3InvokeBusyHandler(pPager->pBusyHandler) );
|
||||
}while( rc==SQLITE_BUSY && pPager->xBusyHandler(pPager->pBusyHandlerArg) );
|
||||
if( rc==SQLITE_OK ){
|
||||
pPager->state = locktype;
|
||||
IOTRACE(("LOCK %p %d\n", pPager, locktype))
|
||||
@@ -2182,7 +2191,7 @@ int sqlite3PagerTruncate(Pager *pPager, Pgno nPage){
|
||||
sqlite3PagerPagecount(pPager, 0);
|
||||
if( pPager->errCode ){
|
||||
rc = pPager->errCode;
|
||||
}else if( nPage<(unsigned)pPager->dbSize ){
|
||||
}else if( nPage<pPager->dbSize ){
|
||||
rc = syncJournal(pPager);
|
||||
if( rc==SQLITE_OK ){
|
||||
/* Get an exclusive lock on the database before truncating. */
|
||||
@@ -2339,19 +2348,9 @@ static int syncJournal(Pager *pPager){
|
||||
|
||||
/* Erase the needSync flag from every page.
|
||||
*/
|
||||
sqlite3PcacheClearFlags(pPager->pPCache, PGHDR_NEED_SYNC);
|
||||
sqlite3PcacheClearSyncFlags(pPager->pPCache);
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
/* If the Pager.needSync flag is clear then the PgHdr.needSync
|
||||
** flag must also be clear for all pages. Verify that this
|
||||
** invariant is true.
|
||||
*/
|
||||
else{
|
||||
sqlite3PcacheAssertFlags(pPager->pPCache, 0, PGHDR_NEED_SYNC);
|
||||
}
|
||||
#endif
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2702,6 +2701,7 @@ static int pagerSharedLock(Pager *pPager){
|
||||
goto failed;
|
||||
}
|
||||
|
||||
assert( pPager->dbSizeValid );
|
||||
if( pPager->dbSize>0 ){
|
||||
IOTRACE(("CKVERS %p %d\n", pPager, sizeof(dbFileVers)));
|
||||
rc = sqlite3OsRead(pPager->fd, &dbFileVers, sizeof(dbFileVers), 24);
|
||||
@@ -2852,9 +2852,6 @@ int sqlite3PagerAcquire(
|
||||
int nMax;
|
||||
PAGER_INCR(pPager->nMiss);
|
||||
pPg->pPager = pPager;
|
||||
if( sqlite3BitvecTest(pPager->pInJournal, pgno) ){
|
||||
pPg->flags |= PGHDR_IN_JOURNAL;
|
||||
}
|
||||
memset(pPg->pExtra, 0, pPager->nExtra);
|
||||
|
||||
rc = sqlite3PagerPagecount(pPager, &nMax);
|
||||
@@ -3058,7 +3055,6 @@ int sqlite3PagerBegin(DbPage *pPg, int exFlag){
|
||||
if( pPager->state==PAGER_SHARED ){
|
||||
assert( pPager->pInJournal==0 );
|
||||
assert( !MEMDB );
|
||||
sqlite3PcacheAssertFlags(pPager->pPCache, 0, PGHDR_IN_JOURNAL);
|
||||
rc = sqlite3OsLock(pPager->fd, RESERVED_LOCK);
|
||||
if( rc==SQLITE_OK ){
|
||||
pPager->state = PAGER_RESERVED;
|
||||
@@ -3167,9 +3163,7 @@ static int pager_write(PgHdr *pPg){
|
||||
** to the journal then we can return right away.
|
||||
*/
|
||||
makeDirty(pPg);
|
||||
if( (pPg->flags&PGHDR_IN_JOURNAL)
|
||||
&& (pageInStatement(pPg) || pPager->stmtInUse==0)
|
||||
){
|
||||
if( pageInJournal(pPg) && (pageInStatement(pPg) || pPager->stmtInUse==0) ){
|
||||
pPager->dirtyCache = 1;
|
||||
pPager->dbModified = 1;
|
||||
}else{
|
||||
@@ -3199,8 +3193,8 @@ static int pager_write(PgHdr *pPg){
|
||||
** EXCLUSIVE lock on the main database file. Write the current page to
|
||||
** the transaction journal if it is not there already.
|
||||
*/
|
||||
if( !(pPg->flags&PGHDR_IN_JOURNAL) && pPager->journalOpen ){
|
||||
if( (int)pPg->pgno <= pPager->origDbSize ){
|
||||
if( !pageInJournal(pPg) && pPager->journalOpen ){
|
||||
if( pPg->pgno<=pPager->origDbSize ){
|
||||
u32 cksum;
|
||||
char *pData2;
|
||||
|
||||
@@ -3254,7 +3248,6 @@ static int pager_write(PgHdr *pPg){
|
||||
if( pPg->flags&PGHDR_NEED_SYNC ){
|
||||
pPager->needSync = 1;
|
||||
}
|
||||
pPg->flags |= PGHDR_IN_JOURNAL;
|
||||
}
|
||||
|
||||
/* If the statement journal is open and the page is not in it,
|
||||
@@ -3264,12 +3257,11 @@ static int pager_write(PgHdr *pPg){
|
||||
*/
|
||||
if( pPager->stmtInUse
|
||||
&& !pageInStatement(pPg)
|
||||
&& (int)pPg->pgno<=pPager->stmtSize
|
||||
&& pPg->pgno<=pPager->stmtSize
|
||||
){
|
||||
i64 offset = pPager->stmtNRec*(4+pPager->pageSize);
|
||||
char *pData2 = CODEC2(pPager, pData, pPg->pgno, 7);
|
||||
assert( (pPg->flags&PGHDR_IN_JOURNAL)
|
||||
|| (int)pPg->pgno>pPager->origDbSize );
|
||||
assert( pageInJournal(pPg) || pPg->pgno>pPager->origDbSize );
|
||||
rc = write32bits(pPager->stfd, offset, pPg->pgno);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3OsWrite(pPager->stfd, pData2, pPager->pageSize, offset+4);
|
||||
@@ -3287,9 +3279,9 @@ static int pager_write(PgHdr *pPg){
|
||||
/* Update the database size and return.
|
||||
*/
|
||||
assert( pPager->state>=PAGER_SHARED );
|
||||
if( pPager->dbSize<(int)pPg->pgno ){
|
||||
if( pPager->dbSize<pPg->pgno ){
|
||||
pPager->dbSize = pPg->pgno;
|
||||
if( pPager->dbSize==PENDING_BYTE/pPager->pageSize ){
|
||||
if( pPager->dbSize==(PAGER_MJ_PGNO(pPager)-1) ){
|
||||
pPager->dbSize++;
|
||||
}
|
||||
}
|
||||
@@ -3447,7 +3439,7 @@ int sqlite3PagerDontWrite(DbPage *pDbPage){
|
||||
|
||||
if( rc==SQLITE_OK && (pPg->flags&PGHDR_DIRTY) && !pPager->stmtInUse ){
|
||||
assert( pPager->state>=PAGER_SHARED );
|
||||
if( pPager->dbSize==(int)pPg->pgno && pPager->origDbSize<pPager->dbSize ){
|
||||
if( pPager->dbSize==pPg->pgno && pPager->origDbSize<pPager->dbSize ){
|
||||
/* If this pages is the last page in the file and the file has grown
|
||||
** during the current transaction, then do NOT mark the page as clean.
|
||||
** When the database file grows, we must make sure that the last page
|
||||
@@ -3496,7 +3488,8 @@ void sqlite3PagerDontRollback(DbPage *pPg){
|
||||
}
|
||||
|
||||
#ifdef SQLITE_SECURE_DELETE
|
||||
if( (pPg->flags & PGHDR_IN_JOURNAL)!=0 || (int)pPg->pgno>pPager->origDbSize ){
|
||||
if( sqlite3BitvecTest(pPager->pInJournal, pPg->pgno)!=0
|
||||
|| pPg->pgno>pPager->origDbSize ){
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -3515,7 +3508,6 @@ void sqlite3PagerDontRollback(DbPage *pPg){
|
||||
|
||||
assert( pPager->pInJournal!=0 );
|
||||
sqlite3BitvecSet(pPager->pInJournal, pPg->pgno);
|
||||
pPg->flags |= PGHDR_IN_JOURNAL;
|
||||
pPg->flags &= ~PGHDR_NEED_READ;
|
||||
if( pPager->stmtInUse ){
|
||||
assert( pPager->stmtSize >= pPager->origDbSize );
|
||||
@@ -3696,7 +3688,7 @@ int sqlite3PagerCommitPhaseOne(
|
||||
** file.
|
||||
*/
|
||||
Pgno i;
|
||||
int iSkip = PAGER_MJ_PGNO(pPager);
|
||||
Pgno iSkip = PAGER_MJ_PGNO(pPager);
|
||||
for( i=nTrunc+1; i<=pPager->origDbSize; i++ ){
|
||||
if( !sqlite3BitvecTest(pPager->pInJournal, i) && i!=iSkip ){
|
||||
rc = sqlite3PagerGet(pPager, i, &pPg);
|
||||
@@ -3826,7 +3818,7 @@ int sqlite3PagerRollback(Pager *pPager){
|
||||
}
|
||||
|
||||
if( !MEMDB ){
|
||||
pPager->dbSize = -1;
|
||||
pPager->dbSizeValid = 0;
|
||||
}
|
||||
|
||||
/* If an error occurs during a ROLLBACK, we can no longer trust the pager
|
||||
@@ -3869,7 +3861,7 @@ int *sqlite3PagerStats(Pager *pPager){
|
||||
a[0] = sqlite3PcacheRefCount(pPager->pPCache);
|
||||
a[1] = sqlite3PcachePagecount(pPager->pPCache);
|
||||
a[2] = sqlite3PcacheGetCachesize(pPager->pPCache);
|
||||
a[3] = pPager->dbSize;
|
||||
a[3] = pPager->dbSizeValid ? (int) pPager->dbSize : -1;
|
||||
a[4] = pPager->state;
|
||||
a[5] = pPager->errCode;
|
||||
a[6] = pPager->nHit;
|
||||
@@ -3895,7 +3887,7 @@ static int pagerStmtBegin(Pager *pPager){
|
||||
int rc;
|
||||
assert( !pPager->stmtInUse );
|
||||
assert( pPager->state>=PAGER_SHARED );
|
||||
assert( pPager->dbSize>=0 );
|
||||
assert( pPager->dbSizeValid );
|
||||
PAGERTRACE2("STMT-BEGIN %d\n", PAGERID(pPager));
|
||||
if( !pPager->journalOpen ){
|
||||
pPager->stmtAutoopen = 1;
|
||||
@@ -4077,7 +4069,7 @@ int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, int isCommit){
|
||||
*/
|
||||
if( (pPg->flags&PGHDR_NEED_SYNC) && !isCommit ){
|
||||
needSyncPgno = pPg->pgno;
|
||||
assert( (pPg->flags&PGHDR_IN_JOURNAL) || (int)pgno>pPager->origDbSize );
|
||||
assert( pageInJournal(pPg) || pgno>pPager->origDbSize );
|
||||
assert( pPg->flags&PGHDR_DIRTY );
|
||||
assert( pPager->needSync );
|
||||
}
|
||||
@@ -4087,20 +4079,16 @@ int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, int isCommit){
|
||||
** page pgno before the 'move' operation, it needs to be retained
|
||||
** for the page moved there.
|
||||
*/
|
||||
pPg->flags &= ~(PGHDR_NEED_SYNC|PGHDR_IN_JOURNAL);
|
||||
pPg->flags &= ~PGHDR_NEED_SYNC;
|
||||
pPgOld = pager_lookup(pPager, pgno);
|
||||
assert( !pPgOld || pPgOld->nRef==1 );
|
||||
if( pPgOld ){
|
||||
pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
|
||||
}
|
||||
if( sqlite3BitvecTest(pPager->pInJournal, pgno) ){
|
||||
pPg->flags |= PGHDR_IN_JOURNAL;
|
||||
}
|
||||
|
||||
sqlite3PcacheMove(pPg, pgno);
|
||||
if( pPgOld ){
|
||||
sqlite3PcacheMove(pPgOld, 0);
|
||||
sqlite3PcacheRelease(pPgOld);
|
||||
sqlite3PcacheDrop(pPgOld);
|
||||
}
|
||||
|
||||
makeDirty(pPg);
|
||||
@@ -4130,7 +4118,7 @@ int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, int isCommit){
|
||||
assert( pPager->needSync );
|
||||
rc = sqlite3PagerGet(pPager, needSyncPgno, &pPgHdr);
|
||||
if( rc!=SQLITE_OK ){
|
||||
if( pPager->pInJournal && (int)needSyncPgno<=pPager->origDbSize ){
|
||||
if( pPager->pInJournal && needSyncPgno<=pPager->origDbSize ){
|
||||
sqlite3BitvecClear(pPager->pInJournal, needSyncPgno);
|
||||
}
|
||||
return rc;
|
||||
@@ -4138,7 +4126,6 @@ int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, int isCommit){
|
||||
pPager->needSync = 1;
|
||||
assert( pPager->noSync==0 && !MEMDB );
|
||||
pPgHdr->flags |= PGHDR_NEED_SYNC;
|
||||
pPgHdr->flags |= PGHDR_IN_JOURNAL;
|
||||
makeDirty(pPgHdr);
|
||||
sqlite3PagerUnref(pPgHdr);
|
||||
}
|
||||
|
||||
+2
-2
@@ -13,7 +13,7 @@
|
||||
** subsystem. The page cache subsystem reads and writes a file a page
|
||||
** at a time and provides a journal for rollback.
|
||||
**
|
||||
** @(#) $Id: pager.h,v 1.86 2008/10/17 18:51:53 danielk1977 Exp $
|
||||
** @(#) $Id: pager.h,v 1.87 2008/11/19 10:22:33 danielk1977 Exp $
|
||||
*/
|
||||
|
||||
#ifndef _PAGER_H_
|
||||
@@ -73,7 +73,7 @@ typedef struct PgHdr DbPage;
|
||||
** routines:
|
||||
*/
|
||||
int sqlite3PagerOpen(sqlite3_vfs *, Pager **ppPager, const char*, int,int,int);
|
||||
void sqlite3PagerSetBusyhandler(Pager*, BusyHandler *pBusyHandler);
|
||||
void sqlite3PagerSetBusyhandler(Pager*, int(*)(void *), void *);
|
||||
void sqlite3PagerSetReiniter(Pager*, void(*)(DbPage*));
|
||||
int sqlite3PagerSetPagesize(Pager*, u16*);
|
||||
int sqlite3PagerMaxPageCount(Pager*, int);
|
||||
|
||||
+225
-852
File diff suppressed because it is too large
Load Diff
+14
-28
@@ -12,7 +12,7 @@
|
||||
** This header file defines the interface that the sqlite page cache
|
||||
** subsystem.
|
||||
**
|
||||
** @(#) $Id: pcache.h,v 1.14 2008/10/17 18:51:53 danielk1977 Exp $
|
||||
** @(#) $Id: pcache.h,v 1.16 2008/11/19 16:52:44 danielk1977 Exp $
|
||||
*/
|
||||
|
||||
#ifndef _PCACHE_H_
|
||||
@@ -34,6 +34,7 @@ struct PgHdr {
|
||||
u32 pageHash; /* Hash of page content */
|
||||
#endif
|
||||
u16 flags; /* PGHDR flags defined below */
|
||||
|
||||
/**********************************************************************
|
||||
** Elements above are public. All that follows is private to pcache.c
|
||||
** and should not be accessed by other modules.
|
||||
@@ -41,18 +42,11 @@ struct PgHdr {
|
||||
i16 nRef; /* Number of users of this page */
|
||||
PCache *pCache; /* Cache that owns this page */
|
||||
|
||||
/**********************************************************************
|
||||
** Elements above are accessible at any time by the owner of the cache
|
||||
** without the need for a mutex. The elements that follow can only be
|
||||
** accessed while holding the SQLITE_MUTEX_STATIC_LRU mutex.
|
||||
*/
|
||||
PgHdr *pNextHash, *pPrevHash; /* Hash collision chain for PgHdr.pgno */
|
||||
PgHdr *pNext, *pPrev; /* List of clean or dirty pages */
|
||||
PgHdr *pNextLru, *pPrevLru; /* Part of global LRU list */
|
||||
PgHdr *pDirtyNext; /* Next element in list of dirty pages */
|
||||
PgHdr *pDirtyPrev; /* Previous element in list of dirty pages */
|
||||
};
|
||||
|
||||
/* Bit values for PgHdr.flags */
|
||||
#define PGHDR_IN_JOURNAL 0x001 /* Page is in rollback journal */
|
||||
#define PGHDR_DIRTY 0x002 /* Page has changed */
|
||||
#define PGHDR_NEED_SYNC 0x004 /* Fsync the rollback journal before
|
||||
** writing this page to the database */
|
||||
@@ -68,8 +62,6 @@ void sqlite3PcacheShutdown(void);
|
||||
** These routines implement SQLITE_CONFIG_PAGECACHE.
|
||||
*/
|
||||
void sqlite3PCacheBufferSetup(void *, int sz, int n);
|
||||
void *sqlite3PCacheMalloc(int sz);
|
||||
void sqlite3PCacheFree(void*);
|
||||
|
||||
/* Create a new pager cache.
|
||||
** Under memory stress, invoke xStress to try to make pages clean.
|
||||
@@ -116,17 +108,7 @@ PgHdr *sqlite3PcacheDirtyList(PCache*);
|
||||
void sqlite3PcacheClose(PCache*);
|
||||
|
||||
/* Clear flags from pages of the page cache */
|
||||
void sqlite3PcacheClearFlags(PCache*, int mask);
|
||||
|
||||
/* Assert flags settings on all pages. Debugging only */
|
||||
#ifndef NDEBUG
|
||||
void sqlite3PcacheAssertFlags(PCache*, int trueMask, int falseMask);
|
||||
#else
|
||||
# define sqlite3PcacheAssertFlags(A,B,C)
|
||||
#endif
|
||||
|
||||
/* Return true if the number of dirty pages is 0 or 1 */
|
||||
int sqlite3PcacheZeroOrOneDirtyPages(PCache*);
|
||||
void sqlite3PcacheClearSyncFlags(PCache *);
|
||||
|
||||
/* Discard the contents of the cache */
|
||||
int sqlite3PcacheClear(PCache*);
|
||||
@@ -143,11 +125,11 @@ int sqlite3PcachePageRefcount(PgHdr*);
|
||||
int sqlite3PcachePagecount(PCache*);
|
||||
|
||||
#ifdef SQLITE_CHECK_PAGES
|
||||
/* Iterate through all pages currently stored in the cache. This interface
|
||||
** is only available if SQLITE_CHECK_PAGES is defined when the library is
|
||||
** built.
|
||||
/* Iterate through all dirty pages currently stored in the cache. This
|
||||
** interface is only available if SQLITE_CHECK_PAGES is defined when the
|
||||
** library is built.
|
||||
*/
|
||||
void sqlite3PcacheIterate(PCache *pCache, void (*xIter)(PgHdr *));
|
||||
void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
|
||||
#endif
|
||||
|
||||
/* Set and get the suggested cache-size for the specified pager-cache.
|
||||
@@ -156,8 +138,10 @@ void sqlite3PcacheIterate(PCache *pCache, void (*xIter)(PgHdr *));
|
||||
** the total number of pages cached by purgeable pager-caches to the sum
|
||||
** of the suggested cache-sizes.
|
||||
*/
|
||||
int sqlite3PcacheGetCachesize(PCache *);
|
||||
void sqlite3PcacheSetCachesize(PCache *, int);
|
||||
#ifdef SQLITE_TEST
|
||||
int sqlite3PcacheGetCachesize(PCache *);
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
|
||||
/* Try to return memory used by the pcache module to the main memory heap */
|
||||
@@ -168,4 +152,6 @@ int sqlite3PcacheReleaseMemory(int);
|
||||
void sqlite3PcacheStats(int*,int*,int*,int*);
|
||||
#endif
|
||||
|
||||
void sqlite3PCacheSetDefault(void);
|
||||
|
||||
#endif /* _PCACHE_H_ */
|
||||
|
||||
+737
@@ -0,0 +1,737 @@
|
||||
/*
|
||||
** 2008 November 05
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
**
|
||||
** This file implements the default page cache implementation (the
|
||||
** sqlite3_pcache interface). It also contains part of the implementation
|
||||
** of the SQLITE_CONFIG_PAGECACHE and sqlite3_release_memory() features.
|
||||
** If the default page cache implementation is overriden, then neither of
|
||||
** these two features are available.
|
||||
**
|
||||
** @(#) $Id: pcache1.c,v 1.3 2008/11/19 09:05:27 danielk1977 Exp $
|
||||
*/
|
||||
|
||||
#include "sqliteInt.h"
|
||||
|
||||
typedef struct PCache1 PCache1;
|
||||
typedef struct PgHdr1 PgHdr1;
|
||||
typedef struct PgFreeslot PgFreeslot;
|
||||
|
||||
/* Pointers to structures of this type are cast and returned as
|
||||
** opaque sqlite3_pcache* handles
|
||||
*/
|
||||
struct PCache1 {
|
||||
/* Cache configuration parameters. Page size (szPage) and the purgeable
|
||||
** flag (bPurgeable) are set when the cache is created. nMax may be
|
||||
** modified at any time by a call to the pcache1CacheSize() method.
|
||||
** The global mutex must be held when accessing nMax.
|
||||
*/
|
||||
int szPage; /* Size of allocated pages in bytes */
|
||||
int bPurgeable; /* True if cache is purgeable */
|
||||
unsigned int nMin; /* Minimum number of pages reserved */
|
||||
unsigned int nMax; /* Configured "cache_size" value */
|
||||
|
||||
/* Hash table of all pages. The following variables may only be accessed
|
||||
** when the accessor is holding the global mutex (see pcache1EnterMutex()
|
||||
** and pcache1LeaveMutex()).
|
||||
*/
|
||||
unsigned int nRecyclable; /* Number of pages in the LRU list */
|
||||
unsigned int nPage; /* Total number of pages in apHash */
|
||||
unsigned int nHash; /* Number of slots in apHash[] */
|
||||
PgHdr1 **apHash; /* Hash table for fast lookup by key */
|
||||
};
|
||||
|
||||
/*
|
||||
** Each cache entry is represented by an instance of the following
|
||||
** structure. A buffer of PgHdr1.pCache->szPage bytes is allocated
|
||||
** directly after the structure in memory (see the PGHDR1_TO_PAGE()
|
||||
** macro below).
|
||||
*/
|
||||
struct PgHdr1 {
|
||||
unsigned int iKey; /* Key value (page number) */
|
||||
PgHdr1 *pNext; /* Next in hash table chain */
|
||||
PCache1 *pCache; /* Cache that currently owns this page */
|
||||
PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
|
||||
PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
|
||||
};
|
||||
|
||||
/*
|
||||
** Free slots in the allocator used to divide up the buffer provided using
|
||||
** the SQLITE_CONFIG_PAGECACHE mechanism.
|
||||
*/
|
||||
struct PgFreeslot {
|
||||
PgFreeslot *pNext; /* Next free slot */
|
||||
};
|
||||
|
||||
/*
|
||||
** Global data used by this cache.
|
||||
*/
|
||||
static SQLITE_WSD struct PCacheGlobal {
|
||||
sqlite3_mutex *mutex; /* static mutex MUTEX_STATIC_LRU */
|
||||
|
||||
int nMaxPage; /* Sum of nMaxPage for purgeable caches */
|
||||
int nMinPage; /* Sum of nMinPage for purgeable caches */
|
||||
int nCurrentPage; /* Number of purgeable pages allocated */
|
||||
PgHdr1 *pLruHead, *pLruTail; /* LRU list of unpinned pages */
|
||||
|
||||
/* Variables related to SQLITE_CONFIG_PAGECACHE settings. */
|
||||
int szSlot; /* Size of each free slot */
|
||||
void *pStart, *pEnd; /* Bounds of pagecache malloc range */
|
||||
PgFreeslot *pFree; /* Free page blocks */
|
||||
} pcache1_g;
|
||||
|
||||
/*
|
||||
** All code in this file should access the global structure above via the
|
||||
** alias "pcache1". This ensures that the WSD emulation is used when
|
||||
** compiling for systems that do not support real WSD.
|
||||
*/
|
||||
#define pcache1 (GLOBAL(struct PCacheGlobal, pcache1_g))
|
||||
|
||||
/*
|
||||
** When a PgHdr1 structure is allocated, the associated PCache1.szPage
|
||||
** bytes of data are located directly after it in memory (i.e. the total
|
||||
** size of the allocation is sizeof(PgHdr1)+PCache1.szPage byte). The
|
||||
** PGHDR1_TO_PAGE() macro takes a pointer to a PgHdr1 structure as
|
||||
** an argument and returns a pointer to the associated block of szPage
|
||||
** bytes. The PAGE_TO_PGHDR1() macro does the opposite: its argument is
|
||||
** a pointer to a block of szPage bytes of data and the return value is
|
||||
** a pointer to the associated PgHdr1 structure.
|
||||
**
|
||||
** assert( PGHDR1_TO_PAGE(PAGE_TO_PGHDR1(X))==X );
|
||||
*/
|
||||
#define PGHDR1_TO_PAGE(p) (void *)(&((unsigned char *)p)[sizeof(PgHdr1)])
|
||||
#define PAGE_TO_PGHDR1(p) (PgHdr1 *)(&((unsigned char *)p)[-1*sizeof(PgHdr1)])
|
||||
|
||||
/*
|
||||
** Macros to enter and leave the global LRU mutex.
|
||||
*/
|
||||
#define pcache1EnterMutex() sqlite3_mutex_enter(pcache1.mutex)
|
||||
#define pcache1LeaveMutex() sqlite3_mutex_leave(pcache1.mutex)
|
||||
|
||||
/******************************************************************************/
|
||||
/******** Page Allocation/SQLITE_CONFIG_PCACHE Related Functions **************/
|
||||
|
||||
/*
|
||||
** This function is called during initialization if a static buffer is
|
||||
** supplied to use for the page-cache by passing the SQLITE_CONFIG_PAGECACHE
|
||||
** verb to sqlite3_config(). Parameter pBuf points to an allocation large
|
||||
** enough to contain 'n' buffers of 'sz' bytes each.
|
||||
*/
|
||||
void sqlite3PCacheBufferSetup(void *pBuf, int sz, int n){
|
||||
PgFreeslot *p;
|
||||
sz &= ~7;
|
||||
pcache1.szSlot = sz;
|
||||
pcache1.pStart = pBuf;
|
||||
pcache1.pFree = 0;
|
||||
while( n-- ){
|
||||
p = (PgFreeslot*)pBuf;
|
||||
p->pNext = pcache1.pFree;
|
||||
pcache1.pFree = p;
|
||||
pBuf = (void*)&((char*)pBuf)[sz];
|
||||
}
|
||||
pcache1.pEnd = pBuf;
|
||||
}
|
||||
|
||||
/*
|
||||
** Malloc function used within this file to allocate space from the buffer
|
||||
** configured using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no
|
||||
** such buffer exists or there is no space left in it, this function falls
|
||||
** back to sqlite3Malloc().
|
||||
*/
|
||||
static void *pcache1Alloc(int nByte){
|
||||
void *p;
|
||||
assert( sqlite3_mutex_held(pcache1.mutex) );
|
||||
if( nByte<=pcache1.szSlot && pcache1.pFree ){
|
||||
p = (PgHdr1 *)pcache1.pFree;
|
||||
pcache1.pFree = pcache1.pFree->pNext;
|
||||
sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte);
|
||||
sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, 1);
|
||||
}else{
|
||||
|
||||
/* Allocate a new buffer using sqlite3Malloc. Before doing so, exit the
|
||||
** global pcache mutex and unlock the pager-cache object pCache. This is
|
||||
** so that if the attempt to allocate a new buffer causes the the
|
||||
** configured soft-heap-limit to be breached, it will be possible to
|
||||
** reclaim memory from this pager-cache.
|
||||
*/
|
||||
pcache1LeaveMutex();
|
||||
p = sqlite3Malloc(nByte);
|
||||
pcache1EnterMutex();
|
||||
if( p ){
|
||||
int sz = sqlite3MallocSize(p);
|
||||
sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
** Free an allocated buffer obtained from pcache1Alloc().
|
||||
*/
|
||||
static void pcache1Free(void *p){
|
||||
assert( sqlite3_mutex_held(pcache1.mutex) );
|
||||
if( p==0 ) return;
|
||||
if( p>=pcache1.pStart && p<pcache1.pEnd ){
|
||||
PgFreeslot *pSlot;
|
||||
sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, -1);
|
||||
pSlot = (PgFreeslot*)p;
|
||||
pSlot->pNext = pcache1.pFree;
|
||||
pcache1.pFree = pSlot;
|
||||
}else{
|
||||
int iSize = sqlite3MallocSize(p);
|
||||
sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -iSize);
|
||||
sqlite3_free(p);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Allocate a new page object initially associated with cache pCache.
|
||||
*/
|
||||
static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
|
||||
int nByte = sizeof(PgHdr1) + pCache->szPage;
|
||||
PgHdr1 *p = (PgHdr1 *)pcache1Alloc(nByte);
|
||||
if( p ){
|
||||
memset(p, 0, nByte);
|
||||
if( pCache->bPurgeable ){
|
||||
pcache1.nCurrentPage++;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
** Free a page object allocated by pcache1AllocPage().
|
||||
*/
|
||||
static void pcache1FreePage(PgHdr1 *p){
|
||||
if( p ){
|
||||
if( p->pCache->bPurgeable ){
|
||||
pcache1.nCurrentPage--;
|
||||
}
|
||||
pcache1Free(p);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Malloc function used by SQLite to obtain space from the buffer configured
|
||||
** using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no such buffer
|
||||
** exists, this function falls back to sqlite3Malloc().
|
||||
*/
|
||||
void *sqlite3PageMalloc(int sz){
|
||||
void *p;
|
||||
pcache1EnterMutex();
|
||||
p = pcache1Alloc(sz);
|
||||
pcache1LeaveMutex();
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
** Free an allocated buffer obtained from sqlite3PageMalloc().
|
||||
*/
|
||||
void sqlite3PageFree(void *p){
|
||||
pcache1EnterMutex();
|
||||
pcache1Free(p);
|
||||
pcache1LeaveMutex();
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/******** General Implementation Functions ************************************/
|
||||
|
||||
/*
|
||||
** This function is used to resize the hash table used by the cache passed
|
||||
** as the first argument.
|
||||
**
|
||||
** The global mutex must be held when this function is called.
|
||||
*/
|
||||
static int pcache1ResizeHash(PCache1 *p){
|
||||
PgHdr1 **apNew;
|
||||
unsigned int nNew;
|
||||
unsigned int i;
|
||||
|
||||
assert( sqlite3_mutex_held(pcache1.mutex) );
|
||||
|
||||
nNew = p->nHash*2;
|
||||
if( nNew<256 ){
|
||||
nNew = 256;
|
||||
}
|
||||
|
||||
pcache1LeaveMutex();
|
||||
apNew = (PgHdr1 **)sqlite3_malloc(sizeof(PgHdr1 *)*nNew);
|
||||
pcache1EnterMutex();
|
||||
if( apNew ){
|
||||
memset(apNew, 0, sizeof(PgHdr1 *)*nNew);
|
||||
for(i=0; i<p->nHash; i++){
|
||||
PgHdr1 *pPage;
|
||||
PgHdr1 *pNext = p->apHash[i];
|
||||
while( (pPage = pNext) ){
|
||||
unsigned int h = pPage->iKey % nNew;
|
||||
pNext = pPage->pNext;
|
||||
pPage->pNext = apNew[h];
|
||||
apNew[h] = pPage;
|
||||
}
|
||||
}
|
||||
sqlite3_free(p->apHash);
|
||||
p->apHash = apNew;
|
||||
p->nHash = nNew;
|
||||
}
|
||||
|
||||
return (p->apHash ? SQLITE_OK : SQLITE_NOMEM);
|
||||
}
|
||||
|
||||
/*
|
||||
** This function is used internally to remove the page pPage from the
|
||||
** global LRU list, if is part of it. If pPage is not part of the global
|
||||
** LRU list, then this function is a no-op.
|
||||
**
|
||||
** The global mutex must be held when this function is called.
|
||||
*/
|
||||
static void pcache1PinPage(PgHdr1 *pPage){
|
||||
assert( sqlite3_mutex_held(pcache1.mutex) );
|
||||
if( pPage && (pPage->pLruNext || pPage==pcache1.pLruTail) ){
|
||||
if( pPage->pLruPrev ){
|
||||
pPage->pLruPrev->pLruNext = pPage->pLruNext;
|
||||
}
|
||||
if( pPage->pLruNext ){
|
||||
pPage->pLruNext->pLruPrev = pPage->pLruPrev;
|
||||
}
|
||||
if( pcache1.pLruHead==pPage ){
|
||||
pcache1.pLruHead = pPage->pLruNext;
|
||||
}
|
||||
if( pcache1.pLruTail==pPage ){
|
||||
pcache1.pLruTail = pPage->pLruPrev;
|
||||
}
|
||||
pPage->pLruNext = 0;
|
||||
pPage->pLruPrev = 0;
|
||||
pPage->pCache->nRecyclable--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Remove the page supplied as an argument from the hash table
|
||||
** (PCache1.apHash structure) that it is currently stored in.
|
||||
**
|
||||
** The global mutex must be held when this function is called.
|
||||
*/
|
||||
static void pcache1RemoveFromHash(PgHdr1 *pPage){
|
||||
unsigned int h;
|
||||
PCache1 *pCache = pPage->pCache;
|
||||
PgHdr1 **pp;
|
||||
|
||||
h = pPage->iKey % pCache->nHash;
|
||||
for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext);
|
||||
*pp = (*pp)->pNext;
|
||||
|
||||
pCache->nPage--;
|
||||
}
|
||||
|
||||
/*
|
||||
** If there are currently more than pcache.nMaxPage pages allocated, try
|
||||
** to recycle pages to reduce the number allocated to pcache.nMaxPage.
|
||||
*/
|
||||
static void pcache1EnforceMaxPage(void){
|
||||
assert( sqlite3_mutex_held(pcache1.mutex) );
|
||||
while( pcache1.nCurrentPage>pcache1.nMaxPage && pcache1.pLruTail ){
|
||||
PgHdr1 *p = pcache1.pLruTail;
|
||||
pcache1PinPage(p);
|
||||
pcache1RemoveFromHash(p);
|
||||
pcache1FreePage(p);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Discard all pages from cache pCache with a page number (key value)
|
||||
** greater than or equal to iLimit. Any pinned pages that meet this
|
||||
** criteria are unpinned before they are discarded.
|
||||
**
|
||||
** The global mutex must be held when this function is called.
|
||||
*/
|
||||
static void pcache1TruncateUnsafe(
|
||||
PCache1 *pCache,
|
||||
unsigned int iLimit
|
||||
){
|
||||
unsigned int h;
|
||||
assert( sqlite3_mutex_held(pcache1.mutex) );
|
||||
for(h=0; h<pCache->nHash; h++){
|
||||
PgHdr1 **pp = &pCache->apHash[h];
|
||||
PgHdr1 *pPage;
|
||||
while( (pPage = *pp) ){
|
||||
if( pPage->iKey>=iLimit ){
|
||||
pcache1PinPage(pPage);
|
||||
*pp = pPage->pNext;
|
||||
pcache1FreePage(pPage);
|
||||
}else{
|
||||
pp = &pPage->pNext;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/******** sqlite3_pcache Methods **********************************************/
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xInit method.
|
||||
*/
|
||||
static int pcache1Init(void *NotUsed){
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
memset(&pcache1, 0, sizeof(pcache1));
|
||||
if( sqlite3GlobalConfig.bCoreMutex ){
|
||||
pcache1.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU);
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xShutdown method.
|
||||
*/
|
||||
static void pcache1Shutdown(void *NotUsed){
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
/* no-op */
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xCreate method.
|
||||
**
|
||||
** Allocate a new cache.
|
||||
*/
|
||||
static sqlite3_pcache *pcache1Create(int szPage, int bPurgeable){
|
||||
PCache1 *pCache;
|
||||
|
||||
pCache = (PCache1 *)sqlite3_malloc(sizeof(PCache1));
|
||||
if( pCache ){
|
||||
memset(pCache, 0, sizeof(PCache1));
|
||||
pCache->szPage = szPage;
|
||||
pCache->bPurgeable = (bPurgeable ? 1 : 0);
|
||||
if( bPurgeable ){
|
||||
pCache->nMin = 10;
|
||||
pcache1EnterMutex();
|
||||
pcache1.nMinPage += pCache->nMin;
|
||||
pcache1LeaveMutex();
|
||||
}
|
||||
}
|
||||
return (sqlite3_pcache *)pCache;
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xCachesize method.
|
||||
**
|
||||
** Configure the cache_size limit for a cache.
|
||||
*/
|
||||
static void pcache1Cachesize(sqlite3_pcache *p, int nMax){
|
||||
PCache1 *pCache = (PCache1 *)p;
|
||||
if( pCache->bPurgeable ){
|
||||
pcache1EnterMutex();
|
||||
pcache1.nMaxPage += (nMax - pCache->nMax);
|
||||
pCache->nMax = nMax;
|
||||
pcache1EnforceMaxPage();
|
||||
pcache1LeaveMutex();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xPagecount method.
|
||||
*/
|
||||
static int pcache1Pagecount(sqlite3_pcache *p){
|
||||
int n;
|
||||
pcache1EnterMutex();
|
||||
n = ((PCache1 *)p)->nPage;
|
||||
pcache1LeaveMutex();
|
||||
return n;
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xFetch method.
|
||||
**
|
||||
** Fetch a page by key value.
|
||||
**
|
||||
** Whether or not a new page may be allocated by this function depends on
|
||||
** the value of the createFlag argument.
|
||||
**
|
||||
** There are three different approaches to obtaining space for a page,
|
||||
** depending on the value of parameter createFlag (which may be 0, 1 or 2).
|
||||
**
|
||||
** 1. Regardless of the value of createFlag, the cache is searched for a
|
||||
** copy of the requested page. If one is found, it is returned.
|
||||
**
|
||||
** 2. If createFlag==0 and the page is not already in the cache, NULL is
|
||||
** returned.
|
||||
**
|
||||
** 3. If createFlag is 1, the cache is marked as purgeable and the page is
|
||||
** not already in the cache, and if either of the following are true,
|
||||
** return NULL:
|
||||
**
|
||||
** (a) the number of pages pinned by the cache is greater than
|
||||
** PCache1.nMax, or
|
||||
** (b) the number of pages pinned by the cache is greater than
|
||||
** the sum of nMax for all purgeable caches, less the sum of
|
||||
** nMin for all other purgeable caches.
|
||||
**
|
||||
** 4. If none of the first three conditions apply and the cache is marked
|
||||
** as purgeable, and if one of the following is true:
|
||||
**
|
||||
** (a) The number of pages allocated for the cache is already
|
||||
** PCache1.nMax, or
|
||||
**
|
||||
** (b) The number of pages allocated for all purgeable caches is
|
||||
** already equal to or greater than the sum of nMax for all
|
||||
** purgeable caches,
|
||||
**
|
||||
** then attempt to recycle a page from the LRU list. If it is the right
|
||||
** size, return the recycled buffer. Otherwise, free the buffer and
|
||||
** proceed to step 5.
|
||||
**
|
||||
** 5. Otherwise, allocate and return a new page buffer.
|
||||
*/
|
||||
static void *pcache1Fetch(sqlite3_pcache *p, unsigned int iKey, int createFlag){
|
||||
unsigned int nPinned;
|
||||
PCache1 *pCache = (PCache1 *)p;
|
||||
PgHdr1 *pPage = 0;
|
||||
|
||||
pcache1EnterMutex();
|
||||
if( createFlag==1 ) sqlite3BeginBenignMalloc();
|
||||
|
||||
/* Search the hash table for an existing entry. */
|
||||
if( pCache->nHash>0 ){
|
||||
unsigned int h = iKey % pCache->nHash;
|
||||
for(pPage=pCache->apHash[h]; pPage&&pPage->iKey!=iKey; pPage=pPage->pNext);
|
||||
}
|
||||
|
||||
if( pPage || createFlag==0 ){
|
||||
pcache1PinPage(pPage);
|
||||
goto fetch_out;
|
||||
}
|
||||
|
||||
/* Step 3 of header comment. */
|
||||
nPinned = pCache->nPage - pCache->nRecyclable;
|
||||
if( createFlag==1 && pCache->bPurgeable && (
|
||||
nPinned>=(pcache1.nMaxPage+pCache->nMin-pcache1.nMinPage)
|
||||
|| nPinned>=(pCache->nMax)
|
||||
)){
|
||||
goto fetch_out;
|
||||
}
|
||||
|
||||
if( pCache->nPage>=pCache->nHash && pcache1ResizeHash(pCache) ){
|
||||
goto fetch_out;
|
||||
}
|
||||
|
||||
/* Step 4. Try to recycle a page buffer if appropriate. */
|
||||
if( pCache->bPurgeable && pcache1.pLruTail && (
|
||||
pCache->nPage>=pCache->nMax-1 || pcache1.nCurrentPage>=pcache1.nMaxPage
|
||||
)){
|
||||
pPage = pcache1.pLruTail;
|
||||
pcache1RemoveFromHash(pPage);
|
||||
pcache1PinPage(pPage);
|
||||
if( pPage->pCache->szPage!=pCache->szPage ){
|
||||
pcache1FreePage(pPage);
|
||||
pPage = 0;
|
||||
}else{
|
||||
pcache1.nCurrentPage -= (pPage->pCache->bPurgeable - pCache->bPurgeable);
|
||||
}
|
||||
}
|
||||
|
||||
/* Step 5. If a usable page buffer has still not been found,
|
||||
** attempt to allocate a new one.
|
||||
*/
|
||||
if( !pPage ){
|
||||
pPage = pcache1AllocPage(pCache);
|
||||
}
|
||||
|
||||
if( pPage ){
|
||||
unsigned int h = iKey % pCache->nHash;
|
||||
memset(pPage, 0, pCache->szPage + sizeof(PgHdr1));
|
||||
pCache->nPage++;
|
||||
pPage->iKey = iKey;
|
||||
pPage->pNext = pCache->apHash[h];
|
||||
pPage->pCache = pCache;
|
||||
pCache->apHash[h] = pPage;
|
||||
}
|
||||
|
||||
fetch_out:
|
||||
if( createFlag==1 ) sqlite3EndBenignMalloc();
|
||||
pcache1LeaveMutex();
|
||||
return (pPage ? PGHDR1_TO_PAGE(pPage) : 0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xUnpin method.
|
||||
**
|
||||
** Mark a page as unpinned (eligible for asynchronous recycling).
|
||||
*/
|
||||
static void pcache1Unpin(sqlite3_pcache *p, void *pPg, int reuseUnlikely){
|
||||
PCache1 *pCache = (PCache1 *)p;
|
||||
PgHdr1 *pPage = PAGE_TO_PGHDR1(pPg);
|
||||
|
||||
pcache1EnterMutex();
|
||||
|
||||
/* It is an error to call this function if the page is already
|
||||
** part of the global LRU list.
|
||||
*/
|
||||
assert( pPage->pLruPrev==0 && pPage->pLruNext==0 );
|
||||
assert( pcache1.pLruHead!=pPage && pcache1.pLruTail!=pPage );
|
||||
|
||||
if( reuseUnlikely || pcache1.nCurrentPage>pcache1.nMaxPage ){
|
||||
pcache1RemoveFromHash(pPage);
|
||||
pcache1FreePage(pPage);
|
||||
}else{
|
||||
/* Add the page to the global LRU list. Normally, the page is added to
|
||||
** the head of the list (last page to be recycled). However, if the
|
||||
** reuseUnlikely flag passed to this function is true, the page is added
|
||||
** to the tail of the list (first page to be recycled).
|
||||
*/
|
||||
if( pcache1.pLruHead ){
|
||||
pcache1.pLruHead->pLruPrev = pPage;
|
||||
pPage->pLruNext = pcache1.pLruHead;
|
||||
pcache1.pLruHead = pPage;
|
||||
}else{
|
||||
pcache1.pLruTail = pPage;
|
||||
pcache1.pLruHead = pPage;
|
||||
}
|
||||
pCache->nRecyclable++;
|
||||
}
|
||||
|
||||
pcache1LeaveMutex();
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xRekey method.
|
||||
*/
|
||||
static void pcache1Rekey(
|
||||
sqlite3_pcache *p,
|
||||
void *pPg,
|
||||
unsigned int iOld,
|
||||
unsigned int iNew
|
||||
){
|
||||
PCache1 *pCache = (PCache1 *)p;
|
||||
PgHdr1 *pPage = PAGE_TO_PGHDR1(pPg);
|
||||
PgHdr1 **pp;
|
||||
unsigned int h;
|
||||
assert( pPage->iKey==iOld );
|
||||
|
||||
pcache1EnterMutex();
|
||||
|
||||
h = iOld%pCache->nHash;
|
||||
pp = &pCache->apHash[h];
|
||||
while( (*pp)!=pPage ){
|
||||
pp = &(*pp)->pNext;
|
||||
}
|
||||
*pp = pPage->pNext;
|
||||
|
||||
h = iNew%pCache->nHash;
|
||||
pPage->iKey = iNew;
|
||||
pPage->pNext = pCache->apHash[h];
|
||||
pCache->apHash[h] = pPage;
|
||||
|
||||
pcache1LeaveMutex();
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xTruncate method.
|
||||
**
|
||||
** Discard all unpinned pages in the cache with a page number equal to
|
||||
** or greater than parameter iLimit. Any pinned pages with a page number
|
||||
** equal to or greater than iLimit are implicitly unpinned.
|
||||
*/
|
||||
static void pcache1Truncate(sqlite3_pcache *p, unsigned int iLimit){
|
||||
PCache1 *pCache = (PCache1 *)p;
|
||||
pcache1EnterMutex();
|
||||
pcache1TruncateUnsafe(pCache, iLimit);
|
||||
pcache1LeaveMutex();
|
||||
}
|
||||
|
||||
/*
|
||||
** Implementation of the sqlite3_pcache.xDestroy method.
|
||||
**
|
||||
** Destroy a cache allocated using pcache1Create().
|
||||
*/
|
||||
static void pcache1Destroy(sqlite3_pcache *p){
|
||||
PCache1 *pCache = (PCache1 *)p;
|
||||
pcache1EnterMutex();
|
||||
pcache1TruncateUnsafe(pCache, 0);
|
||||
pcache1.nMaxPage -= pCache->nMax;
|
||||
pcache1.nMinPage -= pCache->nMin;
|
||||
pcache1EnforceMaxPage();
|
||||
pcache1LeaveMutex();
|
||||
sqlite3_free(pCache->apHash);
|
||||
sqlite3_free(pCache);
|
||||
}
|
||||
|
||||
/*
|
||||
** This function is called during initialization (sqlite3_initialize()) to
|
||||
** install the default pluggable cache module, assuming the user has not
|
||||
** already provided an alternative.
|
||||
*/
|
||||
void sqlite3PCacheSetDefault(void){
|
||||
static sqlite3_pcache_methods defaultMethods = {
|
||||
0, /* pArg */
|
||||
pcache1Init, /* xInit */
|
||||
pcache1Shutdown, /* xShutdown */
|
||||
pcache1Create, /* xCreate */
|
||||
pcache1Cachesize, /* xCachesize */
|
||||
pcache1Pagecount, /* xPagecount */
|
||||
pcache1Fetch, /* xFetch */
|
||||
pcache1Unpin, /* xUnpin */
|
||||
pcache1Rekey, /* xRekey */
|
||||
pcache1Truncate, /* xTruncate */
|
||||
pcache1Destroy /* xDestroy */
|
||||
};
|
||||
sqlite3_config(SQLITE_CONFIG_PCACHE, &defaultMethods);
|
||||
}
|
||||
|
||||
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
|
||||
/*
|
||||
** This function is called to free superfluous dynamically allocated memory
|
||||
** held by the pager system. Memory in use by any SQLite pager allocated
|
||||
** by the current thread may be sqlite3_free()ed.
|
||||
**
|
||||
** nReq is the number of bytes of memory required. Once this much has
|
||||
** been released, the function returns. The return value is the total number
|
||||
** of bytes of memory released.
|
||||
*/
|
||||
int sqlite3PcacheReleaseMemory(int nReq){
|
||||
int nFree = 0;
|
||||
if( pcache1.pStart==0 ){
|
||||
PgHdr1 *p;
|
||||
pcache1EnterMutex();
|
||||
while( (nReq<0 || nFree<nReq) && (p=pcache1.pLruTail) ){
|
||||
nFree += sqlite3MallocSize(p);
|
||||
pcache1PinPage(p);
|
||||
pcache1RemoveFromHash(p);
|
||||
pcache1FreePage(p);
|
||||
}
|
||||
pcache1LeaveMutex();
|
||||
}
|
||||
return nFree;
|
||||
}
|
||||
#endif /* SQLITE_ENABLE_MEMORY_MANAGEMENT */
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
/*
|
||||
** This function is used by test procedures to inspect the internal state
|
||||
** of the global cache.
|
||||
*/
|
||||
void sqlite3PcacheStats(
|
||||
int *pnCurrent, /* OUT: Total number of pages cached */
|
||||
int *pnMax, /* OUT: Global maximum cache size */
|
||||
int *pnMin, /* OUT: Sum of PCache1.nMin for purgeable caches */
|
||||
int *pnRecyclable /* OUT: Total number of pages available for recycling */
|
||||
){
|
||||
PgHdr1 *p;
|
||||
int nRecyclable = 0;
|
||||
for(p=pcache1.pLruHead; p; p=p->pLruNext){
|
||||
nRecyclable++;
|
||||
}
|
||||
*pnCurrent = pcache1.nCurrentPage;
|
||||
*pnMax = pcache1.nMaxPage;
|
||||
*pnMin = pcache1.nMinPage;
|
||||
*pnRecyclable = nRecyclable;
|
||||
}
|
||||
#endif
|
||||
+3
-3
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the PRAGMA command.
|
||||
**
|
||||
** $Id: pragma.c,v 1.193 2008/11/10 19:24:38 shane Exp $
|
||||
** $Id: pragma.c,v 1.194 2008/11/17 19:18:55 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@@ -41,7 +41,7 @@ static int getSafetyLevel(const char *z){
|
||||
return atoi(z);
|
||||
}
|
||||
n = strlen(z);
|
||||
for(i=0; i<sizeof(iLength); i++){
|
||||
for(i=0; i<ArraySize(iLength); i++){
|
||||
if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0 ){
|
||||
return iValue[i];
|
||||
}
|
||||
@@ -191,7 +191,7 @@ static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
|
||||
};
|
||||
int i;
|
||||
const struct sPragmaType *p;
|
||||
for(i=0, p=aPragma; i<sizeof(aPragma)/sizeof(aPragma[0]); i++, p++){
|
||||
for(i=0, p=aPragma; i<ArraySize(aPragma); i++, p++){
|
||||
if( sqlite3StrICmp(zLeft, p->zName)==0 ){
|
||||
sqlite3 *db = pParse->db;
|
||||
Vdbe *v;
|
||||
|
||||
+5
-4
@@ -13,7 +13,7 @@
|
||||
** interface, and routines that contribute to loading the database schema
|
||||
** from disk.
|
||||
**
|
||||
** $Id: prepare.c,v 1.98 2008/10/31 10:53:23 danielk1977 Exp $
|
||||
** $Id: prepare.c,v 1.101 2008/11/19 16:52:44 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@@ -52,11 +52,13 @@ static void corruptSchema(
|
||||
** argv[2] = SQL text for the CREATE statement.
|
||||
**
|
||||
*/
|
||||
int sqlite3InitCallback(void *pInit, int argc, char **argv, char **azColName){
|
||||
int sqlite3InitCallback(void *pInit, int argc, char **argv, char **NotUsed){
|
||||
InitData *pData = (InitData*)pInit;
|
||||
sqlite3 *db = pData->db;
|
||||
int iDb = pData->iDb;
|
||||
|
||||
assert( argc==3 );
|
||||
UNUSED_PARAMETER2(NotUsed, argc);
|
||||
assert( sqlite3_mutex_held(db->mutex) );
|
||||
DbClearProperty(db, iDb, DB_Empty);
|
||||
if( db->mallocFailed ){
|
||||
@@ -64,7 +66,6 @@ int sqlite3InitCallback(void *pInit, int argc, char **argv, char **azColName){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
|
||||
assert( argc==3 );
|
||||
assert( iDb>=0 && iDb<db->nDb );
|
||||
if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
|
||||
if( argv[1]==0 ){
|
||||
@@ -244,7 +245,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
|
||||
*/
|
||||
if( rc==SQLITE_OK ){
|
||||
int i;
|
||||
for(i=0; i<sizeof(meta)/sizeof(meta[0]); i++){
|
||||
for(i=0; i<ArraySize(meta); i++){
|
||||
rc = sqlite3BtreeGetMeta(pDb->pBt, i+1, (u32 *)&meta[i]);
|
||||
if( rc ){
|
||||
sqlite3SetString(pzErrMsg, db, "%s", sqlite3ErrStr(rc));
|
||||
|
||||
+7
-5
@@ -5,7 +5,7 @@
|
||||
** an historical reference. Most of the "enhancements" have been backed
|
||||
** out so that the functionality is now the same as standard printf().
|
||||
**
|
||||
** $Id: printf.c,v 1.94 2008/08/22 14:08:36 drh Exp $
|
||||
** $Id: printf.c,v 1.96 2008/11/20 18:20:28 drh Exp $
|
||||
**
|
||||
**************************************************************************
|
||||
**
|
||||
@@ -137,7 +137,6 @@ static const et_info fmtinfo[] = {
|
||||
{ 'S', 0, 2, etSRCLIST, 0, 0 },
|
||||
{ 'r', 10, 3, etORDINAL, 0, 0 },
|
||||
};
|
||||
#define etNINFO (sizeof(fmtinfo)/sizeof(fmtinfo[0]))
|
||||
|
||||
/*
|
||||
** If SQLITE_OMIT_FLOATING_POINT is defined, then none of the floating point
|
||||
@@ -174,7 +173,7 @@ static int et_getdigit(LONGDOUBLE_TYPE *val, int *cnt){
|
||||
*/
|
||||
static void appendSpace(StrAccum *pAccum, int N){
|
||||
static const char zSpaces[] = " ";
|
||||
while( N>=sizeof(zSpaces)-1 ){
|
||||
while( N>=(int)sizeof(zSpaces)-1 ){
|
||||
sqlite3StrAccumAppend(pAccum, zSpaces, sizeof(zSpaces)-1);
|
||||
N -= sizeof(zSpaces)-1;
|
||||
}
|
||||
@@ -337,7 +336,7 @@ void sqlite3VXPrintf(
|
||||
}
|
||||
/* Fetch the info entry for the field */
|
||||
infop = 0;
|
||||
for(idx=0; idx<etNINFO; idx++){
|
||||
for(idx=0; idx<ArraySize(fmtinfo); idx++){
|
||||
if( c==fmtinfo[idx].fmttype ){
|
||||
infop = &fmtinfo[idx];
|
||||
if( useExtended || (infop->flags & FLAG_INTERN)==0 ){
|
||||
@@ -646,7 +645,10 @@ void sqlite3VXPrintf(
|
||||
n += i + 1 + needQuote*2;
|
||||
if( n>etBUFSIZE ){
|
||||
bufpt = zExtra = sqlite3Malloc( n );
|
||||
if( bufpt==0 ) return;
|
||||
if( bufpt==0 ){
|
||||
pAccum->mallocFailed = 1;
|
||||
return;
|
||||
}
|
||||
}else{
|
||||
bufpt = buf;
|
||||
}
|
||||
|
||||
+4
-4
@@ -14,7 +14,7 @@
|
||||
** resolve all identifiers by associating them with a particular
|
||||
** table and column.
|
||||
**
|
||||
** $Id: resolve.c,v 1.10 2008/10/19 21:03:27 drh Exp $
|
||||
** $Id: resolve.c,v 1.11 2008/11/17 19:18:55 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <stdlib.h>
|
||||
@@ -349,9 +349,9 @@ static int lookupName(
|
||||
*/
|
||||
if( pExpr->iColumn>=0 && pMatch!=0 ){
|
||||
int n = pExpr->iColumn;
|
||||
testcase( n==sizeof(Bitmask)*8-1 );
|
||||
if( n>=sizeof(Bitmask)*8 ){
|
||||
n = sizeof(Bitmask)*8-1;
|
||||
testcase( n==BMS-1 );
|
||||
if( n>=BMS ){
|
||||
n = BMS-1;
|
||||
}
|
||||
assert( pMatch->iCursor==pExpr->iTable );
|
||||
pMatch->colUsed |= ((Bitmask)1)<<n;
|
||||
|
||||
+7
-6
@@ -12,7 +12,7 @@
|
||||
** This file contains C code routines that are called by the parser
|
||||
** to handle SELECT statements in SQLite.
|
||||
**
|
||||
** $Id: select.c,v 1.484 2008/11/12 12:27:31 drh Exp $
|
||||
** $Id: select.c,v 1.486 2008/11/19 09:05:27 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -144,14 +144,14 @@ int sqlite3JoinType(Parse *pParse, Token *pA, Token *pB, Token *pC){
|
||||
apAll[2] = pC;
|
||||
for(i=0; i<3 && apAll[i]; i++){
|
||||
p = apAll[i];
|
||||
for(j=0; j<sizeof(keywords)/sizeof(keywords[0]); j++){
|
||||
for(j=0; j<ArraySize(keywords); j++){
|
||||
if( p->n==keywords[j].nChar
|
||||
&& sqlite3StrNICmp((char*)p->z, keywords[j].zKeyword, p->n)==0 ){
|
||||
jointype |= keywords[j].code;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( j>=sizeof(keywords)/sizeof(keywords[0]) ){
|
||||
if( j>=ArraySize(keywords) ){
|
||||
jointype |= JT_ERROR;
|
||||
break;
|
||||
}
|
||||
@@ -2921,7 +2921,7 @@ static int flattenSubquery(
|
||||
** 2. There is a single expression in the result set, and it is
|
||||
** either min(x) or max(x), where x is a column reference.
|
||||
*/
|
||||
static int minMaxQuery(Parse *pParse, Select *p){
|
||||
static int minMaxQuery(Select *p){
|
||||
Expr *pExpr;
|
||||
ExprList *pEList = p->pEList;
|
||||
|
||||
@@ -3221,7 +3221,8 @@ static int selectExpander(Walker *pWalker, Select *p){
|
||||
** Walker.xSelectCallback is set to do something useful for every
|
||||
** subquery in the parser tree.
|
||||
*/
|
||||
static int exprWalkNoop(Walker *pWalker, Expr *pExpr){
|
||||
static int exprWalkNoop(Walker *NotUsed, Expr *NotUsed2){
|
||||
UNUSED_PARAMETER2(NotUsed, NotUsed2);
|
||||
return WRC_Continue;
|
||||
}
|
||||
|
||||
@@ -4012,7 +4013,7 @@ int sqlite3Select(
|
||||
** satisfying the 'ORDER BY' clause than it does in other cases.
|
||||
** Refer to code and comments in where.c for details.
|
||||
*/
|
||||
flag = minMaxQuery(pParse, p);
|
||||
flag = minMaxQuery(p);
|
||||
if( flag ){
|
||||
pDel = pMinMax = sqlite3ExprListDup(db, p->pEList->a[0].pExpr->pList);
|
||||
if( pMinMax && !db->mallocFailed ){
|
||||
|
||||
+8
-4
@@ -12,7 +12,7 @@
|
||||
** This file contains code to implement the "sqlite" command line
|
||||
** utility for accessing SQLite databases.
|
||||
**
|
||||
** $Id: shell.c,v 1.187 2008/11/11 18:55:04 drh Exp $
|
||||
** $Id: shell.c,v 1.188 2008/11/17 08:05:32 chw Exp $
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -24,7 +24,9 @@
|
||||
|
||||
#if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__)
|
||||
# include <signal.h>
|
||||
# include <pwd.h>
|
||||
# if !defined(__RTP__) && !defined(_WRS_KERNEL)
|
||||
# include <pwd.h>
|
||||
# endif
|
||||
# include <unistd.h>
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
@@ -60,7 +62,7 @@ extern int isatty();
|
||||
#define isatty(x) 1
|
||||
#endif
|
||||
|
||||
#if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__)
|
||||
#if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) && !defined(__RTP__) && !defined(_WRS_KERNEL)
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
@@ -1773,7 +1775,7 @@ static int process_input(struct callback_data *p, FILE *in){
|
||||
static char *find_home_dir(void){
|
||||
char *home_dir = NULL;
|
||||
|
||||
#if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) && !defined(_WIN32_WCE)
|
||||
#if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) && !defined(_WIN32_WCE) && !defined(__RTP__) && !defined(_WRS_KERNEL)
|
||||
struct passwd *pwent;
|
||||
uid_t uid = getuid();
|
||||
if( (pwent=getpwuid(uid)) != NULL) {
|
||||
@@ -1843,7 +1845,9 @@ static void process_sqliterc(
|
||||
if (sqliterc == NULL) {
|
||||
home_dir = find_home_dir();
|
||||
if( home_dir==0 ){
|
||||
#if !defined(__RTP__) && !defined(_WRS_KERNEL)
|
||||
fprintf(stderr,"%s: cannot locate your home directory!\n", Argv0);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
nBuf = strlen(home_dir) + 16;
|
||||
|
||||
+161
-2
@@ -30,7 +30,7 @@
|
||||
** the version number) and changes its name to "sqlite3.h" as
|
||||
** part of the build process.
|
||||
**
|
||||
** @(#) $Id: sqlite.h.in,v 1.412 2008/11/10 23:54:06 drh Exp $
|
||||
** @(#) $Id: sqlite.h.in,v 1.415 2008/11/19 01:20:26 drh Exp $
|
||||
*/
|
||||
#ifndef _SQLITE3_H_
|
||||
#define _SQLITE3_H_
|
||||
@@ -1274,7 +1274,10 @@ struct sqlite3_mem_methods {
|
||||
**
|
||||
** <dt>SQLITE_CONFIG_PAGECACHE</dt>
|
||||
** <dd>This option specifies a static memory buffer that SQLite can use for
|
||||
** the database page cache. There are three arguments: A pointer to the
|
||||
** the database page cache with the default page cache implemenation.
|
||||
** This configuration should not be used if an application-define page
|
||||
** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option.
|
||||
** There are three arguments to this option: A pointer to the
|
||||
** memory, the size of each page buffer (sz), and the number of pages (N).
|
||||
** The sz argument must be a power of two between 512 and 32768. The first
|
||||
** argument should point to an allocation of at least sz*N bytes of memory.
|
||||
@@ -1319,6 +1322,17 @@ struct sqlite3_mem_methods {
|
||||
** size of each lookaside buffer slot and the second is the number of
|
||||
** slots allocated to each database connection.</dd>
|
||||
**
|
||||
** <dt>SQLITE_CONFIG_PCACHE</dt>
|
||||
** <dd>This option takes a single argument which is a pointer to
|
||||
** an [sqlite3_pcache_methods] object. This object specifies the interface
|
||||
** to a custom page cache implementation. SQLite makes a copy of the
|
||||
** object and uses it for page cache memory allocations.</dd>
|
||||
**
|
||||
** <dt>SQLITE_CONFIG_GETPCACHE</dt>
|
||||
** <dd>This option takes a single argument which is a pointer to an
|
||||
** [sqlite3_pcache_methods] object. SQLite copies of the current
|
||||
** page cache implementation into that object.</dd>
|
||||
**
|
||||
** </dl>
|
||||
*/
|
||||
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
|
||||
@@ -1334,6 +1348,8 @@ struct sqlite3_mem_methods {
|
||||
#define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */
|
||||
/* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
|
||||
#define SQLITE_CONFIG_LOOKASIDE 13 /* int int */
|
||||
#define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
|
||||
#define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
|
||||
|
||||
/*
|
||||
** CAPI3REF: Configuration Options {H10170} <S20000>
|
||||
@@ -6555,6 +6571,149 @@ SQLITE_EXPERIMENTAL int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
|
||||
#define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
|
||||
#define SQLITE_STMTSTATUS_SORT 2
|
||||
|
||||
/*
|
||||
** CAPI3REF: Custom Page Cache Object
|
||||
** EXPERIMENTAL
|
||||
**
|
||||
** The sqlite3_pcache type is opaque. It is implemented by
|
||||
** the pluggable module. The SQLite core has no knowledge of
|
||||
** its size or internal structure and never deals with the
|
||||
** sqlite3_pcache object except by holding and passing pointers
|
||||
** to the object.
|
||||
**
|
||||
** See [sqlite3_pcache_methods] for additional information.
|
||||
*/
|
||||
typedef struct sqlite3_pcache sqlite3_pcache;
|
||||
|
||||
/*
|
||||
** CAPI3REF: Application Defined Page Cache.
|
||||
** EXPERIMENTAL
|
||||
**
|
||||
** The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
|
||||
** register an alternative page cache implementation by passing in an
|
||||
** instance of the sqlite3_pcache_methods structure. The majority of the
|
||||
** heap memory used by sqlite is used by the page cache to cache data read
|
||||
** from, or ready to be written to, the database file. By implementing a
|
||||
** custom page cache using this API, an application can control more
|
||||
** precisely the amount of memory consumed by sqlite, the way in which
|
||||
** said memory is allocated and released, and the policies used to
|
||||
** determine exactly which parts of a database file are cached and for
|
||||
** how long.
|
||||
**
|
||||
** The contents of the structure are copied to an internal buffer by sqlite
|
||||
** within the call to [sqlite3_config].
|
||||
**
|
||||
** The xInit() method is called once for each call to [sqlite3_initialize()]
|
||||
** (usually only once during the lifetime of the process). It is passed
|
||||
** a copy of the sqlite3_pcache_methods.pArg value. It can be used to set
|
||||
** up global structures and mutexes required by the custom page cache
|
||||
** implementation. The xShutdown() method is called from within
|
||||
** [sqlite3_shutdown()], if the application invokes this API. It can be used
|
||||
** to clean up any outstanding resources before process shutdown, if required.
|
||||
**
|
||||
** The xCreate() method is used to construct a new cache instance. The
|
||||
** first parameter, szPage, is the size in bytes of the pages that must
|
||||
** be allocated by the cache. szPage will not be a power of two. The
|
||||
** second argument, bPurgeable, is true if the cache being created will
|
||||
** be used to cache database pages read from a file stored on disk, or
|
||||
** false if it is used for an in-memory database. The cache implementation
|
||||
** does not have to do anything special based on the value of bPurgeable,
|
||||
** it is purely advisory.
|
||||
**
|
||||
** The xCachesize() method may be called at any time by SQLite to set the
|
||||
** suggested maximum cache-size (number of pages stored by) the cache
|
||||
** instance passed as the first argument. This is the value configured using
|
||||
** the SQLite "[PRAGMA cache_size]" command. As with the bPurgeable parameter,
|
||||
** the implementation is not required to do anything special with this
|
||||
** value, it is advisory only.
|
||||
**
|
||||
** The xPagecount() method should return the number of pages currently
|
||||
** stored in the cache supplied as an argument.
|
||||
**
|
||||
** The xFetch() method is used to fetch a page and return a pointer to it.
|
||||
** A 'page', in this context, is a buffer of szPage bytes aligned at an
|
||||
** 8-byte boundary. The page to be fetched is determined by the key. The
|
||||
** mimimum key value is 1. After it has been retrieved using xFetch, the page
|
||||
** is considered to be pinned.
|
||||
**
|
||||
** If the requested page is already in the page cache, then a pointer to
|
||||
** the cached buffer should be returned with its contents intact. If the
|
||||
** page is not already in the cache, then the expected behaviour of the
|
||||
** cache is determined by the value of the createFlag parameter passed
|
||||
** to xFetch, according to the following table:
|
||||
**
|
||||
** <table border=1 width=85% align=center>
|
||||
** <tr><th>createFlag<th>Expected Behaviour
|
||||
** <tr><td>0<td>NULL should be returned. No new cache entry is created.
|
||||
** <tr><td>1<td>If createFlag is set to 1, this indicates that
|
||||
** SQLite is holding pinned pages that can be unpinned
|
||||
** by writing their contents to the database file (a
|
||||
** relatively expensive operation). In this situation the
|
||||
** cache implementation has two choices: it can return NULL,
|
||||
** in which case SQLite will attempt to unpin one or more
|
||||
** pages before re-requesting the same page, or it can
|
||||
** allocate a new page and return a pointer to it. If a new
|
||||
** page is allocated, then it must be completely zeroed before
|
||||
** it is returned.
|
||||
** <tr><td>2<td>If createFlag is set to 2, then SQLite is not holding any
|
||||
** pinned pages associated with the specific cache passed
|
||||
** as the first argument to xFetch() that can be unpinned. The
|
||||
** cache implementation should attempt to allocate a new
|
||||
** cache entry and return a pointer to it. Again, the new
|
||||
** page should be zeroed before it is returned. If the xFetch()
|
||||
** method returns NULL when createFlag==2, SQLite assumes that
|
||||
** a memory allocation failed and returns SQLITE_NOMEM to the
|
||||
** user.
|
||||
** </table>
|
||||
**
|
||||
** xUnpin() is called by SQLite with a pointer to a currently pinned page
|
||||
** as its second argument. If the third parameter, discard, is non-zero,
|
||||
** then the page should be evicted from the cache. In this case SQLite
|
||||
** assumes that the next time the page is retrieved from the cache using
|
||||
** the xFetch() method, it will be zeroed. If the discard parameter is
|
||||
** zero, then the page is considered to be unpinned. The cache implementation
|
||||
** may choose to reclaim (free or recycle) unpinned pages at any time.
|
||||
** SQLite assumes that next time the page is retrieved from the cache
|
||||
** it will either be zeroed, or contain the same data that it did when it
|
||||
** was unpinned.
|
||||
**
|
||||
** The cache is not required to perform any reference counting. A single
|
||||
** call to xUnpin() unpins the page regardless of the number of prior calls
|
||||
** to xFetch().
|
||||
**
|
||||
** The xRekey() method is used to change the key value associated with the
|
||||
** page passed as the second argument from oldKey to newKey. If the cache
|
||||
** previously contains an entry associated with newKey, it should be
|
||||
** discarded. Any prior cache entry associated with newKey is guaranteed not
|
||||
** to be pinned.
|
||||
**
|
||||
** When SQLite calls the xTruncate() method, the cache must discard all
|
||||
** existing cache entries with page numbers (keys) greater than or equal
|
||||
** to the value of the iLimit parameter passed to xTruncate(). If any
|
||||
** of these pages are pinned, they are implicitly unpinned, meaning that
|
||||
** they can be safely discarded.
|
||||
**
|
||||
** The xDestroy() method is used to delete a cache allocated by xCreate().
|
||||
** All resources associated with the specified cache should be freed. After
|
||||
** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
|
||||
** handle invalid, and will not use it with any other sqlite3_pcache_methods
|
||||
** functions.
|
||||
*/
|
||||
typedef struct sqlite3_pcache_methods sqlite3_pcache_methods;
|
||||
struct sqlite3_pcache_methods {
|
||||
void *pArg;
|
||||
int (*xInit)(void*);
|
||||
void (*xShutdown)(void*);
|
||||
sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable);
|
||||
void (*xCachesize)(sqlite3_pcache*, int nCachesize);
|
||||
int (*xPagecount)(sqlite3_pcache*);
|
||||
void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
|
||||
void (*xUnpin)(sqlite3_pcache*, void*, int discard);
|
||||
void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey);
|
||||
void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
|
||||
void (*xDestroy)(sqlite3_pcache*);
|
||||
};
|
||||
|
||||
/*
|
||||
** Undo the hack that converts floating point types to integer for
|
||||
** builds on processors without floating point support.
|
||||
|
||||
+47
-15
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** Internal interface definitions for SQLite.
|
||||
**
|
||||
** @(#) $Id: sqliteInt.h,v 1.790 2008/11/11 18:29:00 drh Exp $
|
||||
** @(#) $Id: sqliteInt.h,v 1.798 2008/11/19 16:52:44 danielk1977 Exp $
|
||||
*/
|
||||
#ifndef _SQLITEINT_H_
|
||||
#define _SQLITEINT_H_
|
||||
@@ -444,7 +444,7 @@ struct BusyHandler {
|
||||
** A convenience macro that returns the number of elements in
|
||||
** an array.
|
||||
*/
|
||||
#define ArraySize(X) (sizeof(X)/sizeof(X[0]))
|
||||
#define ArraySize(X) ((int)(sizeof(X)/sizeof(X[0])))
|
||||
|
||||
/*
|
||||
** The following value as a destructor means to use sqlite3DbFree().
|
||||
@@ -478,6 +478,25 @@ struct BusyHandler {
|
||||
#define sqlite3GlobalConfig sqlite3Config
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The following macros are used to suppress compiler warnings and to
|
||||
** make it clear to human readers when a function parameter is deliberately
|
||||
** left unused within the body of a function. This usually happens when
|
||||
** a function is called via a function pointer. For example the
|
||||
** implementation of an SQL aggregate step callback may not use the
|
||||
** parameter indicating the number of arguments passed to the aggregate,
|
||||
** if it knows that this is enforced elsewhere.
|
||||
**
|
||||
** When a function parameter is not used at all within the body of a function,
|
||||
** it is generally named "NotUsed" or "NotUsed2" to make things even clearer.
|
||||
** However, these macros may also be used to suppress warnings related to
|
||||
** parameters that may or may not be used depending on compilation options.
|
||||
** For example those parameters only used in assert() statements. In these
|
||||
** cases the parameters are named as per the usual conventions.
|
||||
*/
|
||||
#define UNUSED_PARAMETER(x) (void)(x)
|
||||
#define UNUSED_PARAMETER2(x,y) UNUSED_PARAMETER(x),UNUSED_PARAMETER(y)
|
||||
|
||||
/*
|
||||
** Forward references to structures
|
||||
*/
|
||||
@@ -685,7 +704,7 @@ struct sqlite3 {
|
||||
CollSeq *pDfltColl; /* The default collating sequence (BINARY) */
|
||||
i64 lastRowid; /* ROWID of most recent insert (see above) */
|
||||
i64 priorNewRowid; /* Last randomly generated ROWID */
|
||||
int magic; /* Magic number for detect library misuse */
|
||||
u32 magic; /* Magic number for detect library misuse */
|
||||
int nChange; /* Value returned by sqlite3_changes() */
|
||||
int nTotalChange; /* Value returned by sqlite3_total_changes() */
|
||||
sqlite3_mutex *mutex; /* Connection mutex */
|
||||
@@ -848,13 +867,13 @@ struct FuncDef {
|
||||
** parameter.
|
||||
*/
|
||||
#define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
|
||||
{nArg, SQLITE_UTF8, bNC*8, SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName}
|
||||
{nArg, SQLITE_UTF8, bNC*8, SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0}
|
||||
#define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
|
||||
{nArg, SQLITE_UTF8, bNC*8, pArg, 0, xFunc, 0, 0, #zName}
|
||||
{nArg, SQLITE_UTF8, bNC*8, pArg, 0, xFunc, 0, 0, #zName, 0}
|
||||
#define LIKEFUNC(zName, nArg, arg, flags) \
|
||||
{nArg, SQLITE_UTF8, flags, (void *)arg, 0, likeFunc, 0, 0, #zName}
|
||||
{nArg, SQLITE_UTF8, flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0}
|
||||
#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
|
||||
{nArg, SQLITE_UTF8, nc*8, SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal, #zName}
|
||||
{nArg, SQLITE_UTF8, nc*8, SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0}
|
||||
|
||||
|
||||
/*
|
||||
@@ -1423,6 +1442,11 @@ struct IdList {
|
||||
*/
|
||||
typedef u64 Bitmask;
|
||||
|
||||
/*
|
||||
** The number of bits in a Bitmask. "BMS" means "BitMask Size".
|
||||
*/
|
||||
#define BMS ((int)(sizeof(Bitmask)*8))
|
||||
|
||||
/*
|
||||
** The following structure describes the FROM clause of a SELECT statement.
|
||||
** Each table or subquery in the FROM clause is a separate element of
|
||||
@@ -1958,6 +1982,7 @@ struct Sqlite3Config {
|
||||
int nLookaside; /* Default lookaside buffer count */
|
||||
sqlite3_mem_methods m; /* Low-level memory allocation interface */
|
||||
sqlite3_mutex_methods mutex; /* Low-level mutex interface */
|
||||
sqlite3_pcache_methods pcache; /* Low-level page-cache interface */
|
||||
void *pHeap; /* Heap storage space */
|
||||
int nHeap; /* Size of pHeap[] */
|
||||
int mnReq, mxReq; /* Min and max heap requests sizes */
|
||||
@@ -2054,11 +2079,17 @@ void sqlite3ScratchFree(void*);
|
||||
void *sqlite3PageMalloc(int);
|
||||
void sqlite3PageFree(void*);
|
||||
void sqlite3MemSetDefault(void);
|
||||
const sqlite3_mem_methods *sqlite3MemGetMemsys3(void);
|
||||
const sqlite3_mem_methods *sqlite3MemGetMemsys5(void);
|
||||
void sqlite3BenignMallocHooks(void (*)(void), void (*)(void));
|
||||
int sqlite3MemoryAlarm(void (*)(void*, sqlite3_int64, int), void*, sqlite3_int64);
|
||||
|
||||
#ifdef SQLITE_ENABLE_MEMSYS3
|
||||
const sqlite3_mem_methods *sqlite3MemGetMemsys3(void);
|
||||
#endif
|
||||
#ifdef SQLITE_ENABLE_MEMSYS5
|
||||
const sqlite3_mem_methods *sqlite3MemGetMemsys5(void);
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef SQLITE_MUTEX_OMIT
|
||||
sqlite3_mutex_methods *sqlite3DefaultMutex(void);
|
||||
sqlite3_mutex *sqlite3MutexAlloc(int);
|
||||
@@ -2217,7 +2248,7 @@ void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int*);
|
||||
int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int);
|
||||
void sqlite3GenerateConstraintChecks(Parse*,Table*,int,int,
|
||||
int*,int,int,int,int);
|
||||
void sqlite3CompleteInsertion(Parse*, Table*, int, int, int*,int,int,int,int);
|
||||
void sqlite3CompleteInsertion(Parse*, Table*, int, int, int*, int, int, int);
|
||||
int sqlite3OpenTableAndIndices(Parse*, Table*, int, int);
|
||||
void sqlite3BeginWriteOperation(Parse*, int, int);
|
||||
Expr *sqlite3ExprDup(sqlite3*,Expr*);
|
||||
@@ -2231,7 +2262,6 @@ FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,int);
|
||||
void sqlite3RegisterBuiltinFunctions(sqlite3*);
|
||||
void sqlite3RegisterDateTimeFunctions(void);
|
||||
void sqlite3RegisterGlobalFunctions(void);
|
||||
int sqlite3GetBuiltinFunction(const char *, int, FuncDef **);
|
||||
#ifdef SQLITE_DEBUG
|
||||
int sqlite3SafetyOn(sqlite3*);
|
||||
int sqlite3SafetyOff(sqlite3*);
|
||||
@@ -2253,7 +2283,7 @@ void sqlite3MaterializeView(Parse*, Table*, Expr*, int);
|
||||
void sqlite3FinishTrigger(Parse*, TriggerStep*, Token*);
|
||||
void sqlite3DropTrigger(Parse*, SrcList*, int);
|
||||
void sqlite3DropTriggerPtr(Parse*, Trigger*);
|
||||
int sqlite3TriggersExist(Parse*, Table*, int, ExprList*);
|
||||
int sqlite3TriggersExist(Table*, int, ExprList*);
|
||||
int sqlite3CodeRowTrigger(Parse*, int, ExprList*, int, Table *, int, int,
|
||||
int, int, u32*, u32*);
|
||||
void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*);
|
||||
@@ -2266,7 +2296,7 @@ void sqlite3MaterializeView(Parse*, Table*, Expr*, int);
|
||||
void sqlite3DeleteTrigger(sqlite3*, Trigger*);
|
||||
void sqlite3UnlinkAndDeleteTrigger(sqlite3*,int,const char*);
|
||||
#else
|
||||
# define sqlite3TriggersExist(A,B,C,D,E,F) 0
|
||||
# define sqlite3TriggersExist(B,C,D,E,F) 0
|
||||
# define sqlite3DeleteTrigger(A,B)
|
||||
# define sqlite3DropTriggerPtr(A,B)
|
||||
# define sqlite3UnlinkAndDeleteTrigger(A,B,C)
|
||||
@@ -2334,8 +2364,8 @@ int sqlite3VarintLen(u64 v);
|
||||
** x = putVarint32( A, B );
|
||||
**
|
||||
*/
|
||||
#define getVarint32(A,B) ((*(A)<(unsigned char)0x80) ? ((B) = (u32)*(A)),1 : sqlite3GetVarint32((A), &(B)))
|
||||
#define putVarint32(A,B) (((B)<(u32)0x80) ? (*(A) = (unsigned char)(B)),1 : sqlite3PutVarint32((A), (B)))
|
||||
#define getVarint32(A,B) ((*(A)<(unsigned char)0x80) ? ((B) = (u32)*(A)),1 : sqlite3GetVarint32((A), (u32 *)&(B)))
|
||||
#define putVarint32(A,B) (((u32)(B)<(u32)0x80) ? (*(A) = (unsigned char)(B)),1 : sqlite3PutVarint32((A), (B)))
|
||||
#define getVarint sqlite3GetVarint
|
||||
#define putVarint sqlite3PutVarint
|
||||
|
||||
@@ -2446,11 +2476,13 @@ int sqlite3AutoLoadExtensions(sqlite3*);
|
||||
# define sqlite3VtabSync(X,Y) SQLITE_OK
|
||||
# define sqlite3VtabRollback(X)
|
||||
# define sqlite3VtabCommit(X)
|
||||
# define sqlite3VtabInSync(db) 0
|
||||
#else
|
||||
void sqlite3VtabClear(Table*);
|
||||
int sqlite3VtabSync(sqlite3 *db, char **);
|
||||
int sqlite3VtabRollback(sqlite3 *db);
|
||||
int sqlite3VtabCommit(sqlite3 *db);
|
||||
# define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
|
||||
#endif
|
||||
void sqlite3VtabMakeWritable(Parse*,Table*);
|
||||
void sqlite3VtabLock(sqlite3_vtab*);
|
||||
|
||||
+39
-2
@@ -13,7 +13,7 @@
|
||||
** This file contains code used to implement test interfaces to the
|
||||
** memory allocation subsystem.
|
||||
**
|
||||
** $Id: test_malloc.c,v 1.50 2008/11/10 18:05:36 shane Exp $
|
||||
** $Id: test_malloc.c,v 1.51 2008/11/19 01:20:26 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "tcl.h"
|
||||
@@ -945,6 +945,42 @@ static int test_config_pagecache(
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite3_config_alt_pcache INSTALL_FLAG DISCARD_CHANCE PRNG_SEED
|
||||
**
|
||||
** Set up the alternative test page cache. Install if INSTALL_FLAG is
|
||||
** true and uninstall (reverting to the default page cache) if INSTALL_FLAG
|
||||
** is false. DISCARD_CHANGE is an integer between 0 and 100 inclusive
|
||||
** which determines the chance of discarding a page when unpinned. 100
|
||||
** is certainty. 0 is never. PRNG_SEED is the pseudo-random number generator
|
||||
** seed.
|
||||
*/
|
||||
static int test_alt_pcache(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
int installFlag;
|
||||
int discardChance;
|
||||
int prngSeed;
|
||||
extern void installTestPCache(int,unsigned,unsigned);
|
||||
if( objc!=4 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "INSTALLFLAG DISCARDCHANCE PRNGSEEED");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetIntFromObj(interp, objv[1], &installFlag) ) return TCL_ERROR;
|
||||
if( Tcl_GetIntFromObj(interp, objv[2], &discardChance) ) return TCL_ERROR;
|
||||
if( Tcl_GetIntFromObj(interp, objv[3], &prngSeed) ) return TCL_ERROR;
|
||||
if( discardChance<0 || discardChance>100 ){
|
||||
Tcl_AppendResult(interp, "discard-chance should be between 0 and 100",
|
||||
(char*)0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
installTestPCache(installFlag, (unsigned)discardChance, (unsigned)prngSeed);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite3_config_memstatus BOOLEAN
|
||||
**
|
||||
@@ -1312,6 +1348,7 @@ int Sqlitetest_malloc_Init(Tcl_Interp *interp){
|
||||
{ "sqlite3_memdebug_log", test_memdebug_log ,0 },
|
||||
{ "sqlite3_config_scratch", test_config_scratch ,0 },
|
||||
{ "sqlite3_config_pagecache", test_config_pagecache ,0 },
|
||||
{ "sqlite3_config_alt_pcache", test_alt_pcache ,0 },
|
||||
{ "sqlite3_status", test_status ,0 },
|
||||
{ "sqlite3_db_status", test_db_status ,0 },
|
||||
{ "install_malloc_faultsim", test_install_malloc_faultsim ,0 },
|
||||
@@ -1321,7 +1358,7 @@ int Sqlitetest_malloc_Init(Tcl_Interp *interp){
|
||||
{ "sqlite3_config_error", test_config_error ,0 },
|
||||
{ "sqlite3_db_config_lookaside",test_db_config_lookaside ,0 },
|
||||
{ "sqlite3_dump_memsys3", test_dump_memsys3 ,3 },
|
||||
{ "sqlite3_dump_memsys5", test_dump_memsys3 ,5 }
|
||||
{ "sqlite3_dump_memsys5", test_dump_memsys3 ,5 },
|
||||
};
|
||||
int i;
|
||||
for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
|
||||
|
||||
@@ -0,0 +1,438 @@
|
||||
/*
|
||||
** 2008 November 18
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
**
|
||||
** This file contains code used for testing the SQLite system.
|
||||
** None of the code in this file goes into a deliverable build.
|
||||
**
|
||||
** This file contains an application-defined pager cache
|
||||
** implementation that can be plugged in in place of the
|
||||
** default pcache. This alternative pager cache will throw
|
||||
** some errors that the default cache does not.
|
||||
**
|
||||
** This pagecache implementation is designed for simplicity
|
||||
** not speed.
|
||||
**
|
||||
** $Id: test_pcache.c,v 1.1 2008/11/19 01:20:26 drh Exp $
|
||||
*/
|
||||
#include "sqlite3.h"
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
/*
|
||||
** Global data used by this test implementation. There is no
|
||||
** mutexing, which means this page cache will not work in a
|
||||
** multi-threaded test.
|
||||
*/
|
||||
typedef struct testpcacheGlobalType testpcacheGlobalType;
|
||||
struct testpcacheGlobalType {
|
||||
void *pDummy; /* Dummy allocation to simulate failures */
|
||||
int nInstance; /* Number of current instances */
|
||||
unsigned discardChance; /* Chance of discarding on an unpin */
|
||||
unsigned prngSeed; /* Seed for the PRNG */
|
||||
};
|
||||
static testpcacheGlobalType testpcacheGlobal;
|
||||
|
||||
/*
|
||||
** Initializer.
|
||||
**
|
||||
** Verify that the initializer is only called when the system is
|
||||
** uninitialized. Allocate some memory and report SQLITE_NOMEM if
|
||||
** the allocation fails. This provides a means to test the recovery
|
||||
** from a failed initialization attempt. It also verifies that the
|
||||
** the destructor always gets call - otherwise there would be a
|
||||
** memory leak.
|
||||
*/
|
||||
static int testpcacheInit(void *pArg){
|
||||
assert( pArg==(void*)&testpcacheGlobal );
|
||||
assert( testpcacheGlobal.pDummy==0 );
|
||||
assert( testpcacheGlobal.nInstance==0 );
|
||||
testpcacheGlobal.pDummy = sqlite3_malloc(10);
|
||||
return testpcacheGlobal.pDummy==0 ? SQLITE_NOMEM : SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Destructor
|
||||
**
|
||||
** Verify that this is only called after initialization.
|
||||
** Free the memory allocated by the initializer.
|
||||
*/
|
||||
static void testpcacheShutdown(void *pArg){
|
||||
assert( pArg==(void*)&testpcacheGlobal );
|
||||
assert( testpcacheGlobal.pDummy!=0 );
|
||||
assert( testpcacheGlobal.nInstance==0 );
|
||||
sqlite3_free( testpcacheGlobal.pDummy );
|
||||
testpcacheGlobal.pDummy = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Number of pages in a cache
|
||||
*/
|
||||
#define TESTPCACHE_NPAGE 217
|
||||
#define TESTPCACHE_RESERVE 17
|
||||
|
||||
/*
|
||||
** Magic numbers used to determine validity of the page cache.
|
||||
*/
|
||||
#define TESTPCACHE_VALID 0x364585fd
|
||||
#define TESTPCACHE_CLEAR 0xd42670d4
|
||||
|
||||
/*
|
||||
** Private implementation of a page cache.
|
||||
*/
|
||||
typedef struct testpcache testpcache;
|
||||
struct testpcache {
|
||||
int szPage; /* Size of each page. Multiple of 8. */
|
||||
int bPurgeable; /* True if the page cache is purgeable */
|
||||
int nFree; /* Number of unused slots in a[] */
|
||||
int nPinned; /* Number of pinned slots in a[] */
|
||||
unsigned iRand; /* State of the PRNG */
|
||||
unsigned iMagic; /* Magic number for sanity checking */
|
||||
struct testpcachePage {
|
||||
unsigned key; /* The key for this page. 0 means unallocated */
|
||||
int isPinned; /* True if the page is pinned */
|
||||
void *pData; /* Data for this page */
|
||||
} a[TESTPCACHE_NPAGE]; /* All pages in the cache */
|
||||
};
|
||||
|
||||
/*
|
||||
** Get a random number using the PRNG in the given page cache.
|
||||
*/
|
||||
static unsigned testpcacheRandom(testpcache *p){
|
||||
unsigned x = 0;
|
||||
int i;
|
||||
for(i=0; i<4; i++){
|
||||
p->iRand = (p->iRand*69069 + 5);
|
||||
x = (x<<8) | ((p->iRand>>16)&0xff);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Allocate a new page cache instance.
|
||||
*/
|
||||
static sqlite3_pcache *testpcacheCreate(int szPage, int bPurgeable){
|
||||
int nMem;
|
||||
char *x;
|
||||
testpcache *p;
|
||||
int i;
|
||||
assert( testpcacheGlobal.pDummy!=0 );
|
||||
szPage = (szPage+7)&~7;
|
||||
nMem = sizeof(testpcache) + TESTPCACHE_NPAGE*szPage;
|
||||
p = sqlite3_malloc( nMem );
|
||||
if( p==0 ) return 0;
|
||||
x = (char*)&p[1];
|
||||
p->szPage = szPage;
|
||||
p->nFree = TESTPCACHE_NPAGE;
|
||||
p->nPinned = 0;
|
||||
p->iRand = testpcacheGlobal.prngSeed;
|
||||
p->bPurgeable = bPurgeable;
|
||||
p->iMagic = TESTPCACHE_VALID;
|
||||
for(i=0; i<TESTPCACHE_NPAGE; i++, x += szPage){
|
||||
p->a[i].key = 0;
|
||||
p->a[i].isPinned = 0;
|
||||
p->a[i].pData = (void*)x;
|
||||
}
|
||||
testpcacheGlobal.nInstance++;
|
||||
return (sqlite3_pcache*)p;
|
||||
}
|
||||
|
||||
/*
|
||||
** Set the cache size
|
||||
*/
|
||||
static void testpcacheCachesize(sqlite3_pcache *pCache, int newSize){
|
||||
testpcache *p = (testpcache*)pCache;
|
||||
assert( p->iMagic==TESTPCACHE_VALID );
|
||||
assert( newSize>=1 );
|
||||
assert( testpcacheGlobal.pDummy!=0 );
|
||||
assert( testpcacheGlobal.nInstance>0 );
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the number of pages in the cache that are being used.
|
||||
** This includes both pinned and unpinned pages.
|
||||
*/
|
||||
static int testpcachePagecount(sqlite3_pcache *pCache){
|
||||
testpcache *p = (testpcache*)pCache;
|
||||
assert( p->iMagic==TESTPCACHE_VALID );
|
||||
assert( testpcacheGlobal.pDummy!=0 );
|
||||
assert( testpcacheGlobal.nInstance>0 );
|
||||
return TESTPCACHE_NPAGE - p->nFree;
|
||||
}
|
||||
|
||||
/*
|
||||
** Fetch a page.
|
||||
*/
|
||||
static void *testpcacheFetch(
|
||||
sqlite3_pcache *pCache,
|
||||
unsigned key,
|
||||
int createFlag
|
||||
){
|
||||
testpcache *p = (testpcache*)pCache;
|
||||
int i, j;
|
||||
assert( p->iMagic==TESTPCACHE_VALID );
|
||||
assert( testpcacheGlobal.pDummy!=0 );
|
||||
assert( testpcacheGlobal.nInstance>0 );
|
||||
|
||||
/* See if the page is already in cache. Return immediately if it is */
|
||||
for(i=0; i<TESTPCACHE_NPAGE; i++){
|
||||
if( p->a[i].key==key ){
|
||||
if( !p->a[i].isPinned ){
|
||||
p->nPinned++;
|
||||
assert( p->nPinned <= TESTPCACHE_NPAGE - p->nFree );
|
||||
p->a[i].isPinned = 1;
|
||||
}
|
||||
return p->a[i].pData;
|
||||
}
|
||||
}
|
||||
|
||||
/* If createFlag is 0, never allocate a new page */
|
||||
if( createFlag==0 ){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* If no pages are available, always fail */
|
||||
if( p->nPinned==TESTPCACHE_NPAGE ){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Do not allocate the last TESTPCACHE_RESERVE pages unless createFlag is 2 */
|
||||
if( p->nPinned>=TESTPCACHE_NPAGE-TESTPCACHE_RESERVE && createFlag<2 ){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Find a free page to allocate if there are any free pages.
|
||||
** Withhold TESTPCACHE_RESERVE free pages until createFlag is 2.
|
||||
*/
|
||||
if( p->nFree>TESTPCACHE_RESERVE || (createFlag==2 && p->nFree>0) ){
|
||||
j = testpcacheRandom(p) % TESTPCACHE_NPAGE;
|
||||
for(i=0; i<TESTPCACHE_NPAGE; i++, j = (j+1)%TESTPCACHE_NPAGE){
|
||||
if( p->a[j].key==0 ){
|
||||
p->a[j].key = key;
|
||||
p->a[j].isPinned = 1;
|
||||
memset(p->a[j].pData, 0, p->szPage);
|
||||
p->nPinned++;
|
||||
p->nFree--;
|
||||
assert( p->nPinned <= TESTPCACHE_NPAGE - p->nFree );
|
||||
return p->a[j].pData;
|
||||
}
|
||||
}
|
||||
|
||||
/* The prior loop always finds a freepage to allocate */
|
||||
assert( 0 );
|
||||
}
|
||||
|
||||
/* If this cache is not purgeable then we have to fail.
|
||||
*/
|
||||
if( p->bPurgeable==0 ){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* If there are no free pages, recycle a page. The page to
|
||||
** recycle is selected at random from all unpinned pages.
|
||||
*/
|
||||
j = testpcacheRandom(p) % TESTPCACHE_NPAGE;
|
||||
for(i=0; i<TESTPCACHE_NPAGE; i++, j = (j+1)%TESTPCACHE_NPAGE){
|
||||
if( p->a[j].key>0 && p->a[j].isPinned==0 ){
|
||||
p->a[j].key = key;
|
||||
p->a[j].isPinned = 1;
|
||||
memset(p->a[j].pData, 0, p->szPage);
|
||||
p->nPinned++;
|
||||
assert( p->nPinned <= TESTPCACHE_NPAGE - p->nFree );
|
||||
return p->a[j].pData;
|
||||
}
|
||||
}
|
||||
|
||||
/* The previous loop always finds a page to recycle. */
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Unpin a page.
|
||||
*/
|
||||
static void testpcacheUnpin(
|
||||
sqlite3_pcache *pCache,
|
||||
void *pOldPage,
|
||||
int discard
|
||||
){
|
||||
testpcache *p = (testpcache*)pCache;
|
||||
int i;
|
||||
assert( p->iMagic==TESTPCACHE_VALID );
|
||||
assert( testpcacheGlobal.pDummy!=0 );
|
||||
assert( testpcacheGlobal.nInstance>0 );
|
||||
|
||||
/* Randomly discard pages as they are unpinned according to the
|
||||
** discardChance setting. If discardChance is 0, the random discard
|
||||
** never happens. If discardChance is 100, it always happens.
|
||||
*/
|
||||
if( p->bPurgeable
|
||||
&& (100-testpcacheGlobal.discardChance) <= (testpcacheRandom(p)%100)
|
||||
){
|
||||
discard = 1;
|
||||
}
|
||||
|
||||
for(i=0; i<TESTPCACHE_NPAGE; i++){
|
||||
if( p->a[i].pData==pOldPage ){
|
||||
/* The pOldPage pointer always points to a pinned page */
|
||||
assert( p->a[i].isPinned );
|
||||
p->a[i].isPinned = 0;
|
||||
p->nPinned--;
|
||||
assert( p->nPinned>=0 );
|
||||
if( discard ){
|
||||
p->a[i].key = 0;
|
||||
p->nFree++;
|
||||
assert( p->nFree<=TESTPCACHE_NPAGE );
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* The pOldPage pointer always points to a valid page */
|
||||
assert( 0 );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Rekey a single page.
|
||||
*/
|
||||
static void testpcacheRekey(
|
||||
sqlite3_pcache *pCache,
|
||||
void *pOldPage,
|
||||
unsigned oldKey,
|
||||
unsigned newKey
|
||||
){
|
||||
testpcache *p = (testpcache*)pCache;
|
||||
int i;
|
||||
assert( p->iMagic==TESTPCACHE_VALID );
|
||||
assert( testpcacheGlobal.pDummy!=0 );
|
||||
assert( testpcacheGlobal.nInstance>0 );
|
||||
|
||||
/* If there already exists another page at newKey, verify that
|
||||
** the other page is unpinned and discard it.
|
||||
*/
|
||||
for(i=0; i<TESTPCACHE_NPAGE; i++){
|
||||
if( p->a[i].key==newKey ){
|
||||
/* The new key is never a page that is already pinned */
|
||||
assert( p->a[i].isPinned==0 );
|
||||
p->a[i].key = 0;
|
||||
p->nFree++;
|
||||
assert( p->nFree<=TESTPCACHE_NPAGE );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Find the page to be rekeyed and rekey it.
|
||||
*/
|
||||
for(i=0; i<TESTPCACHE_NPAGE; i++){
|
||||
if( p->a[i].key==oldKey ){
|
||||
/* The oldKey and pOldPage parameters match */
|
||||
assert( p->a[i].pData==pOldPage );
|
||||
/* Page to be rekeyed must be pinned */
|
||||
assert( p->a[i].isPinned );
|
||||
p->a[i].key = newKey;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Rekey is always given a valid page to work with */
|
||||
assert( 0 );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Truncate the page cache. Every page with a key of iLimit or larger
|
||||
** is discarded.
|
||||
*/
|
||||
static void testpcacheTruncate(sqlite3_pcache *pCache, unsigned iLimit){
|
||||
testpcache *p = (testpcache*)pCache;
|
||||
unsigned int i;
|
||||
assert( p->iMagic==TESTPCACHE_VALID );
|
||||
assert( testpcacheGlobal.pDummy!=0 );
|
||||
assert( testpcacheGlobal.nInstance>0 );
|
||||
for(i=0; i<TESTPCACHE_NPAGE; i++){
|
||||
if( p->a[i].key>=iLimit ){
|
||||
p->a[i].key = 0;
|
||||
if( p->a[i].isPinned ){
|
||||
p->nPinned--;
|
||||
assert( p->nPinned>=0 );
|
||||
}
|
||||
p->nFree++;
|
||||
assert( p->nFree<=TESTPCACHE_NPAGE );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Destroy a page cache.
|
||||
*/
|
||||
static void testpcacheDestroy(sqlite3_pcache *pCache){
|
||||
testpcache *p = (testpcache*)pCache;
|
||||
assert( p->iMagic==TESTPCACHE_VALID );
|
||||
assert( testpcacheGlobal.pDummy!=0 );
|
||||
assert( testpcacheGlobal.nInstance>0 );
|
||||
p->iMagic = TESTPCACHE_CLEAR;
|
||||
sqlite3_free(p);
|
||||
testpcacheGlobal.nInstance--;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Invoke this routine to register or unregister the testing pager cache
|
||||
** implemented by this file.
|
||||
**
|
||||
** Install the test pager cache if installFlag is 1 and uninstall it if
|
||||
** installFlag is 0.
|
||||
**
|
||||
** When installing, discardChance is a number between 0 and 100 that
|
||||
** indicates the probability of discarding a page when unpinning the
|
||||
** page. 0 means never discard (unless the discard flag is set).
|
||||
** 100 means always discard.
|
||||
*/
|
||||
void installTestPCache(
|
||||
int installFlag, /* True to install. False to uninstall. */
|
||||
unsigned discardChance, /* 0-100. Chance to discard on unpin */
|
||||
unsigned prngSeed /* Seed for the PRNG */
|
||||
){
|
||||
static const sqlite3_pcache_methods testPcache = {
|
||||
(void*)&testpcacheGlobal,
|
||||
testpcacheInit,
|
||||
testpcacheShutdown,
|
||||
testpcacheCreate,
|
||||
testpcacheCachesize,
|
||||
testpcachePagecount,
|
||||
testpcacheFetch,
|
||||
testpcacheUnpin,
|
||||
testpcacheRekey,
|
||||
testpcacheTruncate,
|
||||
testpcacheDestroy,
|
||||
};
|
||||
static sqlite3_pcache_methods defaultPcache;
|
||||
static int isInstalled = 0;
|
||||
|
||||
assert( testpcacheGlobal.nInstance==0 );
|
||||
assert( testpcacheGlobal.pDummy==0 );
|
||||
assert( discardChance<=100 );
|
||||
testpcacheGlobal.discardChance = discardChance;
|
||||
testpcacheGlobal.prngSeed = prngSeed ^ (prngSeed<<16);
|
||||
if( installFlag!=isInstalled ){
|
||||
if( installFlag ){
|
||||
sqlite3_config(SQLITE_CONFIG_GETPCACHE, &defaultPcache);
|
||||
assert( defaultPcache.xCreate!=testpcacheCreate );
|
||||
sqlite3_config(SQLITE_CONFIG_PCACHE, &testPcache);
|
||||
}else{
|
||||
assert( defaultPcache.xCreate!=0 );
|
||||
sqlite3_config(SQLITE_CONFIG_PCACHE, &defaultPcache);
|
||||
}
|
||||
isInstalled = installFlag;
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -10,7 +10,7 @@
|
||||
*************************************************************************
|
||||
**
|
||||
**
|
||||
** $Id: trigger.c,v 1.129 2008/08/20 16:35:10 drh Exp $
|
||||
** $Id: trigger.c,v 1.130 2008/11/19 09:05:27 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -603,7 +603,6 @@ static int checkColumnOverLap(IdList *pIdList, ExprList *pEList){
|
||||
** TRIGGER_AFTER.
|
||||
*/
|
||||
int sqlite3TriggersExist(
|
||||
Parse *pParse, /* Used to check for recursive triggers */
|
||||
Table *pTab, /* The table the contains the triggers */
|
||||
int op, /* one of TK_DELETE, TK_INSERT, TK_UPDATE */
|
||||
ExprList *pChanges /* Columns that change in an UPDATE statement */
|
||||
|
||||
+3
-3
@@ -12,7 +12,7 @@
|
||||
** This file contains C code routines that are called by the parser
|
||||
** to handle UPDATE statements.
|
||||
**
|
||||
** $Id: update.c,v 1.186 2008/10/31 10:53:23 danielk1977 Exp $
|
||||
** $Id: update.c,v 1.187 2008/11/19 09:05:27 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -142,7 +142,7 @@ void sqlite3Update(
|
||||
** updated is a view
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
triggers_exist = sqlite3TriggersExist(pParse, pTab, TK_UPDATE, pChanges);
|
||||
triggers_exist = sqlite3TriggersExist(pTab, TK_UPDATE, pChanges);
|
||||
isView = pTab->pSelect!=0;
|
||||
#else
|
||||
# define triggers_exist 0
|
||||
@@ -525,7 +525,7 @@ void sqlite3Update(
|
||||
/* Create the new index entries and the new record.
|
||||
*/
|
||||
sqlite3CompleteInsertion(pParse, pTab, iCur, regNewRowid,
|
||||
aRegIdx, chngRowid, 1, -1, 0);
|
||||
aRegIdx, 1, -1, 0);
|
||||
}
|
||||
|
||||
/* Increment the row counter
|
||||
|
||||
+4
-4
@@ -14,7 +14,7 @@
|
||||
** This file contains functions for allocating memory, comparing
|
||||
** strings, and stuff like that.
|
||||
**
|
||||
** $Id: util.c,v 1.241 2008/07/28 19:34:54 drh Exp $
|
||||
** $Id: util.c,v 1.242 2008/11/17 19:18:55 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <stdarg.h>
|
||||
@@ -57,7 +57,7 @@ int sqlite3IsNaN(double x){
|
||||
int sqlite3Strlen(sqlite3 *db, const char *z){
|
||||
const char *z2 = z;
|
||||
int len;
|
||||
size_t x;
|
||||
int x;
|
||||
while( *z2 ){ z2++; }
|
||||
x = z2 - z;
|
||||
len = 0x7fffffff & x;
|
||||
@@ -934,7 +934,7 @@ int sqlite3SafetyOff(sqlite3 *db){
|
||||
** used as an argument to sqlite3_errmsg() or sqlite3_close().
|
||||
*/
|
||||
int sqlite3SafetyCheckOk(sqlite3 *db){
|
||||
int magic;
|
||||
u32 magic;
|
||||
if( db==0 ) return 0;
|
||||
magic = db->magic;
|
||||
if( magic!=SQLITE_MAGIC_OPEN &&
|
||||
@@ -942,7 +942,7 @@ int sqlite3SafetyCheckOk(sqlite3 *db){
|
||||
return 1;
|
||||
}
|
||||
int sqlite3SafetyCheckSickOrOk(sqlite3 *db){
|
||||
int magic;
|
||||
u32 magic;
|
||||
if( db==0 ) return 0;
|
||||
magic = db->magic;
|
||||
if( magic!=SQLITE_MAGIC_SICK &&
|
||||
|
||||
+2
-2
@@ -14,7 +14,7 @@
|
||||
** Most of the code in this file may be omitted by defining the
|
||||
** SQLITE_OMIT_VACUUM macro.
|
||||
**
|
||||
** $Id: vacuum.c,v 1.83 2008/08/26 21:07:27 drh Exp $
|
||||
** $Id: vacuum.c,v 1.84 2008/11/17 19:18:55 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
@@ -251,7 +251,7 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
|
||||
assert( 1==sqlite3BtreeIsInTrans(pMain) );
|
||||
|
||||
/* Copy Btree meta values */
|
||||
for(i=0; i<sizeof(aCopy)/sizeof(aCopy[0]); i+=2){
|
||||
for(i=0; i<ArraySize(aCopy); i+=2){
|
||||
rc = sqlite3BtreeGetMeta(pMain, aCopy[i], &meta);
|
||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||
rc = sqlite3BtreeUpdateMeta(pTemp, aCopy[i], meta+aCopy[i+1]);
|
||||
|
||||
+13
-11
@@ -43,7 +43,7 @@
|
||||
** in this file for details. If in doubt, do not deviate from existing
|
||||
** commenting and indentation practices when changing or adding code.
|
||||
**
|
||||
** $Id: vdbe.c,v 1.786 2008/11/05 16:37:35 drh Exp $
|
||||
** $Id: vdbe.c,v 1.788 2008/11/17 15:31:48 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@@ -177,7 +177,7 @@ static const unsigned char opcodeProperty[] = OPFLG_INITIALIZER;
|
||||
** specified by mask.
|
||||
*/
|
||||
int sqlite3VdbeOpcodeHasProperty(int opcode, int mask){
|
||||
assert( opcode>0 && opcode<sizeof(opcodeProperty) );
|
||||
assert( opcode>0 && opcode<(int)sizeof(opcodeProperty) );
|
||||
return (opcodeProperty[opcode]&mask)!=0;
|
||||
}
|
||||
|
||||
@@ -552,7 +552,6 @@ int sqlite3VdbeExec(
|
||||
#endif
|
||||
UnpackedRecord aTempRec[16]; /* Space to hold a transient UnpackedRecord */
|
||||
|
||||
|
||||
assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
|
||||
assert( db->magic==SQLITE_MAGIC_BUSY );
|
||||
sqlite3BtreeMutexArrayEnter(&p->aMutex);
|
||||
@@ -1964,7 +1963,7 @@ case OP_SetNumColumns: {
|
||||
** the result.
|
||||
*/
|
||||
case OP_Column: {
|
||||
u32 payloadSize; /* Number of bytes in the record */
|
||||
int payloadSize; /* Number of bytes in the record */
|
||||
int p1 = pOp->p1; /* P1 value of the opcode */
|
||||
int p2 = pOp->p2; /* column number to retrieve */
|
||||
VdbeCursor *pC = 0;/* The VDBE cursor */
|
||||
@@ -1972,7 +1971,7 @@ case OP_Column: {
|
||||
BtCursor *pCrsr; /* The BTree cursor */
|
||||
u32 *aType; /* aType[i] holds the numeric type of the i-th column */
|
||||
u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
|
||||
u32 nField; /* number of fields in the record */
|
||||
int nField; /* number of fields in the record */
|
||||
int len; /* The length of the serialized data for the column */
|
||||
int i; /* Loop counter */
|
||||
char *zData; /* Part of the record being decoded */
|
||||
@@ -2020,7 +2019,7 @@ case OP_Column: {
|
||||
sqlite3BtreeKeySize(pCrsr, &payloadSize64);
|
||||
payloadSize = payloadSize64;
|
||||
}else{
|
||||
sqlite3BtreeDataSize(pCrsr, &payloadSize);
|
||||
sqlite3BtreeDataSize(pCrsr, (u32 *)&payloadSize);
|
||||
}
|
||||
nField = pC->nField;
|
||||
}else{
|
||||
@@ -2054,7 +2053,7 @@ case OP_Column: {
|
||||
}else{
|
||||
u8 *zIdx; /* Index into header */
|
||||
u8 *zEndHdr; /* Pointer to first byte after the header */
|
||||
u32 offset; /* Offset into the data */
|
||||
int offset; /* Offset into the data */
|
||||
int szHdrSz; /* Size of the header size field at start of record */
|
||||
int avail; /* Number of bytes of available data */
|
||||
|
||||
@@ -2255,7 +2254,7 @@ case OP_MakeRecord: {
|
||||
Mem *pRec; /* The new record */
|
||||
u64 nData = 0; /* Number of bytes of data space */
|
||||
int nHdr = 0; /* Number of bytes of header space */
|
||||
u64 nByte = 0; /* Data space required for this record */
|
||||
i64 nByte = 0; /* Data space required for this record */
|
||||
int nZero = 0; /* Number of zero bytes at the end of the record */
|
||||
int nVarint; /* Number of bytes in a varint */
|
||||
u32 serial_type; /* Type field */
|
||||
@@ -2698,7 +2697,10 @@ case OP_OpenWrite: {
|
||||
pIn2 = &p->aMem[p2];
|
||||
sqlite3VdbeMemIntegerify(pIn2);
|
||||
p2 = pIn2->u.i;
|
||||
assert( p2>=2 );
|
||||
if( p2<2 ) {
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
goto abort_due_to_error;
|
||||
}
|
||||
}
|
||||
assert( i>=0 );
|
||||
pCur = allocateCursor(p, i, &pOp[-1], iDb, 1);
|
||||
@@ -3325,7 +3327,7 @@ case OP_NewRowid: { /* out2-prerelease */
|
||||
** Others complain about 0x7ffffffffffffffffLL. The following macro seems
|
||||
** to provide the constant while making all compilers happy.
|
||||
*/
|
||||
# define MAX_ROWID ( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
|
||||
# define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
|
||||
#endif
|
||||
|
||||
if( !pC->useRandomRowid ){
|
||||
@@ -3631,7 +3633,7 @@ case OP_RowData: {
|
||||
n = n64;
|
||||
}else{
|
||||
sqlite3BtreeDataSize(pCrsr, &n);
|
||||
if( n>db->aLimit[SQLITE_LIMIT_LENGTH] ){
|
||||
if( (int)n>db->aLimit[SQLITE_LIMIT_LENGTH] ){
|
||||
goto too_big;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@
|
||||
** 6000 lines long) it was split up into several smaller files and
|
||||
** this header information was factored out.
|
||||
**
|
||||
** $Id: vdbeInt.h,v 1.157 2008/11/05 16:37:35 drh Exp $
|
||||
** $Id: vdbeInt.h,v 1.158 2008/11/17 15:31:48 danielk1977 Exp $
|
||||
*/
|
||||
#ifndef _VDBEINT_H_
|
||||
#define _VDBEINT_H_
|
||||
@@ -296,7 +296,7 @@ struct Vdbe {
|
||||
Mem *aVar; /* Values for the OP_Variable opcode. */
|
||||
char **azVar; /* Name of variables */
|
||||
int okVar; /* True if azVar[] has been initialized */
|
||||
int magic; /* Magic number for sanity checking */
|
||||
u32 magic; /* Magic number for sanity checking */
|
||||
int nMem; /* Number of memory locations currently allocated */
|
||||
Mem *aMem; /* The memory locations */
|
||||
int nCallback; /* Number of callbacks invoked so far */
|
||||
|
||||
+4
-3
@@ -13,7 +13,7 @@
|
||||
** This file contains code use to implement APIs that are part of the
|
||||
** VDBE.
|
||||
**
|
||||
** $Id: vdbeapi.c,v 1.148 2008/11/05 16:37:35 drh Exp $
|
||||
** $Id: vdbeapi.c,v 1.149 2008/11/19 09:05:27 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
@@ -601,11 +601,12 @@ sqlite3 *sqlite3_context_db_handle(sqlite3_context *p){
|
||||
*/
|
||||
void sqlite3InvalidFunction(
|
||||
sqlite3_context *context, /* The function calling context */
|
||||
int argc, /* Number of arguments to the function */
|
||||
sqlite3_value **argv /* Value of each argument */
|
||||
int NotUsed, /* Number of arguments to the function */
|
||||
sqlite3_value **NotUsed2 /* Value of each argument */
|
||||
){
|
||||
const char *zName = context->pFunc->zName;
|
||||
char *zErr;
|
||||
UNUSED_PARAMETER2(NotUsed, NotUsed2);
|
||||
zErr = sqlite3MPrintf(0,
|
||||
"unable to use function %s in the requested context", zName);
|
||||
sqlite3_result_error(context, zErr, -1);
|
||||
|
||||
+24
-29
@@ -14,7 +14,7 @@
|
||||
** to version 2.8.7, all this code was combined into the vdbe.c source file.
|
||||
** But that file was getting too big so this subroutines were split out.
|
||||
**
|
||||
** $Id: vdbeaux.c,v 1.418 2008/11/05 17:41:19 drh Exp $
|
||||
** $Id: vdbeaux.c,v 1.420 2008/11/17 19:18:55 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@@ -100,21 +100,23 @@ void sqlite3VdbeTrace(Vdbe *p, FILE *trace){
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Resize the Vdbe.aOp array so that it contains at least N
|
||||
** elements.
|
||||
** Resize the Vdbe.aOp array so that it is at least one op larger than
|
||||
** it was.
|
||||
**
|
||||
** If an out-of-memory error occurs while resizing the array,
|
||||
** Vdbe.aOp and Vdbe.nOpAlloc remain unchanged (this is so that
|
||||
** any opcodes already allocated can be correctly deallocated
|
||||
** along with the rest of the Vdbe).
|
||||
** If an out-of-memory error occurs while resizing the array, return
|
||||
** SQLITE_NOMEM. In this case Vdbe.aOp and Vdbe.nOpAlloc remain
|
||||
** unchanged (this is so that any opcodes already allocated can be
|
||||
** correctly deallocated along with the rest of the Vdbe).
|
||||
*/
|
||||
static void resizeOpArray(Vdbe *p, int N){
|
||||
static int growOpArray(Vdbe *p){
|
||||
VdbeOp *pNew;
|
||||
pNew = sqlite3DbRealloc(p->db, p->aOp, N*sizeof(Op));
|
||||
int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op)));
|
||||
pNew = sqlite3DbRealloc(p->db, p->aOp, nNew*sizeof(Op));
|
||||
if( pNew ){
|
||||
p->nOpAlloc = N;
|
||||
p->nOpAlloc = nNew;
|
||||
p->aOp = pNew;
|
||||
}
|
||||
return (pNew ? SQLITE_OK : SQLITE_NOMEM);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -140,8 +142,7 @@ int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){
|
||||
i = p->nOp;
|
||||
assert( p->magic==VDBE_MAGIC_INIT );
|
||||
if( p->nOpAlloc<=i ){
|
||||
resizeOpArray(p, p->nOpAlloc ? p->nOpAlloc*2 : 1024/sizeof(Op));
|
||||
if( p->db->mallocFailed ){
|
||||
if( growOpArray(p) ){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -342,11 +343,7 @@ int sqlite3VdbeCurrentAddr(Vdbe *p){
|
||||
int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){
|
||||
int addr;
|
||||
assert( p->magic==VDBE_MAGIC_INIT );
|
||||
if( p->nOp + nOp > p->nOpAlloc ){
|
||||
resizeOpArray(p, p->nOpAlloc ? p->nOpAlloc*2 : 1024/sizeof(Op));
|
||||
assert( p->nOp+nOp<=p->nOpAlloc || p->db->mallocFailed );
|
||||
}
|
||||
if( p->db->mallocFailed ){
|
||||
if( p->nOp + nOp > p->nOpAlloc && growOpArray(p) ){
|
||||
return 0;
|
||||
}
|
||||
addr = p->nOp;
|
||||
@@ -731,7 +728,7 @@ static char *displayP4(Op *pOp, char *zTemp, int nTemp){
|
||||
void sqlite3VdbeUsesBtree(Vdbe *p, int i){
|
||||
int mask;
|
||||
assert( i>=0 && i<p->db->nDb );
|
||||
assert( i<sizeof(p->btreeMask)*8 );
|
||||
assert( i<(int)sizeof(p->btreeMask)*8 );
|
||||
mask = 1<<i;
|
||||
if( (p->btreeMask & mask)==0 ){
|
||||
p->btreeMask |= mask;
|
||||
@@ -1017,11 +1014,7 @@ void sqlite3VdbeMakeReady(
|
||||
*/
|
||||
assert( p->nOp>0 );
|
||||
|
||||
/* Set the magic to VDBE_MAGIC_RUN sooner rather than later. This
|
||||
* is because the call to resizeOpArray() below may shrink the
|
||||
* p->aOp[] array to save memory if called when in VDBE_MAGIC_RUN
|
||||
* state.
|
||||
*/
|
||||
/* Set the magic to VDBE_MAGIC_RUN sooner rather than later. */
|
||||
p->magic = VDBE_MAGIC_RUN;
|
||||
|
||||
/* For each cursor required, also allocate a memory cell. Memory
|
||||
@@ -1041,7 +1034,6 @@ void sqlite3VdbeMakeReady(
|
||||
if( p->aMem==0 ){
|
||||
int nArg; /* Maximum number of args passed to a user function. */
|
||||
resolveP2Values(p, &nArg);
|
||||
/*resizeOpArray(p, p->nOp);*/
|
||||
assert( nVar>=0 );
|
||||
if( isExplain && nMem<10 ){
|
||||
nMem = 10;
|
||||
@@ -1585,7 +1577,10 @@ int sqlite3VdbeHalt(Vdbe *p){
|
||||
** Note: This block also runs if one of the special errors handled
|
||||
** above has occurred.
|
||||
*/
|
||||
if( db->autoCommit && db->writeVdbeCnt==(p->readOnly==0) ){
|
||||
if( !sqlite3VtabInSync(db)
|
||||
&& db->autoCommit
|
||||
&& db->writeVdbeCnt==(p->readOnly==0)
|
||||
){
|
||||
if( p->rc==SQLITE_OK || (p->errorAction==OE_Fail && !isSpecialError) ){
|
||||
/* The auto-commit flag is true, and the vdbe program was
|
||||
** successful or hit an 'OR FAIL' constraint. This means a commit
|
||||
@@ -2212,8 +2207,8 @@ UnpackedRecord *sqlite3VdbeRecordUnpack(
|
||||
){
|
||||
const unsigned char *aKey = (const unsigned char *)pKey;
|
||||
UnpackedRecord *p;
|
||||
int nByte;
|
||||
int idx, d;
|
||||
int nByte, d;
|
||||
u32 idx;
|
||||
u16 u; /* Unsigned loop counter */
|
||||
u32 szHdr;
|
||||
Mem *pMem;
|
||||
@@ -2237,7 +2232,7 @@ UnpackedRecord *sqlite3VdbeRecordUnpack(
|
||||
while( idx<szHdr && u<p->nField ){
|
||||
u32 serial_type;
|
||||
|
||||
idx += getVarint32( aKey+idx, serial_type);
|
||||
idx += getVarint32(&aKey[idx], serial_type);
|
||||
if( d>=nKey && sqlite3VdbeSerialTypeLen(serial_type)>0 ) break;
|
||||
pMem->enc = pKeyInfo->enc;
|
||||
pMem->db = pKeyInfo->db;
|
||||
@@ -2302,7 +2297,7 @@ int sqlite3VdbeRecordCompare(
|
||||
int nKey1, const void *pKey1, /* Left key */
|
||||
UnpackedRecord *pPKey2 /* Right key */
|
||||
){
|
||||
u32 d1; /* Offset into aKey[] of next data element */
|
||||
int d1; /* Offset into aKey[] of next data element */
|
||||
u32 idx1; /* Offset into aKey[] of next header element */
|
||||
u32 szHdr1; /* Number of bytes in header */
|
||||
int i = 0;
|
||||
|
||||
+3
-3
@@ -12,7 +12,7 @@
|
||||
** This file implements a FIFO queue of rowids used for processing
|
||||
** UPDATE and DELETE statements.
|
||||
**
|
||||
** $Id: vdbefifo.c,v 1.8 2008/07/28 19:34:54 drh Exp $
|
||||
** $Id: vdbefifo.c,v 1.9 2008/11/17 19:18:55 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
@@ -24,9 +24,9 @@
|
||||
*/
|
||||
#define FIFOSIZE_FIRST (((128-sizeof(FifoPage))/8)+1)
|
||||
#ifdef SQLITE_MALLOC_SOFT_LIMIT
|
||||
# define FIFOSIZE_MAX (((SQLITE_MALLOC_SOFT_LIMIT-sizeof(FifoPage))/8)+1)
|
||||
# define FIFOSIZE_MAX (int)(((SQLITE_MALLOC_SOFT_LIMIT-sizeof(FifoPage))/8)+1)
|
||||
#else
|
||||
# define FIFOSIZE_MAX (((262144-sizeof(FifoPage))/8)+1)
|
||||
# define FIFOSIZE_MAX (int)(((262144-sizeof(FifoPage))/8)+1)
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
||||
+4
-2
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** This file contains code used to help implement virtual tables.
|
||||
**
|
||||
** $Id: vtab.c,v 1.76 2008/08/20 16:35:10 drh Exp $
|
||||
** $Id: vtab.c,v 1.78 2008/11/13 19:12:36 danielk1977 Exp $
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
#include "sqliteInt.h"
|
||||
@@ -46,6 +46,8 @@ static int createModule(
|
||||
db->mallocFailed = 1;
|
||||
}
|
||||
sqlite3ResetInternalSchema(db, 0);
|
||||
}else if( xDestroy ){
|
||||
xDestroy(pAux);
|
||||
}
|
||||
rc = sqlite3ApiExit(db, SQLITE_OK);
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
@@ -710,7 +712,7 @@ int sqlite3VtabBegin(sqlite3 *db, sqlite3_vtab *pVtab){
|
||||
** virtual module xSync() callback. It is illegal to write to
|
||||
** virtual module tables in this case, so return SQLITE_LOCKED.
|
||||
*/
|
||||
if( 0==db->aVTrans && db->nVTrans>0 ){
|
||||
if( sqlite3VtabInSync(db) ){
|
||||
return SQLITE_LOCKED;
|
||||
}
|
||||
if( !pVtab ){
|
||||
|
||||
+3
-8
@@ -16,15 +16,10 @@
|
||||
** so is applicable. Because this module is responsible for selecting
|
||||
** indices, you might also think of this module as the "query optimizer".
|
||||
**
|
||||
** $Id: where.c,v 1.328 2008/11/03 09:06:06 danielk1977 Exp $
|
||||
** $Id: where.c,v 1.330 2008/11/17 19:18:55 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** The number of bits in a Bitmask. "BMS" means "BitMask Size".
|
||||
*/
|
||||
#define BMS (sizeof(Bitmask)*8)
|
||||
|
||||
/*
|
||||
** Trace output macros
|
||||
*/
|
||||
@@ -139,7 +134,7 @@ struct WhereClause {
|
||||
*/
|
||||
struct ExprMaskSet {
|
||||
int n; /* Number of assigned cursor values */
|
||||
int ix[sizeof(Bitmask)*8]; /* Cursor assigned to each bit */
|
||||
int ix[BMS]; /* Cursor assigned to each bit */
|
||||
};
|
||||
|
||||
|
||||
@@ -2320,7 +2315,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
if( (pLevel->flags & WHERE_IDX_ONLY)==0 ){
|
||||
int op = pWInfo->okOnePass ? OP_OpenWrite : OP_OpenRead;
|
||||
sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, op);
|
||||
if( !pWInfo->okOnePass && pTab->nCol<(sizeof(Bitmask)*8) ){
|
||||
if( !pWInfo->okOnePass && pTab->nCol<BMS ){
|
||||
Bitmask b = pTabItem->colUsed;
|
||||
int n = 0;
|
||||
for(; b; b=b>>1, n++){}
|
||||
|
||||
+1
-5
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# Unit testing of the Bitvec object.
|
||||
#
|
||||
# $Id: bitvec.test,v 1.2 2008/03/21 16:45:48 drh Exp $
|
||||
# $Id: bitvec.test,v 1.3 2008/11/19 18:30:35 shane Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -185,7 +185,3 @@ for {set n 1} {$go} {incr n} {
|
||||
|
||||
finish_test
|
||||
return
|
||||
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
+143
-30
@@ -15,21 +15,19 @@
|
||||
# data base file, then tests that single byte corruptions in
|
||||
# increasingly larger quantities are handled gracefully.
|
||||
#
|
||||
# $Id: corruptC.test,v 1.7 2008/11/12 14:22:25 danielk1977 Exp $
|
||||
# $Id: corruptC.test,v 1.10 2008/11/19 18:43:07 drh Exp $
|
||||
|
||||
catch {file delete -force test.db test.db-journal test.bu}
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Set a uniform random seed
|
||||
expr srand(0)
|
||||
|
||||
# Construct a compact, dense database for testing.
|
||||
#
|
||||
do_test corruptC-1.1 {
|
||||
execsql {
|
||||
PRAGMA auto_vacuum = 0;
|
||||
PRAGMA legacy_file_format=1;
|
||||
BEGIN;
|
||||
CREATE TABLE t1(x,y);
|
||||
INSERT INTO t1 VALUES(1,1);
|
||||
@@ -52,19 +50,13 @@ ifcapable {integrityck} {
|
||||
# Generate random integer
|
||||
#
|
||||
proc random {range} {
|
||||
return [expr {round(rand()*$range)}]
|
||||
return [expr {round(rand()*$range)}]
|
||||
}
|
||||
|
||||
# Copy file $from into $to
|
||||
#
|
||||
proc copy_file {from to} {
|
||||
set f [open $from]
|
||||
fconfigure $f -translation binary
|
||||
set t [open $to w]
|
||||
fconfigure $t -translation binary
|
||||
puts -nonewline $t [read $f [file size $from]]
|
||||
close $t
|
||||
close $f
|
||||
file copy -force $from $to
|
||||
}
|
||||
|
||||
# Setup for the tests. Make a backup copy of the good database in test.bu.
|
||||
@@ -74,8 +66,22 @@ copy_file test.db test.bu
|
||||
sqlite3 db test.db
|
||||
set fsize [file size test.db]
|
||||
|
||||
# Set a quasi-random random seed.
|
||||
if {[info exists SOAKTEST]} {
|
||||
# If we are doing SOAK tests, we want a different
|
||||
# random seed for each run. Ideally we would like
|
||||
# to use [clock clicks] or something like that here.
|
||||
set qseed [file mtime test.db]
|
||||
} else {
|
||||
# If we are not doing soak tests,
|
||||
# make it repeatable.
|
||||
set qseed 0
|
||||
}
|
||||
expr srand($qseed)
|
||||
|
||||
#
|
||||
# first test some specific corruption tests found from earlier runs
|
||||
# First test some specific corruption tests found from earlier runs
|
||||
# with specific seeds.
|
||||
#
|
||||
|
||||
# test that a corrupt content offset size is handled (seed 5577)
|
||||
@@ -150,8 +156,8 @@ do_test corruptC-2.5 {
|
||||
catchsql {PRAGMA integrity_check}
|
||||
} {0 {{*** in database main ***
|
||||
Corruption detected in cell 710 on page 4
|
||||
Multiple uses for byte 116 of page 4
|
||||
Fragmented space is 0 byte reported as 21 on page 4}}}
|
||||
Multiple uses for byte 661 of page 4
|
||||
Fragmented space is 249 byte reported as 21 on page 4}}}
|
||||
|
||||
# test that a corrupt free cell size is handled (seed 169595)
|
||||
do_test corruptC-2.6 {
|
||||
@@ -166,13 +172,98 @@ do_test corruptC-2.6 {
|
||||
catchsql {BEGIN; UPDATE t2 SET y='abcdef-uvwxyz'; ROLLBACK;}
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
# corruption (seed 178692)
|
||||
do_test corruptC-2.7 {
|
||||
db close
|
||||
copy_file test.bu test.db
|
||||
|
||||
# insert corrupt byte(s)
|
||||
hexio_write test.db 3074 [format %02x 0xa0]
|
||||
|
||||
sqlite3 db test.db
|
||||
catchsql {BEGIN; UPDATE t2 SET y='abcdef-uvwxyz'; ROLLBACK;}
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
# corruption (seed 179069)
|
||||
do_test corruptC-2.8 {
|
||||
db close
|
||||
copy_file test.bu test.db
|
||||
|
||||
# insert corrupt byte(s)
|
||||
hexio_write test.db 1393 [format %02x 0x7d]
|
||||
hexio_write test.db 84 [format %02x 0x19]
|
||||
hexio_write test.db 3287 [format %02x 0x3b]
|
||||
hexio_write test.db 2564 [format %02x 0xed]
|
||||
hexio_write test.db 2139 [format %02x 0x55]
|
||||
|
||||
sqlite3 db test.db
|
||||
catchsql {BEGIN; DELETE FROM t1 WHERE x>13; ROLLBACK;}
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
# corruption (seed 170434)
|
||||
do_test corruptC-2.9 {
|
||||
db close
|
||||
copy_file test.bu test.db
|
||||
|
||||
# insert corrupt byte(s)
|
||||
hexio_write test.db 2095 [format %02x 0xd6]
|
||||
|
||||
sqlite3 db test.db
|
||||
catchsql {BEGIN; DELETE FROM t1 WHERE x>13; ROLLBACK;}
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
# corruption (seed 186504)
|
||||
do_test corruptC-2.10 {
|
||||
db close
|
||||
copy_file test.bu test.db
|
||||
|
||||
# insert corrupt byte(s)
|
||||
hexio_write test.db 3130 [format %02x 0x02]
|
||||
|
||||
sqlite3 db test.db
|
||||
catchsql {BEGIN; UPDATE t2 SET y='abcdef-uvwxyz'; ROLLBACK;}
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
# corruption (seed 1589)
|
||||
do_test corruptC-2.11 {
|
||||
db close
|
||||
copy_file test.bu test.db
|
||||
|
||||
# insert corrupt byte(s)
|
||||
hexio_write test.db 55 [format %02x 0xa7]
|
||||
|
||||
sqlite3 db test.db
|
||||
catchsql {BEGIN; CREATE TABLE t3 AS SELECT x,3 as y FROM t2 WHERE rowid%5!=0; ROLLBACK;}
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
# corruption (seed 14166)
|
||||
do_test corruptC-2.12 {
|
||||
db close
|
||||
copy_file test.bu test.db
|
||||
|
||||
# insert corrupt byte(s)
|
||||
hexio_write test.db 974 [format %02x 0x2e]
|
||||
|
||||
sqlite3 db test.db
|
||||
catchsql {SELECT count(*) FROM sqlite_master;}
|
||||
} {1 {malformed database schema (t1i1) - corrupt database}}
|
||||
|
||||
# corruption (seed 218803)
|
||||
do_test corruptC-2.13 {
|
||||
db close
|
||||
copy_file test.bu test.db
|
||||
|
||||
# insert corrupt byte(s)
|
||||
hexio_write test.db 102 [format %02x 0x12]
|
||||
|
||||
sqlite3 db test.db
|
||||
catchsql {BEGIN; CREATE TABLE t3 AS SELECT x,3 as y FROM t2 WHERE rowid%5!=0; ROLLBACK;}
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
|
||||
#
|
||||
# now test for a series of quasi-random seeds
|
||||
#
|
||||
for {set tn 0} {$tn<=1024} {incr tn 1} {
|
||||
|
||||
# Set a quasi-random random seed
|
||||
expr srand($tn)
|
||||
for {set tn 0} {$tn<1024} {incr tn 1} {
|
||||
|
||||
# setup for test
|
||||
db close
|
||||
@@ -184,43 +275,65 @@ for {set tn 0} {$tn<=1024} {incr tn 1} {
|
||||
# the database engine can handle the corruption gracefully.
|
||||
#
|
||||
set last 0
|
||||
for {set i 1} {$i<=1024 && !$last} {incr i 1} {
|
||||
for {set i 1} {$i<=512 && !$last} {incr i 1} {
|
||||
|
||||
# insert random byte at random location
|
||||
db close
|
||||
hexio_write test.db [random $fsize] [format %02x [random 255]]
|
||||
set roffset [random $fsize]
|
||||
set rbyte [format %02x [random 255]]
|
||||
|
||||
# You can uncomment the following to have it trace
|
||||
# exactly how it's corrupting the file. This is
|
||||
# useful for generating the "seed specific" tests
|
||||
# above.
|
||||
# set rline "$roffset $rbyte"
|
||||
# puts stdout $rline
|
||||
|
||||
hexio_write test.db $roffset $rbyte
|
||||
sqlite3 db test.db
|
||||
|
||||
# do a few random operations to make sure that if
|
||||
# they error, they error gracefully instead of crashing.
|
||||
do_test corruptC-3.$tn.$i.1 {
|
||||
do_test corruptC-3.$tn.($qseed).$i.1 {
|
||||
catchsql {SELECT count(*) FROM sqlite_master}
|
||||
set x {}
|
||||
} {}
|
||||
do_test corruptC-3.$tn.$i.2 {
|
||||
do_test corruptC-3.$tn.($qseed).$i.2 {
|
||||
catchsql {SELECT count(*) FROM t1}
|
||||
set x {}
|
||||
} {}
|
||||
do_test corruptC-3.$tn.$i.3 {
|
||||
do_test corruptC-3.$tn.($qseed).$i.3 {
|
||||
catchsql {SELECT count(*) FROM t1 WHERE x>13}
|
||||
set x {}
|
||||
} {}
|
||||
do_test corruptC-3.$tn.$i.4 {
|
||||
do_test corruptC-3.$tn.($qseed).$i.4 {
|
||||
catchsql {SELECT count(*) FROM t2}
|
||||
set x {}
|
||||
} {}
|
||||
do_test corruptC-3.$tn.$i.5 {
|
||||
do_test corruptC-3.$tn.($qseed).$i.5 {
|
||||
catchsql {SELECT count(*) FROM t2 WHERE x<13}
|
||||
set x {}
|
||||
} {}
|
||||
do_test corruptC-3.$tn.$i.6 {
|
||||
do_test corruptC-3.$tn.($qseed).$i.6 {
|
||||
catchsql {BEGIN; UPDATE t1 SET y=1; ROLLBACK;}
|
||||
set x {}
|
||||
} {}
|
||||
do_test corruptC-3.$tn.$i.7 {
|
||||
do_test corruptC-3.$tn.($qseed).$i.7 {
|
||||
catchsql {BEGIN; UPDATE t2 SET y='abcdef-uvwxyz'; ROLLBACK;}
|
||||
set x {}
|
||||
} {}
|
||||
do_test corruptC-3.$tn.($qseed).$i.8 {
|
||||
catchsql {BEGIN; DELETE FROM t1 WHERE x>13; ROLLBACK;}
|
||||
set x {}
|
||||
} {}
|
||||
do_test corruptC-3.$tn.($qseed).$i.9 {
|
||||
catchsql {BEGIN; DELETE FROM t2 WHERE x<13; ROLLBACK;}
|
||||
set x {}
|
||||
} {}
|
||||
do_test corruptC-3.$tn.($qseed).$i.10 {
|
||||
catchsql {BEGIN; CREATE TABLE t3 AS SELECT x,3 as y FROM t2 WHERE rowid%5!=0; ROLLBACK;}
|
||||
set x {}
|
||||
} {}
|
||||
|
||||
# check the integrity of the database.
|
||||
# once the corruption is detected, we can stop.
|
||||
@@ -243,7 +356,7 @@ for {set tn 0} {$tn<=1024} {incr tn 1} {
|
||||
# TBD: need to figure out why this doesn't work
|
||||
# work with ROLLBACKs...
|
||||
if {0} {
|
||||
do_test corruptC-3.$tn.$i.8 {
|
||||
do_test corruptC-3.$tn.($qseed).$i.11 {
|
||||
set bt [btree_from_db db]
|
||||
db_enter db
|
||||
array set stats [btree_pager_stats $bt]
|
||||
|
||||
+7
-1
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# This file is focused on testing the pcache module.
|
||||
#
|
||||
# $Id: pcache2.test,v 1.2 2008/10/14 19:21:52 danielk1977 Exp $
|
||||
# $Id: pcache2.test,v 1.3 2008/11/13 16:21:50 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -22,9 +22,11 @@ source $testdir/tester.tcl
|
||||
#
|
||||
do_test pcache2-1.1 {
|
||||
db close
|
||||
sqlite3_reset_auto_extension
|
||||
sqlite3_shutdown
|
||||
sqlite3_config_pagecache 6000 100
|
||||
sqlite3_initialize
|
||||
autoinstall_test_functions
|
||||
sqlite3_status SQLITE_STATUS_PAGECACHE_USED 1
|
||||
sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0
|
||||
} {0 0 0}
|
||||
@@ -68,6 +70,10 @@ do_test pcache2-1.4 {
|
||||
|
||||
db close
|
||||
catch {db2 close}
|
||||
sqlite3_reset_auto_extension
|
||||
sqlite3_shutdown
|
||||
sqlite3_config_pagecache 0 0
|
||||
sqlite3_initialize
|
||||
autoinstall_test_functions
|
||||
|
||||
finish_test
|
||||
|
||||
+102
-2
@@ -9,7 +9,7 @@
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# $Id: permutations.test,v 1.37 2008/11/10 18:05:36 shane Exp $
|
||||
# $Id: permutations.test,v 1.39 2008/11/19 01:20:26 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -505,7 +505,7 @@ ifcapable mem5 {
|
||||
bitvec.test index2.test memsubsys1.test
|
||||
capi3c.test ioerr.test memsubsys2.test
|
||||
capi3.test join3.test pagesize.test
|
||||
collate5.test limit.test
|
||||
collate5.test limit.test zeroblob.test
|
||||
} -initialize {
|
||||
catch {db close}
|
||||
sqlite3_reset_auto_extension
|
||||
@@ -604,6 +604,106 @@ run_tests "safe_append" -description {
|
||||
} -include [lsort [concat shared_err.test $ALLTESTS]] \
|
||||
-exclude async3.test
|
||||
|
||||
# The set of tests to run on the alternative-pcache
|
||||
set perm-alt-pcache-testset {
|
||||
async.test
|
||||
attach.test
|
||||
delete.test delete2.test
|
||||
index.test
|
||||
insert.test insert2.test
|
||||
join.test join2.test
|
||||
rollback.test
|
||||
select1.test select2.test
|
||||
trans.test
|
||||
update.test
|
||||
}
|
||||
|
||||
run_tests "pcache0" -description {
|
||||
Alternative pcache implementation without random discard
|
||||
} -initialize {
|
||||
catch {db close}
|
||||
sqlite3_reset_auto_extension
|
||||
sqlite3_shutdown
|
||||
sqlite3_config_alt_pcache 1 0 1
|
||||
sqlite3_initialize
|
||||
autoinstall_test_functions
|
||||
} -shutdown {
|
||||
catch {db close}
|
||||
sqlite3_reset_auto_extension
|
||||
sqlite3_shutdown
|
||||
sqlite3_config_alt_pcache 0 0 0
|
||||
sqlite3_config_lookaside 100 500
|
||||
install_malloc_faultsim 1
|
||||
sqlite3_initialize
|
||||
} -include ${perm-alt-pcache-testset}
|
||||
|
||||
run_tests "pcache10" -description {
|
||||
Alternative pcache implementation without 10% random discard
|
||||
} -initialize {
|
||||
catch {db close}
|
||||
sqlite3_reset_auto_extension
|
||||
sqlite3_shutdown
|
||||
sqlite3_config_alt_pcache 1 50 1
|
||||
sqlite3_initialize
|
||||
autoinstall_test_functions
|
||||
} -shutdown {
|
||||
catch {db close}
|
||||
sqlite3_reset_auto_extension
|
||||
sqlite3_shutdown
|
||||
sqlite3_config_alt_pcache 0 0 0
|
||||
sqlite3_initialize
|
||||
} -include ${perm-alt-pcache-testset}
|
||||
|
||||
run_tests "pcache50" -description {
|
||||
Alternative pcache implementation without 50% random discard
|
||||
} -initialize {
|
||||
catch {db close}
|
||||
sqlite3_reset_auto_extension
|
||||
sqlite3_shutdown
|
||||
sqlite3_config_alt_pcache 1 50 1
|
||||
sqlite3_initialize
|
||||
autoinstall_test_functions
|
||||
} -shutdown {
|
||||
catch {db close}
|
||||
sqlite3_reset_auto_extension
|
||||
sqlite3_shutdown
|
||||
sqlite3_config_alt_pcache 0 0 0
|
||||
sqlite3_initialize
|
||||
} -include ${perm-alt-pcache-testset}
|
||||
|
||||
run_tests "pcache90" -description {
|
||||
Alternative pcache implementation without 90% random discard
|
||||
} -initialize {
|
||||
catch {db close}
|
||||
sqlite3_reset_auto_extension
|
||||
sqlite3_shutdown
|
||||
sqlite3_config_alt_pcache 1 50 1
|
||||
sqlite3_initialize
|
||||
autoinstall_test_functions
|
||||
} -shutdown {
|
||||
catch {db close}
|
||||
sqlite3_reset_auto_extension
|
||||
sqlite3_shutdown
|
||||
sqlite3_config_alt_pcache 0 0 0
|
||||
sqlite3_initialize
|
||||
} -include ${perm-alt-pcache-testset}
|
||||
|
||||
run_tests "pcache100" -description {
|
||||
Alternative pcache implementation that always discards when unpinning
|
||||
} -initialize {
|
||||
catch {db close}
|
||||
sqlite3_reset_auto_extension
|
||||
sqlite3_shutdown
|
||||
sqlite3_config_alt_pcache 1 100 1
|
||||
sqlite3_initialize
|
||||
autoinstall_test_functions
|
||||
} -shutdown {
|
||||
catch {db close}
|
||||
sqlite3_reset_auto_extension
|
||||
sqlite3_shutdown
|
||||
sqlite3_config_alt_pcache 0 0 0
|
||||
sqlite3_initialize
|
||||
} -include ${perm-alt-pcache-testset}
|
||||
|
||||
# End of tests
|
||||
#############################################################################
|
||||
|
||||
+6
-5
@@ -11,7 +11,7 @@
|
||||
# This file is the driver for the "soak" tests. It is a peer of the
|
||||
# quick.test and all.test scripts.
|
||||
#
|
||||
# $Id: soak.test,v 1.3 2008/07/12 14:52:20 drh Exp $
|
||||
# $Id: soak.test,v 1.4 2008/11/13 18:29:51 shane Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -47,10 +47,10 @@ set argv [list]
|
||||
# global variable $TIMEOUT - tests are run for at least $TIMEOUT
|
||||
# seconds.
|
||||
#
|
||||
# fuzz.test (pseudo-random SQL statements)
|
||||
# trans.test (pseudo-random changes to a database followed by rollbacks)
|
||||
#
|
||||
# fuzzy malloc?
|
||||
# fuzz.test (pseudo-random SQL statements)
|
||||
# trans.test (pseudo-random changes to a database followed by rollbacks)
|
||||
# fuzz_malloc.test
|
||||
# corruptC.test (pseudo-random corruption to a database)
|
||||
#
|
||||
# Many database changes maintaining some kind of invariant.
|
||||
# Storing checksums etc.
|
||||
@@ -62,6 +62,7 @@ set SOAKTESTS {
|
||||
fuzz.test
|
||||
fuzz_malloc.test
|
||||
trans.test
|
||||
corruptC.test
|
||||
}
|
||||
|
||||
set ISQUICK 1
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# $Id: tkt3472.test,v 1.2 2008/11/12 14:07:52 drh Exp $
|
||||
# $Id: tkt3472.test,v 1.3 2008/11/13 18:02:52 shane Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -20,7 +20,7 @@ ifcapable {!threadsafe} {
|
||||
}
|
||||
if {$::tcl_platform(platform)!="unix"} {
|
||||
finish_test
|
||||
rturn
|
||||
return
|
||||
}
|
||||
|
||||
set ::correctvalue $threadsOverrideEachOthersLocks
|
||||
|
||||
@@ -99,6 +99,11 @@ COMPILATION
|
||||
|
||||
gcc genfkey.c sqlite3.c -o genfkey
|
||||
|
||||
Or, to use an installed version of sqlite (the kind linux distributions
|
||||
install as part of the sqlite3-dev package):
|
||||
|
||||
gcc genfkey.c -lsqlite3 -o genfkey
|
||||
|
||||
If compiled/linked against an SQLite version earlier than 3.6.4, then
|
||||
all foreign key constraints are assumed to be "ON UPDATE RESTRICT" and
|
||||
"ON DELETE RESTRICT". If linked against 3.6.4 or newer, "CASCADE" and
|
||||
|
||||
@@ -266,6 +266,8 @@ void *ParseAlloc(void *(*mallocProc)(size_t)){
|
||||
pParser->yyidxMax = 0;
|
||||
#endif
|
||||
#if YYSTACKDEPTH<=0
|
||||
pParser->yystack = NULL;
|
||||
pParser->yystksz = 0;
|
||||
yyGrowStack(pParser);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -235,6 +235,7 @@ foreach file {
|
||||
|
||||
bitvec.c
|
||||
pcache.c
|
||||
pcache1.c
|
||||
pager.c
|
||||
|
||||
btmutex.c
|
||||
|
||||
Reference in New Issue
Block a user