Enable async testing. Modify the OS layer interface. Add the sqlite3_aux.h include file. Add tests for boolean value representation in file format 4. (CVS 2866)

FossilOrigin-Name: b8332aa8b83142898779972b3dff13cbe3c78623
This commit is contained in:
drh 2006-01-06 03:29:56 +00:00
parent 47ded16fdc
commit e19d594067
10 changed files with 325 additions and 285 deletions

View File

@ -191,6 +191,7 @@ TESTSRC = \
$(TOP)/src/test4.c \
$(TOP)/src/test5.c \
$(TOP)/src/test6.c \
$(TOP)/src/test_async.c \
$(TOP)/src/utf.c \
$(TOP)/src/util.c \
$(TOP)/src/vdbe.c \
@ -207,6 +208,7 @@ HDR = \
$(TOP)/src/os.h \
$(TOP)/src/os_common.h \
$(TOP)/src/sqliteInt.h \
$(TOP)/src/sqlite3_aux.h \
$(TOP)/src/vdbe.h \
parse.h

View File

@ -133,6 +133,7 @@ TESTSRC = \
$(TOP)/src/test4.c \
$(TOP)/src/test5.c \
$(TOP)/src/test6.c \
$(TOP)/src/test_async.c \
$(TOP)/src/utf.c \
$(TOP)/src/util.c \
$(TOP)/src/vdbe.c \
@ -151,6 +152,7 @@ HDR = \
$(TOP)/src/os.h \
$(TOP)/src/os_common.h \
$(TOP)/src/sqliteInt.h \
$(TOP)/src/sqlite3_aux.h \
$(TOP)/src/vdbe.h \
parse.h

View File

@ -1,6 +1,6 @@
C Formatting\schanges\sin\sbtree.c.\s(CVS\s2865)
D 2006-01-06T01:42:58
F Makefile.in e3c6b3a38d734d41574c04f2fc90d18de2b87102
C Enable\sasync\stesting.\s\sModify\sthe\sOS\slayer\sinterface.\s\sAdd\sthe\ssqlite3_aux.h\sinclude\sfile.\s\sAdd\stests\sfor\sboolean\svalue\srepresentation\sin\sfile\sformat\s4.\s(CVS\s2866)
D 2006-01-06T03:29:57
F Makefile.in 899551ac1dfad4131a4480176eab9e03c64b71ea
F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
F VERSION b818cce180263e590a00ad4509a713892c3eecea
@ -19,7 +19,7 @@ F doc/lemon.html f0f682f50210928c07e562621c3b7e8ab912a538
F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
F ltmain.sh f6b283068efa69f06eb8aa1fe4bddfdbdeb35826
F main.mk a0d69de7dcb8f2d439412a78a58a999edc28561c
F main.mk d5fbd33af46d70d654689429f30be08c6f5d36b9
F mkdll.sh 5ec23622515d5bf8969404e80cfb5e220ddf0512
F mkopcodec.awk bd46ad001c98dfbab07b1713cb8e692fa0e5415d
F mkopcodeh.awk 071dbba4eaf56c8d643baf4604a043af35683316
@ -50,8 +50,8 @@ F src/insert.c d167f9d41932ddaff9162f116e2abc514b0680b6
F src/legacy.c 59757d857ab95fcbb0ac27692d3201e35f093dd7
F src/main.c c1d8d2022a65104c847880882fbce9ba32381530
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
F src/os.c 7b4a002d9c9421580276db55d2329636a604e8ef
F src/os.h cc99e1515696728ba64c77fffa781ebadea34619
F src/os.c a1953975771e1afa161a96e720e58a6f77f946e4
F src/os.h 1f825a8ec854abe8f4cd3a1851c5f6c43e58fbf8
F src/os_common.h d0b1f2f32926e9b6db7886a7f43008b596a9e926
F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c
F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3
@ -69,16 +69,17 @@ F src/random.c ff5e9a8cad790e2a51cd4d2e7737dc8540e09d1d
F src/select.c a60e5c7fad9ce7adc78d9eb32a0a89dd5acd04fb
F src/shell.c 66b073375efbdee19045e7e0cd38b85f9aff71da
F src/sqlite.h.in ba3a29daa6a16e054191ccb384a981964e882a1d
F src/sqlite3_aux.h c449ecf05325e4341da930ac963430c86055c52f
F src/sqliteInt.h 06a37ed74f803ae669292f65e35977254d8e7be1
F src/table.c 486dcfce532685b53b5a2b5da8bba0ded6fb2316
F src/tclsqlite.c 351ae47649ac7119d772ab74ed7091f5e400041e
F src/tclsqlite.c 6794d34f6ad3dc7dd25eecde887696e569f8efe1
F src/test1.c 89e25646feceaf09e55c11ecba03ddcfd7cf7c0a
F src/test2.c 36390cdfc70c08e5ee0b466d0654a117f398bbff
F src/test3.c 9742aa146eb750cab81c1d5605286c3a0eb88054
F src/test4.c a8fd681e139e1c61f22a77d07fc3a99cb28fff3f
F src/test5.c 7162f8526affb771c4ed256826eee7bb9eca265f
F src/test6.c cb811391ec0b7c75f29e545d4820a9cf19f3637e
F src/test_async.c a383aed2753e47d2ac4b5397c43f6ac216a237ae
F src/test_async.c 7b27d91e288503a568bfbc607b58dcfb74f09057
F src/tokenize.c 7a3a3d3cc734f684a77c4dfd09eb46fcee25394c
F src/trigger.c 858c0a4974035b002fd2192399c6076ac7b75e1f
F src/update.c c72e9cbbc0adf8d728c1c39ace03d4adb29b5cfb
@ -157,6 +158,7 @@ F test/enc2.test 6ea55732ddffd340f3d3a29cc33645e9ded481c7
F test/enc3.test f6a5f0b7b7f3a88f030d3143729b87cd5c86d837
F test/expr.test 06381174d8c25fbbfd9ed335fe0cde835d39123d
F test/fkey1.test 153004438d51e6769fb1ce165f6313972d6263ce
F test/format4.test 9f31d41d4f926cab97b2ebe6be00a6ab12dece87
F test/func.test a7119afcc16abdf24b24486684fb888279008f75
F test/hook.test fc6821544ab2e0aacb398b742cdca925d4fb884c
F test/in.test cead6165aebbe0d451bb2263a307173acfeb6240
@ -336,7 +338,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P 3aa8befedf4534cd100a7309997a4ad2ba08af20
R 9cd535a89cd298ffd8e9b65d3f2c3f9a
P f1922da2d20c5091678e47cc4f43a2a9d141a3b1
R cef6c464b1bd96d585319f7184eaa0c9
U drh
Z a5a9ef920432f3770a07cda8da51fc95
Z 3e96ca4b789b1816bc110ed7eb3a7071

View File

@ -1 +1 @@
f1922da2d20c5091678e47cc4f43a2a9d141a3b1
b8332aa8b83142898779972b3dff13cbe3c78623

View File

@ -69,42 +69,6 @@ int sqlite3OsLockState(OsFile *id){
int sqlite3OsCheckReservedLock(OsFile *id){
return id->pMethod->xCheckReservedLock(id);
}
static void**getOsRoutinePtr(int eRoutine){
switch( eRoutine ){
case SQLITE_OS_ROUTINE_OPENREADWRITE:
return (void **)(&sqlite3Os.xOpenReadWrite);
case SQLITE_OS_ROUTINE_OPENREADONLY:
return (void **)(&sqlite3Os.xOpenReadOnly);
case SQLITE_OS_ROUTINE_OPENEXCLUSIVE:
return (void **)(&sqlite3Os.xOpenExclusive);
case SQLITE_OS_ROUTINE_DELETE:
return (void **)(&sqlite3Os.xDelete);
case SQLITE_OS_ROUTINE_FILEEXISTS:
return (void **)(&sqlite3Os.xFileExists);
case SQLITE_OS_ROUTINE_SYNCDIRECTORY:
return (void **)(&sqlite3Os.xSyncDirectory);
default:
assert(!"Illegal eRoutine value");
}
return 0;
struct sqlite3OsVtbl *sqlite3_os_switch(void){
return &sqlite3Os;
}
void *sqlite3_os_routine_get(int eRoutine){
return *getOsRoutinePtr(eRoutine);
}
void *sqlite3_os_routine_set(int eRoutine, void *pRoutine){
void **ppRet = getOsRoutinePtr(eRoutine);
void *pRet = *ppRet;
*ppRet = pRoutine;
return pRet;
}
void sqlite3_os_enter_mutex(){
sqlite3Os.xEnterMutex();
}
void sqlite3_os_leave_mutex(){
sqlite3Os.xLeaveMutex();
}

198
src/os.h
View File

@ -16,6 +16,7 @@
*/
#ifndef _SQLITE_OS_H_
#define _SQLITE_OS_H_
#include "sqlite3_aux.h"
/*
** Figure out if we are dealing with Unix, Windows or MacOS.
@ -43,45 +44,6 @@
#endif
/*
** Forward declarations
*/
typedef struct OsFile OsFile;
typedef struct IoMethod IoMethod;
/*
** An instance of the following structure contains pointers to all
** methods on an OsFile object.
*/
struct IoMethod {
int (*xClose)(OsFile**);
int (*xOpenDirectory)(OsFile*, const char*);
int (*xRead)(OsFile*, void*, int amt);
int (*xWrite)(OsFile*, const void*, int amt);
int (*xSeek)(OsFile*, i64 offset);
int (*xTruncate)(OsFile*, i64 size);
int (*xSync)(OsFile*, int);
void (*xSetFullSync)(OsFile *id, int setting);
int (*xFileHandle)(OsFile *id);
int (*xFileSize)(OsFile*, i64 *pSize);
int (*xLock)(OsFile*, int);
int (*xUnlock)(OsFile*, int);
int (*xLockState)(OsFile *id);
int (*xCheckReservedLock)(OsFile *id);
};
/*
** The OsFile object describes an open disk file in an OS-dependent way.
** The version of OsFile defined here is a generic version. Each OS
** implementation defines its own subclass of this structure that contains
** additional information needed to handle file I/O. But the pMethod
** entry (pointing to the virtual function table) always occurs first
** so that we can always find the appropriate methods.
*/
struct OsFile {
IoMethod const *pMethod;
};
/*
** Define the maximum size of a temporary filename
*/
@ -112,164 +74,6 @@ struct OsFile {
# define TEMP_FILE_PREFIX "sqlite_"
#endif
/*
** The following values may be passed as the second argument to
** sqlite3OsLock(). The various locks exhibit the following semantics:
**
** SHARED: Any number of processes may hold a SHARED lock simultaneously.
** RESERVED: A single process may hold a RESERVED lock on a file at
** any time. Other processes may hold and obtain new SHARED locks.
** PENDING: A single process may hold a PENDING lock on a file at
** any one time. Existing SHARED locks may persist, but no new
** SHARED locks may be obtained by other processes.
** EXCLUSIVE: An EXCLUSIVE lock precludes all other locks.
**
** PENDING_LOCK may not be passed directly to sqlite3OsLock(). Instead, a
** process that requests an EXCLUSIVE lock may actually obtain a PENDING
** lock. This can be upgraded to an EXCLUSIVE lock by a subsequent call to
** sqlite3OsLock().
*/
#define NO_LOCK 0
#define SHARED_LOCK 1
#define RESERVED_LOCK 2
#define PENDING_LOCK 3
#define EXCLUSIVE_LOCK 4
/*
** File Locking Notes: (Mostly about windows but also some info for Unix)
**
** We cannot use LockFileEx() or UnlockFileEx() on Win95/98/ME because
** those functions are not available. So we use only LockFile() and
** UnlockFile().
**
** LockFile() prevents not just writing but also reading by other processes.
** A SHARED_LOCK is obtained by locking a single randomly-chosen
** byte out of a specific range of bytes. The lock byte is obtained at
** random so two separate readers can probably access the file at the
** same time, unless they are unlucky and choose the same lock byte.
** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range.
** There can only be one writer. A RESERVED_LOCK is obtained by locking
** a single byte of the file that is designated as the reserved lock byte.
** A PENDING_LOCK is obtained by locking a designated byte different from
** the RESERVED_LOCK byte.
**
** On WinNT/2K/XP systems, LockFileEx() and UnlockFileEx() are available,
** which means we can use reader/writer locks. When reader/writer locks
** are used, the lock is placed on the same range of bytes that is used
** for probabilistic locking in Win95/98/ME. Hence, the locking scheme
** will support two or more Win95 readers or two or more WinNT readers.
** But a single Win95 reader will lock out all WinNT readers and a single
** WinNT reader will lock out all other Win95 readers.
**
** The following #defines specify the range of bytes used for locking.
** SHARED_SIZE is the number of bytes available in the pool from which
** a random byte is selected for a shared lock. The pool of bytes for
** shared locks begins at SHARED_FIRST.
**
** These #defines are available in os.h so that Unix can use the same
** byte ranges for locking. This leaves open the possiblity of having
** clients on win95, winNT, and unix all talking to the same shared file
** and all locking correctly. To do so would require that samba (or whatever
** tool is being used for file sharing) implements locks correctly between
** windows and unix. I'm guessing that isn't likely to happen, but by
** using the same locking range we are at least open to the possibility.
**
** Locking in windows is manditory. For this reason, we cannot store
** actual data in the bytes used for locking. The pager never allocates
** the pages involved in locking therefore. SHARED_SIZE is selected so
** that all locks will fit on a single page even at the minimum page size.
** PENDING_BYTE defines the beginning of the locks. By default PENDING_BYTE
** is set high so that we don't have to allocate an unused page except
** for very large databases. But one should test the page skipping logic
** by setting PENDING_BYTE low and running the entire regression suite.
**
** Changing the value of PENDING_BYTE results in a subtly incompatible
** file format. Depending on how it is changed, you might not notice
** the incompatibility right away, even running a full regression test.
** The default location of PENDING_BYTE is the first byte past the
** 1GB boundary.
**
*/
#ifndef SQLITE_TEST
#define PENDING_BYTE 0x40000000 /* First byte past the 1GB boundary */
#else
extern unsigned int sqlite3_pending_byte;
#define PENDING_BYTE sqlite3_pending_byte
#endif
#define RESERVED_BYTE (PENDING_BYTE+1)
#define SHARED_FIRST (PENDING_BYTE+2)
#define SHARED_SIZE 510
/*
** A single global instance of the following structure holds pointers to the
** various system-specific interface routines.
*/
extern struct sqlite3OsVtbl {
int (*xOpenReadWrite)(const char*, OsFile**, int*);
int (*xOpenExclusive)(const char*, OsFile**, int);
int (*xOpenReadOnly)(const char*, OsFile**);
int (*xDelete)(const char*);
int (*xFileExists)(const char*);
char *(*xFullPathname)(const char*);
int (*xIsDirWritable)(char*);
int (*xSyncDirectory)(const char*);
int (*xTempFileName)(char*);
int (*xRandomSeed)(char*);
int (*xSleep)(int ms);
int (*xCurrentTime)(double*);
void (*xEnterMutex)(void);
void (*xLeaveMutex)(void);
int (*xInMutex)(void);
void *(*xThreadSpecificData)(int);
void *(*xMalloc)(int);
void *(*xRealloc)(void *, int);
void (*xFree)(void *);
int (*xAllocationSize)(void *);
} sqlite3Os;
/*
** The semi-published API for setting and getting methods from the
** global sqlite3OsVtbl structure. Neither sqlite3_os_routine_XXX() function
** is intriniscally thread-safe.
**
** External get/set access is only provided to the routines identified
** by the following SQLITE_OS_ROUTINE symbols:
*/
#define SQLITE_OS_ROUTINE_OPENREADWRITE 1
#define SQLITE_OS_ROUTINE_OPENREADONLY 2
#define SQLITE_OS_ROUTINE_OPENEXCLUSIVE 3
#define SQLITE_OS_ROUTINE_DELETE 4
#define SQLITE_OS_ROUTINE_FILEEXISTS 5
#define SQLITE_OS_ROUTINE_SYNCDIRECTORY 6
void *sqlite3_os_routine_get(int);
void *sqlite3_os_routine_set(int, void *);
void sqlite3_os_enter_mutex();
void sqlite3_os_leave_mutex();
/*
** Prototypes for routines found in os.c
*/
int sqlite3OsClose(OsFile**);
int sqlite3OsOpenDirectory(OsFile*, const char*);
int sqlite3OsRead(OsFile*, void*, int amt);
int sqlite3OsWrite(OsFile*, const void*, int amt);
int sqlite3OsSeek(OsFile*, i64 offset);
int sqlite3OsTruncate(OsFile*, i64 size);
int sqlite3OsSync(OsFile*, int);
void sqlite3OsSetFullSync(OsFile *id, int setting);
int sqlite3OsFileHandle(OsFile *id);
int sqlite3OsFileSize(OsFile*, i64 *pSize);
int sqlite3OsLock(OsFile*, int);
int sqlite3OsUnlock(OsFile*, int);
int sqlite3OsLockState(OsFile *id);
int sqlite3OsCheckReservedLock(OsFile *id);
#endif /* _SQLITE_OS_H_ */

229
src/sqlite3_aux.h Normal file
View File

@ -0,0 +1,229 @@
/*
** 2006 January 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 header file defines auxiliary interfaces to the SQLite library.
** This header file is a companion to the official "sqlite.h" interface
** file. The difference is that the extraordinary efforts are made to
** insure that the interface defined in "sqlite.h" is always backwards
** compatible. No such guarantees are made for the auxiliary interfaces
** defined in this header file. The interfaces defined here are subject
** to change in future releases of SQLite.
**
** We justify the volitility of the interfaces defined here by noting that
** these interfaces are designed not for users of the SQLite library but
** by code that wishes to expand and extend the SQLite library. Some
** knowledge of what SQLite is doing internally is necessary to use these
** interfaces.
**
** We have no intention of changing the interfaces defined in this file
** gratuitously. No interfaces will be changed without good reason. But
** on the other hand, if the quality and functionality of SQLite can be
** enhanced by modifying the interfaces found here, then we will do so.
**
** Since these interfaces are variable, it is suggested that they not
** be accessed as a shared library. Users of these interfaces should
** statically link.
**
** @(#) $Id: sqlite3_aux.h,v 1.1 2006/01/06 03:29:58 drh Exp $
*/
/*
** Forward declarations
*/
typedef struct OsFile OsFile;
typedef struct IoMethod IoMethod;
/*
** An instance of the following structure contains pointers to all
** methods on an OsFile object.
*/
struct IoMethod {
int (*xClose)(OsFile**);
int (*xOpenDirectory)(OsFile*, const char*);
int (*xRead)(OsFile*, void*, int amt);
int (*xWrite)(OsFile*, const void*, int amt);
int (*xSeek)(OsFile*, i64 offset);
int (*xTruncate)(OsFile*, i64 size);
int (*xSync)(OsFile*, int);
void (*xSetFullSync)(OsFile *id, int setting);
int (*xFileHandle)(OsFile *id);
int (*xFileSize)(OsFile*, i64 *pSize);
int (*xLock)(OsFile*, int);
int (*xUnlock)(OsFile*, int);
int (*xLockState)(OsFile *id);
int (*xCheckReservedLock)(OsFile *id);
};
/*
** The OsFile object describes an open disk file in an OS-dependent way.
** The version of OsFile defined here is a generic version. Each OS
** implementation defines its own subclass of this structure that contains
** additional information needed to handle file I/O. But the pMethod
** entry (pointing to the virtual function table) always occurs first
** so that we can always find the appropriate methods.
*/
struct OsFile {
IoMethod const *pMethod;
};
/*
** The following values may be passed as the second argument to
** sqlite3OsLock(). The various locks exhibit the following semantics:
**
** SHARED: Any number of processes may hold a SHARED lock simultaneously.
** RESERVED: A single process may hold a RESERVED lock on a file at
** any time. Other processes may hold and obtain new SHARED locks.
** PENDING: A single process may hold a PENDING lock on a file at
** any one time. Existing SHARED locks may persist, but no new
** SHARED locks may be obtained by other processes.
** EXCLUSIVE: An EXCLUSIVE lock precludes all other locks.
**
** PENDING_LOCK may not be passed directly to sqlite3OsLock(). Instead, a
** process that requests an EXCLUSIVE lock may actually obtain a PENDING
** lock. This can be upgraded to an EXCLUSIVE lock by a subsequent call to
** sqlite3OsLock().
*/
#define NO_LOCK 0
#define SHARED_LOCK 1
#define RESERVED_LOCK 2
#define PENDING_LOCK 3
#define EXCLUSIVE_LOCK 4
/*
** File Locking Notes: (Mostly about windows but also some info for Unix)
**
** We cannot use LockFileEx() or UnlockFileEx() on Win95/98/ME because
** those functions are not available. So we use only LockFile() and
** UnlockFile().
**
** LockFile() prevents not just writing but also reading by other processes.
** A SHARED_LOCK is obtained by locking a single randomly-chosen
** byte out of a specific range of bytes. The lock byte is obtained at
** random so two separate readers can probably access the file at the
** same time, unless they are unlucky and choose the same lock byte.
** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range.
** There can only be one writer. A RESERVED_LOCK is obtained by locking
** a single byte of the file that is designated as the reserved lock byte.
** A PENDING_LOCK is obtained by locking a designated byte different from
** the RESERVED_LOCK byte.
**
** On WinNT/2K/XP systems, LockFileEx() and UnlockFileEx() are available,
** which means we can use reader/writer locks. When reader/writer locks
** are used, the lock is placed on the same range of bytes that is used
** for probabilistic locking in Win95/98/ME. Hence, the locking scheme
** will support two or more Win95 readers or two or more WinNT readers.
** But a single Win95 reader will lock out all WinNT readers and a single
** WinNT reader will lock out all other Win95 readers.
**
** The following #defines specify the range of bytes used for locking.
** SHARED_SIZE is the number of bytes available in the pool from which
** a random byte is selected for a shared lock. The pool of bytes for
** shared locks begins at SHARED_FIRST.
**
** These #defines are available in sqlite_aux.h so that adaptors for
** connecting SQLite to other operating systems can use the same byte
** ranges for locking. In particular, the same locking strategy and
** byte ranges are used for Unix. This leaves open the possiblity of having
** clients on win95, winNT, and unix all talking to the same shared file
** and all locking correctly. To do so would require that samba (or whatever
** tool is being used for file sharing) implements locks correctly between
** windows and unix. I'm guessing that isn't likely to happen, but by
** using the same locking range we are at least open to the possibility.
**
** Locking in windows is manditory. For this reason, we cannot store
** actual data in the bytes used for locking. The pager never allocates
** the pages involved in locking therefore. SHARED_SIZE is selected so
** that all locks will fit on a single page even at the minimum page size.
** PENDING_BYTE defines the beginning of the locks. By default PENDING_BYTE
** is set high so that we don't have to allocate an unused page except
** for very large databases. But one should test the page skipping logic
** by setting PENDING_BYTE low and running the entire regression suite.
**
** Changing the value of PENDING_BYTE results in a subtly incompatible
** file format. Depending on how it is changed, you might not notice
** the incompatibility right away, even running a full regression test.
** The default location of PENDING_BYTE is the first byte past the
** 1GB boundary.
**
*/
#ifndef SQLITE_TEST
#define PENDING_BYTE 0x40000000 /* First byte past the 1GB boundary */
#else
extern unsigned int sqlite3_pending_byte;
#define PENDING_BYTE sqlite3_pending_byte
#endif
#define RESERVED_BYTE (PENDING_BYTE+1)
#define SHARED_FIRST (PENDING_BYTE+2)
#define SHARED_SIZE 510
/*
** A single global instance of the following structure holds pointers to
** the routines that SQLite uses to talk with the underlying operating
** system. Clever programmers can substitute alternative implementations
** of these routine (prior to using any SQLite API!) in order to modify
** the way SQLite interacts with its environment. For example, modifications
** could be supplied that allow SQLite to talk to a virtual file system.
*/
extern struct sqlite3OsVtbl {
int (*xOpenReadWrite)(const char*, OsFile**, int*);
int (*xOpenExclusive)(const char*, OsFile**, int);
int (*xOpenReadOnly)(const char*, OsFile**);
int (*xDelete)(const char*);
int (*xFileExists)(const char*);
char *(*xFullPathname)(const char*);
int (*xIsDirWritable)(char*);
int (*xSyncDirectory)(const char*);
int (*xTempFileName)(char*);
int (*xRandomSeed)(char*);
int (*xSleep)(int ms);
int (*xCurrentTime)(double*);
void (*xEnterMutex)(void);
void (*xLeaveMutex)(void);
int (*xInMutex)(void);
void *(*xThreadSpecificData)(int);
void *(*xMalloc)(int);
void *(*xRealloc)(void *, int);
void (*xFree)(void *);
int (*xAllocationSize)(void *);
} sqlite3Os;
/*
** The following API routine returns a pointer to the sqlite3Os global
** variable. It is probably easier just to reference the global variable
** directly. This routine is provided for backwards compatibility with
** an older interface design.
*/
struct sqlite3OsVtbl *sqlite3_os_switch(void);
/*
** The following are prototypes of convenience routines that simply
** call the corresponding routines in the OsFile.pMethod virtual
** function table.
*/
int sqlite3OsClose(OsFile**);
int sqlite3OsOpenDirectory(OsFile*, const char*);
int sqlite3OsRead(OsFile*, void*, int amt);
int sqlite3OsWrite(OsFile*, const void*, int amt);
int sqlite3OsSeek(OsFile*, i64 offset);
int sqlite3OsTruncate(OsFile*, i64 size);
int sqlite3OsSync(OsFile*, int);
void sqlite3OsSetFullSync(OsFile *id, int setting);
int sqlite3OsFileHandle(OsFile *id);
int sqlite3OsFileSize(OsFile*, i64 *pSize);
int sqlite3OsLock(OsFile*, int);
int sqlite3OsUnlock(OsFile*, int);
int sqlite3OsLockState(OsFile *id);
int sqlite3OsCheckReservedLock(OsFile *id);

View File

@ -11,7 +11,7 @@
*************************************************************************
** A TCL Interface to SQLite
**
** $Id: tclsqlite.c,v 1.145 2006/01/05 15:50:07 drh Exp $
** $Id: tclsqlite.c,v 1.146 2006/01/06 03:29:58 drh Exp $
*/
#ifndef NO_TCL /* Omit this whole file if TCL is unavailable */
@ -2161,7 +2161,7 @@ int TCLSH_MAIN(int argc, char **argv){
Sqlitetest4_Init(interp);
Sqlitetest5_Init(interp);
Sqlitetest6_Init(interp);
/* Sqlitetestasync_Init(interp); */
Sqlitetestasync_Init(interp);
Md5_Init(interp);
#ifdef SQLITE_SSE
Sqlitetestsse_Init(interp);

View File

@ -235,7 +235,7 @@ struct AsyncFile {
** sqlite3_async_flush() ).
*/
static void addAsyncWrite(AsyncWrite *pWrite){
sqlite3_os_enter_mutex();
sqlite3Os.xEnterMutex();
assert( !pWrite->pNext );
if( sqlite3_asyncListLast ){
assert( sqlite3_asyncListFirst );
@ -244,7 +244,7 @@ static void addAsyncWrite(AsyncWrite *pWrite){
sqlite3_asyncListFirst = pWrite;
}
sqlite3_asyncListLast = pWrite;
sqlite3_os_leave_mutex();
sqlite3Os.xLeaveMutex();
}
/*
@ -360,7 +360,7 @@ static int asyncRead(OsFile *id, void *obuf, int amt){
AsyncFile *pFile = (AsyncFile *)id;
/* Grab the mutex for the duration of the call */
sqlite3_os_enter_mutex();
sqlite3Os.xEnterMutex();
if( pFile->pBaseRead ){
rc = sqlite3OsFileSize(pFile->pBaseRead, &filesize);
@ -401,7 +401,7 @@ static int asyncRead(OsFile *id, void *obuf, int amt){
}
asyncread_out:
sqlite3_os_leave_mutex();
sqlite3Os.xLeaveMutex();
return rc;
}
@ -427,7 +427,7 @@ int asyncFileSize(OsFile *id, i64 *pSize){
int rc = SQLITE_OK;
i64 s = 0;
OsFile *pBase;
sqlite3_os_enter_mutex();
sqlite3Os.xEnterMutex();
/* Read the filesystem size from the base file. If pBaseRead is NULL, this
** means the file hasn't been opened yet. In this case all relevant data
@ -455,7 +455,7 @@ int asyncFileSize(OsFile *id, i64 *pSize){
}
*pSize = s;
}
sqlite3_os_leave_mutex();
sqlite3Os.xLeaveMutex();
return rc;
}
@ -622,7 +622,7 @@ static int asyncSyncDirectory(const char *z){
static int asyncFileExists(const char *z){
int ret;
AsyncWrite *p;
sqlite3_os_enter_mutex();
sqlite3Os.xEnterMutex();
/* See if the real file system contains the specified file. */
ret = xOrigFileExists(z);
@ -635,7 +635,7 @@ static int asyncFileExists(const char *z){
}
}
sqlite3_os_leave_mutex();
sqlite3Os.xLeaveMutex();
return ret;
}
@ -648,28 +648,19 @@ static int asyncFileExists(const char *z){
*/
int sqlite3_async_enable(void){
if( xOrigOpenReadWrite==0 ){
#define ROUTINE(a,b,c) {(void**)&a,SQLITE_OS_ROUTINE_ ## b,(void *)c}
struct ReplacementOp {
void ** pOldRoutine;
int eRoutine;
void * pNewRoutine;
} aRoutines[] = {
ROUTINE(xOrigOpenReadWrite, OPENREADWRITE, asyncOpenReadWrite),
ROUTINE(xOrigOpenReadOnly, OPENREADONLY, asyncOpenReadOnly),
ROUTINE(xOrigOpenExclusive, OPENEXCLUSIVE, asyncOpenExclusive),
ROUTINE(xOrigDelete, DELETE, asyncDelete),
ROUTINE(xOrigFileExists, FILEEXISTS, asyncFileExists),
ROUTINE(xOrigSyncDirectory, SYNCDIRECTORY, asyncSyncDirectory)
};
#undef ROUTINE
int i;
xOrigOpenReadWrite = sqlite3Os.xOpenReadWrite;
xOrigOpenReadOnly = sqlite3Os.xOpenReadOnly;
xOrigOpenExclusive = sqlite3Os.xOpenExclusive;
xOrigDelete = sqlite3Os.xDelete;
xOrigFileExists = sqlite3Os.xFileExists;
xOrigSyncDirectory = sqlite3Os.xSyncDirectory;
sqlite3_os_enter_mutex();
for(i=0; i<sizeof(aRoutines)/sizeof(aRoutines[0]); i++){
struct ReplacementOp *p = &aRoutines[i];
*(p->pOldRoutine) = sqlite3_os_routine_set(p->eRoutine, p->pNewRoutine);
}
sqlite3_os_leave_mutex();
sqlite3Os.xOpenReadWrite = asyncOpenReadWrite;
sqlite3Os.xOpenReadOnly = asyncOpenReadOnly;
sqlite3Os.xOpenExclusive = asyncOpenExclusive;
sqlite3Os.xDelete = asyncDelete;
sqlite3Os.xFileExists = asyncFileExists;
sqlite3Os.xSyncDirectory = asyncSyncDirectory;
}
return SQLITE_OK;
}
@ -688,9 +679,9 @@ int sqlite3_async_flush(void){
** Or, if some other thread is already inside this function, return
** SQLITE_BUSY to the caller.
*/
sqlite3_os_enter_mutex();
sqlite3Os.xEnterMutex();
if( sqlite3_asyncIoBusy ){
sqlite3_os_leave_mutex();
sqlite3Os.xLeaveMutex();
return SQLITE_BUSY;
}
sqlite3_asyncIoBusy = 1;
@ -724,7 +715,7 @@ int sqlite3_async_flush(void){
p->op==ASYNC_OPENEXCLUSIVE ||
(pBase && (p->op==ASYNC_SYNC || p->op==ASYNC_WRITE) )
){
sqlite3_os_leave_mutex();
sqlite3Os.xLeaveMutex();
isInsideMutex = 0;
}
if( !pBase ){
@ -781,7 +772,7 @@ int sqlite3_async_flush(void){
OsFile *pBase = 0;
rc = xOrigOpenExclusive(p->zBuf, &pBase, delFlag);
sqlite3_os_enter_mutex();
sqlite3Os.xEnterMutex();
isInsideMutex = 1;
if( rc==SQLITE_OK ){
pFile->pBaseRead = pBase;
@ -797,7 +788,7 @@ int sqlite3_async_flush(void){
** global write-op queue.
*/
if( !isInsideMutex ){
sqlite3_os_enter_mutex();
sqlite3Os.xEnterMutex();
}
if( rc==SQLITE_OK ){
removeAsyncWrite(p);
@ -808,7 +799,7 @@ int sqlite3_async_flush(void){
/* Clear the io-busy flag and exit the mutex */
assert( sqlite3_asyncIoBusy );
sqlite3_asyncIoBusy = 0;
sqlite3_os_leave_mutex();
sqlite3Os.xLeaveMutex();
return rc;
}
@ -926,4 +917,3 @@ int Sqlitetestasync_Init(Tcl_Interp *interp){
}
#endif

47
test/format4.test Normal file
View File

@ -0,0 +1,47 @@
# 2005 December 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.
#
# This file implements tests to verify that the new serial_type
# values of 8 (integer 0) and 9 (integer 1) work correctly.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
do_test format4-1.1 {
execsql {
CREATE TABLE t1(x0,x1,x2,x3,x4,x5,x6,x7,x8,x9);
INSERT INTO t1 VALUES(0,0,0,0,0,0,0,0,0,0);
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
}
file size test.db
} {2048}
do_test format4-1.2 {
execsql {
UPDATE t1 SET x0=1, x1=1, x2=1, x3=1, x4=1, x5=1, x6=1, x7=1, x8=1, x9=1
}
file size test.db
} {2048}
do_test format4-1.3 {
execsql {
UPDATE t1 SET x0=2, x1=2, x2=2, x3=2, x4=2, x5=2, x6=2, x7=2, x8=2, x9=2
}
file size test.db
} {4096}
finish_test