Compare commits
110 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 | |||
| f99b7c8d56 | |||
| 7ab49bfd1e | |||
| ef988b47a4 | |||
| 03c7a2f1a1 | |||
| 0d7f4fc4b0 | |||
| d72a276e9a | |||
| ab396298c4 | |||
| 360e634ed4 | |||
| 259a455f71 | |||
| 0af3f8935f | |||
| 34ac18daf5 | |||
| 826d5b7e1c | |||
| dfef499856 | |||
| 95338ab70c | |||
| 41a6a61d94 | |||
| a78c22c433 | |||
| 5780ebdf79 | |||
| 86a7a69cbe | |||
| 4d01aeedbb | |||
| c717b382b8 | |||
| 753cc1077b | |||
| 2e904c5f9e | |||
| b2111838c6 | |||
| c782f69abb | |||
| c8330f4b1d | |||
| 2479de3a20 | |||
| 831c329542 | |||
| 7ba429a61c | |||
| bbf695d6ea | |||
| 98c58356ae | |||
| 4c17c3fb11 | |||
| 1735fa8892 | |||
| 0793f1bdb4 | |||
| ad4a4b8047 | |||
| 7b607a081f | |||
| 5f6d0268fb | |||
| 2838b47234 | |||
| c46f52034f | |||
| 4413d0e976 | |||
| 3e0a3c9df4 | |||
| dfe88ece74 | |||
| e435975093 | |||
| 3072c5ea11 | |||
| 2d16fb1d34 | |||
| 10fb749b37 | |||
| 1c0dc8256b | |||
| f150c9de55 | |||
| 99dfe5eb47 | |||
| 281d8bd3ac | |||
| d1370b6d92 | |||
| 27c3bd7b73 | |||
| 0f3f072d9f | |||
| 52bd7912af | |||
| c7af484b4b | |||
| 9a02fb444c | |||
| a7435e31ab | |||
| 31daa63f3e | |||
| a2f8c24ca3 | |||
| f96a3778f9 | |||
| b1cd7308dc | |||
| 891adeac5c | |||
| 049fc21db9 | |||
| 3ed4e64cd8 | |||
| d207d8084e | |||
| 6553c5c81a | |||
| 1885d1c201 | |||
| 39281b4b42 | |||
| b3175389c7 | |||
| 7b228b3e39 | |||
| d39fa70c79 | |||
| 9e885cd885 | |||
| d138dd8687 |
+27
-16
@@ -76,13 +76,17 @@ TLIBS = @LIBS@
|
||||
TEMP_STORE = -DSQLITE_TEMP_STORE=@TEMP_STORE@
|
||||
|
||||
# Enable/disable loadable extensions, and other optional features
|
||||
# based on configuration. (-DSQLITE_OMIT*). The same set of OMIT
|
||||
# flags should be passed to the LEMON parser generator and the
|
||||
# mkkeywordhash tool as well.
|
||||
# based on configuration. (-DSQLITE_OMIT*, -DSQLITE_ENABLE*).
|
||||
# The same set of OMIT and ENABLE flags should be passed to the
|
||||
# LEMON parser generator and the mkkeywordhash tool as well.
|
||||
OPT_FEATURE_FLAGS = @OPT_FEATURE_FLAGS@
|
||||
|
||||
TCC += $(OPT_FEATURE_FLAGS)
|
||||
|
||||
# Add in any optional parameters specified on the make commane line
|
||||
# ie. make "OPTS=-DSQLITE_ENABLE_FOO=1 -DSQLITE_OMIT_FOO=1".
|
||||
TCC += $(OPTS)
|
||||
|
||||
# Version numbers and release number for the SQLite being compiled.
|
||||
#
|
||||
VERSION = @VERSION@
|
||||
@@ -121,7 +125,7 @@ SHLIB_SUFFIX = @TCL_SHLIB_SUFFIX@
|
||||
#
|
||||
# for more info.
|
||||
#
|
||||
GCOV_CFLAGS1 = -fprofile-arcs -ftest-coverage
|
||||
GCOV_CFLAGS1 = -DSQLITE_COVERAGE_TEST=1 -fprofile-arcs -ftest-coverage
|
||||
GCOV_LDFLAGS1 = -lgcov
|
||||
USE_GCOV = @USE_GCOV@
|
||||
LTCOMPILE_EXTRAS += $(GCOV_CFLAGS$(USE_GCOV))
|
||||
@@ -159,11 +163,12 @@ OBJS0 = alter.lo analyze.lo attach.lo auth.lo bitvec.lo btmutex.lo \
|
||||
btree.lo build.lo callback.lo complete.lo date.lo \
|
||||
delete.lo expr.lo fault.lo func.lo global.lo \
|
||||
hash.lo journal.lo insert.lo legacy.lo loadext.lo \
|
||||
main.lo malloc.lo mem1.lo mem2.lo mem3.lo mem4.lo mem5.lo mem6.lo \
|
||||
main.lo malloc.lo mem0.lo mem1.lo mem2.lo mem3.lo mem5.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 \
|
||||
@@ -209,12 +214,12 @@ SRC = \
|
||||
$(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/mem4.c \
|
||||
$(TOP)/src/mem5.c \
|
||||
$(TOP)/src/mem6.c \
|
||||
$(TOP)/src/memjournal.c \
|
||||
$(TOP)/src/mutex.c \
|
||||
$(TOP)/src/mutex.h \
|
||||
$(TOP)/src/mutex_noop.c \
|
||||
@@ -232,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 \
|
||||
@@ -330,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 \
|
||||
@@ -369,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 \
|
||||
@@ -552,6 +560,9 @@ main.lo: $(TOP)/src/main.c $(HDR)
|
||||
malloc.lo: $(TOP)/src/malloc.c $(HDR)
|
||||
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/malloc.c
|
||||
|
||||
mem0.lo: $(TOP)/src/mem0.c $(HDR)
|
||||
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/mem0.c
|
||||
|
||||
mem1.lo: $(TOP)/src/mem1.c $(HDR)
|
||||
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/mem1.c
|
||||
|
||||
@@ -561,14 +572,11 @@ mem2.lo: $(TOP)/src/mem2.c $(HDR)
|
||||
mem3.lo: $(TOP)/src/mem3.c $(HDR)
|
||||
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/mem3.c
|
||||
|
||||
mem4.lo: $(TOP)/src/mem4.c $(HDR)
|
||||
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/mem4.c
|
||||
|
||||
mem5.lo: $(TOP)/src/mem5.c $(HDR)
|
||||
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/mem5.c
|
||||
|
||||
mem6.lo: $(TOP)/src/mem6.c $(HDR)
|
||||
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/mem6.c
|
||||
memjournal.lo: $(TOP)/src/memjournal.c $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/memjournal.c
|
||||
|
||||
mutex.lo: $(TOP)/src/mutex.c $(HDR)
|
||||
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/mutex.c
|
||||
@@ -591,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
|
||||
|
||||
@@ -619,7 +630,7 @@ parse.h: parse.c
|
||||
|
||||
parse.c: $(TOP)/src/parse.y lemon$(BEXE) $(TOP)/addopcodes.awk
|
||||
cp $(TOP)/src/parse.y .
|
||||
./lemon$(BEXE) $(OPTS) $(OPT_FEATURE_FLAGS) parse.y
|
||||
./lemon$(BEXE) $(OPT_FEATURE_FLAGS) $(OPTS) parse.y
|
||||
mv parse.h parse.h.temp
|
||||
$(NAWK) -f $(TOP)/addopcodes.awk parse.h.temp >parse.h
|
||||
|
||||
@@ -658,7 +669,7 @@ tokenize.lo: $(TOP)/src/tokenize.c keywordhash.h $(HDR)
|
||||
$(LTCOMPILE) -c $(TOP)/src/tokenize.c
|
||||
|
||||
keywordhash.h: $(TOP)/tool/mkkeywordhash.c
|
||||
$(BCC) -o mkkeywordhash$(BEXE) $(OPTS) $(OPT_FEATURE_FLAGS) $(TOP)/tool/mkkeywordhash.c
|
||||
$(BCC) -o mkkeywordhash$(BEXE) $(OPT_FEATURE_FLAGS) $(OPTS) $(TOP)/tool/mkkeywordhash.c
|
||||
./mkkeywordhash$(BEXE) >keywordhash.h
|
||||
|
||||
trigger.lo: $(TOP)/src/trigger.c $(HDR)
|
||||
|
||||
+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)
|
||||
@@ -1489,7 +1489,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
||||
|
||||
|
||||
# The following RCS revision string applies to configure.in
|
||||
# $Revision: 1.64 $
|
||||
# $Revision: 1.65 $
|
||||
|
||||
#########
|
||||
# Programs needed
|
||||
@@ -12071,34 +12071,37 @@ else
|
||||
fi
|
||||
|
||||
#########
|
||||
# attempt to duplicate any OMITS into the $(OPT_FEATURE_FLAGS) parameter
|
||||
# attempt to duplicate any OMITS and ENABLES into the $(OPT_FEATURE_FLAGS) parameter
|
||||
for option in $CFLAGS $CPPFLAGS
|
||||
do
|
||||
case $option in
|
||||
-DSQLITE_OMIT*) OPT_FEATURE_FLAGS="$OPT_FEATURE_FLAGS $option";;
|
||||
-DSQLITE_ENABLE*) OPT_FEATURE_FLAGS="$OPT_FEATURE_FLAGS $option";;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
|
||||
# attempt to remove any OMITS from the $(CFLAGS) parameter
|
||||
# attempt to remove any OMITS and ENABLES from the $(CFLAGS) parameter
|
||||
ac_temp_CFLAGS=""
|
||||
for option in $CFLAGS
|
||||
do
|
||||
case $option in
|
||||
-DSQLITE_OMIT*) ;;
|
||||
-DSQLITE_ENABLE*) ;;
|
||||
*) ac_temp_CFLAGS="$ac_temp_CFLAGS $option";;
|
||||
esac
|
||||
done
|
||||
CFLAGS=$ac_temp_CFLAGS
|
||||
|
||||
|
||||
# attempt to remove any OMITS from the $(CPPFLAGS) parameter
|
||||
# attempt to remove any OMITS and ENABLES from the $(CPPFLAGS) parameter
|
||||
ac_temp_CPPFLAGS=""
|
||||
for option in $CPPFLAGS
|
||||
do
|
||||
case $option in
|
||||
-DSQLITE_OMIT*) ;;
|
||||
-DSQLITE_ENABLE*) ;;
|
||||
*) ac_temp_CPPFLAGS="$ac_temp_CPPFLAGS $option";;
|
||||
esac
|
||||
done
|
||||
@@ -12111,6 +12114,7 @@ for option in $BUILD_CFLAGS
|
||||
do
|
||||
case $option in
|
||||
-DSQLITE_OMIT*) ;;
|
||||
-DSQLITE_ENABLE*) ;;
|
||||
*) ac_temp_BUILD_CFLAGS="$ac_temp_BUILD_CFLAGS $option";;
|
||||
esac
|
||||
done
|
||||
|
||||
+9
-5
@@ -92,7 +92,7 @@ AC_INIT(sqlite, m4_esyscmd([cat VERSION | tr -d '\n']))
|
||||
dnl Put the RCS revision string after AC_INIT so that it will also
|
||||
dnl show in in configure.
|
||||
# The following RCS revision string applies to configure.in
|
||||
# $Revision: 1.49 $
|
||||
# $Revision: 1.50 $
|
||||
|
||||
#########
|
||||
# Programs needed
|
||||
@@ -611,46 +611,50 @@ else
|
||||
fi
|
||||
|
||||
#########
|
||||
# attempt to duplicate any OMITS into the $(OPT_FEATURE_FLAGS) parameter
|
||||
# attempt to duplicate any OMITS and ENABLES into the $(OPT_FEATURE_FLAGS) parameter
|
||||
for option in $CFLAGS $CPPFLAGS
|
||||
do
|
||||
case $option in
|
||||
-DSQLITE_OMIT*) OPT_FEATURE_FLAGS="$OPT_FEATURE_FLAGS $option";;
|
||||
-DSQLITE_ENABLE*) OPT_FEATURE_FLAGS="$OPT_FEATURE_FLAGS $option";;
|
||||
esac
|
||||
done
|
||||
AC_SUBST(OPT_FEATURE_FLAGS)
|
||||
|
||||
|
||||
# attempt to remove any OMITS from the $(CFLAGS) parameter
|
||||
# attempt to remove any OMITS and ENABLES from the $(CFLAGS) parameter
|
||||
ac_temp_CFLAGS=""
|
||||
for option in $CFLAGS
|
||||
do
|
||||
case $option in
|
||||
-DSQLITE_OMIT*) ;;
|
||||
-DSQLITE_ENABLE*) ;;
|
||||
*) ac_temp_CFLAGS="$ac_temp_CFLAGS $option";;
|
||||
esac
|
||||
done
|
||||
CFLAGS=$ac_temp_CFLAGS
|
||||
|
||||
|
||||
# attempt to remove any OMITS from the $(CPPFLAGS) parameter
|
||||
# attempt to remove any OMITS and ENABLES from the $(CPPFLAGS) parameter
|
||||
ac_temp_CPPFLAGS=""
|
||||
for option in $CPPFLAGS
|
||||
do
|
||||
case $option in
|
||||
-DSQLITE_OMIT*) ;;
|
||||
-DSQLITE_ENABLE*) ;;
|
||||
*) ac_temp_CPPFLAGS="$ac_temp_CPPFLAGS $option";;
|
||||
esac
|
||||
done
|
||||
CPPFLAGS=$ac_temp_CPPFLAGS
|
||||
|
||||
|
||||
# attempt to remove any OMITS from the $(BUILD_CFLAGS) parameter
|
||||
# attempt to remove any OMITS and ENABLES from the $(BUILD_CFLAGS) parameter
|
||||
ac_temp_BUILD_CFLAGS=""
|
||||
for option in $BUILD_CFLAGS
|
||||
do
|
||||
case $option in
|
||||
-DSQLITE_OMIT*) ;;
|
||||
-DSQLITE_ENABLE*) ;;
|
||||
*) ac_temp_BUILD_CFLAGS="$ac_temp_BUILD_CFLAGS $option";;
|
||||
esac
|
||||
done
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
+13
-9
@@ -12,7 +12,7 @@
|
||||
** This file contains code for implementations of the r-tree and r*-tree
|
||||
** algorithms packaged as an SQLite virtual table module.
|
||||
**
|
||||
** $Id: rtree.c,v 1.9 2008/09/08 11:07:03 danielk1977 Exp $
|
||||
** $Id: rtree.c,v 1.11 2008/11/12 15:24:27 drh Exp $
|
||||
*/
|
||||
|
||||
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RTREE)
|
||||
@@ -226,8 +226,12 @@ struct RtreeCell {
|
||||
RtreeCoord aCoord[RTREE_MAX_DIMENSIONS*2];
|
||||
};
|
||||
|
||||
#define MAX(x,y) ((x) < (y) ? (y) : (x))
|
||||
#define MIN(x,y) ((x) > (y) ? (y) : (x))
|
||||
#ifndef MAX
|
||||
# define MAX(x,y) ((x) < (y) ? (y) : (x))
|
||||
#endif
|
||||
#ifndef MIN
|
||||
# define MIN(x,y) ((x) > (y) ? (y) : (x))
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Functions to deserialize a 16 bit integer, 32 bit real number and
|
||||
@@ -600,7 +604,7 @@ static void nodeGetCell(
|
||||
** the virtual table module xCreate() and xConnect() methods.
|
||||
*/
|
||||
static int rtreeInit(
|
||||
sqlite3 *, void *, int, const char *const*, sqlite3_vtab **, char **, int, int
|
||||
sqlite3 *, void *, int, const char *const*, sqlite3_vtab **, char **, int
|
||||
);
|
||||
|
||||
/*
|
||||
@@ -613,7 +617,7 @@ static int rtreeCreate(
|
||||
sqlite3_vtab **ppVtab,
|
||||
char **pzErr
|
||||
){
|
||||
return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 1, (int)pAux);
|
||||
return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -626,7 +630,7 @@ static int rtreeConnect(
|
||||
sqlite3_vtab **ppVtab,
|
||||
char **pzErr
|
||||
){
|
||||
return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 0, (int)pAux);
|
||||
return rtreeInit(db, pAux, argc, argv, ppVtab, pzErr, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2651,18 +2655,18 @@ static int getPageSize(sqlite3 *db, const char *zDb, int *piPageSize){
|
||||
*/
|
||||
static int rtreeInit(
|
||||
sqlite3 *db, /* Database connection */
|
||||
void *pAux, /* Pointer to head of rtree list */
|
||||
void *pAux, /* One of the RTREE_COORD_* constants */
|
||||
int argc, const char *const*argv, /* Parameters to CREATE TABLE statement */
|
||||
sqlite3_vtab **ppVtab, /* OUT: New virtual table */
|
||||
char **pzErr, /* OUT: Error message, if any */
|
||||
int isCreate, /* True for xCreate, false for xConnect */
|
||||
int eCoordType /* One of the RTREE_COORD_* constants */
|
||||
int isCreate /* True for xCreate, false for xConnect */
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
int iPageSize = 0;
|
||||
Rtree *pRtree;
|
||||
int nDb; /* Length of string argv[1] */
|
||||
int nName; /* Length of string argv[2] */
|
||||
int eCoordType = (int)pAux;
|
||||
|
||||
const char *aErrMsg[] = {
|
||||
0, /* 0 */
|
||||
|
||||
@@ -56,10 +56,11 @@ LIBOBJ+= alter.o analyze.o attach.o auth.o \
|
||||
fts3_tokenizer.o fts3_tokenizer1.o \
|
||||
func.o global.o hash.o \
|
||||
icu.o insert.o journal.o legacy.o loadext.o \
|
||||
main.o malloc.o mem1.o mem2.o mem3.o mem4.o mem5.o mem6.o \
|
||||
main.o malloc.o mem0.o mem1.o mem2.o mem3.o mem5.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 \
|
||||
@@ -98,12 +99,12 @@ SRC = \
|
||||
$(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/mem4.c \
|
||||
$(TOP)/src/mem5.c \
|
||||
$(TOP)/src/mem6.c \
|
||||
$(TOP)/src/memjournal.c \
|
||||
$(TOP)/src/mutex.c \
|
||||
$(TOP)/src/mutex.h \
|
||||
$(TOP)/src/mutex_noop.c \
|
||||
@@ -121,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 \
|
||||
@@ -226,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 \
|
||||
@@ -241,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.4\s(CVS\s5825)
|
||||
D 2008-10-15T11:59:24
|
||||
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 2014e5a4010ad5ebbcaedff98240b3d14ee83838
|
||||
F Makefile.in 0aa7bbe3be6acc4045706e3bb3fd0b8f38f4a3b5
|
||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||
F Makefile.vxwSH4 d53b4be86491060d498b22148951b6d765884cab
|
||||
F README b974cdc3f9f12b87e851b04e75996d720ebf81ac
|
||||
F VERSION 5ba795c6239d62450dd2cb8b469acebda412ebc9
|
||||
F VERSION 0fb8ff48a435ea7ea0f720a79cb3c4911a7ab06c
|
||||
F aclocal.m4 7d02b11fed45174e11156144227278deb6236eea
|
||||
F addopcodes.awk 215333be9d99c260e076c3080a81dba3ae928c45
|
||||
F art/2005osaward.gif 0d1851b2a7c1c9d0ccce545f3e14bca42d7fd248
|
||||
@@ -17,8 +18,8 @@ F art/powered_by_sqlite.gif 7fbcd7d3675391fd3d21672c14c05f5999eb60d1
|
||||
F config.guess 226d9a188c6196f3033ffc651cbc9dcee1a42977
|
||||
F config.h.in 3fda160d9a0ebbd6c22c0391354fa0036474680f
|
||||
F config.sub 9ebe4c3b3dab6431ece34f16828b594fb420da55
|
||||
F configure a013a40a9215b92fb9267603823f95d007ab5b00 x
|
||||
F configure.ac 24d54c19c2fb8045598495250230d117c2464502
|
||||
F configure f5bb190d8e9290c4e95349fd6919fd611b438bcf x
|
||||
F configure.ac 34d1ef70f1170b770049660b5de8398aa0ed7d28
|
||||
F contrib/sqlitecon.tcl 210a913ad63f9f991070821e599d600bd913e0ad
|
||||
F doc/lemon.html f0f682f50210928c07e562621c3b7e8ab912a538
|
||||
F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac
|
||||
@@ -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
|
||||
@@ -65,7 +66,7 @@ F ext/icu/README.txt 3b130aa66e7a681136f6add198b076a2f90d1e33
|
||||
F ext/icu/icu.c 12e763d288d23b5a49de37caa30737b971a2f1e2
|
||||
F ext/icu/sqliteicu.h 728867a802baa5a96de7495e9689a8e01715ef37
|
||||
F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761
|
||||
F ext/rtree/rtree.c 9a9ef98ea5c36841cedf95d8cfbe79ebb411fef6
|
||||
F ext/rtree/rtree.c 05d517734dad60165255581cc8dacea00c03b5c0
|
||||
F ext/rtree/rtree.h 834dbcb82dc85b2481cde6a07cdadfddc99e9b9e
|
||||
F ext/rtree/rtree1.test 620223886bf1a319317e63235aac20790375c544
|
||||
F ext/rtree/rtree2.test 9ac9d28fa948779df66916c67a5dcf9704c3cb74
|
||||
@@ -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 725b8b0ee2c1a7e53adb172984c43165eca61be1
|
||||
F main.mk 87a73e91a3d0827dc796a249260866335e38a36e
|
||||
F mkdll.sh 7d09b23c05d56532e9d44a50868eb4b12ff4f74a
|
||||
F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f
|
||||
F mkextw.sh 4123480947681d9b434a5e7b1ee08135abe409ac
|
||||
@@ -93,73 +94,74 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
|
||||
F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
|
||||
F sqlite3.def a1be7b9a4b8b51ac41c6ff6e8e44a14ef66b338b
|
||||
F sqlite3.pc.in ae6f59a76e862f5c561eb32a380228a02afc3cad
|
||||
F src/alter.c f462b637bac6c6576a9b7bc6da59c7a82ed5aab2
|
||||
F src/analyze.c 747ce8cb6b318bb0d0576cfb5277aed98cbbeb5c
|
||||
F src/attach.c db3f4a60538733c1e4dcb9d0217a6e0d6ccd615b
|
||||
F src/alter.c 0a00c184052b7fd20271e783f65fec4efec6fe30
|
||||
F src/analyze.c 301a1358f4f4d84d96608927d8ddcf471c53ad9a
|
||||
F src/attach.c 85c6a3d0daf11965b47604190d7cf5597dc88382
|
||||
F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
|
||||
F src/bitvec.c 95c86bd18d8fedf0533f5af196192546e10a7e7d
|
||||
F src/btmutex.c 3a90096c3080b9057dc570b8e16e46511e1c788a
|
||||
F src/btree.c 3e686f899659df8d79f2587d0f34f51fdf6a6276
|
||||
F src/btree.h 903682f2a88da37435f103da00cb915d63bc8015
|
||||
F src/btreeInt.h e38e9b2b285f40f5bc0a6664f630d4a141622f16
|
||||
F src/build.c 8714bd809583bbe07bf22d0e1808a3fc31abe330
|
||||
F src/bitvec.c 4300d311b17fb3c1476623fd895a8feac02a0b08
|
||||
F src/btmutex.c 63c5cc4ad5715690767ffcb741e185d7bc35ec1a
|
||||
F src/btree.c adfb7974429f79f188fabcdb26145fca3a7d04ed
|
||||
F src/btree.h 179c3ea813780df78a289a8f5130db18e6d4616e
|
||||
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 d3f2adfdd07e701115a111cc81dca33ed6039d10
|
||||
F src/expr.c f84e7606f4d6c4b7ae48f324ca625e3b4a90acdd
|
||||
F src/date.c 88898ae96a0d7f66711caffa40b2cf30e623a387
|
||||
F src/delete.c 2f85d6d00333343a76824a899e15f241ca383c7c
|
||||
F src/expr.c 01b1cf0783a6d0093d72b799fcb22c86146362ef
|
||||
F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff
|
||||
F src/func.c 8431b40a7843d1024145684d303c55b4ee087bbe
|
||||
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 110cca7845ed5a66c08fdd413b02e706ae34455f
|
||||
F src/insert.c 73c4b33767d9540f8ead5d903504ed93f48ad147
|
||||
F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e
|
||||
F src/legacy.c aac57bd984e666059011ea01ec4383892a253be3
|
||||
F src/loadext.c 3872457afdf25bb174fd383cb4e3e0d2a9e60552
|
||||
F src/main.c ff40f9f21c76d5062bc0bc06bd8853fc217dd170
|
||||
F src/malloc.c a213fb461b8df08aed7606f6a1e1d3452e089000
|
||||
F src/mem1.c 5a529ff121c55ab067be14de00f86f6dcc4f4fb9
|
||||
F src/mem2.c f87e681d0d1ed8436870d089332ed0d27d885b5c
|
||||
F src/mem3.c 1594f117fde4cf11a6c16521f3f30af8d04bbe68
|
||||
F src/mem4.c 6703adb1717b26d9d70a1c2586b4b7b7ffee7909
|
||||
F src/mem5.c 706d462c13a9819dfec7c10d9dccedf8d199960c
|
||||
F src/mem6.c febe4db9ddef73df500989e68a9d4ac68602a075
|
||||
F src/main.c d67d2eee7a643a4a894e5de91231a99ad88400b9
|
||||
F src/malloc.c 4e7bf5a3fcfd848a09f7ce7abb00f7b358128161
|
||||
F src/mem0.c f2f84062d1f35814d6535c9f9e33de3bfb3b132c
|
||||
F src/mem1.c bb8e26adde7d463270e961f045802c61dbabc8f1
|
||||
F src/mem2.c 5d9968f576ba1babc787adbfb613cf428ab484ec
|
||||
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 5356c291c6c58c09163888d2116f830468cd8157
|
||||
F src/mutex_noop.c 0004efdbc2fd48d261d5b3416fe537e888c79a54
|
||||
F src/mutex_os2.c 9c5637aa4c307c552566d0f0b3bd206245b54a97
|
||||
F src/mutex_unix.c 29049a61755cccddb2ee53904e6906bb7674223c
|
||||
F src/mutex_w32.c f0d21ff1f6981e5aedc56796adf3a347423ef736
|
||||
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 24221ff5ab20cf3472e3ec7eec595f759de55298
|
||||
F src/os_unix.c 48527028ce548efb23c1e13f2e737eed8ee01444
|
||||
F src/os_win.c 13bed718f62d64031b17bb3685adcf994dbf0232
|
||||
F src/pager.c d98f56128e849083f2f612196efebd982c491fea
|
||||
F src/pager.h 9c1917be28fff58118e1fe0ddbc7adfb8dd4f44d
|
||||
F src/parse.y f4620f42b5e0141e20243b5f963d0fc9c180ab9b
|
||||
F src/pcache.c f8d7beceba164a34441ac37e88abb3a404f968a7
|
||||
F src/pcache.h 974d8ba609c7069af7c050cd3de698cadd090405
|
||||
F src/pragma.c f0f48d0d50e9d8fa785178fc2410244c06f6a287
|
||||
F src/prepare.c c7e00ed1b0bdcf699b1aad651247d4dc3d281b0b
|
||||
F src/printf.c 785f87120589c1db672e37c6eb1087c456e6f84d
|
||||
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 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 86a6f7e48ec58658576092b2289e780d6ec69992
|
||||
F src/select.c d910d7350df0d918e22286c5bfd39d4ea68ec813
|
||||
F src/shell.c d83b578a8ccdd3e0e7fef4388a0887ce9f810967
|
||||
F src/sqlite.h.in c255878b950548a136375f3ecdfcc367026dc951
|
||||
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 69ad0023756cc738d2a5f9def8a0b21d90350667
|
||||
F src/sqliteInt.h beacd5768e55285097fbb419bcd741721b455003
|
||||
F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8
|
||||
F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76
|
||||
F src/table.c 22744786199c9195720c15a7a42cb97b2e2728d8
|
||||
F src/tclsqlite.c 96049bd454f1547abff0a57c45f0dfa57701e076
|
||||
F src/test1.c a7310348961945e656c096e5f91d4d87dee6b61d
|
||||
F src/test1.c 9b440b38e1710e9be1512c003fa141e0e3948e05
|
||||
F src/test2.c 897528183edf2839c2a3c991d415905db56f1240
|
||||
F src/test3.c e85b7ce5c28c3ce7fbdbf7f98e1467b19786c62b
|
||||
F src/test3.c 88a246b56b824275300e6c899634fbac1dc94b14
|
||||
F src/test4.c f79ab52d27ff49b784b631a42e2ccd52cfd5c84c
|
||||
F src/test5.c 162a1cea2105a2c460a3f39fa6919617b562a288
|
||||
F src/test6.c 0a0304a69cfa4962a429d084c6d451ff9e4fb572
|
||||
@@ -174,41 +176,42 @@ 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 243244eb3ba2095db8b65a797d23de72c75e848c
|
||||
F src/test_malloc.c 5127337c9fb4c851a7f604c0170e0e5ca1fbfe33
|
||||
F src/test_md5.c 28209a4e2068711b5443c33104fe41f21d160071
|
||||
F src/test_mutex.c d3422d9f60cc1330249d102e74b333f0d24a0cb6
|
||||
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 ed233298db6dd23d340e449e4b4a81b9306da6aa
|
||||
F src/utf.c c63e6f69082f85c19ab88d62dedaf91d71ac1a50
|
||||
F src/util.c afe659ccc05d1f8af9e8631dabfec3ee3a7144af
|
||||
F src/vacuum.c fd77433d0c26d3ff1eb96eab017a1787ac5aa642
|
||||
F src/vdbe.c b78adf571b9abac4092c641bec148832e8f26f34
|
||||
F src/vdbe.h 41c99aaad9167c1b5431993db446de74b2f71fc3
|
||||
F src/vdbeInt.h a20f479ec3bf41c61b0c2bd5176a9bad6b2a07ef
|
||||
F src/vdbeapi.c 6798c70cf176d23594ec557db88190ca8c7fa860
|
||||
F src/vdbeaux.c e007aa723a059b1e5357c15420eea84095de828a
|
||||
F src/trigger.c b86eb6d216c0014138f858a04185113cb54518e4
|
||||
F src/update.c 37d03659f4d2186ffb8d0ab1df9c3038273fb488
|
||||
F src/utf.c 86dc0f8076f606432a01f1498ae054c32de1f9d2
|
||||
F src/util.c b9a5d1c4c1a433e17d5828f9717fac763016a2cb
|
||||
F src/vacuum.c 383d6297bddc011ab04a9eed110db6eaf523e8e9
|
||||
F src/vdbe.c c5270245fcb5368634a9301481ab94a22e7a21b2
|
||||
F src/vdbe.h 03516f28bf5aca00a53c4dccd6c313f96adb94f6
|
||||
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/vdbemem.c ead88713b852576e2a924bc4ae696964bfbaec0a
|
||||
F src/vtab.c 527c180e9c5fca417c9167d02af4b5039f892b4b
|
||||
F src/vdbefifo.c e6326ad6d16ccd8c2ef659046e3a509c0ae4990a
|
||||
F src/vdbemem.c 223e03281855515e9474dbf66f157452093a77c2
|
||||
F src/vtab.c 02c51eac45dbff1a1d6e73f58febf92ecb563f7f
|
||||
F src/walker.c 488c2660e13224ff70c0c82761118efb547f8f0d
|
||||
F src/where.c 76bc0a7a5eb2e20b72b644f7c5f104c285143a54
|
||||
F src/where.c 96f7c2bd9e83c252d90ee2794f7a902fc5ba505b
|
||||
F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
|
||||
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
|
||||
F test/alias.test c321c114a8a31a33e3cbda910fa39949f5d9dcb2
|
||||
F test/alias.test 597662c5d777a122f9a3df0047ea5c5bd383a911
|
||||
F test/all.test 03cdd58d389e35bee8d57b7d24357b827aecc463
|
||||
F test/alter.test 6353aae6839e486c9b7d8f73b1f4a1e98e57332c
|
||||
F test/alter2.test dd55146e812622c8fc51fd2216bcd8dca8880752
|
||||
F test/alter3.test 25b95a136708f22b87184fa6a4309eea03d65153
|
||||
F test/altermalloc.test 11116c58953b6275a48a87c2912b7d4b72c52840
|
||||
F test/altermalloc.test e81ac9657ed25c6c5bb09bebfa5a047cd8e4acfc
|
||||
F test/analyze.test ad5329098fe4de4a96852231d53e3e9e6283ad4b
|
||||
F test/async.test 0ed384c12d556ce38a4fe21fd41cda7e6dbf55be
|
||||
F test/async2.test 8998e089b0fbb3d84cdd51c25a78833486d721af
|
||||
@@ -216,9 +219,10 @@ F test/async3.test 9ffa0977a78cc6351862a1583be2b1eecd41736d
|
||||
F test/attach.test 75a5d22f88e730967d68f2c9f95e786e3953d8e3
|
||||
F test/attach2.test a295d2d7061adcee5884ef4a93c7c96a82765437
|
||||
F test/attach3.test 7b92dc8e40c1ebca9732ca6f2d3fefbd46f196df
|
||||
F test/attachmalloc.test ccbde53bcb0a61020afa3e0670ca9c6c5b99af32
|
||||
F test/auth.test 9eb4b6b99eee54c95711c74c4b9694acf4d850ed
|
||||
F test/attachmalloc.test cf8cf17d183de357b1147a9baacbdfc85b940b61
|
||||
F test/auth.test 0e901aeb399f766fd58f5e19b8b9a09e2df9a341
|
||||
F test/auth2.test ee3ba272e2b975e913afc9b041ee75706e190005
|
||||
F test/auth3.test b3308950d3839a45193cdcd0473432e33fe38b61
|
||||
F test/autoinc.test ab549b48b389cabd92967b86c379ec8b31fa6c16
|
||||
F test/autovacuum.test 61260e25744189ff766f61ca3df23c1eeec0060e
|
||||
F test/autovacuum_ioerr2.test 598b0663074d3673a9c1bc9a16e80971313bafe6
|
||||
@@ -229,16 +233,16 @@ 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
|
||||
F test/capi2.test 36f87803c811b5986dd31eb5492cb704552776b4
|
||||
F test/capi3.test ffc1156d1f28738eb335df0b88dd294bb3c94c27
|
||||
F test/capi3.test 4d9c110e8c78fdfe0ea61171a17609e627630ca6
|
||||
F test/capi3b.test 664eb55318132f292f2c436f90906f578cad6b97
|
||||
F test/capi3c.test 440ba10acccb74c0f160d7462a93abd1dc328224
|
||||
F test/capi3c.test ce0fcbbaccfc9703fb247ea9ac5ada96dc9ca047
|
||||
F test/capi3d.test 57d83b690d7364bde02cddbf8339a4b50d80ce23
|
||||
F test/cast.test ce8f14fc80f70b30ed984480cc0d8914a459e8f9
|
||||
F test/cast.test 166951664a0b0a2e0f8fb5997a152490c6363932
|
||||
F test/check.test 024ed399600b799160378cf9d9f436bdf5dfd184
|
||||
F test/collate1.test e3eaa48c21e150814be1a7b852d2a8af24458d04
|
||||
F test/collate2.test 04cebe4a033be319d6ddbb3bbc69464e01700b49
|
||||
@@ -264,6 +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 c798aa395a8d052fba88bd1be8e1945309e3f94a
|
||||
F test/crash.test 1b6ac8410689ff78028887f445062dc897c9ac89
|
||||
F test/crash2.test 5b14d4eb58b880e231361d3b609b216acda86651
|
||||
F test/crash3.test 776f9363554c029fcce71d9e6600fa0ba6359ce7
|
||||
@@ -364,7 +369,7 @@ F test/in.test d49419c6df515852f477fa513f3317181d46bc92
|
||||
F test/in2.test 5d4c61d17493c832f7d2d32bef785119e87bde75
|
||||
F test/in3.test 3cbf58c87f4052cee3a58b37b6389777505aa0c0
|
||||
F test/in4.test c043f75147295e9f6ad5040a5cda2c485736c2c8
|
||||
F test/incrblob.test 4040ac885090f147345bedb89bf5e9b5eee1c1f0
|
||||
F test/incrblob.test 4b9437bbb38724343dadbbcca6356bc2a9b435d1
|
||||
F test/incrblob2.test 5cca1c3cb29064c504b3b0cc3e2cd43e8053cfdf
|
||||
F test/incrblob_err.test c577c91d4ed9e8336cdb188b15d6ee2a6fe9604e
|
||||
F test/incrvacuum.test 9a6346c56ffa141024054ae7ba6c8655edf2d137
|
||||
@@ -393,9 +398,9 @@ F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0
|
||||
F test/join4.test 1a352e4e267114444c29266ce79e941af5885916
|
||||
F test/join5.test 86675fc2919269aa923c84dd00ee4249b97990fe
|
||||
F test/journal1.test 36f2d1bb9bf03f790f43fbdb439e44c0657fab19
|
||||
F test/jrnlmode.test 54469696db41e185a37aed3b3848998cca4e0c37
|
||||
F test/jrnlmode.test c4e4e40afdb6a128957e1f8ee404c8d670c4ce6f
|
||||
F test/lastinsert.test 474d519c68cb79d07ecae56a763aa7f322c72f51
|
||||
F test/laststmtchanges.test 18ead86c8a87ade949a1d5658f6dc4bb111d1b02
|
||||
F test/laststmtchanges.test ae613f53819206b3222771828d024154d51db200
|
||||
F test/like.test fef924922828d5a2a5bff80b9bdd9ff57a1ca500
|
||||
F test/like2.test 3b2ee13149ba4a8a60b59756f4e5d345573852da
|
||||
F test/limit.test 2db7b3b34fb925b8e847d583d2eb67531d0ce67e
|
||||
@@ -408,7 +413,7 @@ F test/lock4.test 09d97d52cae18fadfe631552af9880dac6b3ae90
|
||||
F test/lock5.test 904c20aec51d5dbff0a3aec6a4d35c5ae0257449
|
||||
F test/lookaside.test e69f822f13745f1d5c445c6e30e30f059f30c8e5
|
||||
F test/main.test 187a9a1b5248ed74a83838c581c15ec6023b555b
|
||||
F test/malloc.test 2fa351108503f0da80e9183a8157fbd943c5d533
|
||||
F test/malloc.test 248fc5e0be632d8db1d771ed5413a93c47212c5a
|
||||
F test/malloc3.test 4bc57f850b212f706f3e1b37c4eced1d5a727cd1
|
||||
F test/malloc4.test 957337613002b7058a85116493a262f679f3a261
|
||||
F test/malloc5.test c8d0f7673337e8a29afa558735ae937a0d629751
|
||||
@@ -426,7 +431,7 @@ F test/mallocF.test 2d5c590ebc2fc7f0dcebdf5aa8498b9aed69107e
|
||||
F test/mallocG.test 4584d0d8ddb8009f16ca0c8bab1fa37f6358efa2
|
||||
F test/mallocH.test 79b65aed612c9b3ed2dcdaa727c85895fd1bfbdb
|
||||
F test/mallocI.test 6e24fe6444bd2999ccc81f984977b44c0d6e5591
|
||||
F test/mallocJ.test d7a6e82de88d194055ae715da50cc09179603282
|
||||
F test/mallocJ.test 44dfbbaca731cb933818ad300b4566265d652609
|
||||
F test/malloc_common.tcl 984baeb6c6b185e798827d1187d426acc2bc4962
|
||||
F test/manydb.test 8de36b8d33aab5ef295b11d9e95310aeded31af8
|
||||
F test/memdb.test a67bda4ff90a38f2b19f6c7f95aa7289e051d893
|
||||
@@ -442,23 +447,23 @@ F test/misc3.test 7212ed8dad01427e9acab9bd3e7e5e2c2e89be9e
|
||||
F test/misc4.test 91e8ed25c092c2bb4e0bb01864631e2930f8d7de
|
||||
F test/misc5.test 6a5c1e3217a95b0db05ff9a0f1ecb5ce9043ffef
|
||||
F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91
|
||||
F test/misc7.test 0d763f703a34521e55ab30145b747aafa0e5f794
|
||||
F test/misc7.test edbbe77d48c7d70a60f8c33e2c7d182ca25f0181
|
||||
F test/misuse.test 30b3a458e5a70c31e74c291937b6c82204c59f33
|
||||
F test/mutex1.test ff260ddaf7240390dbb013d28aba3a33ec0dada4
|
||||
F test/mutex1.test 820bf4a91af8cf3c9aa63c261d6c65e07b3705b9
|
||||
F test/mutex2.test bfeaeac2e73095b2ac32285d2756e3a65e681660
|
||||
F test/nan.test c627d79b3d36ea892563fd67584b3e8a18f0618a
|
||||
F test/notnull.test 44d600f916b770def8b095a9962dbe3be5a70d82
|
||||
F test/null.test a8b09b8ed87852742343b33441a9240022108993
|
||||
F test/openv2.test f5dd6b23e4dce828eb211649b600763c42a668df
|
||||
F test/pager.test 1e1832795e9e07a359c959ffdddcf7275a88f54c
|
||||
F test/pager2.test 070983b89a308adaba525a2f9c1ba0592c72fa3d
|
||||
F test/pager.test fd3f5009985728ef7bf0dfe32a1bbc112e6895c5
|
||||
F test/pager2.test d84c59ae4a803e03d19d72cbb5b14c71850c6163
|
||||
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 a80a319ed2e825fa828af086d322b47fc9d9c664
|
||||
F test/pragma.test 583937903d01cad823ae195573d90c02ea945717
|
||||
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
|
||||
F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301 x
|
||||
@@ -467,7 +472,7 @@ F test/quick.test 70695607082b3e1ca54023b2c856991604b07703
|
||||
F test/quote.test 215897dbe8de1a6f701265836d6601cc6ed103e6
|
||||
F test/rdonly.test bd054831f8a3078e765a0657e247182486f0cb47
|
||||
F test/reindex.test 44edd3966b474468b823d481eafef0c305022254
|
||||
F test/rollback.test d67022e8f99fdb1f115de7e8ea65139263b4bd40
|
||||
F test/rollback.test 1f70ab4301d8d105d41438a436cad1fc8897f5e5
|
||||
F test/rowid.test 1c8fc43c60d273e6ea44dfb992db587f3164312c
|
||||
F test/rtree.test b85fd4f0861a40ca366ac195e363be2528dcfadf
|
||||
F test/safety.test b69e2b2dd5d52a3f78e216967086884bbc1a09c6
|
||||
@@ -493,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
|
||||
@@ -559,7 +564,7 @@ F test/tkt2854.test a2bc584ac26bcebe174229e7a1ad4e6d43c3d569
|
||||
F test/tkt2920.test a8737380e4ae6424e00c0273dc12775704efbebf
|
||||
F test/tkt2927.test 4752868b9eeeb07a217f7f19f4cbaac98d6d086d
|
||||
F test/tkt2942.test c5c87d179799ca6d1fbe83c815510b87cd5ec7ce
|
||||
F test/tkt3080.test 31a02e87a4c80ed443831c2c5b0e8216ff95ac14
|
||||
F test/tkt3080.test 1bca7579260920a66b4dd7e196e807c0f25ff804
|
||||
F test/tkt3093.test fbdbc5b4969244ad11f540759003e361fcaf391f
|
||||
F test/tkt3121.test 536df66a02838c26a12fe98639354ca1290ca68b
|
||||
F test/tkt3201.test 607d433ad2c1f6a8cb1af55aaca427f63c83191b
|
||||
@@ -570,10 +575,16 @@ F test/tkt3346.test 2f9a2be8621a87cbdb6283177dd419c7c46dd2a1
|
||||
F test/tkt3357.test b37a51a12ba5e143d6714778276438606f8f9e27
|
||||
F test/tkt3419.test 1bbf36d7ea03b638c15804251287c2391f5c1f6b
|
||||
F test/tkt3424.test 3171193ce340cff6b7ea81c03b8fa1cbc34ec36e
|
||||
F test/tkt3442.test 33722a3fa4bdc0614448044eb5e28765aea28eb7
|
||||
F test/tkt3457.test e9ca2b90f0eb1fb8be73a30d29aacb2e3abedeb9
|
||||
F test/tkt3461.test 5a63e8d8ee5ce00f076b1e2f82aba5480a0f14ed
|
||||
F test/tkt3472.test e689a687631e59c7a47d9438148115fee23b16c3
|
||||
F test/tkt3493.test 8472b3464e49a27ff7271308eec46154209e667b
|
||||
F test/tokenize.test ce430a7aed48fc98301611429595883fdfcab5d7
|
||||
F test/trace.test 951cd0f5f571e7f36bf7bfe04be70f90fb16fb00
|
||||
F test/trans.test 2fd24cd7aa0b879d49a224cbd647d698f1e7ac5c
|
||||
F test/trans2.test d5337e61de45e66b1fcbf9db833fa8c82e624b22
|
||||
F test/trans3.test d728abaa318ca364dc370e06576aa7e5fbed7e97
|
||||
F test/trigger1.test 53342dfd582155a599518f1918fdc997e9413177
|
||||
F test/trigger2.test 33bf8ae9b788013be194efe5f66c04a202facbb4
|
||||
F test/trigger3.test 501b8489eb6b9cb5b005f60b071583c01a3c3041
|
||||
@@ -590,9 +601,9 @@ F test/types2.test 3555aacf8ed8dc883356e59efc314707e6247a84
|
||||
F test/types3.test a0f66bf12f80fad89493535474f7a6d16fa58150
|
||||
F test/unique.test 0253c4227a5dc533e312202ce21ecfad18058d18
|
||||
F test/update.test 8bc86fd7ef1a00014f76dc6a6a7c974df4aef172
|
||||
F test/utf16align.test 7360e84472095518c56746f76b1f9d4dce99fb4d
|
||||
F test/utf16align.test 54cd35a27c005a9b6e7815d887718780b6a462ae
|
||||
F test/vacuum.test 0bc75ee74ab9c69322d6563aa2287375697e630b
|
||||
F test/vacuum2.test e7c5f5bf5e1f2266ca668d420393820cf501fdfc
|
||||
F test/vacuum2.test fd87eec0ed72c6cc0809f7867929e2895affed92
|
||||
F test/vacuum3.test f39ad1428347c5808cd2da7578c470f186a4d0ce
|
||||
F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102
|
||||
F test/veryquick.test e265401afefa994cdf2fe4b6f286b1e87c2f9b9d
|
||||
@@ -612,7 +623,7 @@ F test/vtabC.test 9f2d9eb84bf65e606d6616f20977c5a32a11f548
|
||||
F test/vtab_alter.test 3a299749fee97ca3d53bd55717f536e4a2284856
|
||||
F test/vtab_err.test 0d4d8eb4def1d053ac7c5050df3024fd47a3fbd8
|
||||
F test/vtab_shared.test c19b2555b807ef2ee014c882cdda5bc8d84fcf48
|
||||
F test/where.test 12396f15d8bf7a5763aa26129e071cdb441f600c
|
||||
F test/where.test de337a3fe0a459ec7c93db16a519657a90552330
|
||||
F test/where2.test e446f55417f434929522d87164cd1473d54f10e2
|
||||
F test/where3.test 97d3936e6a443b968f1a61cdcc0f673252000e94
|
||||
F test/where4.test e9b9e2f2f98f00379e6031db6a6fca29bae782a2
|
||||
@@ -622,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 8aff2d49beb7d94a63841e86f3ffd4770e5054aa
|
||||
F tool/mksqlite3c.tcl 619c0629ac51f670f1f522cd0ab1fbb62ca97d45
|
||||
F tool/mksqlite3internalh.tcl 7b43894e21bcb1bb39e11547ce7e38a063357e87
|
||||
F tool/omittest.tcl 27d6f6e3b1e95aeb26a1c140e6eb57771c6d794a
|
||||
F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c
|
||||
@@ -648,7 +659,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
|
||||
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
P 9283478e69d84aa99b2d4636587c8c0b34e7c4da
|
||||
R 471b5d462241fc0e1a0cb7b7d4155791
|
||||
P 15d88edf7671822c57238c3f85adf0b40b13e3e2
|
||||
R d2ce2d5b91c1f6ae4cf2c6a18038f9fd
|
||||
U drh
|
||||
Z 9c14935f349136807f4793420af35d7b
|
||||
Z d6e85c23f6cca1b4a3eb502f6411e7b2
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
cd73cffab39d80393f26a20c90aa97cb73d595ea
|
||||
c2266aa094411346a73ab704c03ec919d6e5f46d
|
||||
+9
-6
@@ -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.48 2008/08/08 14:19:41 drh 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
|
||||
@@ -441,11 +444,11 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
|
||||
Expr *pDflt; /* Default value for the new column */
|
||||
sqlite3 *db; /* The database connection; */
|
||||
|
||||
if( pParse->nErr ) return;
|
||||
db = pParse->db;
|
||||
if( pParse->nErr || db->mallocFailed ) return;
|
||||
pNew = pParse->pNewTable;
|
||||
assert( pNew );
|
||||
|
||||
db = pParse->db;
|
||||
assert( sqlite3BtreeHoldsAllMutexes(db) );
|
||||
iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
|
||||
zDb = db->aDb[iDb].zName;
|
||||
|
||||
+6
-4
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** This file contains code associated with the ANALYZE command.
|
||||
**
|
||||
** @(#) $Id: analyze.c,v 1.43 2008/07/28 19:34:53 drh Exp $
|
||||
** @(#) $Id: analyze.c,v 1.46 2008/11/19 16:52:44 danielk1977 Exp $
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_ANALYZE
|
||||
#include "sqliteInt.h"
|
||||
@@ -86,11 +86,11 @@ static void openStatTable(
|
||||
static void analyzeOneTable(
|
||||
Parse *pParse, /* Parser context */
|
||||
Table *pTab, /* Table whose indices are to be analyzed */
|
||||
int iStatCur, /* Cursor that writes to the sqlite_stat1 table */
|
||||
int iStatCur, /* Index of VdbeCursor that writes the sqlite_stat1 table */
|
||||
int iMem /* Available memory locations begin here */
|
||||
){
|
||||
Index *pIdx; /* An index to being analyzed */
|
||||
int iIdxCur; /* Cursor number for index being analyzed */
|
||||
int iIdxCur; /* Index of VdbeCursor for index being analyzed */
|
||||
int nCol; /* Number of columns in the index */
|
||||
Vdbe *v; /* The virtual machine being built up */
|
||||
int i; /* Loop counter */
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+36
-22
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the ATTACH and DETACH commands.
|
||||
**
|
||||
** $Id: attach.c,v 1.78 2008/08/20 16:35:10 drh 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];
|
||||
@@ -283,8 +287,7 @@ detach_error:
|
||||
static void codeAttach(
|
||||
Parse *pParse, /* The parser context */
|
||||
int type, /* Either SQLITE_ATTACH or SQLITE_DETACH */
|
||||
const char *zFunc, /* Either "sqlite_attach" or "sqlite_detach */
|
||||
int nFunc, /* Number of args to pass to zFunc */
|
||||
FuncDef *pFunc, /* FuncDef wrapper for detachFunc() or attachFunc() */
|
||||
Expr *pAuthArg, /* Expression to pass to authorization callback */
|
||||
Expr *pFilename, /* Name of database file */
|
||||
Expr *pDbname, /* Name of the database to use internally */
|
||||
@@ -293,7 +296,6 @@ static void codeAttach(
|
||||
int rc;
|
||||
NameContext sName;
|
||||
Vdbe *v;
|
||||
FuncDef *pFunc;
|
||||
sqlite3* db = pParse->db;
|
||||
int regArgs;
|
||||
|
||||
@@ -332,9 +334,8 @@ static void codeAttach(
|
||||
|
||||
assert( v || db->mallocFailed );
|
||||
if( v ){
|
||||
sqlite3VdbeAddOp3(v, OP_Function, 0, regArgs+3-nFunc, regArgs+3);
|
||||
sqlite3VdbeChangeP5(v, nFunc);
|
||||
pFunc = sqlite3FindFunction(db, zFunc, strlen(zFunc), nFunc, SQLITE_UTF8,0);
|
||||
sqlite3VdbeAddOp3(v, OP_Function, 0, regArgs+3-pFunc->nArg, regArgs+3);
|
||||
sqlite3VdbeChangeP5(v, pFunc->nArg);
|
||||
sqlite3VdbeChangeP4(v, -1, (char *)pFunc, P4_FUNCDEF);
|
||||
|
||||
/* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this
|
||||
@@ -356,7 +357,19 @@ attach_end:
|
||||
** DETACH pDbname
|
||||
*/
|
||||
void sqlite3Detach(Parse *pParse, Expr *pDbname){
|
||||
codeAttach(pParse, SQLITE_DETACH, "sqlite_detach", 1, pDbname, 0, 0, pDbname);
|
||||
static FuncDef detach_func = {
|
||||
1, /* nArg */
|
||||
SQLITE_UTF8, /* iPrefEnc */
|
||||
0, /* flags */
|
||||
0, /* pUserData */
|
||||
0, /* pNext */
|
||||
detachFunc, /* xFunc */
|
||||
0, /* xStep */
|
||||
0, /* xFinalize */
|
||||
"sqlite_detach", /* zName */
|
||||
0 /* pHash */
|
||||
};
|
||||
codeAttach(pParse, SQLITE_DETACH, &detach_func, pDbname, 0, 0, pDbname);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -365,21 +378,22 @@ void sqlite3Detach(Parse *pParse, Expr *pDbname){
|
||||
** ATTACH p AS pDbname KEY pKey
|
||||
*/
|
||||
void sqlite3Attach(Parse *pParse, Expr *p, Expr *pDbname, Expr *pKey){
|
||||
codeAttach(pParse, SQLITE_ATTACH, "sqlite_attach", 3, p, p, pDbname, pKey);
|
||||
static FuncDef attach_func = {
|
||||
3, /* nArg */
|
||||
SQLITE_UTF8, /* iPrefEnc */
|
||||
0, /* flags */
|
||||
0, /* pUserData */
|
||||
0, /* pNext */
|
||||
attachFunc, /* xFunc */
|
||||
0, /* xStep */
|
||||
0, /* xFinalize */
|
||||
"sqlite_attach", /* zName */
|
||||
0 /* pHash */
|
||||
};
|
||||
codeAttach(pParse, SQLITE_ATTACH, &attach_func, p, p, pDbname, pKey);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_ATTACH */
|
||||
|
||||
/*
|
||||
** Register the functions sqlite_attach and sqlite_detach.
|
||||
*/
|
||||
void sqlite3AttachFunctions(sqlite3 *db){
|
||||
#ifndef SQLITE_OMIT_ATTACH
|
||||
static const int enc = SQLITE_UTF8;
|
||||
sqlite3CreateFunc(db, "sqlite_attach", 3, enc, 0, attachFunc, 0, 0);
|
||||
sqlite3CreateFunc(db, "sqlite_detach", 1, enc, 0, detachFunc, 0, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
** Initialize a DbFixer structure. This routine must be called prior
|
||||
** to passing the structure to one of the sqliteFixAAAA() routines below.
|
||||
|
||||
+118
-55
@@ -12,12 +12,14 @@
|
||||
** This file implements an object that represents a fixed-length
|
||||
** bitmap. Bits are numbered starting with 1.
|
||||
**
|
||||
** A bitmap is used to record what pages a database file have been
|
||||
** journalled during a transaction. Usually only a few pages are
|
||||
** journalled. So the bitmap is usually sparse and has low cardinality.
|
||||
** A bitmap is used to record which pages of a database file have been
|
||||
** journalled during a transaction, or which pages have the "dont-write"
|
||||
** property. Usually only a few pages are meet either condition.
|
||||
** So the bitmap is usually sparse and has low cardinality.
|
||||
** But sometimes (for example when during a DROP of a large table) most
|
||||
** or all of the pages get journalled. In those cases, the bitmap becomes
|
||||
** dense. The algorithm needs to handle both cases well.
|
||||
** or all of the pages in a database can get journalled. In those cases,
|
||||
** the bitmap becomes dense with high cardinality. The algorithm needs
|
||||
** to handle both cases well.
|
||||
**
|
||||
** The size of the bitmap is fixed when the object is created.
|
||||
**
|
||||
@@ -32,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.6 2008/06/20 14:59:51 danielk1977 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.
|
||||
@@ -70,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;
|
||||
@@ -103,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++;
|
||||
@@ -125,40 +155,64 @@ int sqlite3BitvecTest(Bitvec *p, u32 i){
|
||||
/*
|
||||
** Set the i-th bit. Return 0 on success and an error code if
|
||||
** anything goes wrong.
|
||||
**
|
||||
** This routine might cause sub-bitmaps to be allocated. Failing
|
||||
** to get the memory needed to hold the sub-bitmap is the only
|
||||
** that can go wrong with an insert, assuming p and i are valid.
|
||||
**
|
||||
** The calling function must ensure that p is a valid Bitvec object
|
||||
** and that the value for "i" is within range of the Bitvec object.
|
||||
** Otherwise the behavior is undefined.
|
||||
*/
|
||||
int sqlite3BitvecSet(Bitvec *p, u32 i){
|
||||
u32 h;
|
||||
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 ){
|
||||
int j, rc;
|
||||
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++){
|
||||
@@ -166,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{
|
||||
int j;
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -206,7 +269,7 @@ void sqlite3BitvecClear(Bitvec *p, u32 i){
|
||||
void sqlite3BitvecDestroy(Bitvec *p){
|
||||
if( p==0 ) return;
|
||||
if( p->iDivisor ){
|
||||
int i;
|
||||
unsigned int i;
|
||||
for(i=0; i<BITVEC_NPTR; i++){
|
||||
sqlite3BitvecDestroy(p->u.apSub[i]);
|
||||
}
|
||||
|
||||
+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 );
|
||||
|
||||
+145
-79
@@ -9,7 +9,7 @@
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** $Id: btree.c,v 1.525 2008/10/08 17:58:49 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.
|
||||
@@ -406,7 +406,7 @@ int sqlite3BtreeRestoreCursorPosition(BtCursor *pCur){
|
||||
|
||||
/*
|
||||
** Determine whether or not a cursor has moved from the position it
|
||||
** was last placed at. Cursor can move when the row they are pointing
|
||||
** was last placed at. Cursors can move when the row they are pointing
|
||||
** at is deleted out from under them.
|
||||
**
|
||||
** This routine returns an error code if something goes wrong. The
|
||||
@@ -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;
|
||||
@@ -702,7 +703,7 @@ static int ptrmapPutOvfl(MemPage *pPage, int iCell){
|
||||
** big FreeBlk that occurs in between the header and cell
|
||||
** pointer array and the cell content area.
|
||||
*/
|
||||
static void defragmentPage(MemPage *pPage){
|
||||
static int defragmentPage(MemPage *pPage){
|
||||
int i; /* Loop counter */
|
||||
int pc; /* Address of a i-th cell */
|
||||
int addr; /* Offset of first byte after cell pointer array */
|
||||
@@ -734,9 +735,15 @@ static void defragmentPage(MemPage *pPage){
|
||||
u8 *pAddr; /* The i-th cell pointer */
|
||||
pAddr = &data[cellOffset + i*2];
|
||||
pc = get2byte(pAddr);
|
||||
assert( pc<pPage->pBt->usableSize );
|
||||
if( pc>=usableSize ){
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
size = cellSizePtr(pPage, &temp[pc]);
|
||||
cbrk -= size;
|
||||
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);
|
||||
}
|
||||
@@ -747,6 +754,10 @@ static void defragmentPage(MemPage *pPage){
|
||||
data[hdr+7] = 0;
|
||||
addr = cellOffset+2*nCell;
|
||||
memset(&data[addr], 0, cbrk-addr);
|
||||
if( cbrk-addr!=pPage->nFree ){
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -825,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;
|
||||
|
||||
@@ -847,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);
|
||||
@@ -867,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);
|
||||
@@ -884,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;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1091,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;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1132,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);
|
||||
@@ -1187,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) );
|
||||
@@ -1304,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 ){
|
||||
@@ -1314,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);
|
||||
@@ -2012,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 ){
|
||||
@@ -2037,7 +2055,6 @@ trans_begun:
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTOVACUUM
|
||||
|
||||
/*
|
||||
@@ -2251,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) ){
|
||||
@@ -2382,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;
|
||||
@@ -2427,7 +2444,7 @@ static int autoVacuumCommit(BtShared *pBt, Pgno *pnTrunc){
|
||||
return rc;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* ifndef SQLITE_OMIT_AUTOVACUUM */
|
||||
|
||||
/*
|
||||
** This routine does the first phase of a two-phase commit. This routine
|
||||
@@ -2594,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);
|
||||
}
|
||||
@@ -2783,6 +2805,7 @@ static int btreeCursor(
|
||||
BtCursor *pCur /* Space for new cursor */
|
||||
){
|
||||
int rc;
|
||||
Pgno nPage;
|
||||
BtShared *pBt = p->pBt;
|
||||
|
||||
assert( sqlite3BtreeHoldsMutex(p) );
|
||||
@@ -2805,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;
|
||||
}
|
||||
@@ -3066,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;
|
||||
@@ -3162,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. */
|
||||
@@ -3173,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);
|
||||
@@ -3188,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;
|
||||
}
|
||||
@@ -3207,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]);
|
||||
@@ -3376,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 );
|
||||
@@ -4066,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 );
|
||||
@@ -4201,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;
|
||||
@@ -4233,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
|
||||
@@ -4277,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;
|
||||
}
|
||||
@@ -4400,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;
|
||||
}
|
||||
|
||||
@@ -4462,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;
|
||||
@@ -4559,11 +4589,12 @@ static int fillInCell(
|
||||
**
|
||||
** "sz" must be the number of bytes in the cell.
|
||||
*/
|
||||
static void dropCell(MemPage *pPage, int idx, int sz){
|
||||
static int dropCell(MemPage *pPage, int idx, int sz){
|
||||
int i; /* Loop counter */
|
||||
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) );
|
||||
@@ -4572,8 +4603,13 @@ static void dropCell(MemPage *pPage, int idx, int sz){
|
||||
data = pPage->aData;
|
||||
ptr = &data[pPage->cellOffset + 2*idx];
|
||||
pc = get2byte(ptr);
|
||||
assert( pc>10 && pc+sz<=pPage->pBt->usableSize );
|
||||
freeSpace(pPage, pc, sz);
|
||||
if ( (pc<pPage->hdrOffset+6+(pPage->leaf?0:4)) || (pc+sz>pPage->pBt->usableSize) ) {
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
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];
|
||||
@@ -4581,6 +4617,7 @@ static void dropCell(MemPage *pPage, int idx, int sz){
|
||||
pPage->nCell--;
|
||||
put2byte(&data[pPage->hdrOffset+3], pPage->nCell);
|
||||
pPage->nFree += 2;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -4627,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;
|
||||
@@ -4644,13 +4681,19 @@ static int insertCell(
|
||||
end = cellOffset + 2*pPage->nCell + 2;
|
||||
ins = cellOffset + 2*i;
|
||||
if( end > top - sz ){
|
||||
defragmentPage(pPage);
|
||||
rc = defragmentPage(pPage);
|
||||
if( rc!=SQLITE_OK ){
|
||||
return rc;
|
||||
}
|
||||
top = get2byte(&data[hdr+5]);
|
||||
assert( end + sz <= top );
|
||||
}
|
||||
idx = allocateSpace(pPage, sz);
|
||||
assert( idx>0 );
|
||||
assert( end <= get2byte(&data[hdr+5]) );
|
||||
if (idx+sz > pPage->pBt->usableSize) {
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
pPage->nCell++;
|
||||
pPage->nFree -= 2;
|
||||
memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip);
|
||||
@@ -5508,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 ){
|
||||
@@ -5545,9 +5588,11 @@ static int balance_shallower(BtCursor *pCur){
|
||||
pChild->pgno, pPage->pgno));
|
||||
}
|
||||
assert( pPage->nOverflow==0 );
|
||||
#ifndef SQLITE_OMIT_AUTOVACUUM
|
||||
if( ISAUTOVACUUM ){
|
||||
rc = setChildPtrmaps(pPage);
|
||||
}
|
||||
#endif
|
||||
releasePage(pChild);
|
||||
}
|
||||
end_shallow_balance:
|
||||
@@ -5594,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]);
|
||||
@@ -5609,9 +5655,11 @@ static int balance_deeper(BtCursor *pCur){
|
||||
TRACE(("BALANCE: copy root %d into %d\n", pPage->pgno, pChild->pgno));
|
||||
if( ISAUTOVACUUM ){
|
||||
rc = ptrmapPut(pBt, pChild->pgno, PTRMAP_BTREE, pPage->pgno);
|
||||
#ifndef SQLITE_OMIT_AUTOVACUUM
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = setChildPtrmaps(pChild);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5808,7 +5856,10 @@ int sqlite3BtreeInsert(
|
||||
szOld = cellSizePtr(pPage, oldCell);
|
||||
rc = clearCell(pPage, oldCell);
|
||||
if( rc ) goto end_insert;
|
||||
dropCell(pPage, idx, szOld);
|
||||
rc = dropCell(pPage, idx, szOld);
|
||||
if( rc!=SQLITE_OK ) {
|
||||
goto end_insert;
|
||||
}
|
||||
}else if( loc<0 && pPage->nCell>0 ){
|
||||
assert( pPage->leaf );
|
||||
idx = ++pCur->aiIdx[pCur->iPage];
|
||||
@@ -6019,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);
|
||||
@@ -6186,8 +6239,8 @@ 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 freePageFlag, /* Deallocate page if true */
|
||||
int *pnChange
|
||||
){
|
||||
MemPage *pPage = 0;
|
||||
int rc;
|
||||
@@ -6195,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;
|
||||
}
|
||||
|
||||
@@ -6204,15 +6257,18 @@ static int clearDatabasePage(
|
||||
for(i=0; i<pPage->nCell; i++){
|
||||
pCell = findCell(pPage, i);
|
||||
if( !pPage->leaf ){
|
||||
rc = clearDatabasePage(pBt, get4byte(pCell), pPage, 1);
|
||||
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);
|
||||
rc = clearDatabasePage(pBt, get4byte(&pPage->aData[8]), 1, pnChange);
|
||||
if( rc ) goto cleardatabasepage_out;
|
||||
}else if( pnChange ){
|
||||
assert( pPage->intKey );
|
||||
*pnChange += pPage->nCell;
|
||||
}
|
||||
if( freePageFlag ){
|
||||
rc = freePage(pPage);
|
||||
@@ -6233,8 +6289,12 @@ cleardatabasepage_out:
|
||||
** This routine will fail with SQLITE_LOCKED if there are any open
|
||||
** read cursors on the table. Open write cursors are moved to the
|
||||
** root of the table.
|
||||
**
|
||||
** If pnChange is not NULL, then table iTable must be an intkey table. The
|
||||
** integer value pointed to by pnChange is incremented by the number of
|
||||
** entries in the table.
|
||||
*/
|
||||
int sqlite3BtreeClearTable(Btree *p, int iTable){
|
||||
int sqlite3BtreeClearTable(Btree *p, int iTable, int *pnChange){
|
||||
int rc;
|
||||
BtShared *pBt = p->pBt;
|
||||
sqlite3BtreeEnter(p);
|
||||
@@ -6246,7 +6306,7 @@ int sqlite3BtreeClearTable(Btree *p, int iTable){
|
||||
}else if( SQLITE_OK!=(rc = saveAllCursors(pBt, iTable, 0)) ){
|
||||
/* nothing to do */
|
||||
}else{
|
||||
rc = clearDatabasePage(pBt, (Pgno)iTable, 0, 0);
|
||||
rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange);
|
||||
}
|
||||
sqlite3BtreeLeave(p);
|
||||
return rc;
|
||||
@@ -6272,7 +6332,7 @@ int sqlite3BtreeClearTable(Btree *p, int iTable){
|
||||
** 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;
|
||||
@@ -6294,7 +6354,7 @@ static int btreeDropTable(Btree *p, int iTable, int *piMoved){
|
||||
|
||||
rc = sqlite3BtreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
|
||||
if( rc ) return rc;
|
||||
rc = sqlite3BtreeClearTable(p, iTable);
|
||||
rc = sqlite3BtreeClearTable(p, iTable, 0);
|
||||
if( rc ){
|
||||
releasePage(pPage);
|
||||
return rc;
|
||||
@@ -6555,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;
|
||||
}
|
||||
@@ -6692,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;
|
||||
@@ -6703,7 +6762,7 @@ static int checkTreePage(
|
||||
BtShared *pBt;
|
||||
int usableSize;
|
||||
char zContext[100];
|
||||
char *hit;
|
||||
char *hit = 0;
|
||||
|
||||
sqlite3_snprintf(sizeof(zContext), zContext, "Page %d: ", iPage);
|
||||
|
||||
@@ -6730,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
|
||||
@@ -6762,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");
|
||||
}
|
||||
@@ -6778,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
|
||||
@@ -6789,8 +6848,14 @@ static int checkTreePage(
|
||||
if( hit==0 ){
|
||||
pCheck->mallocFailed = 1;
|
||||
}else{
|
||||
memset(hit, 0, usableSize );
|
||||
memset(hit, 1, get2byte(&data[hdr+5]));
|
||||
u16 contentOffset = get2byte(&data[hdr+5]);
|
||||
if (contentOffset > usableSize) {
|
||||
checkAppendMsg(pCheck, 0,
|
||||
"Corruption detected in header on page %d",iPage,0);
|
||||
goto check_page_abort;
|
||||
}
|
||||
memset(hit+contentOffset, 0, usableSize-contentOffset);
|
||||
memset(hit, 1, contentOffset);
|
||||
nCell = get2byte(&data[hdr+3]);
|
||||
cellStart = hdr + 12 - 4*pPage->leaf;
|
||||
for(i=0; i<nCell; i++){
|
||||
@@ -6834,7 +6899,8 @@ static int checkTreePage(
|
||||
cnt, data[hdr+7], iPage);
|
||||
}
|
||||
}
|
||||
sqlite3PageFree(hit);
|
||||
check_page_abort:
|
||||
if (hit) sqlite3PageFree(hit);
|
||||
|
||||
releasePage(pPage);
|
||||
return depth+1;
|
||||
@@ -6859,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;
|
||||
@@ -6875,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;
|
||||
@@ -6911,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
|
||||
@@ -7042,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
|
||||
|
||||
+2
-2
@@ -13,7 +13,7 @@
|
||||
** subsystem. See comments in the source code for a detailed description
|
||||
** of what each interface routine does.
|
||||
**
|
||||
** @(#) $Id: btree.h,v 1.104 2008/10/08 17:58:49 danielk1977 Exp $
|
||||
** @(#) $Id: btree.h,v 1.105 2008/10/27 13:59:34 danielk1977 Exp $
|
||||
*/
|
||||
#ifndef _BTREE_H_
|
||||
#define _BTREE_H_
|
||||
@@ -117,7 +117,7 @@ int sqlite3BtreeIncrVacuum(Btree *);
|
||||
#define BTREE_LEAFDATA 4 /* Data stored in leaves only. Implies INTKEY */
|
||||
|
||||
int sqlite3BtreeDropTable(Btree*, int, int*);
|
||||
int sqlite3BtreeClearTable(Btree*, int);
|
||||
int sqlite3BtreeClearTable(Btree*, int, int*);
|
||||
int sqlite3BtreeGetMeta(Btree*, int idx, u32 *pValue);
|
||||
int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
|
||||
void sqlite3BtreeTripAllCursors(Btree*, int);
|
||||
|
||||
+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 */
|
||||
|
||||
+86
-21
@@ -22,7 +22,7 @@
|
||||
** COMMIT
|
||||
** ROLLBACK
|
||||
**
|
||||
** $Id: build.c,v 1.498 2008/10/06 16:18:40 danielk1977 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);
|
||||
}
|
||||
@@ -2401,7 +2405,7 @@ void sqlite3CreateIndex(
|
||||
}
|
||||
pTab = sqlite3LocateTable(pParse, 0, pTblName->a[0].zName,
|
||||
pTblName->a[0].zDatabase);
|
||||
if( !pTab ) goto exit_create_index;
|
||||
if( !pTab || db->mallocFailed ) goto exit_create_index;
|
||||
assert( db->aDb[iDb].pSchema==pTab->pSchema );
|
||||
}else{
|
||||
assert( pName==0 );
|
||||
@@ -2991,11 +2995,81 @@ int sqlite3IdListIndex(IdList *pList, const char *zName){
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
** Expand the space allocated for the given SrcList object by
|
||||
** creating nExtra new slots beginning at iStart. iStart is zero based.
|
||||
** New slots are zeroed.
|
||||
**
|
||||
** For example, suppose a SrcList initially contains two entries: A,B.
|
||||
** To append 3 new entries onto the end, do this:
|
||||
**
|
||||
** sqlite3SrcListEnlarge(db, pSrclist, 3, 2);
|
||||
**
|
||||
** After the call above it would contain: A, B, nil, nil, nil.
|
||||
** If the iStart argument had been 1 instead of 2, then the result
|
||||
** would have been: A, nil, nil, nil, B. To prepend the new slots,
|
||||
** the iStart value would be 0. The result then would
|
||||
** be: nil, nil, nil, A, B.
|
||||
**
|
||||
** If a memory allocation fails the SrcList is unchanged. The
|
||||
** db->mallocFailed flag will be set to true.
|
||||
*/
|
||||
SrcList *sqlite3SrcListEnlarge(
|
||||
sqlite3 *db, /* Database connection to notify of OOM errors */
|
||||
SrcList *pSrc, /* The SrcList to be enlarged */
|
||||
int nExtra, /* Number of new slots to add to pSrc->a[] */
|
||||
int iStart /* Index in pSrc->a[] of first new slot */
|
||||
){
|
||||
int i;
|
||||
|
||||
/* Sanity checking on calling parameters */
|
||||
assert( iStart>=0 );
|
||||
assert( nExtra>=1 );
|
||||
if( pSrc==0 || iStart>pSrc->nSrc ){
|
||||
assert( db->mallocFailed );
|
||||
return pSrc;
|
||||
}
|
||||
|
||||
/* Allocate additional space if needed */
|
||||
if( pSrc->nSrc+nExtra>pSrc->nAlloc ){
|
||||
SrcList *pNew;
|
||||
int nAlloc = pSrc->nSrc+nExtra;
|
||||
pNew = sqlite3DbRealloc(db, pSrc,
|
||||
sizeof(*pSrc) + (nAlloc-1)*sizeof(pSrc->a[0]) );
|
||||
if( pNew==0 ){
|
||||
assert( db->mallocFailed );
|
||||
return pSrc;
|
||||
}
|
||||
pSrc = pNew;
|
||||
pSrc->nAlloc = nAlloc;
|
||||
}
|
||||
|
||||
/* Move existing slots that come after the newly inserted slots
|
||||
** out of the way */
|
||||
for(i=pSrc->nSrc-1; i>=iStart; i--){
|
||||
pSrc->a[i+nExtra] = pSrc->a[i];
|
||||
}
|
||||
pSrc->nSrc += nExtra;
|
||||
|
||||
/* Zero the newly allocated slots */
|
||||
memset(&pSrc->a[iStart], 0, sizeof(pSrc->a[0])*nExtra);
|
||||
for(i=iStart; i<iStart+nExtra; i++){
|
||||
pSrc->a[i].iCursor = -1;
|
||||
}
|
||||
|
||||
/* Return a pointer to the enlarged SrcList */
|
||||
return pSrc;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Append a new table name to the given SrcList. Create a new SrcList if
|
||||
** need be. A new entry is created in the SrcList even if pToken is NULL.
|
||||
**
|
||||
** A new SrcList is returned, or NULL if malloc() fails.
|
||||
** A SrcList is returned, or NULL if there is an OOM error. The returned
|
||||
** SrcList might be the same as the SrcList that was input or it might be
|
||||
** a new one. If an OOM error does occurs, then the prior value of pList
|
||||
** that is input to this routine is automatically freed.
|
||||
**
|
||||
** If pDatabase is not null, it means that the table has an optional
|
||||
** database name prefix. Like this: "database.table". The pDatabase
|
||||
@@ -3028,19 +3102,12 @@ SrcList *sqlite3SrcListAppend(
|
||||
if( pList==0 ) return 0;
|
||||
pList->nAlloc = 1;
|
||||
}
|
||||
if( pList->nSrc>=pList->nAlloc ){
|
||||
SrcList *pNew;
|
||||
pList->nAlloc *= 2;
|
||||
pNew = sqlite3DbRealloc(db, pList,
|
||||
sizeof(*pList) + (pList->nAlloc-1)*sizeof(pList->a[0]) );
|
||||
if( pNew==0 ){
|
||||
sqlite3SrcListDelete(db, pList);
|
||||
return 0;
|
||||
}
|
||||
pList = pNew;
|
||||
pList = sqlite3SrcListEnlarge(db, pList, 1, pList->nSrc);
|
||||
if( db->mallocFailed ){
|
||||
sqlite3SrcListDelete(db, pList);
|
||||
return 0;
|
||||
}
|
||||
pItem = &pList->a[pList->nSrc];
|
||||
memset(pItem, 0, sizeof(pList->a[0]));
|
||||
pItem = &pList->a[pList->nSrc-1];
|
||||
if( pDatabase && pDatabase->z==0 ){
|
||||
pDatabase = 0;
|
||||
}
|
||||
@@ -3051,13 +3118,11 @@ SrcList *sqlite3SrcListAppend(
|
||||
}
|
||||
pItem->zName = sqlite3NameFromToken(db, pTable);
|
||||
pItem->zDatabase = sqlite3NameFromToken(db, pDatabase);
|
||||
pItem->iCursor = -1;
|
||||
pList->nSrc++;
|
||||
return pList;
|
||||
}
|
||||
|
||||
/*
|
||||
** Assign cursors to all tables in a SrcList
|
||||
** Assign VdbeCursor index numbers to all tables in a SrcList
|
||||
*/
|
||||
void sqlite3SrcListAssignCursors(Parse *pParse, SrcList *pList){
|
||||
int i;
|
||||
|
||||
+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) */
|
||||
|
||||
+17
-26
@@ -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.182 2008/10/10 23:48:26 drh Exp $
|
||||
** $Id: delete.c,v 1.187 2008/11/19 09:05:27 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -233,7 +233,8 @@ void sqlite3DeleteFrom(
|
||||
int oldIdx = -1; /* Cursor for the OLD table of AFTER triggers */
|
||||
NameContext sNC; /* Name context to resolve expressions in */
|
||||
int iDb; /* Database number */
|
||||
int memCnt = 0; /* Memory cell used for change counting */
|
||||
int memCnt = -1; /* Memory cell used for change counting */
|
||||
int rcauth; /* Value returned by authorization callback */
|
||||
|
||||
#ifndef SQLITE_OMIT_TRIGGER
|
||||
int isView; /* True if attempting to delete from a view */
|
||||
@@ -264,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
|
||||
@@ -281,9 +282,12 @@ void sqlite3DeleteFrom(
|
||||
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
|
||||
assert( iDb<db->nDb );
|
||||
zDb = db->aDb[iDb].zName;
|
||||
if( sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb) ){
|
||||
rcauth = sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb);
|
||||
assert( rcauth==SQLITE_OK || rcauth==SQLITE_DENY || rcauth==SQLITE_IGNORE );
|
||||
if( rcauth==SQLITE_DENY ){
|
||||
goto delete_from_cleanup;
|
||||
}
|
||||
assert(!isView || triggers_exist);
|
||||
|
||||
/* If pTab is really a view, make sure it has been initialized.
|
||||
*/
|
||||
@@ -369,28 +373,15 @@ void sqlite3DeleteFrom(
|
||||
** It is easier just to erase the whole table. Note, however, that
|
||||
** this means that the row change count will be incorrect.
|
||||
*/
|
||||
if( pWhere==0 && !triggers_exist && !IsVirtual(pTab) ){
|
||||
if( db->flags & SQLITE_CountRows ){
|
||||
/* If counting rows deleted, just count the total number of
|
||||
** entries in the table. */
|
||||
int addr2;
|
||||
if( !isView ){
|
||||
sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
|
||||
}
|
||||
sqlite3VdbeAddOp2(v, OP_Rewind, iCur, sqlite3VdbeCurrentAddr(v)+2);
|
||||
addr2 = sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
|
||||
sqlite3VdbeAddOp2(v, OP_Next, iCur, addr2);
|
||||
sqlite3VdbeAddOp1(v, OP_Close, iCur);
|
||||
if( rcauth==SQLITE_OK && pWhere==0 && !triggers_exist && !IsVirtual(pTab) ){
|
||||
assert( !isView );
|
||||
sqlite3VdbeAddOp3(v, OP_Clear, pTab->tnum, iDb, memCnt);
|
||||
if( !pParse->nested ){
|
||||
sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_STATIC);
|
||||
}
|
||||
if( !isView ){
|
||||
sqlite3VdbeAddOp2(v, OP_Clear, pTab->tnum, iDb);
|
||||
if( !pParse->nested ){
|
||||
sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_STATIC);
|
||||
}
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
assert( pIdx->pSchema==pTab->pSchema );
|
||||
sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
|
||||
}
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
assert( pIdx->pSchema==pTab->pSchema );
|
||||
sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
|
||||
}
|
||||
}else
|
||||
#endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
|
||||
@@ -510,7 +501,7 @@ void sqlite3DeleteFrom(
|
||||
if( db->flags & SQLITE_CountRows && pParse->nested==0 && !pParse->trigStack ){
|
||||
sqlite3VdbeAddOp2(v, OP_ResultRow, memCnt, 1);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows deleted", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows deleted", SQLITE_STATIC);
|
||||
}
|
||||
|
||||
delete_from_cleanup:
|
||||
|
||||
+26
-12
@@ -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.399 2008/10/11 16:47:36 drh Exp $
|
||||
** $Id: expr.c,v 1.404 2008/11/19 16:52:44 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@@ -43,7 +43,9 @@ char sqlite3ExprAffinity(Expr *pExpr){
|
||||
return sqlite3AffinityType(&pExpr->token);
|
||||
}
|
||||
#endif
|
||||
if( (op==TK_COLUMN || op==TK_REGISTER) && pExpr->pTab!=0 ){
|
||||
if( (op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_REGISTER)
|
||||
&& pExpr->pTab!=0
|
||||
){
|
||||
/* op==TK_REGISTER && pExpr->pTab!=0 happens when pExpr was originally
|
||||
** a TK_COLUMN but was previously evaluated and cached in a register */
|
||||
int j = pExpr->iColumn;
|
||||
@@ -89,7 +91,7 @@ CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr){
|
||||
pColl = p->pColl;
|
||||
if( pColl ) break;
|
||||
op = p->op;
|
||||
if( (op==TK_COLUMN || op==TK_REGISTER) && p->pTab!=0 ){
|
||||
if( (op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_REGISTER) && p->pTab!=0 ){
|
||||
/* op==TK_REGISTER && p->pTab!=0 happens when pExpr was originally
|
||||
** a TK_COLUMN but was previously evaluated and cached in a register */
|
||||
const char *zColl;
|
||||
@@ -937,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;
|
||||
}
|
||||
@@ -1457,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);
|
||||
@@ -1718,7 +1722,7 @@ void sqlite3ExprHardCopy(Parse *pParse, int iReg, int nReg){
|
||||
** of the iAlias-th alias is stored. If zero, that means that the
|
||||
** alias has not yet been computed.
|
||||
*/
|
||||
static int codeAlias(Parse *pParse, int iAlias, Expr *pExpr){
|
||||
static int codeAlias(Parse *pParse, int iAlias, Expr *pExpr, int target){
|
||||
sqlite3 *db = pParse->db;
|
||||
int iReg;
|
||||
if( pParse->aAlias==0 ){
|
||||
@@ -1729,9 +1733,13 @@ static int codeAlias(Parse *pParse, int iAlias, Expr *pExpr){
|
||||
assert( iAlias>0 && iAlias<=pParse->nAlias );
|
||||
iReg = pParse->aAlias[iAlias-1];
|
||||
if( iReg==0 ){
|
||||
iReg = ++pParse->nMem;
|
||||
sqlite3ExprCode(pParse, pExpr, iReg);
|
||||
pParse->aAlias[iAlias-1] = iReg;
|
||||
if( pParse->disableColCache ){
|
||||
iReg = sqlite3ExprCodeTarget(pParse, pExpr, target);
|
||||
}else{
|
||||
iReg = ++pParse->nMem;
|
||||
sqlite3ExprCode(pParse, pExpr, iReg);
|
||||
pParse->aAlias[iAlias-1] = iReg;
|
||||
}
|
||||
}
|
||||
return iReg;
|
||||
}
|
||||
@@ -1840,7 +1848,7 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
|
||||
break;
|
||||
}
|
||||
case TK_AS: {
|
||||
inReg = codeAlias(pParse, pExpr->iTable, pExpr->pLeft);
|
||||
inReg = codeAlias(pParse, pExpr->iTable, pExpr->pLeft, target);
|
||||
break;
|
||||
}
|
||||
#ifndef SQLITE_OMIT_CAST
|
||||
@@ -1860,6 +1868,10 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
|
||||
testcase( to_op==OP_ToNumeric );
|
||||
testcase( to_op==OP_ToInt );
|
||||
testcase( to_op==OP_ToReal );
|
||||
if( inReg!=target ){
|
||||
sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
|
||||
inReg = target;
|
||||
}
|
||||
sqlite3VdbeAddOp1(v, to_op, inReg);
|
||||
testcase( usedAsColumnCache(pParse, inReg, inReg) );
|
||||
sqlite3ExprCacheAffinityChange(pParse, inReg, 1);
|
||||
@@ -2500,9 +2512,11 @@ int sqlite3ExprCodeExprList(
|
||||
n = pList->nExpr;
|
||||
for(pItem=pList->a, i=0; i<n; i++, pItem++){
|
||||
if( pItem->iAlias ){
|
||||
int iReg = codeAlias(pParse, pItem->iAlias, pItem->pExpr);
|
||||
int iReg = codeAlias(pParse, pItem->iAlias, pItem->pExpr, target+i);
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
sqlite3VdbeAddOp2(v, OP_SCopy, iReg, target+i);
|
||||
if( iReg!=target+i ){
|
||||
sqlite3VdbeAddOp2(v, OP_SCopy, iReg, target+i);
|
||||
}
|
||||
}else{
|
||||
sqlite3ExprCode(pParse, pItem->pExpr, target+i);
|
||||
}
|
||||
|
||||
+33
-17
@@ -16,7 +16,7 @@
|
||||
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
|
||||
** All other code has file scope.
|
||||
**
|
||||
** $Id: func.c,v 1.203 2008/09/03 17:11:16 drh 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));
|
||||
@@ -1216,9 +1235,6 @@ static void groupConcatFinalize(sqlite3_context *context){
|
||||
void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
|
||||
#ifndef SQLITE_OMIT_ALTERTABLE
|
||||
sqlite3AlterFunctions(db);
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_PARSER
|
||||
sqlite3AttachFunctions(db);
|
||||
#endif
|
||||
if( !db->mallocFailed ){
|
||||
int rc = sqlite3_overload_function(db, "MATCH", 2);
|
||||
|
||||
+11
-13
@@ -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.249 2008/08/20 16:35:10 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
|
||||
);
|
||||
@@ -992,7 +991,7 @@ void sqlite3Insert(
|
||||
if( db->flags & SQLITE_CountRows && pParse->nested==0 && !pParse->trigStack ){
|
||||
sqlite3VdbeAddOp2(v, OP_ResultRow, regRowCount, 1);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows inserted", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows inserted", SQLITE_STATIC);
|
||||
}
|
||||
|
||||
insert_cleanup:
|
||||
@@ -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 */
|
||||
@@ -1385,7 +1383,7 @@ void sqlite3CompleteInsertion(
|
||||
int sqlite3OpenTableAndIndices(
|
||||
Parse *pParse, /* Parsing context */
|
||||
Table *pTab, /* Table to be opened */
|
||||
int baseCur, /* Cursor number assigned to the table */
|
||||
int baseCur, /* Cursor number assigned to the table */
|
||||
int op /* OP_OpenRead or OP_OpenWrite */
|
||||
){
|
||||
int i;
|
||||
|
||||
+32
-9
@@ -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.508 2008/10/12 00:27:53 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 */
|
||||
@@ -340,14 +354,6 @@ int sqlite3_config(int op, ...){
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(SQLITE_ENABLE_MEMSYS6)
|
||||
case SQLITE_CONFIG_CHUNKALLOC: {
|
||||
sqlite3GlobalConfig.nSmall = va_arg(ap, int);
|
||||
sqlite3GlobalConfig.m = *sqlite3MemGetMemsys6();
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
case SQLITE_CONFIG_LOOKASIDE: {
|
||||
sqlite3GlobalConfig.szLookaside = va_arg(ap, int);
|
||||
sqlite3GlobalConfig.nLookaside = va_arg(ap, int);
|
||||
@@ -415,6 +421,13 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the mutex associated with a database connection.
|
||||
*/
|
||||
sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){
|
||||
return db->mutex;
|
||||
}
|
||||
|
||||
/*
|
||||
** Configuration settings for an individual database connection
|
||||
*/
|
||||
@@ -502,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;
|
||||
}
|
||||
@@ -1266,6 +1280,15 @@ int sqlite3_errcode(sqlite3 *db){
|
||||
}
|
||||
return db->errCode & db->errMask;
|
||||
}
|
||||
int sqlite3_extended_errcode(sqlite3 *db){
|
||||
if( db && !sqlite3SafetyCheckSickOrOk(db) ){
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
if( !db || db->mallocFailed ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
return db->errCode;
|
||||
}
|
||||
|
||||
/*
|
||||
** Create a new collating function for database "db". The name is zName
|
||||
|
||||
+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);
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
** 2008 October 28
|
||||
**
|
||||
** 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 a no-op memory allocation drivers for use when
|
||||
** SQLITE_ZERO_MALLOC is defined. The allocation drivers implemented
|
||||
** here always fail. SQLite will not operate with these drivers. These
|
||||
** are merely placeholders. Real drivers must be substituted using
|
||||
** sqlite3_config() before SQLite will operate.
|
||||
**
|
||||
** $Id: mem0.c,v 1.1 2008/10/28 18:58:20 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** This version of the memory allocator is the default. It is
|
||||
** used when no other memory allocator is specified using compile-time
|
||||
** macros.
|
||||
*/
|
||||
#ifdef SQLITE_ZERO_MALLOC
|
||||
|
||||
/*
|
||||
** No-op versions of all memory allocation routines
|
||||
*/
|
||||
static void *sqlite3MemMalloc(int nByte){ return 0; }
|
||||
static void sqlite3MemFree(void *pPrior){ return; }
|
||||
static void *sqlite3MemRealloc(void *pPrior, int nByte){ return 0; }
|
||||
static int sqlite3MemSize(void *pPrior){ return 0; }
|
||||
static int sqlite3MemRoundup(int n){ return n; }
|
||||
static int sqlite3MemInit(void *NotUsed){ return SQLITE_OK; }
|
||||
static void sqlite3MemShutdown(void *NotUsed){ return; }
|
||||
|
||||
/*
|
||||
** This routine is the only routine in this file with external linkage.
|
||||
**
|
||||
** Populate the low-level memory allocation function pointers in
|
||||
** sqlite3GlobalConfig.m with pointers to the routines in this file.
|
||||
*/
|
||||
void sqlite3MemSetDefault(void){
|
||||
static const sqlite3_mem_methods defaultMethods = {
|
||||
sqlite3MemMalloc,
|
||||
sqlite3MemFree,
|
||||
sqlite3MemRealloc,
|
||||
sqlite3MemSize,
|
||||
sqlite3MemRoundup,
|
||||
sqlite3MemInit,
|
||||
sqlite3MemShutdown,
|
||||
0
|
||||
};
|
||||
sqlite3_config(SQLITE_CONFIG_MALLOC, &defaultMethods);
|
||||
}
|
||||
|
||||
#endif /* SQLITE_ZERO_MALLOC */
|
||||
+11
-13
@@ -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.26 2008/09/01 18:34:20 danielk1977 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,10 +118,17 @@ static int sqlite3MemInit(void *NotUsed){
|
||||
** Deinitialize this module.
|
||||
*/
|
||||
static void sqlite3MemShutdown(void *NotUsed){
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
return;
|
||||
}
|
||||
|
||||
const sqlite3_mem_methods *sqlite3MemGetDefault(void){
|
||||
/*
|
||||
** This routine is the only routine in this file with external linkage.
|
||||
**
|
||||
** Populate the low-level memory allocation function pointers in
|
||||
** sqlite3GlobalConfig.m with pointers to the routines in this file.
|
||||
*/
|
||||
void sqlite3MemSetDefault(void){
|
||||
static const sqlite3_mem_methods defaultMethods = {
|
||||
sqlite3MemMalloc,
|
||||
sqlite3MemFree,
|
||||
@@ -131,17 +139,7 @@ const sqlite3_mem_methods *sqlite3MemGetDefault(void){
|
||||
sqlite3MemShutdown,
|
||||
0
|
||||
};
|
||||
return &defaultMethods;
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is the only routine in this file with external linkage.
|
||||
**
|
||||
** Populate the low-level memory allocation function pointers in
|
||||
** sqlite3GlobalConfig.m with pointers to the routines in this file.
|
||||
*/
|
||||
void sqlite3MemSetDefault(void){
|
||||
sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetDefault());
|
||||
sqlite3_config(SQLITE_CONFIG_MALLOC, &defaultMethods);
|
||||
}
|
||||
|
||||
#endif /* SQLITE_SYSTEM_MALLOC */
|
||||
|
||||
+7
-12
@@ -19,7 +19,7 @@
|
||||
** This file contains implementations of the low-level memory allocation
|
||||
** routines specified in the sqlite3_mem_methods object.
|
||||
**
|
||||
** $Id: mem2.c,v 1.39 2008/09/01 18:34:20 danielk1977 Exp $
|
||||
** $Id: mem2.c,v 1.40 2008/10/28 18:58:20 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -323,8 +323,11 @@ static void *sqlite3MemRealloc(void *pPrior, int nByte){
|
||||
return pNew;
|
||||
}
|
||||
|
||||
|
||||
const sqlite3_mem_methods *sqlite3MemGetDefault(void){
|
||||
/*
|
||||
** Populate the low-level memory allocation function pointers in
|
||||
** sqlite3GlobalConfig.m with pointers to the routines in this file.
|
||||
*/
|
||||
void sqlite3MemSetDefault(void){
|
||||
static const sqlite3_mem_methods defaultMethods = {
|
||||
sqlite3MemMalloc,
|
||||
sqlite3MemFree,
|
||||
@@ -335,15 +338,7 @@ const sqlite3_mem_methods *sqlite3MemGetDefault(void){
|
||||
sqlite3MemShutdown,
|
||||
0
|
||||
};
|
||||
return &defaultMethods;
|
||||
}
|
||||
|
||||
/*
|
||||
** Populate the low-level memory allocation function pointers in
|
||||
** sqlite3GlobalConfig.m with pointers to the routines in this file.
|
||||
*/
|
||||
void sqlite3MemSetDefault(void){
|
||||
sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetDefault());
|
||||
sqlite3_config(SQLITE_CONFIG_MALLOC, &defaultMethods);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+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
|
||||
}
|
||||
|
||||
|
||||
-393
@@ -1,393 +0,0 @@
|
||||
/*
|
||||
** 2007 August 14
|
||||
**
|
||||
** 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 the C functions that implement a memory
|
||||
** allocation subsystem for use by SQLite.
|
||||
**
|
||||
** $Id: mem4.c,v 1.3 2008/06/18 17:09:10 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** This version of the memory allocator attempts to obtain memory
|
||||
** from mmap() if the size of the allocation is close to the size
|
||||
** of a virtual memory page. If the size of the allocation is different
|
||||
** from the virtual memory page size, then ordinary malloc() is used.
|
||||
** Ordinary malloc is also used if space allocated to mmap() is
|
||||
** exhausted.
|
||||
**
|
||||
** Enable this memory allocation by compiling with -DSQLITE_MMAP_HEAP_SIZE=nnn
|
||||
** where nnn is the maximum number of bytes of mmap-ed memory you want
|
||||
** to support. This module may choose to use less memory than requested.
|
||||
**
|
||||
*/
|
||||
#ifdef SQLITE_MMAP_HEAP_SIZE
|
||||
|
||||
/*
|
||||
** This is a test version of the memory allocator that attempts to
|
||||
** use mmap() and madvise() for allocations and frees of approximately
|
||||
** the virtual memory page size.
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
/*
|
||||
** All of the static variables used by this module are collected
|
||||
** into a single structure named "mem". This is to keep the
|
||||
** static variables organized and to reduce namespace pollution
|
||||
** when this module is combined with other in the amalgamation.
|
||||
*/
|
||||
static struct {
|
||||
/*
|
||||
** The alarm callback and its arguments. The mem.mutex lock will
|
||||
** be held while the callback is running. Recursive calls into
|
||||
** the memory subsystem are allowed, but no new callbacks will be
|
||||
** issued. The alarmBusy variable is set to prevent recursive
|
||||
** callbacks.
|
||||
*/
|
||||
sqlite3_int64 alarmThreshold;
|
||||
void (*alarmCallback)(void*, sqlite3_int64,int);
|
||||
void *alarmArg;
|
||||
int alarmBusy;
|
||||
|
||||
/*
|
||||
** Mutex to control access to the memory allocation subsystem.
|
||||
*/
|
||||
sqlite3_mutex *mutex;
|
||||
|
||||
/*
|
||||
** Current allocation and high-water mark.
|
||||
*/
|
||||
sqlite3_int64 nowUsed;
|
||||
sqlite3_int64 mxUsed;
|
||||
|
||||
/*
|
||||
** Current allocation and high-water marks for mmap allocated memory.
|
||||
*/
|
||||
sqlite3_int64 nowUsedMMap;
|
||||
sqlite3_int64 mxUsedMMap;
|
||||
|
||||
/*
|
||||
** Size of a single mmap page. Obtained from sysconf().
|
||||
*/
|
||||
int szPage;
|
||||
int mnPage;
|
||||
|
||||
/*
|
||||
** The number of available mmap pages.
|
||||
*/
|
||||
int nPage;
|
||||
|
||||
/*
|
||||
** Index of the first free page. 0 means no pages have been freed.
|
||||
*/
|
||||
int firstFree;
|
||||
|
||||
/* First unused page on the top of the heap.
|
||||
*/
|
||||
int firstUnused;
|
||||
|
||||
/*
|
||||
** Bulk memory obtained from from mmap().
|
||||
*/
|
||||
char *mmapHeap; /* first byte of the heap */
|
||||
|
||||
} mem;
|
||||
|
||||
|
||||
/*
|
||||
** Enter the mutex mem.mutex. Allocate it if it is not already allocated.
|
||||
** The mmap() region is initialized the first time this routine is called.
|
||||
*/
|
||||
static void memsys4Enter(void){
|
||||
if( mem.mutex==0 ){
|
||||
mem.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
|
||||
}
|
||||
sqlite3_mutex_enter(mem.mutex);
|
||||
}
|
||||
|
||||
/*
|
||||
** Attempt to free memory to the mmap heap. This only works if
|
||||
** the pointer p is within the range of memory addresses that
|
||||
** comprise the mmap heap. Return 1 if the memory was freed
|
||||
** successfully. Return 0 if the pointer is out of range.
|
||||
*/
|
||||
static int mmapFree(void *p){
|
||||
char *z;
|
||||
int idx, *a;
|
||||
if( mem.mmapHeap==MAP_FAILED || mem.nPage==0 ){
|
||||
return 0;
|
||||
}
|
||||
z = (char*)p;
|
||||
idx = (z - mem.mmapHeap)/mem.szPage;
|
||||
if( idx<1 || idx>=mem.nPage ){
|
||||
return 0;
|
||||
}
|
||||
a = (int*)mem.mmapHeap;
|
||||
a[idx] = a[mem.firstFree];
|
||||
mem.firstFree = idx;
|
||||
mem.nowUsedMMap -= mem.szPage;
|
||||
madvise(p, mem.szPage, MADV_DONTNEED);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
** Attempt to allocate nBytes from the mmap heap. Return a pointer
|
||||
** to the allocated page. Or, return NULL if the allocation fails.
|
||||
**
|
||||
** The allocation will fail if nBytes is not the right size.
|
||||
** Or, the allocation will fail if the mmap heap has been exhausted.
|
||||
*/
|
||||
static void *mmapAlloc(int nBytes){
|
||||
int idx = 0;
|
||||
if( nBytes>mem.szPage || nBytes<mem.mnPage ){
|
||||
return 0;
|
||||
}
|
||||
if( mem.nPage==0 ){
|
||||
mem.szPage = sysconf(_SC_PAGE_SIZE);
|
||||
mem.mnPage = mem.szPage - mem.szPage/10;
|
||||
mem.nPage = SQLITE_MMAP_HEAP_SIZE/mem.szPage;
|
||||
if( mem.nPage * sizeof(int) > mem.szPage ){
|
||||
mem.nPage = mem.szPage/sizeof(int);
|
||||
}
|
||||
mem.mmapHeap = mmap(0, mem.szPage*mem.nPage, PROT_WRITE|PROT_READ,
|
||||
MAP_ANONYMOUS|MAP_SHARED, -1, 0);
|
||||
if( mem.mmapHeap==MAP_FAILED ){
|
||||
mem.firstUnused = errno;
|
||||
}else{
|
||||
mem.firstUnused = 1;
|
||||
mem.nowUsedMMap = mem.szPage;
|
||||
}
|
||||
}
|
||||
if( mem.mmapHeap==MAP_FAILED ){
|
||||
return 0;
|
||||
}
|
||||
if( mem.firstFree ){
|
||||
int idx = mem.firstFree;
|
||||
int *a = (int*)mem.mmapHeap;
|
||||
mem.firstFree = a[idx];
|
||||
}else if( mem.firstUnused<mem.nPage ){
|
||||
idx = mem.firstUnused++;
|
||||
}
|
||||
if( idx ){
|
||||
mem.nowUsedMMap += mem.szPage;
|
||||
if( mem.nowUsedMMap>mem.mxUsedMMap ){
|
||||
mem.mxUsedMMap = mem.nowUsedMMap;
|
||||
}
|
||||
return (void*)&mem.mmapHeap[idx*mem.szPage];
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Release the mmap-ed memory region if it is currently allocated and
|
||||
** is not in use.
|
||||
*/
|
||||
static void mmapUnmap(void){
|
||||
if( mem.mmapHeap==MAP_FAILED ) return;
|
||||
if( mem.nPage==0 ) return;
|
||||
if( mem.nowUsedMMap>mem.szPage ) return;
|
||||
munmap(mem.mmapHeap, mem.nPage*mem.szPage);
|
||||
mem.nowUsedMMap = 0;
|
||||
mem.nPage = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Return the amount of memory currently checked out.
|
||||
*/
|
||||
sqlite3_int64 sqlite3_memory_used(void){
|
||||
sqlite3_int64 n;
|
||||
memsys4Enter();
|
||||
n = mem.nowUsed + mem.nowUsedMMap;
|
||||
sqlite3_mutex_leave(mem.mutex);
|
||||
return n;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the maximum amount of memory that has ever been
|
||||
** checked out since either the beginning of this process
|
||||
** or since the most recent reset.
|
||||
*/
|
||||
sqlite3_int64 sqlite3_memory_highwater(int resetFlag){
|
||||
sqlite3_int64 n;
|
||||
memsys4Enter();
|
||||
n = mem.mxUsed + mem.mxUsedMMap;
|
||||
if( resetFlag ){
|
||||
mem.mxUsed = mem.nowUsed;
|
||||
mem.mxUsedMMap = mem.nowUsedMMap;
|
||||
}
|
||||
sqlite3_mutex_leave(mem.mutex);
|
||||
return n;
|
||||
}
|
||||
|
||||
/*
|
||||
** Change the alarm callback
|
||||
*/
|
||||
int sqlite3_memory_alarm(
|
||||
void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
|
||||
void *pArg,
|
||||
sqlite3_int64 iThreshold
|
||||
){
|
||||
memsys4Enter();
|
||||
mem.alarmCallback = xCallback;
|
||||
mem.alarmArg = pArg;
|
||||
mem.alarmThreshold = iThreshold;
|
||||
sqlite3_mutex_leave(mem.mutex);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Trigger the alarm
|
||||
*/
|
||||
static void sqlite3MemsysAlarm(int nByte){
|
||||
void (*xCallback)(void*,sqlite3_int64,int);
|
||||
sqlite3_int64 nowUsed;
|
||||
void *pArg;
|
||||
if( mem.alarmCallback==0 || mem.alarmBusy ) return;
|
||||
mem.alarmBusy = 1;
|
||||
xCallback = mem.alarmCallback;
|
||||
nowUsed = mem.nowUsed;
|
||||
pArg = mem.alarmArg;
|
||||
sqlite3_mutex_leave(mem.mutex);
|
||||
xCallback(pArg, nowUsed, nByte);
|
||||
sqlite3_mutex_enter(mem.mutex);
|
||||
mem.alarmBusy = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Allocate nBytes of memory
|
||||
*/
|
||||
static void *memsys4Malloc(int nBytes){
|
||||
sqlite3_int64 *p = 0;
|
||||
if( mem.alarmCallback!=0
|
||||
&& mem.nowUsed+mem.nowUsedMMap+nBytes>=mem.alarmThreshold ){
|
||||
sqlite3MemsysAlarm(nBytes);
|
||||
}
|
||||
if( (p = mmapAlloc(nBytes))==0 ){
|
||||
p = malloc(nBytes+8);
|
||||
if( p==0 ){
|
||||
sqlite3MemsysAlarm(nBytes);
|
||||
p = malloc(nBytes+8);
|
||||
}
|
||||
if( p ){
|
||||
p[0] = nBytes;
|
||||
p++;
|
||||
mem.nowUsed += nBytes;
|
||||
if( mem.nowUsed>mem.mxUsed ){
|
||||
mem.mxUsed = mem.nowUsed;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (void*)p;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the size of a memory allocation
|
||||
*/
|
||||
static int memsys4Size(void *pPrior){
|
||||
char *z = (char*)pPrior;
|
||||
int idx = mem.nPage ? (z - mem.mmapHeap)/mem.szPage : 0;
|
||||
int nByte;
|
||||
if( idx>=1 && idx<mem.nPage ){
|
||||
nByte = mem.szPage;
|
||||
}else{
|
||||
sqlite3_int64 *p = pPrior;
|
||||
p--;
|
||||
nByte = (int)*p;
|
||||
}
|
||||
return nByte;
|
||||
}
|
||||
|
||||
/*
|
||||
** Free memory.
|
||||
*/
|
||||
static void memsys4Free(void *pPrior){
|
||||
sqlite3_int64 *p;
|
||||
int nByte;
|
||||
if( mmapFree(pPrior)==0 ){
|
||||
p = pPrior;
|
||||
p--;
|
||||
nByte = (int)*p;
|
||||
mem.nowUsed -= nByte;
|
||||
free(p);
|
||||
if( mem.nowUsed==0 ){
|
||||
mmapUnmap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Allocate nBytes of memory
|
||||
*/
|
||||
void *sqlite3_malloc(int nBytes){
|
||||
sqlite3_int64 *p = 0;
|
||||
if( nBytes>0 ){
|
||||
memsys4Enter();
|
||||
p = memsys4Malloc(nBytes);
|
||||
sqlite3_mutex_leave(mem.mutex);
|
||||
}
|
||||
return (void*)p;
|
||||
}
|
||||
|
||||
/*
|
||||
** Free memory.
|
||||
*/
|
||||
void sqlite3_free(void *pPrior){
|
||||
if( pPrior==0 ){
|
||||
return;
|
||||
}
|
||||
assert( mem.mutex!=0 );
|
||||
sqlite3_mutex_enter(mem.mutex);
|
||||
memsys4Free(pPrior);
|
||||
sqlite3_mutex_leave(mem.mutex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Change the size of an existing memory allocation
|
||||
*/
|
||||
void *sqlite3_realloc(void *pPrior, int nBytes){
|
||||
int nOld;
|
||||
sqlite3_int64 *p;
|
||||
if( pPrior==0 ){
|
||||
return sqlite3_malloc(nBytes);
|
||||
}
|
||||
if( nBytes<=0 ){
|
||||
sqlite3_free(pPrior);
|
||||
return 0;
|
||||
}
|
||||
nOld = memsys4Size(pPrior);
|
||||
if( nBytes<=nOld && nBytes>=nOld-128 ){
|
||||
return pPrior;
|
||||
}
|
||||
assert( mem.mutex!=0 );
|
||||
sqlite3_mutex_enter(mem.mutex);
|
||||
p = memsys4Malloc(nBytes);
|
||||
if( p ){
|
||||
if( nOld<nBytes ){
|
||||
memcpy(p, pPrior, nOld);
|
||||
}else{
|
||||
memcpy(p, pPrior, nBytes);
|
||||
}
|
||||
memsys4Free(pPrior);
|
||||
}
|
||||
assert( mem.mutex!=0 );
|
||||
sqlite3_mutex_leave(mem.mutex);
|
||||
return (void*)p;
|
||||
}
|
||||
|
||||
#endif /* SQLITE_MMAP_HEAP_SIZE */
|
||||
+11
-29
@@ -23,38 +23,16 @@
|
||||
** This version of the memory allocation subsystem is included
|
||||
** in the build only if SQLITE_ENABLE_MEMSYS5 is defined.
|
||||
**
|
||||
** $Id: mem5.c,v 1.14 2008/09/02 17:52:52 danielk1977 Exp $
|
||||
** $Id: mem5.c,v 1.19 2008/11/19 16:52:44 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** This version of the memory allocator is used only when
|
||||
** SQLITE_POW2_MEMORY_SIZE is defined.
|
||||
** SQLITE_ENABLE_MEMSYS5 is defined.
|
||||
*/
|
||||
#ifdef SQLITE_ENABLE_MEMSYS5
|
||||
|
||||
/*
|
||||
** Log2 of the minimum size of an allocation. For example, if
|
||||
** 4 then all allocations will be rounded up to at least 16 bytes.
|
||||
** If 5 then all allocations will be rounded up to at least 32 bytes.
|
||||
*/
|
||||
#ifndef SQLITE_POW2_LOGMIN
|
||||
# define SQLITE_POW2_LOGMIN 6
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Log2 of the maximum size of an allocation.
|
||||
*/
|
||||
#ifndef SQLITE_POW2_LOGMAX
|
||||
# define SQLITE_POW2_LOGMAX 20
|
||||
#endif
|
||||
#define POW2_MAX (((unsigned int)1)<<SQLITE_POW2_LOGMAX)
|
||||
|
||||
/*
|
||||
** Number of distinct allocation sizes.
|
||||
*/
|
||||
#define NSIZE (SQLITE_POW2_LOGMAX - SQLITE_POW2_LOGMIN + 1)
|
||||
|
||||
/*
|
||||
** A minimum allocation is an instance of the following structure.
|
||||
** Larger allocations are an array of these structures where the
|
||||
@@ -230,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
|
||||
@@ -287,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 );
|
||||
@@ -402,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;
|
||||
}
|
||||
|
||||
@@ -438,6 +417,7 @@ static int memsys5Init(void *NotUsed){
|
||||
** Deinitialize this module.
|
||||
*/
|
||||
static void memsys5Shutdown(void *NotUsed){
|
||||
UNUSED_PARAMETER(NotUsed);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -481,6 +461,8 @@ void sqlite3Memsys5Dump(const char *zFilename){
|
||||
}else{
|
||||
fclose(out);
|
||||
}
|
||||
#else
|
||||
UNUSED_PARAMETER(zFilename);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
-498
@@ -1,498 +0,0 @@
|
||||
/*
|
||||
** 2008 July 24
|
||||
**
|
||||
** 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 an alternative memory allocation system for SQLite.
|
||||
** This system is implemented as a wrapper around the system provided
|
||||
** by the operating system - vanilla malloc(), realloc() and free().
|
||||
**
|
||||
** This system differentiates between requests for "small" allocations
|
||||
** (by default those of 128 bytes or less) and "large" allocations (all
|
||||
** others). The 256 byte threshhold is configurable at runtime.
|
||||
**
|
||||
** All requests for large allocations are passed through to the
|
||||
** default system.
|
||||
**
|
||||
** Requests for small allocations are met by allocating space within
|
||||
** one or more larger "chunks" of memory obtained from the default
|
||||
** memory allocation system. Chunks of memory are usually 64KB or
|
||||
** larger. The algorithm used to manage space within each chunk is
|
||||
** the same as that used by mem5.c.
|
||||
**
|
||||
** This strategy is designed to prevent the default memory allocation
|
||||
** system (usually the system malloc) from suffering from heap
|
||||
** fragmentation. On some systems, heap fragmentation can cause a
|
||||
** significant real-time slowdown.
|
||||
**
|
||||
** $Id: mem6.c,v 1.10 2008/09/02 17:52:52 danielk1977 Exp $
|
||||
*/
|
||||
|
||||
#ifdef SQLITE_ENABLE_MEMSYS6
|
||||
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** Maximum size of any "small" allocation is ((1<<LOGMAX)*Mem6Chunk.nAtom).
|
||||
** Mem6Chunk.nAtom is always at least 8, so this is not a practical
|
||||
** limitation
|
||||
*/
|
||||
#define LOGMAX 30
|
||||
|
||||
/*
|
||||
** Default value for the "small" allocation size threshold.
|
||||
*/
|
||||
#define SMALL_MALLOC_DEFAULT_THRESHOLD 256
|
||||
|
||||
/*
|
||||
** Minimum size for a memory chunk.
|
||||
*/
|
||||
#define MIN_CHUNKSIZE (1<<16)
|
||||
|
||||
#define LOG2_MINALLOC 4
|
||||
|
||||
|
||||
typedef struct Mem6Chunk Mem6Chunk;
|
||||
typedef struct Mem6Link Mem6Link;
|
||||
|
||||
/*
|
||||
** A minimum allocation is an instance of the following structure.
|
||||
** Larger allocations are an array of these structures where the
|
||||
** size of the array is a power of 2.
|
||||
*/
|
||||
struct Mem6Link {
|
||||
int next; /* Index of next free chunk */
|
||||
int prev; /* Index of previous free chunk */
|
||||
};
|
||||
|
||||
/*
|
||||
** Masks used for mem5.aCtrl[] elements.
|
||||
*/
|
||||
#define CTRL_LOGSIZE 0x1f /* Log2 Size of this block relative to POW2_MIN */
|
||||
#define CTRL_FREE 0x20 /* True if not checked out */
|
||||
|
||||
struct Mem6Chunk {
|
||||
Mem6Chunk *pNext;
|
||||
|
||||
/*
|
||||
** Lists of free blocks of various sizes.
|
||||
*/
|
||||
int aiFreelist[LOGMAX+1];
|
||||
|
||||
int nCheckedOut; /* Number of currently outstanding allocations */
|
||||
|
||||
/*
|
||||
** Space for tracking which blocks are checked out and the size
|
||||
** of each block. One byte per block.
|
||||
*/
|
||||
u8 *aCtrl;
|
||||
|
||||
/*
|
||||
** Memory available for allocation
|
||||
*/
|
||||
int nAtom; /* Smallest possible allocation in bytes */
|
||||
int nBlock; /* Number of nAtom sized blocks in zPool */
|
||||
u8 *zPool; /* Pointer to memory chunk from which allocations are made */
|
||||
};
|
||||
|
||||
#define MEM6LINK(idx) ((Mem6Link *)(&pChunk->zPool[(idx)*pChunk->nAtom]))
|
||||
|
||||
static SQLITE_WSD struct Mem6Global {
|
||||
int nMinAlloc; /* Minimum allowed allocation size */
|
||||
int nThreshold; /* Allocs larger than this go to malloc() */
|
||||
int nLogThreshold; /* log2 of (nThreshold/nMinAlloc) */
|
||||
sqlite3_mutex *mutex;
|
||||
Mem6Chunk *pChunk; /* Singly linked list of all memory chunks */
|
||||
} mem6 = { 48642791 };
|
||||
|
||||
#define mem6 GLOBAL(struct Mem6Global, mem6)
|
||||
|
||||
/*
|
||||
** Unlink the chunk at pChunk->aPool[i] from list it is currently
|
||||
** on. It should be found on pChunk->aiFreelist[iLogsize].
|
||||
*/
|
||||
static void memsys6Unlink(Mem6Chunk *pChunk, int i, int iLogsize){
|
||||
int next, prev;
|
||||
assert( i>=0 && i<pChunk->nBlock );
|
||||
assert( iLogsize>=0 && iLogsize<=mem6.nLogThreshold );
|
||||
assert( (pChunk->aCtrl[i] & CTRL_LOGSIZE)==iLogsize );
|
||||
|
||||
next = MEM6LINK(i)->next;
|
||||
prev = MEM6LINK(i)->prev;
|
||||
if( prev<0 ){
|
||||
pChunk->aiFreelist[iLogsize] = next;
|
||||
}else{
|
||||
MEM6LINK(prev)->next = next;
|
||||
}
|
||||
if( next>=0 ){
|
||||
MEM6LINK(next)->prev = prev;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Link the chunk at mem5.aPool[i] so that is on the iLogsize
|
||||
** free list.
|
||||
*/
|
||||
static void memsys6Link(Mem6Chunk *pChunk, int i, int iLogsize){
|
||||
int x;
|
||||
assert( i>=0 && i<pChunk->nBlock );
|
||||
assert( iLogsize>=0 && iLogsize<=mem6.nLogThreshold );
|
||||
assert( (pChunk->aCtrl[i] & CTRL_LOGSIZE)==iLogsize );
|
||||
|
||||
x = MEM6LINK(i)->next = pChunk->aiFreelist[iLogsize];
|
||||
MEM6LINK(i)->prev = -1;
|
||||
if( x>=0 ){
|
||||
assert( x<pChunk->nBlock );
|
||||
MEM6LINK(x)->prev = i;
|
||||
}
|
||||
pChunk->aiFreelist[iLogsize] = i;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Find the first entry on the freelist iLogsize. Unlink that
|
||||
** entry and return its index.
|
||||
*/
|
||||
static int memsys6UnlinkFirst(Mem6Chunk *pChunk, int iLogsize){
|
||||
int i;
|
||||
int iFirst;
|
||||
|
||||
assert( iLogsize>=0 && iLogsize<=mem6.nLogThreshold );
|
||||
i = iFirst = pChunk->aiFreelist[iLogsize];
|
||||
assert( iFirst>=0 );
|
||||
memsys6Unlink(pChunk, iFirst, iLogsize);
|
||||
return iFirst;
|
||||
}
|
||||
|
||||
static int roundupLog2(int n){
|
||||
static const char LogTable256[256] = {
|
||||
0, /* 1 */
|
||||
1, /* 2 */
|
||||
2, 2, /* 3..4 */
|
||||
3, 3, 3, 3, /* 5..8 */
|
||||
4, 4, 4, 4, 4, 4, 4, 4, /* 9..16 */
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, /* 17..32 */
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, /* 33..64 */
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, /* 65..128 */
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, /* 129..256 */
|
||||
};
|
||||
|
||||
assert(n<=(1<<16) && n>0);
|
||||
if( n<=256 ) return LogTable256[n-1];
|
||||
return LogTable256[(n>>8) - ((n&0xFF)?0:1)] + 8;
|
||||
}
|
||||
|
||||
/*
|
||||
** Allocate and return a block of (pChunk->nAtom << iLogsize) bytes from chunk
|
||||
** pChunk. If the allocation request cannot be satisfied, return 0.
|
||||
*/
|
||||
static void *chunkMalloc(Mem6Chunk *pChunk, int iLogsize){
|
||||
int i; /* Index of a mem5.aPool[] slot */
|
||||
int iBin; /* Index into mem5.aiFreelist[] */
|
||||
|
||||
/* Make sure mem5.aiFreelist[iLogsize] contains at least one free
|
||||
** block. If not, then split a block of the next larger power of
|
||||
** two in order to create a new free block of size iLogsize.
|
||||
*/
|
||||
for(iBin=iLogsize; pChunk->aiFreelist[iBin]<0 && iBin<=mem6.nLogThreshold; iBin++){}
|
||||
if( iBin>mem6.nLogThreshold ) return 0;
|
||||
i = memsys6UnlinkFirst(pChunk, iBin);
|
||||
while( iBin>iLogsize ){
|
||||
int newSize;
|
||||
iBin--;
|
||||
newSize = 1 << iBin;
|
||||
pChunk->aCtrl[i+newSize] = CTRL_FREE | iBin;
|
||||
memsys6Link(pChunk, i+newSize, iBin);
|
||||
}
|
||||
pChunk->aCtrl[i] = iLogsize;
|
||||
|
||||
/* Return a pointer to the allocated memory. */
|
||||
pChunk->nCheckedOut++;
|
||||
return (void*)&pChunk->zPool[i*pChunk->nAtom];
|
||||
}
|
||||
|
||||
/*
|
||||
** Free the allocation pointed to by p, which is guaranteed to be non-zero
|
||||
** and a part of chunk object pChunk.
|
||||
*/
|
||||
static void chunkFree(Mem6Chunk *pChunk, void *pOld){
|
||||
u32 size, iLogsize;
|
||||
int iBlock;
|
||||
|
||||
/* Set iBlock to the index of the block pointed to by pOld in
|
||||
** the array of pChunk->nAtom byte blocks pointed to by pChunk->zPool.
|
||||
*/
|
||||
iBlock = ((u8 *)pOld-pChunk->zPool)/pChunk->nAtom;
|
||||
|
||||
/* Check that the pointer pOld points to a valid, non-free block. */
|
||||
assert( iBlock>=0 && iBlock<pChunk->nBlock );
|
||||
assert( ((u8 *)pOld-pChunk->zPool)%pChunk->nAtom==0 );
|
||||
assert( (pChunk->aCtrl[iBlock] & CTRL_FREE)==0 );
|
||||
|
||||
iLogsize = pChunk->aCtrl[iBlock] & CTRL_LOGSIZE;
|
||||
size = 1<<iLogsize;
|
||||
assert( iBlock+size-1<pChunk->nBlock );
|
||||
|
||||
pChunk->aCtrl[iBlock] |= CTRL_FREE;
|
||||
pChunk->aCtrl[iBlock+size-1] |= CTRL_FREE;
|
||||
|
||||
pChunk->aCtrl[iBlock] = CTRL_FREE | iLogsize;
|
||||
while( iLogsize<mem6.nLogThreshold ){
|
||||
int iBuddy;
|
||||
if( (iBlock>>iLogsize) & 1 ){
|
||||
iBuddy = iBlock - size;
|
||||
}else{
|
||||
iBuddy = iBlock + size;
|
||||
}
|
||||
assert( iBuddy>=0 );
|
||||
if( (iBuddy+(1<<iLogsize))>pChunk->nBlock ) break;
|
||||
if( pChunk->aCtrl[iBuddy]!=(CTRL_FREE | iLogsize) ) break;
|
||||
memsys6Unlink(pChunk, iBuddy, iLogsize);
|
||||
iLogsize++;
|
||||
if( iBuddy<iBlock ){
|
||||
pChunk->aCtrl[iBuddy] = CTRL_FREE | iLogsize;
|
||||
pChunk->aCtrl[iBlock] = 0;
|
||||
iBlock = iBuddy;
|
||||
}else{
|
||||
pChunk->aCtrl[iBlock] = CTRL_FREE | iLogsize;
|
||||
pChunk->aCtrl[iBuddy] = 0;
|
||||
}
|
||||
size *= 2;
|
||||
}
|
||||
pChunk->nCheckedOut--;
|
||||
memsys6Link(pChunk, iBlock, iLogsize);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the actual size of the block pointed to by p, which is guaranteed
|
||||
** to have been allocated from chunk pChunk.
|
||||
*/
|
||||
static int chunkSize(Mem6Chunk *pChunk, void *p){
|
||||
int iSize = 0;
|
||||
if( p ){
|
||||
int i = ((u8 *)p-pChunk->zPool)/pChunk->nAtom;
|
||||
assert( i>=0 && i<pChunk->nBlock );
|
||||
iSize = pChunk->nAtom * (1 << (pChunk->aCtrl[i]&CTRL_LOGSIZE));
|
||||
}
|
||||
return iSize;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return true if there are currently no outstanding allocations.
|
||||
*/
|
||||
static int chunkIsEmpty(Mem6Chunk *pChunk){
|
||||
return (pChunk->nCheckedOut==0);
|
||||
}
|
||||
|
||||
/*
|
||||
** Initialize the buffer zChunk, which is nChunk bytes in size, as
|
||||
** an Mem6Chunk object. Return a copy of the zChunk pointer.
|
||||
*/
|
||||
static Mem6Chunk *chunkInit(u8 *zChunk, int nChunk, int nMinAlloc){
|
||||
int ii;
|
||||
int iOffset;
|
||||
Mem6Chunk *pChunk = (Mem6Chunk *)zChunk;
|
||||
|
||||
assert( nChunk>sizeof(Mem6Chunk) );
|
||||
assert( nMinAlloc>sizeof(Mem6Link) );
|
||||
|
||||
memset(pChunk, 0, sizeof(Mem6Chunk));
|
||||
pChunk->nAtom = nMinAlloc;
|
||||
pChunk->nBlock = ((nChunk-sizeof(Mem6Chunk)) / (pChunk->nAtom+sizeof(u8)));
|
||||
|
||||
pChunk->zPool = (u8 *)&pChunk[1];
|
||||
pChunk->aCtrl = &pChunk->zPool[pChunk->nBlock*pChunk->nAtom];
|
||||
|
||||
for(ii=0; ii<=mem6.nLogThreshold; ii++){
|
||||
pChunk->aiFreelist[ii] = -1;
|
||||
}
|
||||
|
||||
iOffset = 0;
|
||||
for(ii=mem6.nLogThreshold; ii>=0; ii--){
|
||||
int nAlloc = (1<<ii);
|
||||
while( (iOffset+nAlloc)<=pChunk->nBlock ){
|
||||
pChunk->aCtrl[iOffset] = ii | CTRL_FREE;
|
||||
memsys6Link(pChunk, iOffset, ii);
|
||||
iOffset += nAlloc;
|
||||
}
|
||||
}
|
||||
|
||||
return pChunk;
|
||||
}
|
||||
|
||||
|
||||
static void mem6Enter(void){
|
||||
sqlite3_mutex_enter(mem6.mutex);
|
||||
}
|
||||
|
||||
static void mem6Leave(void){
|
||||
sqlite3_mutex_leave(mem6.mutex);
|
||||
}
|
||||
|
||||
/*
|
||||
** Based on the number and size of the currently allocated chunks, return
|
||||
** the size of the next chunk to allocate, in bytes.
|
||||
*/
|
||||
static int nextChunkSize(void){
|
||||
int iTotal = MIN_CHUNKSIZE;
|
||||
Mem6Chunk *p;
|
||||
for(p=mem6.pChunk; p; p=p->pNext){
|
||||
iTotal = iTotal*2;
|
||||
}
|
||||
return iTotal;
|
||||
}
|
||||
|
||||
static void freeChunk(Mem6Chunk *pChunk){
|
||||
Mem6Chunk **pp = &mem6.pChunk;
|
||||
for( pp=&mem6.pChunk; *pp!=pChunk; pp = &(*pp)->pNext );
|
||||
*pp = (*pp)->pNext;
|
||||
free(pChunk);
|
||||
}
|
||||
|
||||
static void *memsys6Malloc(int nByte){
|
||||
Mem6Chunk *pChunk;
|
||||
void *p = 0;
|
||||
int nTotal = nByte+8;
|
||||
int iOffset = 0;
|
||||
|
||||
if( nTotal>mem6.nThreshold ){
|
||||
p = malloc(nTotal);
|
||||
}else{
|
||||
int iLogsize = 0;
|
||||
if( nTotal>(1<<LOG2_MINALLOC) ){
|
||||
iLogsize = roundupLog2(nTotal) - LOG2_MINALLOC;
|
||||
}
|
||||
mem6Enter();
|
||||
for(pChunk=mem6.pChunk; pChunk; pChunk=pChunk->pNext){
|
||||
p = chunkMalloc(pChunk, iLogsize);
|
||||
if( p ){
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( !p ){
|
||||
int iSize = nextChunkSize();
|
||||
p = malloc(iSize);
|
||||
if( p ){
|
||||
pChunk = chunkInit((u8 *)p, iSize, mem6.nMinAlloc);
|
||||
pChunk->pNext = mem6.pChunk;
|
||||
mem6.pChunk = pChunk;
|
||||
p = chunkMalloc(pChunk, iLogsize);
|
||||
assert(p);
|
||||
}
|
||||
}
|
||||
iOffset = ((u8*)p - (u8*)pChunk);
|
||||
mem6Leave();
|
||||
}
|
||||
|
||||
if( !p ){
|
||||
return 0;
|
||||
}
|
||||
((u32 *)p)[0] = iOffset;
|
||||
((u32 *)p)[1] = nByte;
|
||||
return &((u32 *)p)[2];
|
||||
}
|
||||
|
||||
static int memsys6Size(void *pPrior){
|
||||
if( pPrior==0 ) return 0;
|
||||
return ((u32*)pPrior)[-1];
|
||||
}
|
||||
|
||||
static void memsys6Free(void *pPrior){
|
||||
int iSlot;
|
||||
void *p = &((u32 *)pPrior)[-2];
|
||||
iSlot = ((u32 *)p)[0];
|
||||
if( iSlot ){
|
||||
Mem6Chunk *pChunk;
|
||||
mem6Enter();
|
||||
pChunk = (Mem6Chunk *)(&((u8 *)p)[-1 * iSlot]);
|
||||
chunkFree(pChunk, p);
|
||||
if( chunkIsEmpty(pChunk) ){
|
||||
freeChunk(pChunk);
|
||||
}
|
||||
mem6Leave();
|
||||
}else{
|
||||
free(p);
|
||||
}
|
||||
}
|
||||
|
||||
static void *memsys6Realloc(void *p, int nByte){
|
||||
void *p2;
|
||||
|
||||
if( p && nByte<=memsys6Size(p) ){
|
||||
p2 = p;
|
||||
}else{
|
||||
p2 = memsys6Malloc(nByte);
|
||||
if( p && p2 ){
|
||||
memcpy(p2, p, memsys6Size(p));
|
||||
memsys6Free(p);
|
||||
}
|
||||
}
|
||||
|
||||
return p2;
|
||||
}
|
||||
|
||||
static int memsys6Roundup(int n){
|
||||
if( n>mem6.nThreshold ){
|
||||
return n;
|
||||
}else{
|
||||
return (1<<roundupLog2(n));
|
||||
}
|
||||
}
|
||||
|
||||
static int memsys6Init(void *pCtx){
|
||||
u8 bMemstat = sqlite3GlobalConfig.bMemstat;
|
||||
mem6.nMinAlloc = (1 << LOG2_MINALLOC);
|
||||
mem6.pChunk = 0;
|
||||
mem6.nThreshold = sqlite3GlobalConfig.nSmall;
|
||||
if( mem6.nThreshold<=0 ){
|
||||
mem6.nThreshold = SMALL_MALLOC_DEFAULT_THRESHOLD;
|
||||
}
|
||||
mem6.nLogThreshold = roundupLog2(mem6.nThreshold) - LOG2_MINALLOC;
|
||||
if( !bMemstat ){
|
||||
mem6.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static void memsys6Shutdown(void *pCtx){
|
||||
memset(&mem6, 0, sizeof(mem6));
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is the only routine in this file with external
|
||||
** linkage. It returns a pointer to a static sqlite3_mem_methods
|
||||
** struct populated with the memsys6 methods.
|
||||
*/
|
||||
const sqlite3_mem_methods *sqlite3MemGetMemsys6(void){
|
||||
static const sqlite3_mem_methods memsys6Methods = {
|
||||
memsys6Malloc,
|
||||
memsys6Free,
|
||||
memsys6Realloc,
|
||||
memsys6Size,
|
||||
memsys6Roundup,
|
||||
memsys6Init,
|
||||
memsys6Shutdown,
|
||||
0
|
||||
};
|
||||
return &memsys6Methods;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,245 @@
|
||||
/*
|
||||
** 2008 October 7
|
||||
**
|
||||
** 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 use to implement an in-memory rollback journal.
|
||||
** 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.5 2008/11/19 16:52:44 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/* Forward references to internal structures */
|
||||
typedef struct MemJournal MemJournal;
|
||||
typedef struct FilePoint FilePoint;
|
||||
typedef struct FileChunk FileChunk;
|
||||
|
||||
/* Space to hold the rollback journal is allocated in increments of
|
||||
** this many bytes.
|
||||
*/
|
||||
#define JOURNAL_CHUNKSIZE 1024
|
||||
|
||||
/* Macro to find the minimum of two numeric values.
|
||||
*/
|
||||
#ifndef MIN
|
||||
# define MIN(x,y) ((x)<(y)?(x):(y))
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The rollback journal is composed of a linked list of these structures.
|
||||
*/
|
||||
struct FileChunk {
|
||||
FileChunk *pNext; /* Next chunk in the journal */
|
||||
u8 zChunk[JOURNAL_CHUNKSIZE]; /* Content of this chunk */
|
||||
};
|
||||
|
||||
/*
|
||||
** An instance of this object serves as a cursor into the rollback journal.
|
||||
** The cursor can be either for reading or writing.
|
||||
*/
|
||||
struct FilePoint {
|
||||
sqlite3_int64 iOffset; /* Offset from the beginning of the file */
|
||||
FileChunk *pChunk; /* Specific chunk into which cursor points */
|
||||
};
|
||||
|
||||
/*
|
||||
** This subclass is a subclass of sqlite3_file. Each open memory-journal
|
||||
** is an instance of this class.
|
||||
*/
|
||||
struct MemJournal {
|
||||
sqlite3_io_methods *pMethod; /* Parent class. MUST BE FIRST */
|
||||
FileChunk *pFirst; /* Head of in-memory chunk-list */
|
||||
FilePoint endpoint; /* Pointer to the end of the file */
|
||||
FilePoint readpoint; /* Pointer to the end of the last xRead() */
|
||||
};
|
||||
|
||||
/*
|
||||
** Read data from the file.
|
||||
*/
|
||||
static int memjrnlRead(
|
||||
sqlite3_file *pJfd, /* The journal file from which to read */
|
||||
void *zBuf, /* Put the results here */
|
||||
int iAmt, /* Number of bytes to read */
|
||||
sqlite_int64 iOfst /* Begin reading at this offset */
|
||||
){
|
||||
MemJournal *p = (MemJournal *)pJfd;
|
||||
u8 *zOut = zBuf;
|
||||
int nRead = iAmt;
|
||||
int iChunkOffset;
|
||||
FileChunk *pChunk;
|
||||
|
||||
assert( iOfst+iAmt<=p->endpoint.iOffset );
|
||||
|
||||
if( p->readpoint.iOffset!=iOfst || iOfst==0 ){
|
||||
sqlite3_int64 iOff = 0;
|
||||
for(pChunk=p->pFirst;
|
||||
pChunk && (iOff+JOURNAL_CHUNKSIZE)<=iOfst;
|
||||
pChunk=pChunk->pNext
|
||||
){
|
||||
iOff += JOURNAL_CHUNKSIZE;
|
||||
}
|
||||
}else{
|
||||
pChunk = p->readpoint.pChunk;
|
||||
}
|
||||
|
||||
iChunkOffset = (iOfst%JOURNAL_CHUNKSIZE);
|
||||
do {
|
||||
int iSpace = JOURNAL_CHUNKSIZE - iChunkOffset;
|
||||
int nCopy = MIN(nRead, (JOURNAL_CHUNKSIZE - iChunkOffset));
|
||||
memcpy(zOut, &pChunk->zChunk[iChunkOffset], nCopy);
|
||||
zOut += nCopy;
|
||||
nRead -= iSpace;
|
||||
iChunkOffset = 0;
|
||||
} while( nRead>=0 && (pChunk=pChunk->pNext) && nRead>0 );
|
||||
p->readpoint.iOffset = iOfst+iAmt;
|
||||
p->readpoint.pChunk = pChunk;
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Write data to the file.
|
||||
*/
|
||||
static int memjrnlWrite(
|
||||
sqlite3_file *pJfd, /* The journal file into which to write */
|
||||
const void *zBuf, /* Take data to be written from here */
|
||||
int iAmt, /* Number of bytes to write */
|
||||
sqlite_int64 iOfst /* Begin writing at this offset into the file */
|
||||
){
|
||||
MemJournal *p = (MemJournal *)pJfd;
|
||||
int nWrite = iAmt;
|
||||
u8 *zWrite = (u8 *)zBuf;
|
||||
|
||||
/* An in-memory journal file should only ever be appended to. Random
|
||||
** access writes are not required by sqlite.
|
||||
*/
|
||||
assert(iOfst==p->endpoint.iOffset);
|
||||
UNUSED_PARAMETER(iOfst);
|
||||
|
||||
while( nWrite>0 ){
|
||||
FileChunk *pChunk = p->endpoint.pChunk;
|
||||
int iChunkOffset = p->endpoint.iOffset%JOURNAL_CHUNKSIZE;
|
||||
int iSpace = MIN(nWrite, JOURNAL_CHUNKSIZE - iChunkOffset);
|
||||
|
||||
if( iChunkOffset==0 ){
|
||||
/* New chunk is required to extend the file. */
|
||||
FileChunk *pNew = sqlite3_malloc(sizeof(FileChunk));
|
||||
if( !pNew ){
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
}
|
||||
pNew->pNext = 0;
|
||||
if( pChunk ){
|
||||
assert( p->pFirst );
|
||||
pChunk->pNext = pNew;
|
||||
}else{
|
||||
assert( !p->pFirst );
|
||||
p->pFirst = pNew;
|
||||
}
|
||||
p->endpoint.pChunk = pNew;
|
||||
}
|
||||
|
||||
memcpy(&p->endpoint.pChunk->zChunk[iChunkOffset], zWrite, iSpace);
|
||||
zWrite += iSpace;
|
||||
nWrite -= iSpace;
|
||||
p->endpoint.iOffset += iSpace;
|
||||
}
|
||||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Truncate the file.
|
||||
*/
|
||||
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;
|
||||
pChunk = pChunk->pNext;
|
||||
sqlite3_free(pTmp);
|
||||
}
|
||||
sqlite3MemJournalOpen(pJfd);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Close the file.
|
||||
*/
|
||||
static int memjrnlClose(sqlite3_file *pJfd){
|
||||
memjrnlTruncate(pJfd, 0);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Sync the file.
|
||||
*/
|
||||
static int memjrnlSync(sqlite3_file *NotUsed, int NotUsed2){
|
||||
UNUSED_PARAMETER2(NotUsed, NotUsed2);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Query the size of the file in bytes.
|
||||
*/
|
||||
static int memjrnlFileSize(sqlite3_file *pJfd, sqlite_int64 *pSize){
|
||||
MemJournal *p = (MemJournal *)pJfd;
|
||||
*pSize = (sqlite_int64) p->endpoint.iOffset;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Table of methods for MemJournal sqlite3_file object.
|
||||
*/
|
||||
static struct sqlite3_io_methods MemJournalMethods = {
|
||||
1, /* iVersion */
|
||||
memjrnlClose, /* xClose */
|
||||
memjrnlRead, /* xRead */
|
||||
memjrnlWrite, /* xWrite */
|
||||
memjrnlTruncate, /* xTruncate */
|
||||
memjrnlSync, /* xSync */
|
||||
memjrnlFileSize, /* xFileSize */
|
||||
0, /* xLock */
|
||||
0, /* xUnlock */
|
||||
0, /* xCheckReservedLock */
|
||||
0, /* xFileControl */
|
||||
0, /* xSectorSize */
|
||||
0 /* xDeviceCharacteristics */
|
||||
};
|
||||
|
||||
/*
|
||||
** Open a journal file.
|
||||
*/
|
||||
void sqlite3MemJournalOpen(sqlite3_file *pJfd){
|
||||
MemJournal *p = (MemJournal *)pJfd;
|
||||
memset(p, 0, sqlite3MemJournalSize());
|
||||
p->pMethod = &MemJournalMethods;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return true if the file-handle passed as an argument is
|
||||
** an in-memory journal
|
||||
*/
|
||||
int sqlite3IsMemJournal(sqlite3_file *pJfd){
|
||||
return pJfd->pMethods==&MemJournalMethods;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the number of bytes required to store a MemJournal that uses vfs
|
||||
** pVfs to create the underlying on-disk files.
|
||||
*/
|
||||
int sqlite3MemJournalSize(){
|
||||
return sizeof(MemJournal);
|
||||
}
|
||||
+2
-2
@@ -25,7 +25,7 @@
|
||||
** that does error checking on mutexes to make sure they are being
|
||||
** called correctly.
|
||||
**
|
||||
** $Id: mutex_noop.c,v 1.1 2008/10/07 15:25:48 drh Exp $
|
||||
** $Id: mutex_noop.c,v 1.2 2008/10/15 19:03:03 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -44,7 +44,7 @@ static sqlite3_mutex *noopMutexAlloc(int id){ return (sqlite3_mutex*)8; }
|
||||
static void noopMutexFree(sqlite3_mutex *p){ return; }
|
||||
static void noopMutexEnter(sqlite3_mutex *p){ return; }
|
||||
static int noopMutexTry(sqlite3_mutex *p){ return SQLITE_OK; }
|
||||
static void debugMutexLeave(sqlite3_mutex *p){ return; }
|
||||
static void noopMutexLeave(sqlite3_mutex *p){ return; }
|
||||
|
||||
sqlite3_mutex_methods *sqlite3DefaultMutex(void){
|
||||
static sqlite3_mutex_methods sMutex = {
|
||||
|
||||
+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;
|
||||
|
||||
+9
-2
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** This file contains the C functions that implement mutexes for win32
|
||||
**
|
||||
** $Id: mutex_w32.c,v 1.11 2008/06/26 10:41:19 danielk1977 Exp $
|
||||
** $Id: mutex_w32.c,v 1.12 2008/11/10 20:01:41 shane Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -41,7 +41,14 @@ struct sqlite3_mutex {
|
||||
** this routine is used to determine if the host is Win95/98/ME or
|
||||
** WinNT/2K/XP so that we will know whether or not we can safely call
|
||||
** the LockFileEx() API.
|
||||
**
|
||||
** mutexIsNT() is only used for the TryEnterCriticalSection() API call,
|
||||
** which is only available if your application was compiled with
|
||||
** _WIN32_WINNT defined to a value >= 0x0400. Currently, the only
|
||||
** call to TryEnterCriticalSection() is #ifdef'ed out, so #ifdef
|
||||
** this out as well.
|
||||
*/
|
||||
#if 0
|
||||
#if SQLITE_OS_WINCE
|
||||
# define mutexIsNT() (1)
|
||||
#else
|
||||
@@ -56,7 +63,7 @@ struct sqlite3_mutex {
|
||||
return osType==2;
|
||||
}
|
||||
#endif /* SQLITE_OS_WINCE */
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_DEBUG
|
||||
/*
|
||||
|
||||
+9
-1
@@ -12,7 +12,7 @@
|
||||
**
|
||||
** This file contains code that is specific to OS/2.
|
||||
**
|
||||
** $Id: os_os2.c,v 1.57 2008/10/13 21:46:47 pweilbacher Exp $
|
||||
** $Id: os_os2.c,v 1.59 2008/11/18 23:03:40 pweilbacher Exp $
|
||||
*/
|
||||
|
||||
#include "sqliteInt.h"
|
||||
@@ -124,6 +124,7 @@ static int os2Read(
|
||||
if( got == (ULONG)amt )
|
||||
return SQLITE_OK;
|
||||
else {
|
||||
/* Unread portions of the input buffer must be zero-filled */
|
||||
memset(&((char*)pBuf)[got], 0, amt-got);
|
||||
return SQLITE_IOERR_SHORT_READ;
|
||||
}
|
||||
@@ -195,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
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+583
-68
File diff suppressed because it is too large
Load Diff
+67
-5
@@ -12,7 +12,7 @@
|
||||
**
|
||||
** This file contains code that is specific to windows.
|
||||
**
|
||||
** $Id: os_win.c,v 1.135 2008/10/12 02:27:39 shane 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 */
|
||||
@@ -73,7 +73,7 @@
|
||||
** Determine if we are dealing with WindowsCE - which has a much
|
||||
** reduced API.
|
||||
*/
|
||||
#if defined(SQLITE_OS_WINCE)
|
||||
#if SQLITE_OS_WINCE
|
||||
# define AreFileApisANSI() 1
|
||||
#endif
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -666,6 +666,7 @@ static int winRead(
|
||||
if( got==(DWORD)amt ){
|
||||
return SQLITE_OK;
|
||||
}else{
|
||||
/* Unread parts of the buffer must be zero-filled */
|
||||
memset(&((char*)pBuf)[got], 0, amt-got);
|
||||
return SQLITE_IOERR_SHORT_READ;
|
||||
}
|
||||
@@ -750,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
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -790,11 +798,15 @@ static int getReadLock(winFile *pFile){
|
||||
ovlp.hEvent = 0;
|
||||
res = LockFileEx(pFile->h, LOCKFILE_FAIL_IMMEDIATELY,
|
||||
0, SHARED_SIZE, 0, &ovlp);
|
||||
/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
|
||||
*/
|
||||
#if SQLITE_OS_WINCE==0
|
||||
}else{
|
||||
int lk;
|
||||
sqlite3_randomness(sizeof(lk), &lk);
|
||||
pFile->sharedLockByte = (lk & 0x7fffffff)%(SHARED_SIZE - 1);
|
||||
res = LockFile(pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
|
||||
#endif
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -806,8 +818,12 @@ static int unlockReadLock(winFile *pFile){
|
||||
int res;
|
||||
if( isNT() ){
|
||||
res = UnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
|
||||
/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
|
||||
*/
|
||||
#if SQLITE_OS_WINCE==0
|
||||
}else{
|
||||
res = UnlockFile(pFile->h, SHARED_FIRST + pFile->sharedLockByte, 0, 1, 0);
|
||||
#endif
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -1080,8 +1096,12 @@ static void *convertUtf8Filename(const char *zFilename){
|
||||
void *zConverted = 0;
|
||||
if( isNT() ){
|
||||
zConverted = utf8ToUnicode(zFilename);
|
||||
/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
|
||||
*/
|
||||
#if SQLITE_OS_WINCE==0
|
||||
}else{
|
||||
zConverted = utf8ToMbcs(zFilename);
|
||||
#endif
|
||||
}
|
||||
/* caller will handle out of memory */
|
||||
return zConverted;
|
||||
@@ -1111,17 +1131,23 @@ static int getTempname(int nBuf, char *zBuf){
|
||||
}else{
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
|
||||
** Since the ASCII version of these Windows API do not exist for WINCE,
|
||||
** it's important to not reference them for WINCE builds.
|
||||
*/
|
||||
#if SQLITE_OS_WINCE==0
|
||||
}else{
|
||||
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);
|
||||
}else{
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
for(i=strlen(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
|
||||
zTempPath[i] = 0;
|
||||
@@ -1249,6 +1275,11 @@ static int winOpen(
|
||||
dwFlagsAndAttributes,
|
||||
NULL
|
||||
);
|
||||
/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
|
||||
** Since the ASCII version of these Windows API do not exist for WINCE,
|
||||
** it's important to not reference them for WINCE builds.
|
||||
*/
|
||||
#if SQLITE_OS_WINCE==0
|
||||
}else{
|
||||
h = CreateFileA((char*)zConverted,
|
||||
dwDesiredAccess,
|
||||
@@ -1258,6 +1289,7 @@ static int winOpen(
|
||||
dwFlagsAndAttributes,
|
||||
NULL
|
||||
);
|
||||
#endif
|
||||
}
|
||||
if( h==INVALID_HANDLE_VALUE ){
|
||||
free(zConverted);
|
||||
@@ -1331,6 +1363,11 @@ static int winDelete(
|
||||
|| ((error = GetLastError()) == ERROR_ACCESS_DENIED))
|
||||
&& (++cnt < MX_DELETION_ATTEMPTS)
|
||||
&& (Sleep(100), 1) );
|
||||
/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
|
||||
** Since the ASCII version of these Windows API do not exist for WINCE,
|
||||
** it's important to not reference them for WINCE builds.
|
||||
*/
|
||||
#if SQLITE_OS_WINCE==0
|
||||
}else{
|
||||
do{
|
||||
DeleteFileA(zConverted);
|
||||
@@ -1338,6 +1375,7 @@ static int winDelete(
|
||||
|| ((error = GetLastError()) == ERROR_ACCESS_DENIED))
|
||||
&& (++cnt < MX_DELETION_ATTEMPTS)
|
||||
&& (Sleep(100), 1) );
|
||||
#endif
|
||||
}
|
||||
free(zConverted);
|
||||
OSTRACE2("DELETE \"%s\"\n", zFilename);
|
||||
@@ -1362,8 +1400,14 @@ static int winAccess(
|
||||
}
|
||||
if( isNT() ){
|
||||
attr = GetFileAttributesW((WCHAR*)zConverted);
|
||||
/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
|
||||
** Since the ASCII version of these Windows API do not exist for WINCE,
|
||||
** it's important to not reference them for WINCE builds.
|
||||
*/
|
||||
#if SQLITE_OS_WINCE==0
|
||||
}else{
|
||||
attr = GetFileAttributesA((char*)zConverted);
|
||||
#endif
|
||||
}
|
||||
free(zConverted);
|
||||
switch( flags ){
|
||||
@@ -1422,6 +1466,11 @@ static int winFullPathname(
|
||||
free(zConverted);
|
||||
zOut = unicodeToUtf8(zTemp);
|
||||
free(zTemp);
|
||||
/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
|
||||
** Since the ASCII version of these Windows API do not exist for WINCE,
|
||||
** it's important to not reference them for WINCE builds.
|
||||
*/
|
||||
#if SQLITE_OS_WINCE==0
|
||||
}else{
|
||||
char *zTemp;
|
||||
nByte = GetFullPathNameA((char*)zConverted, 0, 0, 0) + 3;
|
||||
@@ -1432,8 +1481,9 @@ static int winFullPathname(
|
||||
}
|
||||
GetFullPathNameA((char*)zConverted, nByte, zTemp, 0);
|
||||
free(zConverted);
|
||||
zOut = mbcsToUtf8(zTemp);
|
||||
zOut = sqlite3_win32_mbcs_to_utf8(zTemp);
|
||||
free(zTemp);
|
||||
#endif
|
||||
}
|
||||
if( zOut ){
|
||||
sqlite3_snprintf(pVfs->mxPathname, zFull, "%s", zOut);
|
||||
@@ -1462,8 +1512,14 @@ static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){
|
||||
}
|
||||
if( isNT() ){
|
||||
h = LoadLibraryW((WCHAR*)zConverted);
|
||||
/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
|
||||
** Since the ASCII version of these Windows API do not exist for WINCE,
|
||||
** it's important to not reference them for WINCE builds.
|
||||
*/
|
||||
#if SQLITE_OS_WINCE==0
|
||||
}else{
|
||||
h = LoadLibraryA((char*)zConverted);
|
||||
#endif
|
||||
}
|
||||
free(zConverted);
|
||||
return (void*)h;
|
||||
@@ -1497,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);
|
||||
@@ -1519,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;
|
||||
}
|
||||
|
||||
|
||||
+380
-421
File diff suppressed because it is too large
Load Diff
+3
-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.85 2008/09/29 11:49:48 danielk1977 Exp $
|
||||
** @(#) $Id: pager.h,v 1.87 2008/11/19 10:22:33 danielk1977 Exp $
|
||||
*/
|
||||
|
||||
#ifndef _PAGER_H_
|
||||
@@ -66,13 +66,14 @@ typedef struct PgHdr DbPage;
|
||||
#define PAGER_JOURNALMODE_PERSIST 1 /* Commit by zeroing journal header */
|
||||
#define PAGER_JOURNALMODE_OFF 2 /* Journal omitted. */
|
||||
#define PAGER_JOURNALMODE_TRUNCATE 3 /* Commit by truncating journal */
|
||||
#define PAGER_JOURNALMODE_MEMORY 4 /* In-memory journal file */
|
||||
|
||||
/*
|
||||
** See source code comments for a detailed description of the following
|
||||
** 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);
|
||||
|
||||
+3
-2
@@ -14,7 +14,7 @@
|
||||
** the parser. Lemon will also generate a header file containing
|
||||
** numeric codes for all of the tokens.
|
||||
**
|
||||
** @(#) $Id: parse.y,v 1.261 2008/10/11 17:35:16 drh Exp $
|
||||
** @(#) $Id: parse.y,v 1.262 2008/10/23 05:45:07 danielk1977 Exp $
|
||||
*/
|
||||
|
||||
// All token codes are small integers with #defines that begin with "TK_"
|
||||
@@ -246,8 +246,9 @@ carg ::= ccons.
|
||||
ccons ::= DEFAULT term(X). {sqlite3AddDefaultValue(pParse,X);}
|
||||
ccons ::= DEFAULT LP expr(X) RP. {sqlite3AddDefaultValue(pParse,X);}
|
||||
ccons ::= DEFAULT PLUS term(X). {sqlite3AddDefaultValue(pParse,X);}
|
||||
ccons ::= DEFAULT MINUS term(X). {
|
||||
ccons ::= DEFAULT MINUS(A) term(X). {
|
||||
Expr *p = sqlite3PExpr(pParse, TK_UMINUS, X, 0, 0);
|
||||
sqlite3ExprSpan(p,&A,&X->span);
|
||||
sqlite3AddDefaultValue(pParse,p);
|
||||
}
|
||||
ccons ::= DEFAULT id(X). {
|
||||
|
||||
+225
-927
File diff suppressed because it is too large
Load Diff
+15
-34
@@ -12,7 +12,7 @@
|
||||
** This header file defines the interface that the sqlite page cache
|
||||
** subsystem.
|
||||
**
|
||||
** @(#) $Id: pcache.h,v 1.13 2008/10/11 17:42:29 drh Exp $
|
||||
** @(#) $Id: pcache.h,v 1.16 2008/11/19 16:52:44 danielk1977 Exp $
|
||||
*/
|
||||
|
||||
#ifndef _PCACHE_H_
|
||||
@@ -34,25 +34,19 @@ 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.
|
||||
*/
|
||||
i16 nRef; /* Number of users of this page */
|
||||
PCache *pCache; /* Cache that owns this page */
|
||||
void *apSave[2]; /* Journal entries for in-memory databases */
|
||||
/**********************************************************************
|
||||
** 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.
|
||||
@@ -109,11 +101,6 @@ void sqlite3PcacheMove(PgHdr*, Pgno);
|
||||
/* Remove all pages with pgno>x. Reset the cache if x==0 */
|
||||
void sqlite3PcacheTruncate(PCache*, Pgno x);
|
||||
|
||||
/* Routines used to implement transactions on memory-only databases. */
|
||||
int sqlite3PcachePreserve(PgHdr*, int); /* Preserve current page content */
|
||||
void sqlite3PcacheCommit(PCache*, int); /* Drop preserved copy */
|
||||
void sqlite3PcacheRollback(PCache*, int, void (*xReiniter)(PgHdr*));
|
||||
|
||||
/* Get a list of all dirty pages in the cache, sorted by page number */
|
||||
PgHdr *sqlite3PcacheDirtyList(PCache*);
|
||||
|
||||
@@ -121,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*);
|
||||
@@ -148,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.
|
||||
@@ -161,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 */
|
||||
@@ -173,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
|
||||
+46
-43
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** This file contains code used to implement the PRAGMA command.
|
||||
**
|
||||
** $Id: pragma.c,v 1.189 2008/10/10 17:47:21 danielk1977 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];
|
||||
}
|
||||
@@ -151,7 +151,7 @@ static void returnSingleInt(Parse *pParse, const char *zLabel, int value){
|
||||
sqlite3VdbeAddOp2(v, OP_Integer, value, mem);
|
||||
if( pParse->explain==0 ){
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
|
||||
}
|
||||
sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
|
||||
}
|
||||
@@ -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;
|
||||
@@ -322,7 +322,7 @@ void sqlite3Pragma(
|
||||
sqlite3VdbeUsesBtree(v, iDb);
|
||||
if( !zRight ){
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC);
|
||||
pParse->nMem += 2;
|
||||
addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
|
||||
sqlite3VdbeChangeP1(v, addr, iDb);
|
||||
@@ -403,7 +403,7 @@ void sqlite3Pragma(
|
||||
sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
|
||||
sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "page_count", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "page_count", SQLITE_STATIC);
|
||||
}else
|
||||
|
||||
/*
|
||||
@@ -448,18 +448,20 @@ void sqlite3Pragma(
|
||||
zRet = "exclusive";
|
||||
}
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", SQLITE_STATIC);
|
||||
sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zRet, 0);
|
||||
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
|
||||
}else
|
||||
|
||||
/*
|
||||
** PRAGMA [database.]journal_mode
|
||||
** PRAGMA [database.]journal_mode = (delete|persist|off)
|
||||
** PRAGMA [database.]journal_mode = (delete|persist|off|truncate|memory)
|
||||
*/
|
||||
if( sqlite3StrICmp(zLeft,"journal_mode")==0 ){
|
||||
int eMode;
|
||||
static char * const azModeName[] = {"delete", "persist", "off", "truncate"};
|
||||
static char * const azModeName[] = {
|
||||
"delete", "persist", "off", "truncate", "memory"
|
||||
};
|
||||
|
||||
if( zRight==0 ){
|
||||
eMode = PAGER_JOURNALMODE_QUERY;
|
||||
@@ -503,9 +505,10 @@ void sqlite3Pragma(
|
||||
assert( eMode==PAGER_JOURNALMODE_DELETE
|
||||
|| eMode==PAGER_JOURNALMODE_TRUNCATE
|
||||
|| eMode==PAGER_JOURNALMODE_PERSIST
|
||||
|| eMode==PAGER_JOURNALMODE_OFF );
|
||||
|| eMode==PAGER_JOURNALMODE_OFF
|
||||
|| eMode==PAGER_JOURNALMODE_MEMORY );
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", SQLITE_STATIC);
|
||||
sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0,
|
||||
azModeName[eMode], P4_STATIC);
|
||||
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
|
||||
@@ -672,7 +675,7 @@ void sqlite3Pragma(
|
||||
if( sqlite3_temp_directory ){
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
|
||||
"temp_store_directory", P4_STATIC);
|
||||
"temp_store_directory", SQLITE_STATIC);
|
||||
sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_temp_directory, 0);
|
||||
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
|
||||
}
|
||||
@@ -757,12 +760,12 @@ void sqlite3Pragma(
|
||||
Column *pCol;
|
||||
sqlite3VdbeSetNumCols(v, 6);
|
||||
pParse->nMem = 6;
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", SQLITE_STATIC);
|
||||
sqlite3ViewGetColumnNames(pParse, pTab);
|
||||
for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
|
||||
const Token *pDflt;
|
||||
@@ -774,7 +777,7 @@ void sqlite3Pragma(
|
||||
sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pCol->zName, 0);
|
||||
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
|
||||
pCol->zType ? pCol->zType : "", 0);
|
||||
sqlite3VdbeAddOp2(v, OP_Integer, pCol->notNull, 4);
|
||||
sqlite3VdbeAddOp2(v, OP_Integer, (pCol->notNull ? 1 : 0), 4);
|
||||
if( pCol->pDflt && (pDflt = &pCol->pDflt->span)->z ){
|
||||
sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pDflt->z, pDflt->n);
|
||||
}else{
|
||||
@@ -796,9 +799,9 @@ void sqlite3Pragma(
|
||||
pTab = pIdx->pTable;
|
||||
sqlite3VdbeSetNumCols(v, 3);
|
||||
pParse->nMem = 3;
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC);
|
||||
for(i=0; i<pIdx->nColumn; i++){
|
||||
int cnum = pIdx->aiColumn[i];
|
||||
sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
|
||||
@@ -822,9 +825,9 @@ void sqlite3Pragma(
|
||||
int i = 0;
|
||||
sqlite3VdbeSetNumCols(v, 3);
|
||||
pParse->nMem = 3;
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", SQLITE_STATIC);
|
||||
while(pIdx){
|
||||
sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
|
||||
sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0);
|
||||
@@ -842,9 +845,9 @@ void sqlite3Pragma(
|
||||
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
|
||||
sqlite3VdbeSetNumCols(v, 3);
|
||||
pParse->nMem = 3;
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", SQLITE_STATIC);
|
||||
for(i=0; i<db->nDb; i++){
|
||||
if( db->aDb[i].pBt==0 ) continue;
|
||||
assert( db->aDb[i].zName!=0 );
|
||||
@@ -861,8 +864,8 @@ void sqlite3Pragma(
|
||||
HashElem *p;
|
||||
sqlite3VdbeSetNumCols(v, 2);
|
||||
pParse->nMem = 2;
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
|
||||
for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
|
||||
CollSeq *pColl = (CollSeq *)sqliteHashData(p);
|
||||
sqlite3VdbeAddOp2(v, OP_Integer, i++, 1);
|
||||
@@ -885,14 +888,14 @@ void sqlite3Pragma(
|
||||
int i = 0;
|
||||
sqlite3VdbeSetNumCols(v, 8);
|
||||
pParse->nMem = 8;
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "on_update", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 6, COLNAME_NAME, "on_delete", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 7, COLNAME_NAME, "match", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "on_update", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(v, 6, COLNAME_NAME, "on_delete", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(v, 7, COLNAME_NAME, "match", SQLITE_STATIC);
|
||||
while(pFK){
|
||||
int j;
|
||||
for(j=0; j<pFK->nCol; j++){
|
||||
@@ -970,7 +973,7 @@ void sqlite3Pragma(
|
||||
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
|
||||
pParse->nMem = 6;
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", SQLITE_STATIC);
|
||||
|
||||
/* Set the maximum error count */
|
||||
mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
|
||||
@@ -1149,7 +1152,7 @@ void sqlite3Pragma(
|
||||
if( !zRight ){ /* "PRAGMA encoding" */
|
||||
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", SQLITE_STATIC);
|
||||
sqlite3VdbeAddOp2(v, OP_String8, 0, 1);
|
||||
for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
|
||||
if( pEnc->enc==ENC(pParse->db) ){
|
||||
@@ -1250,7 +1253,7 @@ void sqlite3Pragma(
|
||||
sqlite3VdbeChangeP1(v, addr, iDb);
|
||||
sqlite3VdbeChangeP3(v, addr, iCookie);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, P4_TRANSIENT);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
|
||||
}
|
||||
}else
|
||||
#endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */
|
||||
@@ -1267,8 +1270,8 @@ void sqlite3Pragma(
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
sqlite3VdbeSetNumCols(v, 2);
|
||||
pParse->nMem = 2;
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", SQLITE_STATIC);
|
||||
for(i=0; i<db->nDb; i++){
|
||||
Btree *pBt;
|
||||
Pager *pPager;
|
||||
|
||||
+16
-15
@@ -13,7 +13,7 @@
|
||||
** interface, and routines that contribute to loading the database schema
|
||||
** from disk.
|
||||
**
|
||||
** $Id: prepare.c,v 1.97 2008/09/08 09:06:19 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));
|
||||
@@ -601,19 +602,19 @@ static int sqlite3Prepare(
|
||||
if( rc==SQLITE_OK && sParse.pVdbe && sParse.explain ){
|
||||
if( sParse.explain==2 ){
|
||||
sqlite3VdbeSetNumCols(sParse.pVdbe, 3);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 0, COLNAME_NAME, "order", P4_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "from", P4_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "detail", P4_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 0, COLNAME_NAME, "order", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "from", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "detail", SQLITE_STATIC);
|
||||
}else{
|
||||
sqlite3VdbeSetNumCols(sParse.pVdbe, 8);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 0, COLNAME_NAME, "addr", P4_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "opcode", P4_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "p1", P4_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 3, COLNAME_NAME, "p2", P4_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 4, COLNAME_NAME, "p3", P4_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 5, COLNAME_NAME, "p4", P4_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 6, COLNAME_NAME, "p5", P4_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 7, COLNAME_NAME, "comment",P4_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 0, COLNAME_NAME, "addr", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "opcode", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "p1", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 3, COLNAME_NAME, "p2", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 4, COLNAME_NAME, "p3", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 5, COLNAME_NAME, "p4", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 6, COLNAME_NAME, "p5", SQLITE_STATIC);
|
||||
sqlite3VdbeSetColName(sParse.pVdbe, 7, COLNAME_NAME, "comment", SQLITE_STATIC);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
+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;
|
||||
}
|
||||
|
||||
+5
-4
@@ -14,7 +14,7 @@
|
||||
** resolve all identifiers by associating them with a particular
|
||||
** table and column.
|
||||
**
|
||||
** $Id: resolve.c,v 1.9 2008/10/11 16:47:36 drh Exp $
|
||||
** $Id: resolve.c,v 1.11 2008/11/17 19:18:55 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <stdlib.h>
|
||||
@@ -320,6 +320,7 @@ static int lookupName(
|
||||
if( cnt==0 && zTab==0 && pColumnToken->z[0]=='"' ){
|
||||
sqlite3DbFree(db, zCol);
|
||||
pExpr->op = TK_STRING;
|
||||
pExpr->pTab = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -348,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;
|
||||
|
||||
+132
-73
@@ -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.480 2008/10/07 19:53:14 drh Exp $
|
||||
** $Id: select.c,v 1.486 2008/11/19 09:05:27 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -65,7 +65,7 @@ Select *sqlite3SelectNew(
|
||||
Select standin;
|
||||
sqlite3 *db = pParse->db;
|
||||
pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
|
||||
assert( !pOffset || pLimit ); /* Can't have OFFSET without LIMIT. */
|
||||
assert( db->mallocFailed || !pOffset || pLimit ); /* OFFSET implies LIMIT */
|
||||
if( pNew==0 ){
|
||||
pNew = &standin;
|
||||
memset(pNew, 0, sizeof(*pNew));
|
||||
@@ -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;
|
||||
}
|
||||
@@ -1033,13 +1033,13 @@ static void generateColumnTypes(
|
||||
** column specific strings, in case the schema is reset before this
|
||||
** virtual machine is deleted.
|
||||
*/
|
||||
sqlite3VdbeSetColName(v, i, COLNAME_DATABASE, zOrigDb, P4_TRANSIENT);
|
||||
sqlite3VdbeSetColName(v, i, COLNAME_TABLE, zOrigTab, P4_TRANSIENT);
|
||||
sqlite3VdbeSetColName(v, i, COLNAME_COLUMN, zOrigCol, P4_TRANSIENT);
|
||||
sqlite3VdbeSetColName(v, i, COLNAME_DATABASE, zOrigDb, SQLITE_TRANSIENT);
|
||||
sqlite3VdbeSetColName(v, i, COLNAME_TABLE, zOrigTab, SQLITE_TRANSIENT);
|
||||
sqlite3VdbeSetColName(v, i, COLNAME_COLUMN, zOrigCol, SQLITE_TRANSIENT);
|
||||
#else
|
||||
zType = columnType(&sNC, p, 0, 0, 0);
|
||||
#endif
|
||||
sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, P4_TRANSIENT);
|
||||
sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_DECLTYPE */
|
||||
}
|
||||
@@ -1078,7 +1078,7 @@ static void generateColumnNames(
|
||||
if( p==0 ) continue;
|
||||
if( pEList->a[i].zName ){
|
||||
char *zName = pEList->a[i].zName;
|
||||
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, strlen(zName));
|
||||
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
|
||||
}else if( (p->op==TK_COLUMN || p->op==TK_AGG_COLUMN) && pTabList ){
|
||||
Table *pTab;
|
||||
char *zCol;
|
||||
@@ -1094,7 +1094,8 @@ static void generateColumnNames(
|
||||
zCol = pTab->aCol[iCol].zName;
|
||||
}
|
||||
if( !shortNames && !fullNames ){
|
||||
sqlite3VdbeSetColName(v, i, COLNAME_NAME, (char*)p->span.z, p->span.n);
|
||||
sqlite3VdbeSetColName(v, i, COLNAME_NAME,
|
||||
sqlite3DbStrNDup(db, (char*)p->span.z, p->span.n), SQLITE_DYNAMIC);
|
||||
}else if( fullNames || (!shortNames && pTabList->nSrc>1) ){
|
||||
char *zName = 0;
|
||||
char *zTab;
|
||||
@@ -1102,12 +1103,13 @@ static void generateColumnNames(
|
||||
zTab = pTabList->a[j].zAlias;
|
||||
if( fullNames || zTab==0 ) zTab = pTab->zName;
|
||||
zName = sqlite3MPrintf(db, "%s.%s", zTab, zCol);
|
||||
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, P4_DYNAMIC);
|
||||
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_DYNAMIC);
|
||||
}else{
|
||||
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zCol, strlen(zCol));
|
||||
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zCol, SQLITE_TRANSIENT);
|
||||
}
|
||||
}else{
|
||||
sqlite3VdbeSetColName(v, i, COLNAME_NAME, (char*)p->span.z, p->span.n);
|
||||
sqlite3VdbeSetColName(v, i, COLNAME_NAME,
|
||||
sqlite3DbStrNDup(db, (char*)p->span.z, p->span.n), SQLITE_DYNAMIC);
|
||||
}
|
||||
}
|
||||
generateColumnTypes(pParse, pTabList, pEList);
|
||||
@@ -2144,7 +2146,7 @@ static int multiSelectOrderBy(
|
||||
regPrev = 0;
|
||||
}else{
|
||||
int nExpr = p->pEList->nExpr;
|
||||
assert( nOrderBy>=nExpr );
|
||||
assert( nOrderBy>=nExpr || db->mallocFailed );
|
||||
regPrev = sqlite3GetTempRange(pParse, nExpr+1);
|
||||
sqlite3VdbeAddOp2(v, OP_Integer, 0, regPrev);
|
||||
pKeyDup = sqlite3DbMallocZero(db,
|
||||
@@ -2571,7 +2573,9 @@ static int flattenSubquery(
|
||||
|
||||
/* Check to see if flattening is permitted. Return 0 if not.
|
||||
*/
|
||||
assert( p!=0 );
|
||||
if( p==0 ) return 0;
|
||||
assert( p->pPrior==0 ); /* Unable to flatten compound queries */
|
||||
pSrc = p->pSrc;
|
||||
assert( pSrc && iFrom>=0 && iFrom<pSrc->nSrc );
|
||||
pSubitem = &pSrc->a[iFrom];
|
||||
@@ -2683,92 +2687,146 @@ static int flattenSubquery(
|
||||
** SELECT <expr-list> FROM (<sub-query>) <where-clause>
|
||||
**
|
||||
** followed by any ORDER BY, LIMIT and/or OFFSET clauses. This block
|
||||
** creates N copies of the parent query without any ORDER BY, LIMIT or
|
||||
** creates N-1 copies of the parent query without any ORDER BY, LIMIT or
|
||||
** OFFSET clauses and joins them to the left-hand-side of the original
|
||||
** using UNION ALL operators. In this case N is the number of simple
|
||||
** select statements in the compound sub-query.
|
||||
**
|
||||
** Example:
|
||||
**
|
||||
** SELECT a+1 FROM (
|
||||
** SELECT x FROM tab
|
||||
** UNION ALL
|
||||
** SELECT y FROM tab
|
||||
** UNION ALL
|
||||
** SELECT abs(z*2) FROM tab2
|
||||
** ) WHERE a!=5 ORDER BY 1
|
||||
**
|
||||
** Transformed into:
|
||||
**
|
||||
** SELECT x+1 FROM tab WHERE x+1!=5
|
||||
** UNION ALL
|
||||
** SELECT y+1 FROM tab WHERE y+1!=5
|
||||
** UNION ALL
|
||||
** SELECT abs(z*2)+1 FROM tab2 WHERE abs(z*2)+1!=5
|
||||
** ORDER BY 1
|
||||
**
|
||||
** We call this the "compound-subquery flattening".
|
||||
*/
|
||||
for(pSub=pSub->pPrior; pSub; pSub=pSub->pPrior){
|
||||
Select *pNew;
|
||||
ExprList *pOrderBy = p->pOrderBy;
|
||||
Expr *pLimit = p->pLimit;
|
||||
Expr *pOffset = p->pOffset;
|
||||
Select *pPrior = p->pPrior;
|
||||
p->pOrderBy = 0;
|
||||
p->pSrc = 0;
|
||||
p->pPrior = 0;
|
||||
p->pLimit = 0;
|
||||
pNew = sqlite3SelectDup(db, p);
|
||||
pNew->pPrior = pPrior;
|
||||
p->pPrior = pNew;
|
||||
p->pOrderBy = pOrderBy;
|
||||
p->op = TK_ALL;
|
||||
p->pSrc = pSrc;
|
||||
p->pLimit = pLimit;
|
||||
p->pOffset = pOffset;
|
||||
p->pOrderBy = pOrderBy;
|
||||
p->pSrc = pSrc;
|
||||
p->op = TK_ALL;
|
||||
p->pRightmost = 0;
|
||||
pNew->pRightmost = 0;
|
||||
if( pNew==0 ){
|
||||
pNew = pPrior;
|
||||
}else{
|
||||
pNew->pPrior = pPrior;
|
||||
pNew->pRightmost = 0;
|
||||
}
|
||||
p->pPrior = pNew;
|
||||
if( db->mallocFailed ) return 1;
|
||||
}
|
||||
|
||||
/* Begin flattening the iFrom-th entry of the FROM clause
|
||||
** in the outer query.
|
||||
*/
|
||||
pSub = pSub1 = pSubitem->pSelect;
|
||||
|
||||
/* Delete the transient table structure associated with the
|
||||
** subquery
|
||||
*/
|
||||
sqlite3DbFree(db, pSubitem->zDatabase);
|
||||
sqlite3DbFree(db, pSubitem->zName);
|
||||
sqlite3DbFree(db, pSubitem->zAlias);
|
||||
pSubitem->zDatabase = 0;
|
||||
pSubitem->zName = 0;
|
||||
pSubitem->zAlias = 0;
|
||||
pSubitem->pSelect = 0;
|
||||
|
||||
/* Defer deleting the Table object associated with the
|
||||
** subquery until code generation is
|
||||
** complete, since there may still exist Expr.pTab entries that
|
||||
** refer to the subquery even after flattening. Ticket #3346.
|
||||
*/
|
||||
if( pSubitem->pTab!=0 ){
|
||||
Table *pTabToDel = pSubitem->pTab;
|
||||
if( pTabToDel->nRef==1 ){
|
||||
pTabToDel->pNextZombie = pParse->pZombieTab;
|
||||
pParse->pZombieTab = pTabToDel;
|
||||
}else{
|
||||
pTabToDel->nRef--;
|
||||
}
|
||||
pSubitem->pTab = 0;
|
||||
}
|
||||
|
||||
/* The following loop runs once for each term in a compound-subquery
|
||||
** flattening (as described above). If we are doing a different kind
|
||||
** of flattening - a flattening other than a compound-subquery flattening -
|
||||
** then this loop only runs once.
|
||||
**
|
||||
** This loop moves all of the FROM elements of the subquery into the
|
||||
** the FROM clause of the outer query. Before doing this, remember
|
||||
** the cursor number for the original outer query FROM element in
|
||||
** iParent. The iParent cursor will never be used. Subsequent code
|
||||
** will scan expressions looking for iParent references and replace
|
||||
** those references with expressions that resolve to the subquery FROM
|
||||
** elements we are now copying in.
|
||||
*/
|
||||
for(pParent=p; pParent; pParent=pParent->pPrior, pSub=pSub->pPrior){
|
||||
int nSubSrc = pSubSrc->nSrc;
|
||||
int nSubSrc;
|
||||
int jointype = 0;
|
||||
pSubSrc = pSub->pSrc;
|
||||
pSrc = pParent->pSrc;
|
||||
pSubSrc = pSub->pSrc; /* FROM clause of subquery */
|
||||
nSubSrc = pSubSrc->nSrc; /* Number of terms in subquery FROM clause */
|
||||
pSrc = pParent->pSrc; /* FROM clause of the outer query */
|
||||
|
||||
/* Move all of the FROM elements of the subquery into the
|
||||
** the FROM clause of the outer query. Before doing this, remember
|
||||
** the cursor number for the original outer query FROM element in
|
||||
** iParent. The iParent cursor will never be used. Subsequent code
|
||||
** will scan expressions looking for iParent references and replace
|
||||
** those references with expressions that resolve to the subquery FROM
|
||||
** elements we are now copying in.
|
||||
*/
|
||||
if( pSrc ){
|
||||
Table *pTabToDel;
|
||||
pSubitem = &pSrc->a[iFrom];
|
||||
nSubSrc = pSubSrc->nSrc;
|
||||
assert( pParent==p ); /* First time through the loop */
|
||||
jointype = pSubitem->jointype;
|
||||
sqlite3DbFree(db, pSubitem->zDatabase);
|
||||
sqlite3DbFree(db, pSubitem->zName);
|
||||
sqlite3DbFree(db, pSubitem->zAlias);
|
||||
pSubitem->zDatabase = 0;
|
||||
pSubitem->zName = 0;
|
||||
pSubitem->zAlias = 0;
|
||||
}else{
|
||||
assert( pParent!=p ); /* 2nd and subsequent times through the loop */
|
||||
pSrc = pParent->pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
|
||||
if( pSrc==0 ){
|
||||
assert( db->mallocFailed );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* If the FROM element is a subquery, defer deleting the Table
|
||||
** object associated with that subquery until code generation is
|
||||
** complete, since there may still exist Expr.pTab entires that
|
||||
** refer to the subquery even after flattening. Ticket #3346.
|
||||
*/
|
||||
if( (pTabToDel = pSubitem->pTab)!=0 ){
|
||||
if( pTabToDel->nRef==1 ){
|
||||
pTabToDel->pNextZombie = pParse->pZombieTab;
|
||||
pParse->pZombieTab = pTabToDel;
|
||||
}else{
|
||||
pTabToDel->nRef--;
|
||||
}
|
||||
}
|
||||
pSubitem->pTab = 0;
|
||||
}
|
||||
if( nSubSrc!=1 || !pSrc ){
|
||||
int extra = nSubSrc - 1;
|
||||
for(i=(pSrc?1:0); i<nSubSrc; i++){
|
||||
pSrc = sqlite3SrcListAppend(db, pSrc, 0, 0);
|
||||
if( pSrc==0 ){
|
||||
pParent->pSrc = 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
pParent->pSrc = pSrc;
|
||||
for(i=pSrc->nSrc-1; i-extra>=iFrom; i--){
|
||||
pSrc->a[i] = pSrc->a[i-extra];
|
||||
/* The subquery uses a single slot of the FROM clause of the outer
|
||||
** query. If the subquery has more than one element in its FROM clause,
|
||||
** then expand the outer query to make space for it to hold all elements
|
||||
** of the subquery.
|
||||
**
|
||||
** Example:
|
||||
**
|
||||
** SELECT * FROM tabA, (SELECT * FROM sub1, sub2), tabB;
|
||||
**
|
||||
** The outer query has 3 slots in its FROM clause. One slot of the
|
||||
** outer query (the middle slot) is used by the subquery. The next
|
||||
** block of code will expand the out query to 4 slots. The middle
|
||||
** slot is expanded to two slots in order to make space for the
|
||||
** two elements in the FROM clause of the subquery.
|
||||
*/
|
||||
if( nSubSrc>1 ){
|
||||
pParent->pSrc = pSrc = sqlite3SrcListEnlarge(db, pSrc, nSubSrc-1,iFrom+1);
|
||||
if( db->mallocFailed ){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Transfer the FROM clause terms from the subquery into the
|
||||
** outer query.
|
||||
*/
|
||||
for(i=0; i<nSubSrc; i++){
|
||||
pSrc->a[i+iFrom] = pSubSrc->a[i];
|
||||
memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
|
||||
@@ -2863,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;
|
||||
|
||||
@@ -3163,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;
|
||||
}
|
||||
|
||||
@@ -3954,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 ){
|
||||
|
||||
+10
-6
@@ -12,7 +12,7 @@
|
||||
** This file contains code to implement the "sqlite" command line
|
||||
** utility for accessing SQLite databases.
|
||||
**
|
||||
** $Id: shell.c,v 1.185 2008/08/11 19:12:35 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>
|
||||
|
||||
@@ -1699,7 +1701,7 @@ static int process_input(struct callback_data *p, FILE *in){
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if( _is_command_terminator(zLine) ){
|
||||
if( _is_command_terminator(zLine) && sqlite3_complete(zSql) ){
|
||||
memcpy(zLine,";",2);
|
||||
}
|
||||
nSqlPrior = nSql;
|
||||
@@ -1757,7 +1759,7 @@ static int process_input(struct callback_data *p, FILE *in){
|
||||
}
|
||||
}
|
||||
if( zSql ){
|
||||
if( !_all_whitespace(zSql) ) printf("Incomplete SQL: %s\n", zSql);
|
||||
if( !_all_whitespace(zSql) ) fprintf(stderr, "Incomplete SQL: %s\n", zSql);
|
||||
free(zSql);
|
||||
}
|
||||
free(zLine);
|
||||
@@ -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;
|
||||
|
||||
+213
-12
@@ -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.404 2008/10/12 00:27:54 shane Exp $
|
||||
** @(#) $Id: sqlite.h.in,v 1.415 2008/11/19 01:20:26 drh Exp $
|
||||
*/
|
||||
#ifndef _SQLITE3_H_
|
||||
#define _SQLITE3_H_
|
||||
@@ -378,12 +378,14 @@ typedef int (*sqlite3_callback)(void*,int,char**, char**);
|
||||
** *E to NULL if E is not NULL and there are no errors.
|
||||
**
|
||||
** {H12137} The [sqlite3_exec(D,S,C,A,E)] function shall set the [error code]
|
||||
** and message accessible via [sqlite3_errcode()],
|
||||
** and message accessible via [sqlite3_errcode()],
|
||||
** [sqlite3_extended_errcode()],
|
||||
** [sqlite3_errmsg()], and [sqlite3_errmsg16()].
|
||||
**
|
||||
** {H12138} If the S parameter to [sqlite3_exec(D,S,C,A,E)] is NULL or an
|
||||
** empty string or contains nothing other than whitespace, comments,
|
||||
** and/or semicolons, then results of [sqlite3_errcode()],
|
||||
** [sqlite3_extended_errcode()],
|
||||
** [sqlite3_errmsg()], and [sqlite3_errmsg16()]
|
||||
** shall reset to indicate no errors.
|
||||
**
|
||||
@@ -585,7 +587,7 @@ int sqlite3_exec(
|
||||
** sync operation only needs to flush data to mass storage. Inode
|
||||
** information need not be flushed. The SQLITE_SYNC_NORMAL flag means
|
||||
** to use normal fsync() semantics. The SQLITE_SYNC_FULL flag means
|
||||
** to use Mac OS-X style fullsync instead of fsync().
|
||||
** to use Mac OS X style fullsync instead of fsync().
|
||||
*/
|
||||
#define SQLITE_SYNC_NORMAL 0x00002
|
||||
#define SQLITE_SYNC_FULL 0x00003
|
||||
@@ -617,7 +619,7 @@ struct sqlite3_file {
|
||||
**
|
||||
** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
|
||||
** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
|
||||
** The second choice is a Mac OS-X style fullsync. The [SQLITE_SYNC_DATAONLY]
|
||||
** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]
|
||||
** flag may be ORed in to indicate that only the data of the file
|
||||
** and not its inode needs to be synced.
|
||||
**
|
||||
@@ -680,6 +682,12 @@ struct sqlite3_file {
|
||||
** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
|
||||
** information is written to disk in the same order as calls
|
||||
** to xWrite().
|
||||
**
|
||||
** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill
|
||||
** in the unread portions of the buffer with zeros. A VFS that
|
||||
** fails to zero-fill short reads might seem to work. However,
|
||||
** failure to zero-fill short reads will eventually lead to
|
||||
** database corruption.
|
||||
*/
|
||||
typedef struct sqlite3_io_methods sqlite3_io_methods;
|
||||
struct sqlite3_io_methods {
|
||||
@@ -1266,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.
|
||||
@@ -1311,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 */
|
||||
@@ -1324,8 +1346,10 @@ struct sqlite3_mem_methods {
|
||||
#define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */
|
||||
#define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */
|
||||
#define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */
|
||||
#define SQLITE_CONFIG_CHUNKALLOC 12 /* int threshold */
|
||||
/* 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>
|
||||
@@ -2004,7 +2028,7 @@ char *sqlite3_snprintf(int,char*,const char*, ...);
|
||||
** memory might result in a segmentation fault or other severe error.
|
||||
** Memory corruption, a segmentation fault, or other severe error
|
||||
** might result if sqlite3_free() is called with a non-NULL pointer that
|
||||
** was not obtained from sqlite3_malloc() or sqlite3_free().
|
||||
** was not obtained from sqlite3_malloc() or sqlite3_realloc().
|
||||
**
|
||||
** The sqlite3_realloc() interface attempts to resize a
|
||||
** prior memory allocation to be at least N bytes, where N is the
|
||||
@@ -2375,7 +2399,7 @@ int sqlite3_set_authorizer(
|
||||
#define SQLITE_ANALYZE 28 /* Table Name NULL */
|
||||
#define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
|
||||
#define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
|
||||
#define SQLITE_FUNCTION 31 /* Function Name NULL */
|
||||
#define SQLITE_FUNCTION 31 /* NULL Function Name */
|
||||
#define SQLITE_COPY 0 /* No longer used */
|
||||
|
||||
/*
|
||||
@@ -2658,7 +2682,10 @@ int sqlite3_open_v2(
|
||||
** [extended result code] for the most recent failed sqlite3_* API call
|
||||
** associated with a [database connection]. If a prior API call failed
|
||||
** but the most recent API call succeeded, the return value from
|
||||
** sqlite3_errcode() is undefined.
|
||||
** sqlite3_errcode() is undefined. The sqlite3_extended_errcode()
|
||||
** interface is the same except that it always returns the
|
||||
** [extended result code] even when extended result codes are
|
||||
** disabled.
|
||||
**
|
||||
** The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
|
||||
** text that describes the error, as either UTF-8 or UTF-16 respectively.
|
||||
@@ -2667,6 +2694,16 @@ int sqlite3_open_v2(
|
||||
** However, the error string might be overwritten or deallocated by
|
||||
** subsequent calls to other SQLite interface functions.
|
||||
**
|
||||
** When the serialized [threading mode] is in use, it might be the
|
||||
** case that a second error occurs on a separate thread in between
|
||||
** the time of the first error and the call to these interfaces.
|
||||
** When that happens, the second error will be reported since these
|
||||
** interfaces always report the most recent result. To avoid
|
||||
** this, each thread can obtain exclusive use of the [database connection] D
|
||||
** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning
|
||||
** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after
|
||||
** all calls to the interfaces listed here are completed.
|
||||
**
|
||||
** If an interface fails with SQLITE_MISUSE, that means the interface
|
||||
** was invoked incorrectly by the application. In that case, the
|
||||
** error code and message may or may not be set.
|
||||
@@ -2677,6 +2714,10 @@ int sqlite3_open_v2(
|
||||
** [result code] or [extended result code] for the most recently
|
||||
** failed interface call associated with the [database connection] D.
|
||||
**
|
||||
** {H12802} The [sqlite3_extended_errcode(D)] interface returns the numeric
|
||||
** [extended result code] for the most recently
|
||||
** failed interface call associated with the [database connection] D.
|
||||
**
|
||||
** {H12803} The [sqlite3_errmsg(D)] and [sqlite3_errmsg16(D)]
|
||||
** interfaces return English-language text that describes
|
||||
** the error in the mostly recently failed interface call,
|
||||
@@ -2688,15 +2729,18 @@ int sqlite3_open_v2(
|
||||
** {H12808} Calls to API routines that do not return an error code
|
||||
** (example: [sqlite3_data_count()]) do not
|
||||
** change the error code or message returned by
|
||||
** [sqlite3_errcode()], [sqlite3_errmsg()], or [sqlite3_errmsg16()].
|
||||
** [sqlite3_errcode()], [sqlite3_extended_errcode()],
|
||||
** [sqlite3_errmsg()], or [sqlite3_errmsg16()].
|
||||
**
|
||||
** {H12809} Interfaces that are not associated with a specific
|
||||
** [database connection] (examples:
|
||||
** [sqlite3_mprintf()] or [sqlite3_enable_shared_cache()]
|
||||
** do not change the values returned by
|
||||
** [sqlite3_errcode()], [sqlite3_errmsg()], or [sqlite3_errmsg16()].
|
||||
** [sqlite3_errcode()], [sqlite3_extended_errcode()],
|
||||
** [sqlite3_errmsg()], or [sqlite3_errmsg16()].
|
||||
*/
|
||||
int sqlite3_errcode(sqlite3 *db);
|
||||
int sqlite3_extended_errcode(sqlite3 *db);
|
||||
const char *sqlite3_errmsg(sqlite3*);
|
||||
const void *sqlite3_errmsg16(sqlite3*);
|
||||
|
||||
@@ -4123,7 +4167,7 @@ int sqlite3_create_function16(
|
||||
** backwards compatibility with older code, these functions continue
|
||||
** to be supported. However, new applications should avoid
|
||||
** the use of these functions. To help encourage people to avoid
|
||||
** using these functions, we are not going to tell you want they do.
|
||||
** using these functions, we are not going to tell you what they do.
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
|
||||
@@ -5765,6 +5809,7 @@ typedef struct sqlite3_blob sqlite3_blob;
|
||||
**
|
||||
** {H17821} If an error occurs during evaluation of [sqlite3_blob_open(D,...)]
|
||||
** then subsequent calls to [sqlite3_errcode(D)],
|
||||
** [sqlite3_extended_errcode()],
|
||||
** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] shall return
|
||||
** information appropriate for that error.
|
||||
**
|
||||
@@ -5878,6 +5923,7 @@ int sqlite3_blob_bytes(sqlite3_blob *);
|
||||
**
|
||||
** {H17868} If an error occurs during evaluation of [sqlite3_blob_read(P,...)]
|
||||
** then subsequent calls to [sqlite3_errcode(D)],
|
||||
** [sqlite3_extended_errcode()],
|
||||
** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] shall return
|
||||
** information appropriate for that error, where D is the
|
||||
** [database connection] that was used to open the [BLOB handle] P.
|
||||
@@ -5947,6 +5993,7 @@ int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
|
||||
**
|
||||
** {H17888} If an error occurs during evaluation of [sqlite3_blob_write(D,...)]
|
||||
** then subsequent calls to [sqlite3_errcode(D)],
|
||||
** [sqlite3_extended_errcode()],
|
||||
** [sqlite3_errmsg(D)], and [sqlite3_errmsg16(D)] shall return
|
||||
** information appropriate for that error.
|
||||
*/
|
||||
@@ -6244,6 +6291,17 @@ int sqlite3_mutex_notheld(sqlite3_mutex*);
|
||||
#define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
|
||||
#define SQLITE_MUTEX_STATIC_LRU2 7 /* lru page list */
|
||||
|
||||
/*
|
||||
** CAPI3REF: Retrieve the mutex for a database connection {H17002} <H17000>
|
||||
**
|
||||
** This interface returns a pointer the [sqlite3_mutex] object that
|
||||
** serializes access to the [database connection] given in the argument
|
||||
** when the [threading mode] is Serialized.
|
||||
** If the [threading mode] is Single-thread or Multi-thread then this
|
||||
** routine returns a NULL pointer.
|
||||
*/
|
||||
sqlite3_mutex *sqlite3_db_mutex(sqlite3*);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Low-Level Control Of Database Files {H11300} <S30800>
|
||||
**
|
||||
@@ -6513,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.
|
||||
|
||||
+54
-20
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** Internal interface definitions for SQLite.
|
||||
**
|
||||
** @(#) $Id: sqliteInt.h,v 1.784 2008/10/13 15:35:09 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().
|
||||
@@ -463,7 +463,7 @@ struct BusyHandler {
|
||||
** buffer that holds real variable. The constant is also the initializer
|
||||
** for the run-time allocated buffer.
|
||||
**
|
||||
** In the usually case where WSD is supported, the SQLITE_WSD and GLOBAL
|
||||
** In the usual case where WSD is supported, the SQLITE_WSD and GLOBAL
|
||||
** macros become no-ops and have zero performance impact.
|
||||
*/
|
||||
#ifdef SQLITE_OMIT_WSD
|
||||
@@ -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 */
|
||||
@@ -699,6 +718,7 @@ struct sqlite3 {
|
||||
void **aExtension; /* Array of shared libraray handles */
|
||||
struct Vdbe *pVdbe; /* List of active virtual machines */
|
||||
int activeVdbeCnt; /* Number of vdbes currently executing */
|
||||
int writeVdbeCnt; /* Number of active VDBEs that are writing */
|
||||
void (*xTrace)(void*,const char*); /* Trace function */
|
||||
void *pTraceArg; /* Argument to the trace function */
|
||||
void (*xProfile)(void*,const char*,u64); /* Profiling function */
|
||||
@@ -847,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}
|
||||
|
||||
|
||||
/*
|
||||
@@ -1422,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
|
||||
@@ -1957,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 */
|
||||
@@ -1971,7 +1997,6 @@ struct Sqlite3Config {
|
||||
int isMallocInit; /* True after malloc is initialized */
|
||||
sqlite3_mutex *pInitMutex; /* Mutex used by sqlite3_initialize() */
|
||||
int nRefInitMutex; /* Number of users of pInitMutex */
|
||||
int nSmall; /* alloc size threshold used by mem6.c */
|
||||
int mxParserStack; /* maximum depth of the parser stack */
|
||||
int sharedCacheEnabled; /* true if shared-cache mode enabled */
|
||||
};
|
||||
@@ -2054,13 +2079,17 @@ void sqlite3ScratchFree(void*);
|
||||
void *sqlite3PageMalloc(int);
|
||||
void sqlite3PageFree(void*);
|
||||
void sqlite3MemSetDefault(void);
|
||||
const sqlite3_mem_methods *sqlite3MemGetDefault(void);
|
||||
const sqlite3_mem_methods *sqlite3MemGetMemsys5(void);
|
||||
const sqlite3_mem_methods *sqlite3MemGetMemsys3(void);
|
||||
const sqlite3_mem_methods *sqlite3MemGetMemsys6(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);
|
||||
@@ -2146,6 +2175,7 @@ void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
|
||||
void *sqlite3ArrayAllocate(sqlite3*,void*,int,int,int*,int*,int*);
|
||||
IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*);
|
||||
int sqlite3IdListIndex(IdList*,const char*);
|
||||
SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);
|
||||
SrcList *sqlite3SrcListAppend(sqlite3*, SrcList*, Token*, Token*);
|
||||
SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*,
|
||||
Token*, Select*, Expr*, IdList*);
|
||||
@@ -2218,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*);
|
||||
@@ -2232,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*);
|
||||
@@ -2254,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*);
|
||||
@@ -2267,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)
|
||||
@@ -2335,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
|
||||
|
||||
@@ -2398,7 +2427,6 @@ int sqlite3AnalysisLoad(sqlite3*,int iDB);
|
||||
void sqlite3DefaultRowEst(Index*);
|
||||
void sqlite3RegisterLikeFunctions(sqlite3*, int);
|
||||
int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
|
||||
void sqlite3AttachFunctions(sqlite3 *);
|
||||
void sqlite3MinimumFileFormat(Parse*, int, int);
|
||||
void sqlite3SchemaFree(void *);
|
||||
Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
|
||||
@@ -2448,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*);
|
||||
@@ -2505,6 +2535,10 @@ int sqlite3FindInIndex(Parse *, Expr *, int*);
|
||||
#define sqlite3JournalSize(pVfs) ((pVfs)->szOsFile)
|
||||
#endif
|
||||
|
||||
void sqlite3MemJournalOpen(sqlite3_file *);
|
||||
int sqlite3MemJournalSize();
|
||||
int sqlite3IsMemJournal(sqlite3_file *);
|
||||
|
||||
#if SQLITE_MAX_EXPR_DEPTH>0
|
||||
void sqlite3ExprSetHeight(Parse *pParse, Expr *p);
|
||||
int sqlite3SelectExprHeight(Select *);
|
||||
|
||||
+77
-37
@@ -13,7 +13,7 @@
|
||||
** is not included in the SQLite library. It is used for automated
|
||||
** testing of the SQLite library.
|
||||
**
|
||||
** $Id: test1.c,v 1.328 2008/10/12 00:27:54 shane Exp $
|
||||
** $Id: test1.c,v 1.329 2008/10/30 15:03:16 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "tcl.h"
|
||||
@@ -117,35 +117,53 @@ int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb){
|
||||
|
||||
const char *sqlite3TestErrorName(int rc){
|
||||
const char *zName = 0;
|
||||
switch( rc & 0xff ){
|
||||
case SQLITE_OK: zName = "SQLITE_OK"; break;
|
||||
case SQLITE_ERROR: zName = "SQLITE_ERROR"; break;
|
||||
case SQLITE_PERM: zName = "SQLITE_PERM"; break;
|
||||
case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
|
||||
case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
|
||||
case SQLITE_LOCKED: zName = "SQLITE_LOCKED"; break;
|
||||
case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
|
||||
case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
|
||||
case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
|
||||
case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
|
||||
case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; break;
|
||||
case SQLITE_FULL: zName = "SQLITE_FULL"; break;
|
||||
case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break;
|
||||
case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break;
|
||||
case SQLITE_EMPTY: zName = "SQLITE_EMPTY"; break;
|
||||
case SQLITE_SCHEMA: zName = "SQLITE_SCHEMA"; break;
|
||||
case SQLITE_CONSTRAINT: zName = "SQLITE_CONSTRAINT"; break;
|
||||
case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break;
|
||||
case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break;
|
||||
case SQLITE_NOLFS: zName = "SQLITE_NOLFS"; break;
|
||||
case SQLITE_AUTH: zName = "SQLITE_AUTH"; break;
|
||||
case SQLITE_FORMAT: zName = "SQLITE_FORMAT"; break;
|
||||
case SQLITE_RANGE: zName = "SQLITE_RANGE"; break;
|
||||
case SQLITE_ROW: zName = "SQLITE_ROW"; break;
|
||||
case SQLITE_DONE: zName = "SQLITE_DONE"; break;
|
||||
case SQLITE_NOTADB: zName = "SQLITE_NOTADB"; break;
|
||||
case SQLITE_TOOBIG: zName = "SQLITE_TOOBIG"; break;
|
||||
default: zName = "SQLITE_Unknown"; break;
|
||||
switch( rc ){
|
||||
case SQLITE_OK: zName = "SQLITE_OK"; break;
|
||||
case SQLITE_ERROR: zName = "SQLITE_ERROR"; break;
|
||||
case SQLITE_INTERNAL: zName = "SQLITE_INTERNAL"; break;
|
||||
case SQLITE_PERM: zName = "SQLITE_PERM"; break;
|
||||
case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
|
||||
case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
|
||||
case SQLITE_LOCKED: zName = "SQLITE_LOCKED"; break;
|
||||
case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
|
||||
case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
|
||||
case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
|
||||
case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
|
||||
case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; break;
|
||||
case SQLITE_NOTFOUND: zName = "SQLITE_NOTFOUND"; break;
|
||||
case SQLITE_FULL: zName = "SQLITE_FULL"; break;
|
||||
case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break;
|
||||
case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break;
|
||||
case SQLITE_EMPTY: zName = "SQLITE_EMPTY"; break;
|
||||
case SQLITE_SCHEMA: zName = "SQLITE_SCHEMA"; break;
|
||||
case SQLITE_TOOBIG: zName = "SQLITE_TOOBIG"; break;
|
||||
case SQLITE_CONSTRAINT: zName = "SQLITE_CONSTRAINT"; break;
|
||||
case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break;
|
||||
case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break;
|
||||
case SQLITE_NOLFS: zName = "SQLITE_NOLFS"; break;
|
||||
case SQLITE_AUTH: zName = "SQLITE_AUTH"; break;
|
||||
case SQLITE_FORMAT: zName = "SQLITE_FORMAT"; break;
|
||||
case SQLITE_RANGE: zName = "SQLITE_RANGE"; break;
|
||||
case SQLITE_NOTADB: zName = "SQLITE_NOTADB"; break;
|
||||
case SQLITE_ROW: zName = "SQLITE_ROW"; break;
|
||||
case SQLITE_DONE: zName = "SQLITE_DONE"; break;
|
||||
case SQLITE_IOERR_READ: zName = "SQLITE_IOERR_READ"; break;
|
||||
case SQLITE_IOERR_SHORT_READ: zName = "SQLITE_IOERR_SHORT_READ"; break;
|
||||
case SQLITE_IOERR_WRITE: zName = "SQLITE_IOERR_WRITE"; break;
|
||||
case SQLITE_IOERR_FSYNC: zName = "SQLITE_IOERR_FSYNC"; break;
|
||||
case SQLITE_IOERR_DIR_FSYNC: zName = "SQLITE_IOERR_DIR_FSYNC"; break;
|
||||
case SQLITE_IOERR_TRUNCATE: zName = "SQLITE_IOERR_TRUNCATE"; break;
|
||||
case SQLITE_IOERR_FSTAT: zName = "SQLITE_IOERR_FSTAT"; break;
|
||||
case SQLITE_IOERR_UNLOCK: zName = "SQLITE_IOERR_UNLOCK"; break;
|
||||
case SQLITE_IOERR_RDLOCK: zName = "SQLITE_IOERR_RDLOCK"; break;
|
||||
case SQLITE_IOERR_DELETE: zName = "SQLITE_IOERR_DELETE"; break;
|
||||
case SQLITE_IOERR_BLOCKED: zName = "SQLITE_IOERR_BLOCKED"; break;
|
||||
case SQLITE_IOERR_NOMEM: zName = "SQLITE_IOERR_NOMEM"; break;
|
||||
case SQLITE_IOERR_ACCESS: zName = "SQLITE_IOERR_ACCESS"; break;
|
||||
case SQLITE_IOERR_CHECKRESERVEDLOCK:
|
||||
zName = "SQLITE_IOERR_CHECKRESERVEDLOCK"; break;
|
||||
case SQLITE_IOERR_LOCK: zName = "SQLITE_IOERR_LOCK"; break;
|
||||
default: zName = "SQLITE_Unknown"; break;
|
||||
}
|
||||
return zName;
|
||||
}
|
||||
@@ -3064,6 +3082,33 @@ static int test_sleep(
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite3_extended_errcode DB
|
||||
**
|
||||
** Return the string representation of the most recent sqlite3_* API
|
||||
** error code. e.g. "SQLITE_ERROR".
|
||||
*/
|
||||
static int test_ex_errcode(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
sqlite3 *db;
|
||||
int rc;
|
||||
|
||||
if( objc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
||||
Tcl_GetString(objv[0]), " DB", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
||||
rc = sqlite3_extended_errcode(db);
|
||||
Tcl_AppendResult(interp, (char *)t1ErrorName(rc), 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Usage: sqlite3_errcode DB
|
||||
**
|
||||
@@ -3078,7 +3123,6 @@ static int test_errcode(
|
||||
){
|
||||
sqlite3 *db;
|
||||
int rc;
|
||||
char zBuf[30];
|
||||
|
||||
if( objc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
||||
@@ -3087,12 +3131,7 @@ static int test_errcode(
|
||||
}
|
||||
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
||||
rc = sqlite3_errcode(db);
|
||||
if( (rc&0xff)==rc ){
|
||||
zBuf[0] = 0;
|
||||
}else{
|
||||
sprintf(zBuf,"+%d", rc>>8);
|
||||
}
|
||||
Tcl_AppendResult(interp, (char *)t1ErrorName(rc), zBuf, 0);
|
||||
Tcl_AppendResult(interp, (char *)t1ErrorName(rc), 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
@@ -4667,6 +4706,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
|
||||
{ "sqlite3_clear_bindings", test_clear_bindings, 0},
|
||||
{ "sqlite3_sleep", test_sleep, 0},
|
||||
{ "sqlite3_errcode", test_errcode ,0 },
|
||||
{ "sqlite3_extended_errcode", test_ex_errcode ,0 },
|
||||
{ "sqlite3_errmsg", test_errmsg ,0 },
|
||||
{ "sqlite3_errmsg16", test_errmsg16 ,0 },
|
||||
{ "sqlite3_open", test_open ,0 },
|
||||
|
||||
+2
-2
@@ -13,7 +13,7 @@
|
||||
** is not included in the SQLite library. It is used for automated
|
||||
** testing of the SQLite library.
|
||||
**
|
||||
** $Id: test3.c,v 1.101 2008/08/13 19:11:48 drh Exp $
|
||||
** $Id: test3.c,v 1.102 2008/10/27 13:59:34 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "btreeInt.h"
|
||||
@@ -389,7 +389,7 @@ static int btree_clear_table(
|
||||
pBt = sqlite3TestTextToPtr(argv[1]);
|
||||
if( Tcl_GetInt(interp, argv[2], &iTable) ) return TCL_ERROR;
|
||||
sqlite3BtreeEnter(pBt);
|
||||
rc = sqlite3BtreeClearTable(pBt, iTable);
|
||||
rc = sqlite3BtreeClearTable(pBt, iTable, 0);
|
||||
sqlite3BtreeLeave(pBt);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
|
||||
+39
-25
@@ -13,7 +13,7 @@
|
||||
** This file contains code used to implement test interfaces to the
|
||||
** memory allocation subsystem.
|
||||
**
|
||||
** $Id: test_malloc.c,v 1.49 2008/10/15 11:43:55 danielk1977 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
|
||||
**
|
||||
@@ -967,28 +1003,6 @@ static int test_config_memstatus(
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite3_config_chunkalloc
|
||||
**
|
||||
*/
|
||||
static int test_config_chunkalloc(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
int rc;
|
||||
int nThreshold;
|
||||
if( objc!=2 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "THRESHOLD");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetIntFromObj(interp, objv[1], &nThreshold) ) return TCL_ERROR;
|
||||
rc = sqlite3_config(SQLITE_CONFIG_CHUNKALLOC, nThreshold);
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: sqlite3_config_lookaside SIZE COUNT
|
||||
**
|
||||
@@ -1334,17 +1348,17 @@ 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 },
|
||||
{ "sqlite3_config_heap", test_config_heap ,0 },
|
||||
{ "sqlite3_config_memstatus", test_config_memstatus ,0 },
|
||||
{ "sqlite3_config_chunkalloc", test_config_chunkalloc ,0 },
|
||||
{ "sqlite3_config_lookaside", test_config_lookaside ,0 },
|
||||
{ "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++){
|
||||
|
||||
+55
-1
@@ -10,7 +10,7 @@
|
||||
**
|
||||
*************************************************************************
|
||||
**
|
||||
** $Id: test_mutex.c,v 1.11 2008/07/19 13:43:24 danielk1977 Exp $
|
||||
** $Id: test_mutex.c,v 1.12 2008/11/04 14:55:47 danielk1977 Exp $
|
||||
*/
|
||||
|
||||
#include "tcl.h"
|
||||
@@ -359,6 +359,57 @@ static int test_config(
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
static sqlite3 *getDbPointer(Tcl_Interp *pInterp, Tcl_Obj *pObj){
|
||||
sqlite3 *db;
|
||||
Tcl_CmdInfo info;
|
||||
char *zCmd = Tcl_GetString(pObj);
|
||||
if( 1!=Tcl_GetCommandInfo(pInterp, zCmd, &info) ){
|
||||
Tcl_AppendResult(pInterp, "No such db-handle: \"", zCmd, "\"", 0);
|
||||
return 0;
|
||||
}
|
||||
db = *((sqlite3 **)info.objClientData);
|
||||
assert( db );
|
||||
return db;
|
||||
}
|
||||
|
||||
static int test_enter_db_mutex(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
sqlite3 *db;
|
||||
if( objc!=2 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "DB");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
db = getDbPointer(interp, objv[1]);
|
||||
if( !db ){
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sqlite3_mutex_enter(sqlite3_db_mutex(db));
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
static int test_leave_db_mutex(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
sqlite3 *db;
|
||||
if( objc!=2 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "DB");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
db = getDbPointer(interp, objv[1]);
|
||||
if( !db ){
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sqlite3_mutex_leave(sqlite3_db_mutex(db));
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
int Sqlitetest_mutex_Init(Tcl_Interp *interp){
|
||||
static struct {
|
||||
char *zName;
|
||||
@@ -368,6 +419,9 @@ int Sqlitetest_mutex_Init(Tcl_Interp *interp){
|
||||
{ "sqlite3_initialize", (Tcl_ObjCmdProc*)test_initialize },
|
||||
{ "sqlite3_config", (Tcl_ObjCmdProc*)test_config },
|
||||
|
||||
{ "enter_db_mutex", (Tcl_ObjCmdProc*)test_enter_db_mutex },
|
||||
{ "leave_db_mutex", (Tcl_ObjCmdProc*)test_leave_db_mutex },
|
||||
|
||||
{ "alloc_dealloc_mutex", (Tcl_ObjCmdProc*)test_alloc_mutex },
|
||||
{ "install_mutex_counters", (Tcl_ObjCmdProc*)test_install_mutex_counters },
|
||||
{ "read_mutex_counters", (Tcl_ObjCmdProc*)test_read_mutex_counters },
|
||||
|
||||
@@ -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 */
|
||||
|
||||
+4
-4
@@ -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.185 2008/10/09 18:48:31 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
|
||||
@@ -568,7 +568,7 @@ void sqlite3Update(
|
||||
if( db->flags & SQLITE_CountRows && !pParse->trigStack && pParse->nested==0 ){
|
||||
sqlite3VdbeAddOp2(v, OP_ResultRow, regRowCount, 1);
|
||||
sqlite3VdbeSetNumCols(v, 1);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows updated", P4_STATIC);
|
||||
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows updated", SQLITE_STATIC);
|
||||
}
|
||||
|
||||
update_cleanup:
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
** This file contains routines used to translate between UTF-8,
|
||||
** UTF-16, UTF-16BE, and UTF-16LE.
|
||||
**
|
||||
** $Id: utf.c,v 1.65 2008/08/12 15:04:59 danielk1977 Exp $
|
||||
** $Id: utf.c,v 1.66 2008/11/07 03:29:34 drh Exp $
|
||||
**
|
||||
** Notes on UTF-8:
|
||||
**
|
||||
@@ -226,7 +226,7 @@ int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
zIn = (u8*)pMem->z;
|
||||
zTerm = &zIn[pMem->n];
|
||||
zTerm = &zIn[pMem->n&~1];
|
||||
while( zIn<zTerm ){
|
||||
temp = *zIn;
|
||||
*zIn = *(zIn+1);
|
||||
@@ -244,6 +244,7 @@ int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
|
||||
** A single byte is required for the output string
|
||||
** nul-terminator.
|
||||
*/
|
||||
pMem->n &= ~1;
|
||||
len = pMem->n * 2 + 1;
|
||||
}else{
|
||||
/* When converting from UTF-8 to UTF-16 the maximum growth is caused
|
||||
|
||||
+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]);
|
||||
|
||||
+95
-73
@@ -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.782 2008/10/08 17:58:49 danielk1977 Exp $
|
||||
** $Id: vdbe.c,v 1.788 2008/11/17 15:31:48 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@@ -177,25 +177,25 @@ 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;
|
||||
}
|
||||
|
||||
/*
|
||||
** Allocate cursor number iCur. Return a pointer to it. Return NULL
|
||||
** Allocate VdbeCursor number iCur. Return a pointer to it. Return NULL
|
||||
** if we run out of memory.
|
||||
*/
|
||||
static Cursor *allocateCursor(
|
||||
Vdbe *p,
|
||||
int iCur,
|
||||
Op *pOp,
|
||||
int iDb,
|
||||
int isBtreeCursor
|
||||
static VdbeCursor *allocateCursor(
|
||||
Vdbe *p, /* The virtual machine */
|
||||
int iCur, /* Index of the new VdbeCursor */
|
||||
Op *pOp, /* */
|
||||
int iDb, /* */
|
||||
int isBtreeCursor /* */
|
||||
){
|
||||
/* Find the memory cell that will be used to store the blob of memory
|
||||
** required for this Cursor structure. It is convenient to use a
|
||||
** required for this VdbeCursor structure. It is convenient to use a
|
||||
** vdbe memory cell to manage the memory allocation required for a
|
||||
** Cursor structure for the following reasons:
|
||||
** VdbeCursor structure for the following reasons:
|
||||
**
|
||||
** * Sometimes cursor numbers are used for a couple of different
|
||||
** purposes in a vdbe program. The different uses might require
|
||||
@@ -213,18 +213,18 @@ static Cursor *allocateCursor(
|
||||
Mem *pMem = &p->aMem[p->nMem-iCur];
|
||||
|
||||
int nByte;
|
||||
Cursor *pCx = 0;
|
||||
VdbeCursor *pCx = 0;
|
||||
/* If the opcode of pOp is OP_SetNumColumns, then pOp->p2 contains
|
||||
** the number of fields in the records contained in the table or
|
||||
** index being opened. Use this to reserve space for the
|
||||
** Cursor.aType[] array.
|
||||
** VdbeCursor.aType[] array.
|
||||
*/
|
||||
int nField = 0;
|
||||
if( pOp->opcode==OP_SetNumColumns || pOp->opcode==OP_OpenEphemeral ){
|
||||
nField = pOp->p2;
|
||||
}
|
||||
nByte =
|
||||
sizeof(Cursor) +
|
||||
sizeof(VdbeCursor) +
|
||||
(isBtreeCursor?sqlite3BtreeCursorSize():0) +
|
||||
2*nField*sizeof(u32);
|
||||
|
||||
@@ -234,15 +234,16 @@ static Cursor *allocateCursor(
|
||||
p->apCsr[iCur] = 0;
|
||||
}
|
||||
if( SQLITE_OK==sqlite3VdbeMemGrow(pMem, nByte, 0) ){
|
||||
p->apCsr[iCur] = pCx = (Cursor *)pMem->z;
|
||||
p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
|
||||
memset(pMem->z, 0, nByte);
|
||||
pCx->iDb = iDb;
|
||||
pCx->nField = nField;
|
||||
if( nField ){
|
||||
pCx->aType = (u32 *)&pMem->z[sizeof(Cursor)];
|
||||
pCx->aType = (u32 *)&pMem->z[sizeof(VdbeCursor)];
|
||||
}
|
||||
if( isBtreeCursor ){
|
||||
pCx->pCursor = (BtCursor *)&pMem->z[sizeof(Cursor)+2*nField*sizeof(u32)];
|
||||
pCx->pCursor = (BtCursor*)
|
||||
&pMem->z[sizeof(VdbeCursor)+2*nField*sizeof(u32)];
|
||||
}
|
||||
}
|
||||
return pCx;
|
||||
@@ -551,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);
|
||||
@@ -1958,23 +1958,20 @@ case OP_SetNumColumns: {
|
||||
**
|
||||
** The value extracted is stored in register P3.
|
||||
**
|
||||
** If the KeyAsData opcode has previously executed on this cursor, then the
|
||||
** field might be extracted from the key rather than the data.
|
||||
**
|
||||
** If the column contains fewer than P2 fields, then extract a NULL. Or,
|
||||
** if the P4 argument is a P4_MEM use the value of the P4 argument as
|
||||
** 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 */
|
||||
Cursor *pC = 0; /* The VDBE cursor */
|
||||
VdbeCursor *pC = 0;/* The VDBE cursor */
|
||||
char *zRec; /* Pointer to complete record-data */
|
||||
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 */
|
||||
@@ -1999,7 +1996,7 @@ case OP_Column: {
|
||||
** If the data is unavailable, zRec is set to NULL.
|
||||
**
|
||||
** We also compute the number of columns in the record. For cursors,
|
||||
** the number of columns is stored in the Cursor.nField element.
|
||||
** the number of columns is stored in the VdbeCursor.nField element.
|
||||
*/
|
||||
pC = p->apCsr[p1];
|
||||
assert( pC!=0 );
|
||||
@@ -2022,7 +2019,7 @@ case OP_Column: {
|
||||
sqlite3BtreeKeySize(pCrsr, &payloadSize64);
|
||||
payloadSize = payloadSize64;
|
||||
}else{
|
||||
sqlite3BtreeDataSize(pCrsr, &payloadSize);
|
||||
sqlite3BtreeDataSize(pCrsr, (u32 *)&payloadSize);
|
||||
}
|
||||
nField = pC->nField;
|
||||
}else{
|
||||
@@ -2056,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 */
|
||||
|
||||
@@ -2257,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 */
|
||||
@@ -2395,33 +2392,40 @@ case OP_Statement: {
|
||||
** This instruction causes the VM to halt.
|
||||
*/
|
||||
case OP_AutoCommit: {
|
||||
u8 i = pOp->p1;
|
||||
u8 rollback = pOp->p2;
|
||||
int desiredAutoCommit = pOp->p1;
|
||||
int rollback = pOp->p2;
|
||||
int turnOnAC = desiredAutoCommit && !db->autoCommit;
|
||||
|
||||
assert( i==1 || i==0 );
|
||||
assert( i==1 || rollback==0 );
|
||||
assert( desiredAutoCommit==1 || desiredAutoCommit==0 );
|
||||
assert( desiredAutoCommit==1 || rollback==0 );
|
||||
|
||||
assert( db->activeVdbeCnt>0 ); /* At least this one VM is active */
|
||||
|
||||
if( db->activeVdbeCnt>1 && i && !db->autoCommit ){
|
||||
/* If this instruction implements a COMMIT or ROLLBACK, other VMs are
|
||||
if( turnOnAC && rollback && db->activeVdbeCnt>1 ){
|
||||
/* If this instruction implements a ROLLBACK and other VMs are
|
||||
** still running, and a transaction is active, return an error indicating
|
||||
** that the other VMs must complete first.
|
||||
*/
|
||||
sqlite3SetString(&p->zErrMsg, db, "cannot %s transaction - "
|
||||
"SQL statements in progress",
|
||||
rollback ? "rollback" : "commit");
|
||||
rc = SQLITE_ERROR;
|
||||
}else if( i!=db->autoCommit ){
|
||||
sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
|
||||
"SQL statements in progress");
|
||||
rc = SQLITE_BUSY;
|
||||
}else if( turnOnAC && !rollback && db->writeVdbeCnt>1 ){
|
||||
/* If this instruction implements a COMMIT and other VMs are writing
|
||||
** return an error indicating that the other VMs must complete first.
|
||||
*/
|
||||
sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
|
||||
"SQL statements in progress");
|
||||
rc = SQLITE_BUSY;
|
||||
}else if( desiredAutoCommit!=db->autoCommit ){
|
||||
if( pOp->p2 ){
|
||||
assert( i==1 );
|
||||
assert( desiredAutoCommit==1 );
|
||||
sqlite3RollbackAll(db);
|
||||
db->autoCommit = 1;
|
||||
}else{
|
||||
db->autoCommit = i;
|
||||
db->autoCommit = desiredAutoCommit;
|
||||
if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
|
||||
p->pc = pc;
|
||||
db->autoCommit = 1-i;
|
||||
db->autoCommit = 1-desiredAutoCommit;
|
||||
p->rc = rc = SQLITE_BUSY;
|
||||
goto vdbe_return;
|
||||
}
|
||||
@@ -2434,7 +2438,7 @@ case OP_AutoCommit: {
|
||||
goto vdbe_return;
|
||||
}else{
|
||||
sqlite3SetString(&p->zErrMsg, db,
|
||||
(!i)?"cannot start a transaction within a transaction":(
|
||||
(!desiredAutoCommit)?"cannot start a transaction within a transaction":(
|
||||
(rollback)?"cannot rollback - no transaction is active":
|
||||
"cannot commit - no transaction is active"));
|
||||
|
||||
@@ -2671,7 +2675,7 @@ case OP_OpenWrite: {
|
||||
int iDb = pOp->p3;
|
||||
int wrFlag;
|
||||
Btree *pX;
|
||||
Cursor *pCur;
|
||||
VdbeCursor *pCur;
|
||||
Db *pDb;
|
||||
|
||||
assert( iDb>=0 && iDb<db->nDb );
|
||||
@@ -2693,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);
|
||||
@@ -2771,7 +2778,7 @@ case OP_OpenWrite: {
|
||||
*/
|
||||
case OP_OpenEphemeral: {
|
||||
int i = pOp->p1;
|
||||
Cursor *pCx;
|
||||
VdbeCursor *pCx;
|
||||
static const int openFlags =
|
||||
SQLITE_OPEN_READWRITE |
|
||||
SQLITE_OPEN_CREATE |
|
||||
@@ -2837,7 +2844,7 @@ case OP_OpenEphemeral: {
|
||||
*/
|
||||
case OP_OpenPseudo: {
|
||||
int i = pOp->p1;
|
||||
Cursor *pCx;
|
||||
VdbeCursor *pCx;
|
||||
assert( i>=0 );
|
||||
pCx = allocateCursor(p, i, &pOp[-1], -1, 0);
|
||||
if( pCx==0 ) goto no_mem;
|
||||
@@ -2926,7 +2933,7 @@ case OP_MoveLe: /* jump, in3 */
|
||||
case OP_MoveGe: /* jump, in3 */
|
||||
case OP_MoveGt: { /* jump, in3 */
|
||||
int i = pOp->p1;
|
||||
Cursor *pC;
|
||||
VdbeCursor *pC;
|
||||
|
||||
assert( i>=0 && i<p->nCursor );
|
||||
pC = p->apCsr[i];
|
||||
@@ -3043,7 +3050,7 @@ case OP_NotFound: /* jump, in3 */
|
||||
case OP_Found: { /* jump, in3 */
|
||||
int i = pOp->p1;
|
||||
int alreadyExists = 0;
|
||||
Cursor *pC;
|
||||
VdbeCursor *pC;
|
||||
assert( i>=0 && i<p->nCursor );
|
||||
assert( p->apCsr[i]!=0 );
|
||||
if( (pC = p->apCsr[i])->pCursor!=0 ){
|
||||
@@ -3099,7 +3106,7 @@ case OP_Found: { /* jump, in3 */
|
||||
*/
|
||||
case OP_IsUnique: { /* jump, in3 */
|
||||
int i = pOp->p1;
|
||||
Cursor *pCx;
|
||||
VdbeCursor *pCx;
|
||||
BtCursor *pCrsr;
|
||||
Mem *pK;
|
||||
i64 R;
|
||||
@@ -3196,7 +3203,7 @@ case OP_IsUnique: { /* jump, in3 */
|
||||
*/
|
||||
case OP_NotExists: { /* jump, in3 */
|
||||
int i = pOp->p1;
|
||||
Cursor *pC;
|
||||
VdbeCursor *pC;
|
||||
BtCursor *pCrsr;
|
||||
assert( i>=0 && i<p->nCursor );
|
||||
assert( p->apCsr[i]!=0 );
|
||||
@@ -3265,7 +3272,7 @@ case OP_Sequence: { /* out2-prerelease */
|
||||
case OP_NewRowid: { /* out2-prerelease */
|
||||
int i = pOp->p1;
|
||||
i64 v = 0;
|
||||
Cursor *pC;
|
||||
VdbeCursor *pC;
|
||||
assert( i>=0 && i<p->nCursor );
|
||||
assert( p->apCsr[i]!=0 );
|
||||
if( (pC = p->apCsr[i])->pCursor==0 ){
|
||||
@@ -3320,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 ){
|
||||
@@ -3433,7 +3440,7 @@ case OP_Insert: {
|
||||
|
||||
i64 iKey; /* The integer ROWID or key for the record to be inserted */
|
||||
int i = pOp->p1;
|
||||
Cursor *pC;
|
||||
VdbeCursor *pC;
|
||||
assert( i>=0 && i<p->nCursor );
|
||||
pC = p->apCsr[i];
|
||||
assert( pC!=0 );
|
||||
@@ -3527,7 +3534,7 @@ case OP_Insert: {
|
||||
case OP_Delete: {
|
||||
int i = pOp->p1;
|
||||
i64 iKey;
|
||||
Cursor *pC;
|
||||
VdbeCursor *pC;
|
||||
|
||||
assert( i>=0 && i<p->nCursor );
|
||||
pC = p->apCsr[i];
|
||||
@@ -3598,7 +3605,7 @@ case OP_ResetCount: {
|
||||
case OP_RowKey:
|
||||
case OP_RowData: {
|
||||
int i = pOp->p1;
|
||||
Cursor *pC;
|
||||
VdbeCursor *pC;
|
||||
BtCursor *pCrsr;
|
||||
u32 n;
|
||||
|
||||
@@ -3626,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;
|
||||
}
|
||||
}
|
||||
@@ -3652,7 +3659,7 @@ case OP_RowData: {
|
||||
*/
|
||||
case OP_Rowid: { /* out2-prerelease */
|
||||
int i = pOp->p1;
|
||||
Cursor *pC;
|
||||
VdbeCursor *pC;
|
||||
i64 v;
|
||||
|
||||
assert( i>=0 && i<p->nCursor );
|
||||
@@ -3685,7 +3692,7 @@ case OP_Rowid: { /* out2-prerelease */
|
||||
*/
|
||||
case OP_NullRow: {
|
||||
int i = pOp->p1;
|
||||
Cursor *pC;
|
||||
VdbeCursor *pC;
|
||||
|
||||
assert( i>=0 && i<p->nCursor );
|
||||
pC = p->apCsr[i];
|
||||
@@ -3708,7 +3715,7 @@ case OP_NullRow: {
|
||||
*/
|
||||
case OP_Last: { /* jump */
|
||||
int i = pOp->p1;
|
||||
Cursor *pC;
|
||||
VdbeCursor *pC;
|
||||
BtCursor *pCrsr;
|
||||
int res;
|
||||
|
||||
@@ -3758,7 +3765,7 @@ case OP_Sort: { /* jump */
|
||||
*/
|
||||
case OP_Rewind: { /* jump */
|
||||
int i = pOp->p1;
|
||||
Cursor *pC;
|
||||
VdbeCursor *pC;
|
||||
BtCursor *pCrsr;
|
||||
int res;
|
||||
|
||||
@@ -3803,7 +3810,7 @@ case OP_Rewind: { /* jump */
|
||||
*/
|
||||
case OP_Prev: /* jump */
|
||||
case OP_Next: { /* jump */
|
||||
Cursor *pC;
|
||||
VdbeCursor *pC;
|
||||
BtCursor *pCrsr;
|
||||
int res;
|
||||
|
||||
@@ -3846,7 +3853,7 @@ case OP_Next: { /* jump */
|
||||
*/
|
||||
case OP_IdxInsert: { /* in2 */
|
||||
int i = pOp->p1;
|
||||
Cursor *pC;
|
||||
VdbeCursor *pC;
|
||||
BtCursor *pCrsr;
|
||||
assert( i>=0 && i<p->nCursor );
|
||||
assert( p->apCsr[i]!=0 );
|
||||
@@ -3873,7 +3880,7 @@ case OP_IdxInsert: { /* in2 */
|
||||
*/
|
||||
case OP_IdxDelete: {
|
||||
int i = pOp->p1;
|
||||
Cursor *pC;
|
||||
VdbeCursor *pC;
|
||||
BtCursor *pCrsr;
|
||||
assert( pOp->p3>0 );
|
||||
assert( pOp->p2>0 && pOp->p2+pOp->p3<=p->nMem );
|
||||
@@ -3907,7 +3914,7 @@ case OP_IdxDelete: {
|
||||
case OP_IdxRowid: { /* out2-prerelease */
|
||||
int i = pOp->p1;
|
||||
BtCursor *pCrsr;
|
||||
Cursor *pC;
|
||||
VdbeCursor *pC;
|
||||
|
||||
assert( i>=0 && i<p->nCursor );
|
||||
assert( p->apCsr[i]!=0 );
|
||||
@@ -3957,7 +3964,7 @@ case OP_IdxRowid: { /* out2-prerelease */
|
||||
case OP_IdxLT: /* jump, in3 */
|
||||
case OP_IdxGE: { /* jump, in3 */
|
||||
int i= pOp->p1;
|
||||
Cursor *pC;
|
||||
VdbeCursor *pC;
|
||||
|
||||
assert( i>=0 && i<p->nCursor );
|
||||
assert( p->apCsr[i]!=0 );
|
||||
@@ -4042,7 +4049,7 @@ case OP_Destroy: { /* out2-prerelease */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Opcode: Clear P1 P2 *
|
||||
/* Opcode: Clear P1 P2 P3
|
||||
**
|
||||
** Delete all contents of the database table or index whose root page
|
||||
** in the database file is given by P1. But, unlike Destroy, do not
|
||||
@@ -4052,11 +4059,26 @@ case OP_Destroy: { /* out2-prerelease */
|
||||
** P2==1 then the table to be clear is in the auxiliary database file
|
||||
** that is used to store tables create using CREATE TEMPORARY TABLE.
|
||||
**
|
||||
** If the P3 value is non-zero, then the table refered to must be an
|
||||
** intkey table (an SQL table, not an index). In this case the row change
|
||||
** count is incremented by the number of rows in the table being cleared.
|
||||
** If P3 is greater than zero, then the value stored in register P3 is
|
||||
** also incremented by the number of rows in the table being cleared.
|
||||
**
|
||||
** See also: Destroy
|
||||
*/
|
||||
case OP_Clear: {
|
||||
int nChange = 0;
|
||||
assert( (p->btreeMask & (1<<pOp->p2))!=0 );
|
||||
rc = sqlite3BtreeClearTable(db->aDb[pOp->p2].pBt, pOp->p1);
|
||||
rc = sqlite3BtreeClearTable(
|
||||
db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
|
||||
);
|
||||
if( pOp->p3 ){
|
||||
p->nChange += nChange;
|
||||
if( pOp->p3>0 ){
|
||||
p->aMem[pOp->p3].u.i += nChange;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -4625,7 +4647,7 @@ case OP_VDestroy: {
|
||||
** table and stores that cursor in P1.
|
||||
*/
|
||||
case OP_VOpen: {
|
||||
Cursor *pCur = 0;
|
||||
VdbeCursor *pCur = 0;
|
||||
sqlite3_vtab_cursor *pVtabCursor = 0;
|
||||
|
||||
sqlite3_vtab *pVtab = pOp->p4.pVtab;
|
||||
@@ -4684,7 +4706,7 @@ case OP_VFilter: { /* jump */
|
||||
sqlite3_vtab_cursor *pVtabCursor;
|
||||
sqlite3_vtab *pVtab;
|
||||
|
||||
Cursor *pCur = p->apCsr[pOp->p1];
|
||||
VdbeCursor *pCur = p->apCsr[pOp->p1];
|
||||
|
||||
REGISTER_TRACE(pOp->p3, pQuery);
|
||||
assert( pCur->pVtabCursor );
|
||||
@@ -4741,7 +4763,7 @@ case OP_VRowid: { /* out2-prerelease */
|
||||
sqlite3_vtab *pVtab;
|
||||
const sqlite3_module *pModule;
|
||||
sqlite_int64 iRow;
|
||||
Cursor *pCur = p->apCsr[pOp->p1];
|
||||
VdbeCursor *pCur = p->apCsr[pOp->p1];
|
||||
|
||||
assert( pCur->pVtabCursor );
|
||||
if( pCur->nullRow ){
|
||||
@@ -4775,7 +4797,7 @@ case OP_VColumn: {
|
||||
Mem *pDest;
|
||||
sqlite3_context sContext;
|
||||
|
||||
Cursor *pCur = p->apCsr[pOp->p1];
|
||||
VdbeCursor *pCur = p->apCsr[pOp->p1];
|
||||
assert( pCur->pVtabCursor );
|
||||
assert( pOp->p3>0 && pOp->p3<=p->nMem );
|
||||
pDest = &p->aMem[pOp->p3];
|
||||
@@ -4833,7 +4855,7 @@ case OP_VNext: { /* jump */
|
||||
const sqlite3_module *pModule;
|
||||
int res = 0;
|
||||
|
||||
Cursor *pCur = p->apCsr[pOp->p1];
|
||||
VdbeCursor *pCur = p->apCsr[pOp->p1];
|
||||
assert( pCur->pVtabCursor );
|
||||
if( pCur->nullRow ){
|
||||
break;
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@
|
||||
** or VDBE. The VDBE implements an abstract machine that runs a
|
||||
** simple program to access and modify the underlying database.
|
||||
**
|
||||
** $Id: vdbe.h,v 1.138 2008/08/20 22:06:48 drh Exp $
|
||||
** $Id: vdbe.h,v 1.139 2008/10/31 10:53:23 danielk1977 Exp $
|
||||
*/
|
||||
#ifndef _SQLITE_VDBE_H_
|
||||
#define _SQLITE_VDBE_H_
|
||||
@@ -178,7 +178,7 @@ int sqlite3VdbeCurrentAddr(Vdbe*);
|
||||
void sqlite3VdbeResetStepResult(Vdbe*);
|
||||
int sqlite3VdbeReset(Vdbe*);
|
||||
void sqlite3VdbeSetNumCols(Vdbe*,int);
|
||||
int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, int);
|
||||
int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, void(*)(void*));
|
||||
void sqlite3VdbeCountChanges(Vdbe*);
|
||||
sqlite3 *sqlite3VdbeDb(Vdbe*);
|
||||
void sqlite3VdbeSetSql(Vdbe*, const char *z, int n);
|
||||
|
||||
+15
-13
@@ -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.155 2008/10/07 23:46:38 drh Exp $
|
||||
** $Id: vdbeInt.h,v 1.158 2008/11/17 15:31:48 danielk1977 Exp $
|
||||
*/
|
||||
#ifndef _VDBEINT_H_
|
||||
#define _VDBEINT_H_
|
||||
@@ -50,12 +50,12 @@ typedef unsigned char Bool;
|
||||
** Every cursor that the virtual machine has open is represented by an
|
||||
** instance of the following structure.
|
||||
**
|
||||
** If the Cursor.isTriggerRow flag is set it means that this cursor is
|
||||
** If the VdbeCursor.isTriggerRow flag is set it means that this cursor is
|
||||
** really a single row that represents the NEW or OLD pseudo-table of
|
||||
** a row trigger. The data for the row is stored in Cursor.pData and
|
||||
** the rowid is in Cursor.iKey.
|
||||
** a row trigger. The data for the row is stored in VdbeCursor.pData and
|
||||
** the rowid is in VdbeCursor.iKey.
|
||||
*/
|
||||
struct Cursor {
|
||||
struct VdbeCursor {
|
||||
BtCursor *pCursor; /* The cursor structure of the backend */
|
||||
int iDb; /* Index of cursor database in db->aDb[] (or -1) */
|
||||
i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
|
||||
@@ -93,10 +93,10 @@ struct Cursor {
|
||||
u32 *aOffset; /* Cached offsets to the start of each columns data */
|
||||
u8 *aRow; /* Data for the current row, if all on one page */
|
||||
};
|
||||
typedef struct Cursor Cursor;
|
||||
typedef struct VdbeCursor VdbeCursor;
|
||||
|
||||
/*
|
||||
** A value for Cursor.cacheValid that means the cache is always invalid.
|
||||
** A value for VdbeCursor.cacheValid that means the cache is always invalid.
|
||||
*/
|
||||
#define CACHE_STALE 0
|
||||
|
||||
@@ -291,16 +291,16 @@ struct Vdbe {
|
||||
Mem **apArg; /* Arguments to currently executing user function */
|
||||
Mem *aColName; /* Column names to return */
|
||||
int nCursor; /* Number of slots in apCsr[] */
|
||||
Cursor **apCsr; /* One element of this array for each open cursor */
|
||||
VdbeCursor **apCsr; /* One element of this array for each open cursor */
|
||||
int nVar; /* Number of entries in aVar[] */
|
||||
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 */
|
||||
int cacheCtr; /* Cursor row cache generation counter */
|
||||
int cacheCtr; /* VdbeCursor row cache generation counter */
|
||||
Fifo sFifo; /* A list of ROWIDs */
|
||||
int contextStackTop; /* Index of top element in the context stack */
|
||||
int contextStackDepth; /* The size of the "context" stack */
|
||||
@@ -319,6 +319,8 @@ struct Vdbe {
|
||||
u8 expired; /* True if the VM needs to be recompiled */
|
||||
u8 minWriteFileFormat; /* Minimum file format for writable database files */
|
||||
u8 inVtabMethod; /* See comments above */
|
||||
u8 usesStmtJournal; /* True if uses a statement journal */
|
||||
u8 readOnly; /* True for read-only statements */
|
||||
int nChange; /* Number of db changes made since last reset */
|
||||
i64 startTime; /* Time when query started - used for profiling */
|
||||
int btreeMask; /* Bitmask of db->aDb[] entries referenced */
|
||||
@@ -351,9 +353,9 @@ struct Vdbe {
|
||||
/*
|
||||
** Function prototypes
|
||||
*/
|
||||
void sqlite3VdbeFreeCursor(Vdbe *, Cursor*);
|
||||
void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
|
||||
void sqliteVdbePopStack(Vdbe*,int);
|
||||
int sqlite3VdbeCursorMoveto(Cursor*);
|
||||
int sqlite3VdbeCursorMoveto(VdbeCursor*);
|
||||
#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
|
||||
void sqlite3VdbePrintOp(FILE*, int, Op*);
|
||||
#endif
|
||||
@@ -364,7 +366,7 @@ int sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
|
||||
void sqlite3VdbeDeleteAuxData(VdbeFunc*, int);
|
||||
|
||||
int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
|
||||
int sqlite3VdbeIdxKeyCompare(Cursor*,UnpackedRecord*,int*);
|
||||
int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
|
||||
int sqlite3VdbeIdxRowid(BtCursor *, i64 *);
|
||||
int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
|
||||
int sqlite3VdbeExec(Vdbe*);
|
||||
|
||||
+5
-3
@@ -13,7 +13,7 @@
|
||||
** This file contains code use to implement APIs that are part of the
|
||||
** VDBE.
|
||||
**
|
||||
** $Id: vdbeapi.c,v 1.147 2008/10/13 10:37:50 danielk1977 Exp $
|
||||
** $Id: vdbeapi.c,v 1.149 2008/11/19 09:05:27 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
@@ -468,6 +468,7 @@ static int sqlite3Step(Vdbe *p){
|
||||
#endif
|
||||
|
||||
db->activeVdbeCnt++;
|
||||
if( p->readOnly==0 ) db->writeVdbeCnt++;
|
||||
p->pc = 0;
|
||||
stmtLruRemove(p);
|
||||
}
|
||||
@@ -600,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);
|
||||
|
||||
+67
-85
@@ -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.412 2008/10/11 17:51:39 danielk1977 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;
|
||||
}
|
||||
}
|
||||
@@ -267,6 +268,8 @@ static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
|
||||
int *aLabel = p->aLabel;
|
||||
int doesStatementRollback = 0;
|
||||
int hasStatementBegin = 0;
|
||||
p->readOnly = 1;
|
||||
p->usesStmtJournal = 0;
|
||||
for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
|
||||
u8 opcode = pOp->opcode;
|
||||
|
||||
@@ -283,8 +286,11 @@ static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
|
||||
}
|
||||
}else if( opcode==OP_Statement ){
|
||||
hasStatementBegin = 1;
|
||||
p->usesStmtJournal = 1;
|
||||
}else if( opcode==OP_Destroy ){
|
||||
doesStatementRollback = 1;
|
||||
}else if( opcode==OP_Transaction && pOp->p2!=0 ){
|
||||
p->readOnly = 0;
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
}else if( opcode==OP_VUpdate || opcode==OP_VRename ){
|
||||
doesStatementRollback = 1;
|
||||
@@ -313,6 +319,7 @@ static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
|
||||
** which can be expensive on some platforms.
|
||||
*/
|
||||
if( hasStatementBegin && !doesStatementRollback ){
|
||||
p->usesStmtJournal = 0;
|
||||
for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
|
||||
if( pOp->opcode==OP_Statement ){
|
||||
pOp->opcode = OP_Noop;
|
||||
@@ -336,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;
|
||||
@@ -725,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;
|
||||
@@ -1011,17 +1014,13 @@ 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
|
||||
** cells (nMem+1-nCursor)..nMem, inclusive, will never be used by
|
||||
** the vdbe program. Instead they are used to allocate space for
|
||||
** Cursor/BtCursor structures. The blob of memory associated with
|
||||
** VdbeCursor/BtCursor structures. The blob of memory associated with
|
||||
** cursor 0 is stored in memory cell nMem. Memory cell (nMem-1)
|
||||
** stores the blob of memory associated with cursor 1, etc.
|
||||
**
|
||||
@@ -1035,17 +1034,16 @@ 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 ){
|
||||
p->nMem = nMem = 10;
|
||||
nMem = 10;
|
||||
}
|
||||
p->aMem = sqlite3DbMallocZero(db,
|
||||
nMem*sizeof(Mem) /* aMem */
|
||||
+ nVar*sizeof(Mem) /* aVar */
|
||||
+ nArg*sizeof(Mem*) /* apArg */
|
||||
+ nVar*sizeof(char*) /* azVar */
|
||||
+ nCursor*sizeof(Cursor*) + 1 /* apCsr */
|
||||
+ nCursor*sizeof(VdbeCursor*)+1 /* apCsr */
|
||||
);
|
||||
if( !db->mallocFailed ){
|
||||
p->aMem--; /* aMem[] goes from 1..nMem */
|
||||
@@ -1055,7 +1053,7 @@ void sqlite3VdbeMakeReady(
|
||||
p->okVar = 0;
|
||||
p->apArg = (Mem**)&p->aVar[nVar];
|
||||
p->azVar = (char**)&p->apArg[nArg];
|
||||
p->apCsr = (Cursor**)&p->azVar[nVar];
|
||||
p->apCsr = (VdbeCursor**)&p->azVar[nVar];
|
||||
p->nCursor = nCursor;
|
||||
for(n=0; n<nVar; n++){
|
||||
p->aVar[n].flags = MEM_Null;
|
||||
@@ -1098,7 +1096,7 @@ void sqlite3VdbeMakeReady(
|
||||
** Close a VDBE cursor and release all the resources that cursor
|
||||
** happens to hold.
|
||||
*/
|
||||
void sqlite3VdbeFreeCursor(Vdbe *p, Cursor *pCx){
|
||||
void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){
|
||||
if( pCx==0 ){
|
||||
return;
|
||||
}
|
||||
@@ -1133,7 +1131,7 @@ static void closeAllCursorsExceptActiveVtabs(Vdbe *p){
|
||||
int i;
|
||||
if( p->apCsr==0 ) return;
|
||||
for(i=0; i<p->nCursor; i++){
|
||||
Cursor *pC = p->apCsr[i];
|
||||
VdbeCursor *pC = p->apCsr[i];
|
||||
if( pC && (!p->inVtabMethod || !pC->pVtabCursor) ){
|
||||
sqlite3VdbeFreeCursor(p, pC);
|
||||
p->apCsr[i] = 0;
|
||||
@@ -1201,28 +1199,29 @@ void sqlite3VdbeSetNumCols(Vdbe *p, int nResColumn){
|
||||
**
|
||||
** This call must be made after a call to sqlite3VdbeSetNumCols().
|
||||
**
|
||||
** If N==P4_STATIC it means that zName is a pointer to a constant static
|
||||
** string and we can just copy the pointer. If it is P4_DYNAMIC, then
|
||||
** the string is freed using sqlite3DbFree(db, ) when the vdbe is finished with
|
||||
** it. Otherwise, N bytes of zName are copied.
|
||||
** The final parameter, xDel, must be one of SQLITE_DYNAMIC, SQLITE_STATIC
|
||||
** or SQLITE_TRANSIENT. If it is SQLITE_DYNAMIC, then the buffer pointed
|
||||
** to by zName will be freed by sqlite3DbFree() when the vdbe is destroyed.
|
||||
*/
|
||||
int sqlite3VdbeSetColName(Vdbe *p, int idx, int var, const char *zName, int N){
|
||||
int sqlite3VdbeSetColName(
|
||||
Vdbe *p, /* Vdbe being configured */
|
||||
int idx, /* Index of column zName applies to */
|
||||
int var, /* One of the COLNAME_* constants */
|
||||
const char *zName, /* Pointer to buffer containing name */
|
||||
void (*xDel)(void*) /* Memory management strategy for zName */
|
||||
){
|
||||
int rc;
|
||||
Mem *pColName;
|
||||
assert( idx<p->nResColumn );
|
||||
assert( var<COLNAME_N );
|
||||
if( p->db->mallocFailed ) return SQLITE_NOMEM;
|
||||
if( p->db->mallocFailed ){
|
||||
assert( !zName || xDel!=SQLITE_DYNAMIC );
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
assert( p->aColName!=0 );
|
||||
pColName = &(p->aColName[idx+var*p->nResColumn]);
|
||||
if( N==P4_DYNAMIC || N==P4_STATIC ){
|
||||
rc = sqlite3VdbeMemSetStr(pColName, zName, -1, SQLITE_UTF8, SQLITE_STATIC);
|
||||
}else{
|
||||
rc = sqlite3VdbeMemSetStr(pColName, zName, N, SQLITE_UTF8,SQLITE_TRANSIENT);
|
||||
}
|
||||
if( rc==SQLITE_OK && N==P4_DYNAMIC ){
|
||||
pColName->flags &= (~MEM_Static);
|
||||
pColName->zMalloc = pColName->z;
|
||||
}
|
||||
rc = sqlite3VdbeMemSetStr(pColName, zName, -1, SQLITE_UTF8, xDel);
|
||||
assert( rc!=0 || !zName || (pColName->flags&MEM_Term)!=0 );
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1453,14 +1452,17 @@ static int vdbeCommit(sqlite3 *db, Vdbe *p){
|
||||
static void checkActiveVdbeCnt(sqlite3 *db){
|
||||
Vdbe *p;
|
||||
int cnt = 0;
|
||||
int nWrite = 0;
|
||||
p = db->pVdbe;
|
||||
while( p ){
|
||||
if( p->magic==VDBE_MAGIC_RUN && p->pc>=0 ){
|
||||
cnt++;
|
||||
if( p->readOnly==0 ) nWrite++;
|
||||
}
|
||||
p = p->pNext;
|
||||
}
|
||||
assert( cnt==db->activeVdbeCnt );
|
||||
assert( nWrite==db->writeVdbeCnt );
|
||||
}
|
||||
#else
|
||||
#define checkActiveVdbeCnt(x)
|
||||
@@ -1548,42 +1550,15 @@ int sqlite3VdbeHalt(Vdbe *p){
|
||||
isSpecialError = mrc==SQLITE_NOMEM || mrc==SQLITE_IOERR
|
||||
|| mrc==SQLITE_INTERRUPT || mrc==SQLITE_FULL;
|
||||
if( isSpecialError ){
|
||||
/* This loop does static analysis of the query to see which of the
|
||||
** following three categories it falls into:
|
||||
**
|
||||
** Read-only
|
||||
** Query with statement journal
|
||||
** Query without statement journal
|
||||
**
|
||||
** We could do something more elegant than this static analysis (i.e.
|
||||
** store the type of query as part of the compliation phase), but
|
||||
** handling malloc() or IO failure is a fairly obscure edge case so
|
||||
** this is probably easier. Todo: Might be an opportunity to reduce
|
||||
** code size a very small amount though...
|
||||
*/
|
||||
int notReadOnly = 0;
|
||||
int isStatement = 0;
|
||||
assert(p->aOp || p->nOp==0);
|
||||
for(i=0; i<p->nOp; i++){
|
||||
switch( p->aOp[i].opcode ){
|
||||
case OP_Transaction:
|
||||
notReadOnly |= p->aOp[i].p2;
|
||||
break;
|
||||
case OP_Statement:
|
||||
isStatement = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* If the query was read-only, we need do no rollback at all. Otherwise,
|
||||
** proceed with the special handling.
|
||||
*/
|
||||
if( notReadOnly || mrc!=SQLITE_INTERRUPT ){
|
||||
if( p->rc==SQLITE_IOERR_BLOCKED && isStatement ){
|
||||
if( !p->readOnly || mrc!=SQLITE_INTERRUPT ){
|
||||
if( p->rc==SQLITE_IOERR_BLOCKED && p->usesStmtJournal ){
|
||||
xFunc = sqlite3BtreeRollbackStmt;
|
||||
p->rc = SQLITE_BUSY;
|
||||
} else if( (mrc==SQLITE_NOMEM || mrc==SQLITE_FULL) && isStatement ){
|
||||
}else if( (mrc==SQLITE_NOMEM || mrc==SQLITE_FULL)
|
||||
&& p->usesStmtJournal ){
|
||||
xFunc = sqlite3BtreeRollbackStmt;
|
||||
}else{
|
||||
/* We are forced to roll back the active transaction. Before doing
|
||||
@@ -1600,9 +1575,12 @@ int sqlite3VdbeHalt(Vdbe *p){
|
||||
** we do either a commit or rollback of the current transaction.
|
||||
**
|
||||
** Note: This block also runs if one of the special errors handled
|
||||
** above has occured.
|
||||
** above has occurred.
|
||||
*/
|
||||
if( db->autoCommit && db->activeVdbeCnt==1 ){
|
||||
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
|
||||
@@ -1682,6 +1660,10 @@ int sqlite3VdbeHalt(Vdbe *p){
|
||||
/* We have successfully halted and closed the VM. Record this fact. */
|
||||
if( p->pc>=0 ){
|
||||
db->activeVdbeCnt--;
|
||||
if( !p->readOnly ){
|
||||
db->writeVdbeCnt--;
|
||||
}
|
||||
assert( db->activeVdbeCnt>=db->writeVdbeCnt );
|
||||
}
|
||||
p->magic = VDBE_MAGIC_HALT;
|
||||
checkActiveVdbeCnt(db);
|
||||
@@ -1865,7 +1847,7 @@ void sqlite3VdbeDelete(Vdbe *p){
|
||||
** MoveTo now. Return an error code. If no MoveTo is pending, this
|
||||
** routine does nothing and returns SQLITE_OK.
|
||||
*/
|
||||
int sqlite3VdbeCursorMoveto(Cursor *p){
|
||||
int sqlite3VdbeCursorMoveto(VdbeCursor *p){
|
||||
if( p->deferredMoveto ){
|
||||
int res, rc;
|
||||
#ifdef SQLITE_TEST
|
||||
@@ -1968,7 +1950,7 @@ u32 sqlite3VdbeSerialType(Mem *pMem, int file_format){
|
||||
if( flags&MEM_Real ){
|
||||
return 7;
|
||||
}
|
||||
assert( flags&(MEM_Str|MEM_Blob) );
|
||||
assert( pMem->db->mallocFailed || flags&(MEM_Str|MEM_Blob) );
|
||||
n = pMem->n;
|
||||
if( flags & MEM_Zero ){
|
||||
n += pMem->u.i;
|
||||
@@ -2225,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;
|
||||
@@ -2250,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;
|
||||
@@ -2315,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;
|
||||
@@ -2432,7 +2414,7 @@ int sqlite3VdbeIdxRowid(BtCursor *pCur, i64 *rowid){
|
||||
** supplied it is used in place of pKey,nKey.
|
||||
*/
|
||||
int sqlite3VdbeIdxKeyCompare(
|
||||
Cursor *pC, /* The cursor to compare against */
|
||||
VdbeCursor *pC, /* The cursor to compare against */
|
||||
UnpackedRecord *pUnpacked, /* Unpacked version of pKey and nKey */
|
||||
int *res /* Write the comparison result here */
|
||||
){
|
||||
|
||||
+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
|
||||
|
||||
/*
|
||||
|
||||
+13
-8
@@ -15,7 +15,7 @@
|
||||
** only within the VDBE. Interface routines refer to a Mem using the
|
||||
** name sqlite_value
|
||||
**
|
||||
** $Id: vdbemem.c,v 1.123 2008/09/16 12:06:08 danielk1977 Exp $
|
||||
** $Id: vdbemem.c,v 1.126 2008/11/11 00:21:30 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@@ -86,9 +86,6 @@ int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve){
|
||||
if( sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){
|
||||
if( preserve && pMem->z==pMem->zMalloc ){
|
||||
pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
|
||||
if( !pMem->z ){
|
||||
pMem->flags = MEM_Null;
|
||||
}
|
||||
preserve = 0;
|
||||
}else{
|
||||
sqlite3DbFree(pMem->db, pMem->zMalloc);
|
||||
@@ -104,7 +101,11 @@ int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve){
|
||||
}
|
||||
|
||||
pMem->z = pMem->zMalloc;
|
||||
pMem->flags &= ~(MEM_Ephem|MEM_Static);
|
||||
if( pMem->z==0 ){
|
||||
pMem->flags = MEM_Null;
|
||||
}else{
|
||||
pMem->flags &= ~(MEM_Ephem|MEM_Static);
|
||||
}
|
||||
pMem->xDel = 0;
|
||||
return (pMem->z ? SQLITE_OK : SQLITE_NOMEM);
|
||||
}
|
||||
@@ -606,9 +607,6 @@ int sqlite3VdbeMemSetStr(
|
||||
}
|
||||
flags |= MEM_Term;
|
||||
}
|
||||
if( nByte>iLimit ){
|
||||
return SQLITE_TOOBIG;
|
||||
}
|
||||
|
||||
/* The following block sets the new values of Mem.z and Mem.xDel. It
|
||||
** also sets a flag in local variable "flags" to indicate the memory
|
||||
@@ -619,6 +617,9 @@ int sqlite3VdbeMemSetStr(
|
||||
if( flags&MEM_Term ){
|
||||
nAlloc += (enc==SQLITE_UTF8?1:2);
|
||||
}
|
||||
if( nByte>iLimit ){
|
||||
return SQLITE_TOOBIG;
|
||||
}
|
||||
if( sqlite3VdbeMemGrow(pMem, nAlloc, 0) ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
@@ -633,6 +634,9 @@ int sqlite3VdbeMemSetStr(
|
||||
pMem->xDel = xDel;
|
||||
flags |= ((xDel==SQLITE_STATIC)?MEM_Static:MEM_Dyn);
|
||||
}
|
||||
if( nByte>iLimit ){
|
||||
return SQLITE_TOOBIG;
|
||||
}
|
||||
|
||||
pMem->n = nByte;
|
||||
pMem->flags = flags;
|
||||
@@ -985,6 +989,7 @@ int sqlite3ValueFromExpr(
|
||||
assert( pExpr->token.z[1]=='\'' );
|
||||
assert( pExpr->token.z[pExpr->token.n-1]=='\'' );
|
||||
pVal = sqlite3ValueNew(db);
|
||||
if( !pVal ) goto no_mem;
|
||||
nVal = pExpr->token.n - 3;
|
||||
zVal = (char*)pExpr->token.z + 2;
|
||||
sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(db, zVal, nVal), nVal/2,
|
||||
|
||||
+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 ){
|
||||
|
||||
+21
-12
@@ -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.326 2008/10/11 16:47:36 drh 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++){}
|
||||
@@ -2349,7 +2344,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
*/
|
||||
notReady = ~(Bitmask)0;
|
||||
for(i=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){
|
||||
int j;
|
||||
int j, k;
|
||||
int iCur = pTabItem->iCursor; /* The VDBE cursor for the table */
|
||||
Index *pIdx; /* The index we will be using */
|
||||
int nxt; /* Where to jump to continue with the next IN case */
|
||||
@@ -2472,16 +2467,26 @@ WhereInfo *sqlite3WhereBegin(
|
||||
}
|
||||
if( pStart ){
|
||||
Expr *pX;
|
||||
int r1, regFree1;
|
||||
int r1;
|
||||
pX = pStart->pExpr;
|
||||
assert( pX!=0 );
|
||||
assert( pStart->leftCursor==iCur );
|
||||
r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, ®Free1);
|
||||
|
||||
/* The ForceInt instruction may modify the register that it operates
|
||||
** on. For example it may replace a real value with an integer one,
|
||||
** or if p3 is true it may increment the register value. For this
|
||||
** reason we need to make sure that register r1 is really a newly
|
||||
** allocated temporary register, and not part of the column-cache.
|
||||
** For this reason we cannot use sqlite3ExprCodeTemp() here.
|
||||
*/
|
||||
r1 = sqlite3GetTempReg(pParse);
|
||||
sqlite3ExprCode(pParse, pX->pRight, r1);
|
||||
|
||||
sqlite3VdbeAddOp3(v, OP_ForceInt, r1, brk,
|
||||
pX->op==TK_LE || pX->op==TK_GT);
|
||||
sqlite3VdbeAddOp3(v, bRev ? OP_MoveLt : OP_MoveGe, iCur, brk, r1);
|
||||
VdbeComment((v, "pk"));
|
||||
sqlite3ReleaseTempReg(pParse, regFree1);
|
||||
sqlite3ReleaseTempReg(pParse, r1);
|
||||
disableTerm(pLevel, pStart);
|
||||
}else{
|
||||
sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, brk);
|
||||
@@ -2716,6 +2721,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
/* Insert code to test every subexpression that can be completely
|
||||
** computed using the current set of tables.
|
||||
*/
|
||||
k = 0;
|
||||
for(pTerm=wc.a, j=wc.nTerm; j>0; j--, pTerm++){
|
||||
Expr *pE;
|
||||
testcase( pTerm->flags & TERM_VIRTUAL );
|
||||
@@ -2727,7 +2733,10 @@ WhereInfo *sqlite3WhereBegin(
|
||||
if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
|
||||
continue;
|
||||
}
|
||||
pParse->disableColCache += k;
|
||||
sqlite3ExprIfFalse(pParse, pE, cont, SQLITE_JUMPIFNULL);
|
||||
pParse->disableColCache -= k;
|
||||
k = 1;
|
||||
pTerm->flags |= TERM_CODED;
|
||||
}
|
||||
|
||||
|
||||
+7
-8
@@ -13,7 +13,7 @@
|
||||
# focus of this script is correct code generation of aliased result-set
|
||||
# values. See ticket #3343.
|
||||
#
|
||||
# $Id: alias.test,v 1.1 2008/08/29 02:14:03 drh Exp $
|
||||
# $Id: alias.test,v 1.2 2008/10/25 15:03:21 drh Exp $
|
||||
#
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -47,7 +47,6 @@ do_test alias-1.1 {
|
||||
do_test alias-1.2 {
|
||||
::seq::reset
|
||||
db eval {
|
||||
--pragma vdbe_listing=on; pragma vdbe_trace=on;
|
||||
SELECT x, sequence() AS y FROM t1 WHERE y>0
|
||||
}
|
||||
} {9 1 8 2 7 3}
|
||||
@@ -77,12 +76,12 @@ do_test alias-1.6 {
|
||||
SELECT x, sequence() AS y FROM t1 WHERE y BETWEEN 0 AND 99
|
||||
}
|
||||
} {9 1 8 2 7 3}
|
||||
do_test alias-1.7 {
|
||||
::seq::reset
|
||||
db eval {
|
||||
SELECT x, sequence() AS y FROM t1 WHERE y IN (55,66,3)
|
||||
}
|
||||
} {7 3}
|
||||
#do_test alias-1.7 {
|
||||
# ::seq::reset
|
||||
# db eval {
|
||||
# SELECT x, sequence() AS y FROM t1 WHERE y IN (55,66,3)
|
||||
# }
|
||||
#} {7 3}
|
||||
do_test alias-1.8 {
|
||||
::seq::reset
|
||||
db eval {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
# focus of this script is testing the ALTER TABLE statement and
|
||||
# specifically out-of-memory conditions within that command.
|
||||
#
|
||||
# $Id: altermalloc.test,v 1.9 2008/08/04 20:13:27 drh Exp $
|
||||
# $Id: altermalloc.test,v 1.10 2008/10/30 17:21:13 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -39,6 +39,7 @@ do_malloc_test altermalloc-1 -tclprep {
|
||||
ALTER TABLE t1 ADD COLUMN b INTEGER DEFAULT NULL;
|
||||
ALTER TABLE t1 ADD COLUMN c TEXT DEFAULT 'default-text';
|
||||
ALTER TABLE t1 RENAME TO t2;
|
||||
ALTER TABLE t2 ADD COLUMN d BLOB DEFAULT X'ABCD';
|
||||
}
|
||||
|
||||
# Test malloc() failure on an ALTER TABLE on a virtual table.
|
||||
|
||||
+15
-1
@@ -12,7 +12,7 @@
|
||||
# focus of this script is testing the ATTACH statement and
|
||||
# specifically out-of-memory conditions within that command.
|
||||
#
|
||||
# $Id: attachmalloc.test,v 1.9 2008/08/04 20:13:27 drh Exp $
|
||||
# $Id: attachmalloc.test,v 1.10 2008/10/22 10:45:38 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -46,4 +46,18 @@ do_malloc_test attachmalloc-1 -tclprep {
|
||||
CREATE TABLE four.t1(x);
|
||||
}
|
||||
|
||||
do_malloc_test attachmalloc-2 -tclprep {
|
||||
file delete -force test2.db
|
||||
file delete -force test2.db-journal
|
||||
sqlite3 db2 test2.db
|
||||
db2 eval {
|
||||
CREATE TABLE t1(a, b, c);
|
||||
CREATE INDEX i1 ON t1(a, b);
|
||||
}
|
||||
db2 close
|
||||
} -sqlbody {
|
||||
CREATE TABLE t1(d, e, f);
|
||||
ATTACH 'test2.db' AS db1;
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
+5
-2
@@ -12,7 +12,7 @@
|
||||
# focus of this script is testing the sqlite3_set_authorizer() API
|
||||
# and related functionality.
|
||||
#
|
||||
# $Id: auth.test,v 1.43 2008/07/02 13:13:52 danielk1977 Exp $
|
||||
# $Id: auth.test,v 1.44 2008/10/27 15:34:33 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -418,7 +418,10 @@ do_test auth-1.49 {
|
||||
} {0 {}}
|
||||
do_test auth-1.50 {
|
||||
execsql {SELECT * FROM t2}
|
||||
} {11 2 33}
|
||||
} {}
|
||||
do_test auth-1.50.2 {
|
||||
execsql {INSERT INTO t2 VALUES(11, 2, 33)}
|
||||
} {}
|
||||
|
||||
do_test auth-1.51 {
|
||||
proc auth {code arg1 arg2 arg3 arg4} {
|
||||
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
# 2008 October 27
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# Test that the truncate optimization is disabled if the SQLITE_DELETE
|
||||
# authorization callback returns SQLITE_IGNORE.
|
||||
#
|
||||
# $Id: auth3.test,v 1.1 2008/10/27 15:34:33 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# disable this test if the SQLITE_OMIT_AUTHORIZATION macro is
|
||||
# defined during compilation.
|
||||
if {[catch {db auth {}} msg]} {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
# Disable the statement cache for these tests.
|
||||
#
|
||||
db cache size 0
|
||||
|
||||
db authorizer ::auth
|
||||
proc auth {code arg1 arg2 arg3 arg4} {
|
||||
if {$code=="SQLITE_DELETE"} {
|
||||
return $::authcode
|
||||
}
|
||||
return SQLITE_OK
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# The following tests - auth3-1.* - test that return values of SQLITE_DENY,
|
||||
# SQLITE_IGNORE, SQLITE_OK and <invalid> are correctly handled when returned
|
||||
# by an SQLITE_DELETE authorization callback triggered by a
|
||||
# "DELETE FROM <table-name>" statement.
|
||||
#
|
||||
do_test auth3-1.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a,b,c);
|
||||
INSERT INTO t1 VALUES(1, 2, 3);
|
||||
INSERT INTO t1 VALUES(4, 5, 6);
|
||||
}
|
||||
} {}
|
||||
do_test auth3.1.2 {
|
||||
set ::authcode SQLITE_DENY
|
||||
catchsql { DELETE FROM t1 }
|
||||
} {1 {not authorized}}
|
||||
do_test auth3.1.3 {
|
||||
set ::authcode SQLITE_INVALID
|
||||
catchsql { DELETE FROM t1 }
|
||||
} {1 {illegal return value (1) from the authorization function - should be SQLITE_OK, SQLITE_IGNORE, or SQLITE_DENY}}
|
||||
do_test auth3.1.4 {
|
||||
execsql { SELECT * FROM t1 }
|
||||
} {1 2 3 4 5 6}
|
||||
do_test auth3-1.5 {
|
||||
set ::authcode SQLITE_IGNORE
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {}
|
||||
do_test auth3-1.6 {
|
||||
set ::authcode SQLITE_OK
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(1, 2, 3);
|
||||
INSERT INTO t1 VALUES(4, 5, 6);
|
||||
DELETE FROM t1;
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {}
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# These tests - auth3-2.* - test that returning SQLITE_IGNORE really does
|
||||
# disable the truncate optimization.
|
||||
#
|
||||
do_test auth3-2.1 {
|
||||
set ::authcode SQLITE_OK
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(1, 2, 3);
|
||||
INSERT INTO t1 VALUES(4, 5, 6);
|
||||
}
|
||||
set sqlite_search_count 0
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
}
|
||||
set sqlite_search_count
|
||||
} {0}
|
||||
|
||||
do_test auth3-2.2 {
|
||||
set ::authcode SQLITE_IGNORE
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(1, 2, 3);
|
||||
INSERT INTO t1 VALUES(4, 5, 6);
|
||||
}
|
||||
set sqlite_search_count 0
|
||||
execsql {
|
||||
DELETE FROM t1;
|
||||
}
|
||||
set sqlite_search_count
|
||||
} {1}
|
||||
|
||||
finish_test
|
||||
+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
|
||||
|
||||
+31
-19
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script testing the callback-free C/C++ API.
|
||||
#
|
||||
# $Id: capi3.test,v 1.67 2008/07/12 15:55:55 danielk1977 Exp $
|
||||
# $Id: capi3.test,v 1.69 2008/11/05 16:37:35 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -61,9 +61,12 @@ do_test capi3-1.1 {
|
||||
sqlite3_finalize $STMT
|
||||
set TAIL
|
||||
} {}
|
||||
do_test capi3-1.2 {
|
||||
do_test capi3-1.2.1 {
|
||||
sqlite3_errcode $DB
|
||||
} {SQLITE_OK}
|
||||
do_test capi3-1.2.2 {
|
||||
sqlite3_extended_errcode $DB
|
||||
} {SQLITE_OK}
|
||||
do_test capi3-1.3 {
|
||||
sqlite3_errmsg $DB
|
||||
} {not an error}
|
||||
@@ -92,9 +95,12 @@ do_test capi3-1.7 {
|
||||
set STMT [sqlite3_prepare $DB $sql -1 TAIL]
|
||||
}
|
||||
} {1}
|
||||
do_test capi3-1.8 {
|
||||
do_test capi3-1.8.1 {
|
||||
sqlite3_errcode $DB
|
||||
} {SQLITE_ERROR}
|
||||
do_test capi3-1.8.2 {
|
||||
sqlite3_extended_errcode $DB
|
||||
} {SQLITE_ERROR}
|
||||
do_test capi3-1.9 {
|
||||
sqlite3_errmsg $DB
|
||||
} {no such column: namex}
|
||||
@@ -118,9 +124,12 @@ ifcapable {utf16} {
|
||||
set STMT [sqlite3_prepare16 $DB $sql -1 TAIL]
|
||||
}
|
||||
} {1}
|
||||
do_test capi3-2.4 {
|
||||
do_test capi3-2.4.1 {
|
||||
sqlite3_errcode $DB
|
||||
} {SQLITE_ERROR}
|
||||
do_test capi3-2.4.2 {
|
||||
sqlite3_extended_errcode $DB
|
||||
} {SQLITE_ERROR}
|
||||
do_test capi3-2.5 {
|
||||
sqlite3_errmsg $DB
|
||||
} {no such column: namex}
|
||||
@@ -157,7 +166,7 @@ do_test capi3-3.3 {
|
||||
catch {
|
||||
set db2 [sqlite3_open /bogus/path/test.db {}]
|
||||
}
|
||||
sqlite3_errcode $db2
|
||||
sqlite3_extended_errcode $db2
|
||||
} {SQLITE_CANTOPEN}
|
||||
do_test capi3-3.4 {
|
||||
sqlite3_errmsg $db2
|
||||
@@ -824,14 +833,25 @@ do_test capi3-11.2 {
|
||||
set STMT [sqlite3_prepare $DB "SELECT func(b, a) FROM t1" -1 TAIL]
|
||||
sqlite3_step $STMT
|
||||
} {SQLITE_ROW}
|
||||
do_test capi3-11.3 {
|
||||
|
||||
# As of 3.6.5 a COMMIT is OK during while a query is still running -
|
||||
# as long as it is a read-only query and not an incremental BLOB write.
|
||||
#
|
||||
do_test capi3-11.3.1 {
|
||||
catchsql {
|
||||
COMMIT;
|
||||
}
|
||||
} {1 {cannot commit transaction - SQL statements in progress}}
|
||||
do_test capi3-11.3.1 {
|
||||
} {0 {}}
|
||||
do_test capi3-11.3.2 {
|
||||
sqlite3_extended_errcode $DB
|
||||
} {SQLITE_OK}
|
||||
do_test capi3-11.3.3 {
|
||||
sqlite3_get_autocommit $DB
|
||||
} 0
|
||||
} 1
|
||||
do_test capi3-11.3.4 {
|
||||
db eval {PRAGMA lock_status}
|
||||
} {main shared temp closed}
|
||||
|
||||
do_test capi3-11.4 {
|
||||
sqlite3_step $STMT
|
||||
} {SQLITE_ERROR}
|
||||
@@ -843,15 +863,7 @@ do_test capi3-11.6 {
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {0 {1 int 2 notatype}}
|
||||
do_test capi3-11.6.1 {
|
||||
sqlite3_get_autocommit $DB
|
||||
} 0
|
||||
do_test capi3-11.7 {
|
||||
catchsql {
|
||||
COMMIT;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test capi3-11.7.1 {
|
||||
sqlite3_get_autocommit $DB
|
||||
} 1
|
||||
do_test capi3-11.8 {
|
||||
@@ -938,13 +950,13 @@ do_test capi3-11.20 {
|
||||
BEGIN;
|
||||
COMMIT;
|
||||
}
|
||||
} {1 {cannot commit transaction - SQL statements in progress}}
|
||||
} {0 {}}
|
||||
do_test capi3-11.20 {
|
||||
sqlite3_reset $STMT
|
||||
catchsql {
|
||||
COMMIT;
|
||||
}
|
||||
} {0 {}}
|
||||
} {1 {cannot commit - no transaction is active}}
|
||||
do_test capi3-11.21 {
|
||||
sqlite3_finalize $STMT
|
||||
} {SQLITE_OK}
|
||||
|
||||
+34
-19
@@ -13,7 +13,7 @@
|
||||
# This is a copy of the capi3.test file that has been adapted to
|
||||
# test the new sqlite3_prepare_v2 interface.
|
||||
#
|
||||
# $Id: capi3c.test,v 1.20 2008/10/12 00:27:54 shane Exp $
|
||||
# $Id: capi3c.test,v 1.22 2008/11/05 16:37:35 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -63,9 +63,12 @@ do_test capi3c-1.1 {
|
||||
sqlite3_finalize $STMT
|
||||
set TAIL
|
||||
} {}
|
||||
do_test capi3c-1.2 {
|
||||
do_test capi3c-1.2.1 {
|
||||
sqlite3_errcode $DB
|
||||
} {SQLITE_OK}
|
||||
do_test capi3c-1.2.2 {
|
||||
sqlite3_extended_errcode $DB
|
||||
} {SQLITE_OK}
|
||||
do_test capi3c-1.3 {
|
||||
sqlite3_errmsg $DB
|
||||
} {not an error}
|
||||
@@ -81,9 +84,12 @@ do_test capi3c-1.5 {
|
||||
set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL]
|
||||
}
|
||||
} {1}
|
||||
do_test capi3c-1.6 {
|
||||
do_test capi3c-1.6.1 {
|
||||
sqlite3_errcode $DB
|
||||
} {SQLITE_ERROR}
|
||||
do_test capi3c-1.6.2 {
|
||||
sqlite3_extended_errcode $DB
|
||||
} {SQLITE_ERROR}
|
||||
do_test capi3c-1.7 {
|
||||
sqlite3_errmsg $DB
|
||||
} {no such column: namex}
|
||||
@@ -108,9 +114,12 @@ ifcapable {utf16} {
|
||||
set STMT [sqlite3_prepare16_v2 $DB $sql -1 TAIL]
|
||||
}
|
||||
} {1}
|
||||
do_test capi3c-2.4 {
|
||||
do_test capi3c-2.4.1 {
|
||||
sqlite3_errcode $DB
|
||||
} {SQLITE_ERROR}
|
||||
do_test capi3c-2.4.2 {
|
||||
sqlite3_extended_errcode $DB
|
||||
} {SQLITE_ERROR}
|
||||
do_test capi3c-2.5 {
|
||||
sqlite3_errmsg $DB
|
||||
} {no such column: namex}
|
||||
@@ -779,14 +788,25 @@ do_test capi3c-11.2 {
|
||||
set STMT [sqlite3_prepare_v2 $DB "SELECT func(b, a) FROM t1" -1 TAIL]
|
||||
sqlite3_step $STMT
|
||||
} {SQLITE_ROW}
|
||||
do_test capi3c-11.3 {
|
||||
|
||||
# As of 3.6.5 a COMMIT is OK during while a query is still running -
|
||||
# as long as it is a read-only query and not an incremental BLOB write.
|
||||
#
|
||||
do_test capi3-11.3.1 {
|
||||
catchsql {
|
||||
COMMIT;
|
||||
}
|
||||
} {1 {cannot commit transaction - SQL statements in progress}}
|
||||
do_test capi3c-11.3.1 {
|
||||
} {0 {}}
|
||||
do_test capi3-11.3.2 {
|
||||
sqlite3_extended_errcode $DB
|
||||
} {SQLITE_OK}
|
||||
do_test capi3-11.3.3 {
|
||||
sqlite3_get_autocommit $DB
|
||||
} 0
|
||||
} 1
|
||||
do_test capi3-11.3.4 {
|
||||
db eval {PRAGMA lock_status}
|
||||
} {main shared temp closed}
|
||||
|
||||
do_test capi3c-11.4 {
|
||||
sqlite3_step $STMT
|
||||
} {SQLITE_ERROR}
|
||||
@@ -798,15 +818,7 @@ do_test capi3c-11.6 {
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {0 {1 int 2 notatype}}
|
||||
do_test capi3c-11.6.1 {
|
||||
sqlite3_get_autocommit $DB
|
||||
} 0
|
||||
do_test capi3c-11.7 {
|
||||
catchsql {
|
||||
COMMIT;
|
||||
}
|
||||
} {0 {}}
|
||||
do_test capi3c-11.7.1 {
|
||||
sqlite3_get_autocommit $DB
|
||||
} 1
|
||||
do_test capi3c-11.8 {
|
||||
@@ -893,13 +905,13 @@ do_test capi3c-11.20 {
|
||||
BEGIN;
|
||||
COMMIT;
|
||||
}
|
||||
} {1 {cannot commit transaction - SQL statements in progress}}
|
||||
} {0 {}}
|
||||
do_test capi3c-11.20 {
|
||||
sqlite3_reset $STMT
|
||||
catchsql {
|
||||
COMMIT;
|
||||
}
|
||||
} {0 {}}
|
||||
} {1 {cannot commit - no transaction is active}}
|
||||
do_test capi3c-11.21 {
|
||||
sqlite3_finalize $STMT
|
||||
} {SQLITE_OK}
|
||||
@@ -1231,7 +1243,7 @@ ifcapable progress {
|
||||
sqlite3_step $STMT
|
||||
} {SQLITE_INTERRUPT}
|
||||
do_test capi3c-21.2 {
|
||||
sqlite3_errcode $DB
|
||||
sqlite3_extended_errcode $DB
|
||||
} {SQLITE_INTERRUPT}
|
||||
do_test capi3c-21.3 {
|
||||
sqlite3_finalize $STMT
|
||||
@@ -1250,6 +1262,9 @@ ifcapable progress {
|
||||
do_test capi3c-21.7 {
|
||||
sqlite3_errcode $DB
|
||||
} {SQLITE_INTERRUPT}
|
||||
do_test capi3c-21.8 {
|
||||
sqlite3_extended_errcode $DB
|
||||
} {SQLITE_INTERRUPT}
|
||||
}
|
||||
|
||||
# Make sure sqlite3_result_error_code() returns the correct error code.
|
||||
|
||||
+25
-1
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing the CAST operator.
|
||||
#
|
||||
# $Id: cast.test,v 1.9 2008/01/19 20:11:26 drh Exp $
|
||||
# $Id: cast.test,v 1.10 2008/11/06 15:33:04 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -319,4 +319,28 @@ do_test cast-3.32.3 {
|
||||
sqlite3_finalize $::STMT
|
||||
} {SQLITE_OK}
|
||||
|
||||
|
||||
do_test cast-4.1 {
|
||||
db eval {
|
||||
CREATE TABLE t1(a);
|
||||
INSERT INTO t1 VALUES('abc');
|
||||
SELECT a, CAST(a AS integer) FROM t1;
|
||||
}
|
||||
} {abc 0}
|
||||
do_test cast-4.2 {
|
||||
db eval {
|
||||
SELECT CAST(a AS integer), a FROM t1;
|
||||
}
|
||||
} {0 abc}
|
||||
do_test cast-4.3 {
|
||||
db eval {
|
||||
SELECT a, CAST(a AS integer), a FROM t1;
|
||||
}
|
||||
} {abc 0 abc}
|
||||
do_test cast-4.4 {
|
||||
db eval {
|
||||
SELECT CAST(a AS integer), a, CAST(a AS real), a FROM t1;
|
||||
}
|
||||
} {0 abc 0.0 abc}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -0,0 +1,373 @@
|
||||
# 2004 August 30
|
||||
#
|
||||
# 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 regression tests for SQLite library.
|
||||
#
|
||||
# This file implements tests to make sure SQLite does not crash or
|
||||
# segfault if it sees a corrupt database file. It creates a base
|
||||
# data base file, then tests that single byte corruptions in
|
||||
# increasingly larger quantities are handled gracefully.
|
||||
#
|
||||
# $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
|
||||
|
||||
# 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);
|
||||
INSERT OR IGNORE INTO t1 SELECT x*2,y FROM t1;
|
||||
INSERT OR IGNORE INTO t1 SELECT x*3,y FROM t1;
|
||||
INSERT OR IGNORE INTO t1 SELECT x*5,y FROM t1;
|
||||
INSERT OR IGNORE INTO t1 SELECT x*7,y FROM t1;
|
||||
INSERT OR IGNORE INTO t1 SELECT x*11,y FROM t1;
|
||||
INSERT OR IGNORE INTO t1 SELECT x*13,y FROM t1;
|
||||
CREATE INDEX t1i1 ON t1(x);
|
||||
CREATE TABLE t2 AS SELECT x,2 as y FROM t1 WHERE rowid%5!=0;
|
||||
COMMIT;
|
||||
}
|
||||
} {}
|
||||
|
||||
ifcapable {integrityck} {
|
||||
integrity_check corruptC-1.2
|
||||
}
|
||||
|
||||
# Generate random integer
|
||||
#
|
||||
proc random {range} {
|
||||
return [expr {round(rand()*$range)}]
|
||||
}
|
||||
|
||||
# Copy file $from into $to
|
||||
#
|
||||
proc copy_file {from to} {
|
||||
file copy -force $from $to
|
||||
}
|
||||
|
||||
# Setup for the tests. Make a backup copy of the good database in test.bu.
|
||||
#
|
||||
db close
|
||||
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
|
||||
# with specific seeds.
|
||||
#
|
||||
|
||||
# test that a corrupt content offset size is handled (seed 5577)
|
||||
do_test corruptC-2.1 {
|
||||
db close
|
||||
copy_file test.bu test.db
|
||||
|
||||
# insert corrupt byte(s)
|
||||
hexio_write test.db 2053 [format %02x 0x04]
|
||||
|
||||
sqlite3 db test.db
|
||||
catchsql {PRAGMA integrity_check}
|
||||
} {0 {{*** in database main ***
|
||||
Corruption detected in header on page 3}}}
|
||||
|
||||
# test that a corrupt content offset size is handled (seed 5649)
|
||||
do_test corruptC-2.2 {
|
||||
db close
|
||||
copy_file test.bu test.db
|
||||
|
||||
# insert corrupt byte(s)
|
||||
hexio_write test.db 27 [format %02x 0x08]
|
||||
hexio_write test.db 233 [format %02x 0x6a]
|
||||
hexio_write test.db 328 [format %02x 0x67]
|
||||
hexio_write test.db 750 [format %02x 0x1f]
|
||||
hexio_write test.db 1132 [format %02x 0x52]
|
||||
hexio_write test.db 1133 [format %02x 0x84]
|
||||
hexio_write test.db 1220 [format %02x 0x01]
|
||||
hexio_write test.db 3688 [format %02x 0xc1]
|
||||
hexio_write test.db 3714 [format %02x 0x58]
|
||||
hexio_write test.db 3746 [format %02x 0x9a]
|
||||
|
||||
sqlite3 db test.db
|
||||
catchsql {UPDATE t1 SET y=1}
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
# test that a corrupt free cell size is handled (seed 13329)
|
||||
do_test corruptC-2.3 {
|
||||
db close
|
||||
copy_file test.bu test.db
|
||||
|
||||
# insert corrupt byte(s)
|
||||
hexio_write test.db 1094 [format %02x 0x76]
|
||||
|
||||
sqlite3 db test.db
|
||||
catchsql {UPDATE t1 SET y=1}
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
# test that a corrupt free cell size is handled (seed 169571)
|
||||
do_test corruptC-2.4 {
|
||||
db close
|
||||
copy_file test.bu test.db
|
||||
|
||||
# insert corrupt byte(s)
|
||||
hexio_write test.db 3119 [format %02x 0xdf]
|
||||
|
||||
sqlite3 db test.db
|
||||
catchsql {UPDATE t2 SET y='abcdef-uvwxyz'}
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
# test that a corrupt free cell size is handled (seed 169571)
|
||||
do_test corruptC-2.5 {
|
||||
db close
|
||||
copy_file test.bu test.db
|
||||
|
||||
# insert corrupt byte(s)
|
||||
hexio_write test.db 3119 [format %02x 0xdf]
|
||||
hexio_write test.db 4073 [format %02x 0xbf]
|
||||
|
||||
sqlite3 db test.db
|
||||
catchsql {BEGIN; UPDATE t2 SET y='abcdef-uvwxyz'; ROLLBACK;}
|
||||
catchsql {PRAGMA integrity_check}
|
||||
} {0 {{*** in database main ***
|
||||
Corruption detected in cell 710 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 {
|
||||
db close
|
||||
copy_file test.bu test.db
|
||||
|
||||
# insert corrupt byte(s)
|
||||
hexio_write test.db 619 [format %02x 0xe2]
|
||||
hexio_write test.db 3150 [format %02x 0xa8]
|
||||
|
||||
sqlite3 db test.db
|
||||
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} {
|
||||
|
||||
# setup for test
|
||||
db close
|
||||
copy_file test.bu test.db
|
||||
sqlite3 db test.db
|
||||
|
||||
# Seek to a random location in the file, and write a random single byte
|
||||
# value. Then do various operations on the file to make sure that
|
||||
# the database engine can handle the corruption gracefully.
|
||||
#
|
||||
set last 0
|
||||
for {set i 1} {$i<=512 && !$last} {incr i 1} {
|
||||
|
||||
# insert random byte at random location
|
||||
db close
|
||||
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.($qseed).$i.1 {
|
||||
catchsql {SELECT count(*) FROM sqlite_master}
|
||||
set x {}
|
||||
} {}
|
||||
do_test corruptC-3.$tn.($qseed).$i.2 {
|
||||
catchsql {SELECT count(*) FROM t1}
|
||||
set x {}
|
||||
} {}
|
||||
do_test corruptC-3.$tn.($qseed).$i.3 {
|
||||
catchsql {SELECT count(*) FROM t1 WHERE x>13}
|
||||
set x {}
|
||||
} {}
|
||||
do_test corruptC-3.$tn.($qseed).$i.4 {
|
||||
catchsql {SELECT count(*) FROM t2}
|
||||
set x {}
|
||||
} {}
|
||||
do_test corruptC-3.$tn.($qseed).$i.5 {
|
||||
catchsql {SELECT count(*) FROM t2 WHERE x<13}
|
||||
set x {}
|
||||
} {}
|
||||
do_test corruptC-3.$tn.($qseed).$i.6 {
|
||||
catchsql {BEGIN; UPDATE t1 SET y=1; ROLLBACK;}
|
||||
set x {}
|
||||
} {}
|
||||
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.
|
||||
ifcapable {integrityck} {
|
||||
set res [ catchsql {PRAGMA integrity_check} ]
|
||||
set ans [lindex $res 1]
|
||||
if { [ string compare $ans "ok" ] != 0 } {
|
||||
set last -1
|
||||
}
|
||||
}
|
||||
# if we are not capable of doing an integrity check,
|
||||
# stop after corrupting 5 bytes.
|
||||
ifcapable {!integrityck} {
|
||||
if { $i > 5 } {
|
||||
set last -1
|
||||
}
|
||||
}
|
||||
|
||||
# Check that no page references were leaked.
|
||||
# TBD: need to figure out why this doesn't work
|
||||
# work with ROLLBACKs...
|
||||
if {0} {
|
||||
do_test corruptC-3.$tn.($qseed).$i.11 {
|
||||
set bt [btree_from_db db]
|
||||
db_enter db
|
||||
array set stats [btree_pager_stats $bt]
|
||||
db_leave db
|
||||
set stats(ref)
|
||||
} {0}
|
||||
}
|
||||
}
|
||||
# end for i
|
||||
|
||||
}
|
||||
# end for tn
|
||||
|
||||
finish_test
|
||||
+6
-7
@@ -9,7 +9,7 @@
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# $Id: incrblob.test,v 1.22 2008/10/02 14:49:02 danielk1977 Exp $
|
||||
# $Id: incrblob.test,v 1.23 2008/11/05 16:37:35 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -450,8 +450,10 @@ do_test incrblob-6.9 {
|
||||
flush $::blob
|
||||
} {}
|
||||
|
||||
# At this point rollback or commit should be illegal (because
|
||||
# there is an open blob channel).
|
||||
# At this point rollback should be illegal (because
|
||||
# there is an open blob channel). But commit is allowed because
|
||||
# the blob is read-only.
|
||||
#
|
||||
do_test incrblob-6.10 {
|
||||
catchsql {
|
||||
ROLLBACK;
|
||||
@@ -461,7 +463,7 @@ do_test incrblob-6.11 {
|
||||
catchsql {
|
||||
COMMIT;
|
||||
} db2
|
||||
} {1 {cannot commit transaction - SQL statements in progress}}
|
||||
} {0 {}}
|
||||
|
||||
do_test incrblob-6.12 {
|
||||
execsql {
|
||||
@@ -470,9 +472,6 @@ do_test incrblob-6.12 {
|
||||
} {}
|
||||
do_test incrblob-6.13 {
|
||||
close $::blob
|
||||
execsql {
|
||||
COMMIT;
|
||||
} db2
|
||||
} {}
|
||||
do_test incrblob-6.14 {
|
||||
execsql {
|
||||
|
||||
+14
-13
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The focus
|
||||
# of these tests is the journal mode pragma.
|
||||
#
|
||||
# $Id: jrnlmode.test,v 1.6 2008/09/26 21:08:08 drh Exp $
|
||||
# $Id: jrnlmode.test,v 1.8 2008/11/10 19:24:38 shane Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -95,7 +95,7 @@ ifcapable attach {
|
||||
PRAGMA main.journal_mode;
|
||||
PRAGMA aux1.journal_mode;
|
||||
}
|
||||
} {persist persist}
|
||||
} {persist memory}
|
||||
do_test jrnlmode-1.10 {
|
||||
execsql {
|
||||
PRAGMA main.journal_mode = OFF;
|
||||
@@ -105,7 +105,7 @@ ifcapable attach {
|
||||
PRAGMA temp.journal_mode;
|
||||
PRAGMA aux1.journal_mode;
|
||||
}
|
||||
} {off persist persist}
|
||||
} {off persist memory}
|
||||
do_test jrnlmode-1.11 {
|
||||
execsql {
|
||||
PRAGMA journal_mode;
|
||||
@@ -120,8 +120,9 @@ ifcapable attach {
|
||||
PRAGMA aux1.journal_mode;
|
||||
PRAGMA aux2.journal_mode;
|
||||
}
|
||||
} {off persist persist}
|
||||
do_test jrnlmode-1.11 {
|
||||
} {off memory memory}
|
||||
do_test jrnlmode-1.13 {
|
||||
# The journal-mode used by in-memory databases cannot be changed.
|
||||
execsql {
|
||||
PRAGMA aux1.journal_mode = DELETE;
|
||||
}
|
||||
@@ -130,8 +131,8 @@ ifcapable attach {
|
||||
PRAGMA aux1.journal_mode;
|
||||
PRAGMA aux2.journal_mode;
|
||||
}
|
||||
} {off delete persist}
|
||||
do_test jrnlmode-1.12 {
|
||||
} {off memory memory}
|
||||
do_test jrnlmode-1.14 {
|
||||
execsql {
|
||||
PRAGMA journal_mode = delete;
|
||||
}
|
||||
@@ -141,8 +142,8 @@ ifcapable attach {
|
||||
PRAGMA aux1.journal_mode;
|
||||
PRAGMA aux2.journal_mode;
|
||||
}
|
||||
} {delete delete delete delete}
|
||||
do_test jrnlmode-1.13 {
|
||||
} {delete delete memory memory}
|
||||
do_test jrnlmode-1.15 {
|
||||
execsql {
|
||||
ATTACH ':memory:' as aux3;
|
||||
}
|
||||
@@ -153,8 +154,8 @@ ifcapable attach {
|
||||
PRAGMA aux2.journal_mode;
|
||||
PRAGMA aux3.journal_mode;
|
||||
}
|
||||
} {delete delete delete delete delete}
|
||||
do_test jrnlmode-1.14 {
|
||||
} {delete delete memory memory memory}
|
||||
do_test jrnlmode-1.16 {
|
||||
execsql {
|
||||
PRAGMA journal_mode = TRUNCATE;
|
||||
}
|
||||
@@ -165,8 +166,8 @@ ifcapable attach {
|
||||
PRAGMA aux2.journal_mode;
|
||||
PRAGMA aux3.journal_mode;
|
||||
}
|
||||
} {truncate truncate truncate truncate truncate}
|
||||
|
||||
} {truncate truncate memory memory memory}
|
||||
|
||||
do_test jrnlmode-1.99 {
|
||||
execsql {
|
||||
DETACH aux1;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
@@ -19,6 +20,7 @@
|
||||
# Note 3: changes() is not changed by a change to a view (since everything
|
||||
# is done within instead of trigger context).
|
||||
#
|
||||
# $Id: laststmtchanges.test,v 1.7 2008/10/27 13:59:34 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -278,4 +280,52 @@ do_test laststmtchanges-5.5 {
|
||||
|
||||
} ;# ifcapable view
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# 6.x - Test "DELETE FROM <table>" in the absence of triggers
|
||||
#
|
||||
do_test laststmtchanges-6.1 {
|
||||
execsql {
|
||||
CREATE TABLE t3(a, b, c);
|
||||
INSERT INTO t3 VALUES(1, 2, 3);
|
||||
INSERT INTO t3 VALUES(4, 5, 6);
|
||||
}
|
||||
} {}
|
||||
do_test laststmtchanges-6.2 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
DELETE FROM t3;
|
||||
SELECT changes();
|
||||
}
|
||||
} {2}
|
||||
do_test laststmtchanges-6.3 {
|
||||
execsql {
|
||||
ROLLBACK;
|
||||
BEGIN;
|
||||
DELETE FROM t3 WHERE a IS NOT NULL;
|
||||
SELECT changes();
|
||||
}
|
||||
} {2}
|
||||
do_test laststmtchanges-6.4 {
|
||||
execsql {
|
||||
ROLLBACK;
|
||||
CREATE INDEX t3_i1 ON t3(a);
|
||||
BEGIN;
|
||||
DELETE FROM t3;
|
||||
SELECT changes();
|
||||
}
|
||||
} {2}
|
||||
do_test laststmtchanges-6.5 {
|
||||
execsql { ROLLBACK }
|
||||
set nTotalChange [execsql {SELECT total_changes()}]
|
||||
expr 0
|
||||
} {0}
|
||||
do_test laststmtchanges-6.6 {
|
||||
execsql {
|
||||
SELECT total_changes();
|
||||
DELETE FROM t3;
|
||||
SELECT total_changes();
|
||||
}
|
||||
} [list $nTotalChange [expr $nTotalChange+2]]
|
||||
|
||||
finish_test
|
||||
|
||||
+7
-1
@@ -16,7 +16,7 @@
|
||||
# to see what happens in the library if a malloc were to really fail
|
||||
# due to an out-of-memory situation.
|
||||
#
|
||||
# $Id: malloc.test,v 1.68 2008/10/06 05:32:19 danielk1977 Exp $
|
||||
# $Id: malloc.test,v 1.69 2008/11/03 09:39:45 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -671,6 +671,12 @@ do_malloc_test 28 -sqlprep {
|
||||
SELECT * FROM v1;
|
||||
}
|
||||
|
||||
do_malloc_test 29 -sqlprep {
|
||||
CREATE TABLE t1(a TEXT, b TEXT);
|
||||
} -sqlbody {
|
||||
INSERT INTO t1 VALUES(1, -234);
|
||||
}
|
||||
|
||||
# Ensure that no file descriptors were leaked.
|
||||
do_test malloc-99.X {
|
||||
catch {db close}
|
||||
|
||||
+27
-2
@@ -12,7 +12,7 @@
|
||||
# This test script checks malloc failures in LIMIT operations for
|
||||
# UPDATE/DELETE statements.
|
||||
#
|
||||
# $Id: mallocJ.test,v 1.1 2008/10/10 13:34:30 shane Exp $
|
||||
# $Id: mallocJ.test,v 1.5 2008/11/11 18:29:00 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -20,7 +20,7 @@ source $testdir/malloc_common.tcl
|
||||
|
||||
ifcapable {update_delete_limit} {
|
||||
|
||||
do_malloc_test mallocJ-4 -sqlprep {
|
||||
do_malloc_test mallocJ-1 -sqlprep {
|
||||
DROP TABLE IF EXISTS t1;
|
||||
CREATE TABLE t1(x int, y int);
|
||||
INSERT INTO t1 VALUES(1,1);
|
||||
@@ -38,4 +38,29 @@ ifcapable {update_delete_limit} {
|
||||
|
||||
}
|
||||
|
||||
# ticket #3467
|
||||
do_malloc_test mallocJ-2 -sqlprep {
|
||||
CREATE TABLE t1(a,b);
|
||||
INSERT INTO t1 VALUES(1,2);
|
||||
PRAGMA vdbe_trace=ON;
|
||||
} -sqlbody {
|
||||
SELECT a, b, 'abc' FROM t1
|
||||
UNION
|
||||
SELECT b, a, 'xyz' FROM t1
|
||||
ORDER BY 2, 3;
|
||||
}
|
||||
|
||||
# ticket #3478
|
||||
do_malloc_test mallocJ-3 -sqlbody {
|
||||
EXPLAIN COMMIT
|
||||
}
|
||||
|
||||
# ticket #3485
|
||||
do_malloc_test mallocJ-4 -sqlprep {
|
||||
CREATE TABLE t1(a,b,c);
|
||||
CREATE TABLE t2(x,y,z);
|
||||
} -sqlbody {
|
||||
SELECT * FROM (SELECT a,b FROM t1 UNION ALL SELECT x, y FROM t2) ORDER BY 1
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
+2
-2
@@ -10,7 +10,7 @@
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library.
|
||||
#
|
||||
# $Id: misc7.test,v 1.24 2008/08/22 13:57:39 pweilbacher Exp $
|
||||
# $Id: misc7.test,v 1.25 2008/10/30 15:03:16 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -397,7 +397,7 @@ if {$tcl_platform(platform)!="windows" && $tcl_platform(platform)!="os2"} {
|
||||
catchsql {
|
||||
SELECT count(*) FROM t3;
|
||||
}
|
||||
} {1 {database is locked}}
|
||||
} {1 {unable to open database file}}
|
||||
do_test misc7-17.2 {
|
||||
# Note that the -readonly flag must be cleared before the -permissions
|
||||
# are set. Otherwise, when using tcl 8.5 on mac, the fact that the
|
||||
|
||||
+24
-1
@@ -9,7 +9,7 @@
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# $Id: mutex1.test,v 1.15 2008/10/07 15:25:49 drh Exp $
|
||||
# $Id: mutex1.test,v 1.16 2008/11/04 14:55:47 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -150,6 +150,29 @@ ifcapable threadsafe {
|
||||
} {0}
|
||||
}
|
||||
|
||||
# Test the sqlite3_db_mutex() function.
|
||||
#
|
||||
do_test mutex1.4.1 {
|
||||
catch {db close}
|
||||
sqlite3 db test.db
|
||||
enter_db_mutex db
|
||||
db eval {SELECT 1, 2, 3}
|
||||
} {1 2 3}
|
||||
do_test mutex1.4.2 {
|
||||
leave_db_mutex db
|
||||
db eval {SELECT 1, 2, 3}
|
||||
} {1 2 3}
|
||||
do_test mutex1.4.3 {
|
||||
catch {db close}
|
||||
sqlite3 db test.db -nomutex 1
|
||||
enter_db_mutex db
|
||||
db eval {SELECT 1, 2, 3}
|
||||
} {1 2 3}
|
||||
do_test mutex1.4.4 {
|
||||
leave_db_mutex db
|
||||
db eval {SELECT 1, 2, 3}
|
||||
} {1 2 3}
|
||||
|
||||
do_test mutex1-X {
|
||||
catch {db close}
|
||||
sqlite3_shutdown
|
||||
|
||||
+3
-1
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is page cache subsystem.
|
||||
#
|
||||
# $Id: pager.test,v 1.31 2008/08/20 14:49:25 danielk1977 Exp $
|
||||
# $Id: pager.test,v 1.32 2008/10/17 18:51:53 danielk1977 Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -415,12 +415,14 @@ ifcapable memorydb {
|
||||
pager_truncate $::p2 5
|
||||
} {}
|
||||
do_test pager-4.6.3 {
|
||||
set page1 [page_get $::p2 1]
|
||||
for {set i 1} {$i<5} {incr i} {
|
||||
set p [page_get $::p2 $i]
|
||||
page_write $p "Page $i"
|
||||
pager_commit $::p2
|
||||
page_unref $p
|
||||
}
|
||||
page_unref $page1
|
||||
# pager_truncate $::p2 3
|
||||
} {}
|
||||
do_test pager-4.6.4 {
|
||||
|
||||
+20
-16
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is page cache subsystem.
|
||||
#
|
||||
# $Id: pager2.test,v 1.7 2008/08/20 14:49:25 danielk1977 Exp $
|
||||
# $Id: pager2.test,v 1.8 2008/10/17 18:51:53 danielk1977 Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -33,13 +33,13 @@ do_test pager2-1.0 {
|
||||
} {0}
|
||||
do_test pager2-1.1 {
|
||||
pager_stats $::p1
|
||||
} {ref 0 page 0 max 10 size 0 state 0 err 0 hit 0 miss 0 ovfl 0}
|
||||
} {ref 0 page 0 max 10 size 0 state 4 err 0 hit 0 miss 0 ovfl 0}
|
||||
do_test pager2-1.2 {
|
||||
pager_pagecount $::p1
|
||||
} {0}
|
||||
do_test pager2-1.3 {
|
||||
pager_stats $::p1
|
||||
} {ref 0 page 0 max 10 size 0 state 0 err 0 hit 0 miss 0 ovfl 0}
|
||||
} {ref 0 page 0 max 10 size 0 state 4 err 0 hit 0 miss 0 ovfl 0}
|
||||
do_test pager2-1.4 {
|
||||
pager_close $::p1
|
||||
} {}
|
||||
@@ -62,7 +62,7 @@ do_test pager2-2.3.1 {
|
||||
} {}
|
||||
do_test pager2-2.3.2 {
|
||||
pager_stats $::p1
|
||||
} {ref 0 page 0 max 10 size 0 state 0 err 0 hit 0 miss 0 ovfl 0}
|
||||
} {ref 0 page 0 max 10 size 0 state 4 err 0 hit 0 miss 0 ovfl 0}
|
||||
do_test pager2-2.3.3 {
|
||||
set v [catch {
|
||||
set ::g1 [page_get $::p1 1]
|
||||
@@ -72,7 +72,7 @@ do_test pager2-2.3.3 {
|
||||
} {0}
|
||||
do_test pager2-2.3.3 {
|
||||
pager_stats $::p1
|
||||
} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
|
||||
} {ref 1 page 1 max 10 size 0 state 4 err 0 hit 0 miss 1 ovfl 0}
|
||||
do_test pager2-2.3.4 {
|
||||
set ::gx [page_lookup $::p1 1]
|
||||
page_unref $::gx
|
||||
@@ -80,22 +80,22 @@ do_test pager2-2.3.4 {
|
||||
} {1}
|
||||
do_test pager2-2.3.5 {
|
||||
pager_stats $::p1
|
||||
} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
|
||||
} {ref 1 page 1 max 10 size 0 state 4 err 0 hit 0 miss 1 ovfl 0}
|
||||
do_test pager2-2.3.6 {
|
||||
expr {$::g1==$::gx}
|
||||
} {1}
|
||||
do_test pager2-2.3.7 {
|
||||
pager_stats $::p1
|
||||
} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
|
||||
} {ref 1 page 1 max 10 size 0 state 4 err 0 hit 0 miss 1 ovfl 0}
|
||||
do_test pager2-2.4 {
|
||||
pager_stats $::p1
|
||||
} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
|
||||
} {ref 1 page 1 max 10 size 0 state 4 err 0 hit 0 miss 1 ovfl 0}
|
||||
do_test pager2-2.5 {
|
||||
pager_pagecount $::p1
|
||||
} {0}
|
||||
do_test pager2-2.6 {
|
||||
pager_stats $::p1
|
||||
} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
|
||||
} {ref 1 page 1 max 10 size 0 state 4 err 0 hit 0 miss 1 ovfl 0}
|
||||
do_test pager2-2.7 {
|
||||
page_number $::g1
|
||||
} {1}
|
||||
@@ -107,7 +107,7 @@ do_test pager2-2.9 {
|
||||
} {}
|
||||
do_test pager2-2.10 {
|
||||
pager_stats $::p1
|
||||
} {ref 0 page 1 max 10 size 0 state 0 err 0 hit 0 miss 1 ovfl 0}
|
||||
} {ref 0 page 1 max 10 size 0 state 4 err 0 hit 0 miss 1 ovfl 0}
|
||||
do_test pager2-2.11 {
|
||||
set ::g1 [page_get $::p1 1]
|
||||
expr {$::g1!=0}
|
||||
@@ -117,7 +117,7 @@ do_test pager2-2.12 {
|
||||
} {1}
|
||||
do_test pager2-2.13 {
|
||||
pager_stats $::p1
|
||||
} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 1 miss 1 ovfl 0}
|
||||
} {ref 1 page 1 max 10 size 0 state 4 err 0 hit 1 miss 1 ovfl 0}
|
||||
do_test pager2-2.14 {
|
||||
set v [catch {
|
||||
page_write $::g1 "Page-One"
|
||||
@@ -138,19 +138,19 @@ do_test pager2-2.17 {
|
||||
} {0 {}}
|
||||
do_test pager2-2.20 {
|
||||
pager_stats $::p1
|
||||
} {ref 1 page 1 max 10 size 1 state 1 err 0 hit 1 miss 1 ovfl 0}
|
||||
} {ref 1 page 1 max 10 size 1 state 4 err 0 hit 1 miss 1 ovfl 0}
|
||||
do_test pager2-2.19 {
|
||||
pager_pagecount $::p1
|
||||
} {1}
|
||||
do_test pager2-2.21 {
|
||||
pager_stats $::p1
|
||||
} {ref 1 page 1 max 10 size 1 state 1 err 0 hit 1 miss 1 ovfl 0}
|
||||
} {ref 1 page 1 max 10 size 1 state 4 err 0 hit 1 miss 1 ovfl 0}
|
||||
do_test pager2-2.22 {
|
||||
page_unref $::g1
|
||||
} {}
|
||||
do_test pager2-2.23 {
|
||||
pager_stats $::p1
|
||||
} {ref 0 page 1 max 10 size 1 state 0 err 0 hit 1 miss 1 ovfl 0}
|
||||
} {ref 0 page 1 max 10 size 1 state 4 err 0 hit 1 miss 1 ovfl 0}
|
||||
do_test pager2-2.24 {
|
||||
set v [catch {
|
||||
page_get $::p1 1
|
||||
@@ -215,14 +215,17 @@ do_test pager2-3.5 {
|
||||
page_unref $::g(1)
|
||||
} {}
|
||||
for {set i 2} {$i<=20} {incr i} {
|
||||
set page1 [page_get $::p1 1]
|
||||
do_test pager2-3.6.[expr {$i-1}] [subst {
|
||||
set gx \[page_get $::p1 $i\]
|
||||
set v \[page_read \$gx\]
|
||||
page_unref \$gx
|
||||
set v
|
||||
}] "Page-$i"
|
||||
page_unref $page1
|
||||
}
|
||||
for {set i 1} {$i<=20} {incr i} {
|
||||
set page1 [page_get $::p1 1]
|
||||
regsub -all CNT {
|
||||
set ::g1 [page_get $::p1 CNT]
|
||||
set ::g2 [page_get $::p1 CNT]
|
||||
@@ -244,6 +247,7 @@ for {set i 1} {$i<=20} {incr i} {
|
||||
expr {$vy==$::vx}
|
||||
} $i body;
|
||||
do_test pager2-3.7.$i.3 $body {1}
|
||||
page_unref $page1
|
||||
}
|
||||
do_test pager2-3.99 {
|
||||
pager_close $::p1
|
||||
@@ -281,7 +285,7 @@ do_test pager2-4.3 {
|
||||
} {ref 1}
|
||||
do_test pager2-4.4 {
|
||||
lrange [pager_stats $::p1] 8 9
|
||||
} {state 1}
|
||||
} {state 4}
|
||||
|
||||
for {set i 1} {$i<20} {incr i} {
|
||||
do_test pager2-4.5.$i.0 {
|
||||
@@ -396,7 +400,7 @@ breakpoint
|
||||
do_test pager2-4.5.$i.10 {
|
||||
pager_commit $p1
|
||||
lrange [pager_stats $p1] 8 9
|
||||
} {state 1}
|
||||
} {state 4}
|
||||
}
|
||||
|
||||
do_test pager2-4.99 {
|
||||
|
||||
+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
|
||||
|
||||
+120
-23
@@ -9,7 +9,7 @@
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# $Id: permutations.test,v 1.35 2008/10/11 17:04:04 danielk1977 Exp $
|
||||
# $Id: permutations.test,v 1.39 2008/11/19 01:20:26 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -448,6 +448,24 @@ run_tests "autovacuum_ioerr" -description {
|
||||
pragma auto_vacuum = 1
|
||||
} -include ioerr.test
|
||||
|
||||
# Run tests with an in-memory journal.
|
||||
#
|
||||
run_tests "inmemory_journal" -description {
|
||||
Run tests with an in-memory journal file.
|
||||
} -presql {
|
||||
pragma journal_mode = 'memory'
|
||||
} -exclude {
|
||||
# Exclude all tests that simulate IO errors.
|
||||
autovacuum_ioerr2.test incrvacuum_ioerr.test ioerr.test
|
||||
ioerr.test ioerr2.test ioerr3.test ioerr4.test ioerr5.test
|
||||
vacuum3.test incrblob_err.test diskfull.test
|
||||
|
||||
# Exclude test scripts that use tcl IO to access journal files or count
|
||||
# the number of fsync() calls.
|
||||
pager.test exclusive.test jrnlmode.test sync.test misc1.test
|
||||
journal1.test conflict.test
|
||||
}
|
||||
|
||||
ifcapable mem3 {
|
||||
run_tests "memsys3" -description {
|
||||
Run tests using the allocator in mem3.c.
|
||||
@@ -487,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
|
||||
@@ -547,27 +565,6 @@ ifcapable threadsafe {
|
||||
}
|
||||
}
|
||||
|
||||
run_tests "memsys6" -description {
|
||||
Run tests using the allocator in mem6.c.
|
||||
} -exclude {
|
||||
capi3.test capi3c.test
|
||||
} -initialize {
|
||||
catch {db close}
|
||||
sqlite3_reset_auto_extension
|
||||
sqlite3_shutdown
|
||||
sqlite3_config_chunkalloc 0
|
||||
install_malloc_faultsim 1
|
||||
sqlite3_initialize
|
||||
autoinstall_test_functions
|
||||
} -shutdown {
|
||||
catch {db close}
|
||||
sqlite3_reset_auto_extension
|
||||
sqlite3_shutdown
|
||||
sqlite3_config_heap 0 0
|
||||
install_malloc_faultsim 1
|
||||
sqlite3_initialize
|
||||
}
|
||||
|
||||
# run_tests "crash_safe_append" -description {
|
||||
# Run crash.test with persistent journals on a SAFE_APPEND file-system.
|
||||
# } -initialize {
|
||||
@@ -607,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
|
||||
#############################################################################
|
||||
|
||||
+21
-1
@@ -12,7 +12,7 @@
|
||||
#
|
||||
# This file implements tests for the PRAGMA command.
|
||||
#
|
||||
# $Id: pragma.test,v 1.68 2008/10/10 17:47:21 danielk1977 Exp $
|
||||
# $Id: pragma.test,v 1.69 2008/10/23 05:45:07 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -568,6 +568,26 @@ ifcapable tempdb {
|
||||
}
|
||||
} {0 col_main {} 0 {} 0}
|
||||
}
|
||||
|
||||
breakpoint
|
||||
do_test pragma-6.7 {
|
||||
execsql {
|
||||
CREATE TABLE test_table(
|
||||
one INT NOT NULL DEFAULT -1,
|
||||
two text,
|
||||
three VARCHAR(45, 65) DEFAULT 'abcde',
|
||||
four REAL DEFAULT X'abcdef',
|
||||
five DEFAULT CURRENT_TIME
|
||||
);
|
||||
PRAGMA table_info(test_table);
|
||||
}
|
||||
} [concat \
|
||||
{0 one INT 1 -1 0} \
|
||||
{1 two text 0 {} 0} \
|
||||
{2 three {VARCHAR(45, 65)} 0 'abcde' 0} \
|
||||
{3 four REAL 0 X'abcdef' 0} \
|
||||
{4 five {} 0 CURRENT_TIME 0} \
|
||||
]
|
||||
} ;# ifcapable schema_pragmas
|
||||
# Miscellaneous tests
|
||||
#
|
||||
|
||||
+5
-2
@@ -13,7 +13,7 @@
|
||||
# caused by an ON CONFLICT ROLLBACK clause aborts any other pending
|
||||
# statements.
|
||||
#
|
||||
# $Id: rollback.test,v 1.9 2008/10/13 14:16:11 drh Exp $
|
||||
# $Id: rollback.test,v 1.10 2008/10/17 18:51:53 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -81,7 +81,10 @@ do_test rollback-1.9 {
|
||||
|
||||
set permutation ""
|
||||
catch {set permutation $::permutations_test_prefix}
|
||||
if {$tcl_platform(platform) == "unix" && $permutation ne "onefile"} {
|
||||
if {$tcl_platform(platform) == "unix"
|
||||
&& $permutation ne "onefile"
|
||||
&& $permutation ne "inmemory_journal"
|
||||
} {
|
||||
do_test rollback-2.1 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
|
||||
+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
|
||||
|
||||
+3
-3
@@ -14,7 +14,7 @@
|
||||
# Make sure that application-defined functions are able to recursively
|
||||
# invoke SQL statements that create and drop virtual tables.
|
||||
#
|
||||
# $Id: tkt3080.test,v 1.1 2008/04/28 17:12:11 drh Exp $
|
||||
# $Id: tkt3080.test,v 1.2 2008/11/05 16:37:35 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -48,7 +48,7 @@ do_test tkt3080.4 {
|
||||
db eval {
|
||||
SELECT name FROM sqlite_master;
|
||||
}
|
||||
} {t1 t2}
|
||||
} {t1 t2 t3}
|
||||
|
||||
ifcapable vtab {
|
||||
register_echo_module [sqlite3_connection_pointer db]
|
||||
@@ -66,7 +66,7 @@ ifcapable vtab {
|
||||
SELECT execsql(x) FROM t1
|
||||
}
|
||||
execsql {SELECT name FROM sqlite_master}
|
||||
} {t1 t2}
|
||||
} {t1 t2 t3}
|
||||
do_test tkt3080.11 {
|
||||
execsql {SELECT * FROM t2}
|
||||
} {123}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
# 2008 October 20
|
||||
#
|
||||
# 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 regression tests for SQLite library.
|
||||
#
|
||||
# This file implements tests to verify that ticket #3442 has been
|
||||
# fixed.
|
||||
#
|
||||
#
|
||||
# $Id: tkt3442.test,v 1.1 2008/10/22 16:04:43 shane Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
|
||||
# Create a schema with some indexes.
|
||||
#
|
||||
do_test tkt3442-1.1 {
|
||||
execsql {
|
||||
CREATE TABLE listhash(
|
||||
key INTEGER PRIMARY KEY,
|
||||
id TEXT,
|
||||
node INTEGER
|
||||
);
|
||||
CREATE UNIQUE INDEX ididx ON listhash(id);
|
||||
}
|
||||
} {}
|
||||
|
||||
|
||||
# Explain Query Plan
|
||||
#
|
||||
proc EQP {sql} {
|
||||
uplevel "execsql {EXPLAIN QUERY PLAN $sql}"
|
||||
}
|
||||
|
||||
|
||||
# These tests perform an EXPLAIN QUERY PLAN on both versions of the
|
||||
# SELECT referenced in ticket #3442 (both '5000' and "5000")
|
||||
# and verify that the query plan is the same.
|
||||
#
|
||||
ifcapable explain {
|
||||
do_test tkt3442-1.2 {
|
||||
EQP { SELECT node FROM listhash WHERE id='5000' LIMIT 1; }
|
||||
} {0 0 {TABLE listhash WITH INDEX ididx}}
|
||||
do_test tkt3442-1.3 {
|
||||
EQP { SELECT node FROM listhash WHERE id="5000" LIMIT 1; }
|
||||
} {0 0 {TABLE listhash WITH INDEX ididx}}
|
||||
}
|
||||
|
||||
|
||||
# Some extra tests testing other permutations of 5000.
|
||||
#
|
||||
ifcapable explain {
|
||||
do_test tkt3442-1.4 {
|
||||
EQP { SELECT node FROM listhash WHERE id=5000 LIMIT 1; }
|
||||
} {0 0 {TABLE listhash WITH INDEX ididx}}
|
||||
}
|
||||
do_test tkt3442-1.5 {
|
||||
catchsql {
|
||||
SELECT node FROM listhash WHERE id=[5000] LIMIT 1;
|
||||
}
|
||||
} {1 {no such column: 5000}}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
# 2008 October 29
|
||||
#
|
||||
# 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 regression tests for SQLite library.
|
||||
#
|
||||
# $Id: tkt3457.test,v 1.1 2008/10/29 07:01:57 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
if {$tcl_platform(platform) != "unix"} {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# To roll back a hot-journal file, the application needs read and write
|
||||
# permission on the journal file in question. The following tests test
|
||||
# the outcome of trying to rollback a hot-journal file when this is not
|
||||
# the case.
|
||||
#
|
||||
# tkt3457-1.2: Application has neither read, nor write permission on
|
||||
# the hot-journal file. Result: SQLITE_CANTOPEN.
|
||||
#
|
||||
# tkt3457-1.3: Application has write but not read permission on
|
||||
# the hot-journal file. Result: SQLITE_CANTOPEN.
|
||||
#
|
||||
# tkt3457-1.4: Application has read but not write permission on
|
||||
# the hot-journal file. Result: SQLITE_CANTOPEN.
|
||||
#
|
||||
# tkt3457-1.5: Application has read/write permission on the hot-journal
|
||||
# file. Result: SQLITE_OK.
|
||||
#
|
||||
do_test tkt3457-1.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a, b, c);
|
||||
INSERT INTO t1 VALUES(1, 2, 3);
|
||||
BEGIN;
|
||||
INSERT INTO t1 VALUES(4, 5, 6);
|
||||
}
|
||||
|
||||
file copy -force test.db bak.db
|
||||
file copy -force test.db-journal bak.db-journal
|
||||
|
||||
execsql COMMIT
|
||||
} {}
|
||||
|
||||
do_test tkt3457-1.2 {
|
||||
file copy -force bak.db-journal test.db-journal
|
||||
file attributes test.db-journal -permissions ---------
|
||||
catchsql { SELECT * FROM t1 }
|
||||
} {1 {unable to open database file}}
|
||||
do_test tkt3457-1.3 {
|
||||
file copy -force bak.db-journal test.db-journal
|
||||
file attributes test.db-journal -permissions -w--w--w-
|
||||
catchsql { SELECT * FROM t1 }
|
||||
} {1 {unable to open database file}}
|
||||
do_test tkt3457-1.4 {
|
||||
file copy -force bak.db-journal test.db-journal
|
||||
file attributes test.db-journal -permissions r--r--r--
|
||||
catchsql { SELECT * FROM t1 }
|
||||
} {1 {unable to open database file}}
|
||||
|
||||
do_test tkt3457-1.5 {
|
||||
file copy -force bak.db-journal test.db-journal
|
||||
file attributes test.db-journal -permissions rw-rw-rw-
|
||||
catchsql { SELECT * FROM t1 }
|
||||
} {0 {1 2 3 4 5 6}}
|
||||
|
||||
finish_test
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user