port complete SQLite-3.8.1 to RT-Thread

This commit is contained in:
geniusgogo authored and geniusgogo committed 2013-11-30 14:59:55 +08:00
1 parent 993374d860
commit d47febdc65
49 files changed
+36412 -190

No files matched your search

+26
View File
@@ -2,3 +2,29 @@
## 简介
初始版本基于SQLite 3.8.1版本,使用混合单文件结构源代码
测试方法:
1.
在rtconfig.h中定义一下宏
/*
* SQLite compile macro
*/
#define RT_USING_SQLITE
#define SQLITE_OMIT_LOAD_EXTENSION 1
#define SQLITE_RTT_NO_WIDE 1
#define SQLITE_OMIT_WAL
#define SQLITE_ENABLE_LOCKING_STYLE 0
#define SQLITE_DISABLE_LOCKING_STYLE 1
#define SQLITE_TEMP_STORE 1
#define SQLITE_THREADSAFE 1
#define HAVE_READLINE 0
#define NDEBUG
#define _HAVE_SQLITE_CONFIG_H
#define BUILD_sqlite
#define SQLITE_OS_OTHER 1
#define SQLITE_OS_RTT 1
2.
在test目录下找一个测试样例来加入工程进行测试.
推荐用mini2440bsp,因为板子的ram较大。
注意shell.c还没有移植的。请不要使用。
+3 -1
View File
@@ -3,7 +3,9 @@ import os
from building import *
cwd = GetCurrentDir()
src = Glob('*.c')
src = Split("""
sqlite3.c
""")
CPPPATH = [cwd, str(Dir('#'))]
group = DefineGroup('sqlite', src, depend = ['RT_USING_SQLITE'], CPPPATH = CPPPATH)
+114
View File
@@ -0,0 +1,114 @@
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */
/* Define to 1 if you have the <dlfcn.h> header file. */
/* #undef HAVE_DLFCN_H */
/* Define to 1 if you have the `fdatasync' function. */
/* #undef HAVE_FDATASYNC */
/* Define to 1 if you have the `gmtime_r' function. */
#define HAVE_GMTIME_R 1
/* Define to 1 if the system has the type `int16_t'. */
#define HAVE_INT16_T 1
/* Define to 1 if the system has the type `int32_t'. */
#define HAVE_INT32_T 1
/* Define to 1 if the system has the type `int64_t'. */
#define HAVE_INT64_T 1
/* Define to 1 if the system has the type `int8_t'. */
#define HAVE_INT8_T 1
/* Define to 1 if the system has the type `intptr_t'. */
#define HAVE_INTPTR_T 1
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the `localtime_r' function. */
#define HAVE_LOCALTIME_R 1
/* Define to 1 if you have the `localtime_s' function. */
/* #undef HAVE_LOCALTIME_S */
/* Define to 1 if you have the <malloc.h> header file. */
/* #define HAVE_MALLOC_H 0 */
/* Define to 1 if you have the `malloc_usable_size' function. */
/* #define HAVE_MALLOC_USABLE_SIZE 0 */
/* Define to 1 if you have the <memory.h> header file. */
/* #undef HAVE_MEMORY_H */
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the <strings.h> header file. */
/* #undef HAVE_STRINGS_H */
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if the system has the type `uint16_t'. */
#define HAVE_UINT16_T 1
/* Define to 1 if the system has the type `uint32_t'. */
#define HAVE_UINT32_T 1
/* Define to 1 if the system has the type `uint64_t'. */
#define HAVE_UINT64_T 1
/* Define to 1 if the system has the type `uint8_t'. */
#define HAVE_UINT8_T 1
/* Define to 1 if the system has the type `uintptr_t'. */
#define HAVE_UINTPTR_T 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define to 1 if you have the `usleep' function. */
/* #undef HAVE_USLEEP */
/* Define to 1 if you have the utime() library function. */
/* #undef HAVE_UTIME */
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#define LT_OBJDIR ".libs/"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""
/* Define to the full name of this package. */
#define PACKAGE_NAME "sqlite"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "sqlite 3.8.1"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "sqlite"
/* Define to the version of this package. */
#define PACKAGE_VERSION "3.8.1"
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Number of bits in a file offset, on hosts where this is settable. */
/* #undef _FILE_OFFSET_BITS */
/* Define for large files, on AIX-style hosts. */
/* #undef _LARGE_FILES */
+3421 -189
View File
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+200
View File
@@ -0,0 +1,200 @@
/*
** 2007 March 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 contains obscure tests of the C-interface required
** for completeness. Test code is written in C for these cases
** as there is not much point in binding to Tcl.
*/
#include "sqliteInt.h"
#include "tcl.h"
#include <stdlib.h>
#include <string.h>
/*
** c_collation_test
*/
static int c_collation_test(
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int objc, /* Number of arguments */
Tcl_Obj *CONST objv[] /* Command arguments */
){
const char *zErrFunction = "N/A";
sqlite3 *db;
int rc;
if( objc!=1 ){
Tcl_WrongNumArgs(interp, 1, objv, "");
return TCL_ERROR;
}
/* Open a database. */
rc = sqlite3_open(":memory:", &db);
if( rc!=SQLITE_OK ){
zErrFunction = "sqlite3_open";
goto error_out;
}
rc = sqlite3_create_collation(db, "collate", 456, 0, 0);
if( rc!=SQLITE_MISUSE ){
sqlite3_close(db);
zErrFunction = "sqlite3_create_collation";
goto error_out;
}
sqlite3_close(db);
return TCL_OK;
error_out:
Tcl_ResetResult(interp);
Tcl_AppendResult(interp, "Error testing function: ", zErrFunction, 0);
return TCL_ERROR;
}
/*
** c_realloc_test
*/
static int c_realloc_test(
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int objc, /* Number of arguments */
Tcl_Obj *CONST objv[] /* Command arguments */
){
void *p;
const char *zErrFunction = "N/A";
if( objc!=1 ){
Tcl_WrongNumArgs(interp, 1, objv, "");
return TCL_ERROR;
}
p = sqlite3_malloc(5);
if( !p ){
zErrFunction = "sqlite3_malloc";
goto error_out;
}
/* Test that realloc()ing a block of memory to a negative size is
** the same as free()ing that memory.
*/
p = sqlite3_realloc(p, -1);
if( p ){
zErrFunction = "sqlite3_realloc";
goto error_out;
}
return TCL_OK;
error_out:
Tcl_ResetResult(interp);
Tcl_AppendResult(interp, "Error testing function: ", zErrFunction, 0);
return TCL_ERROR;
}
/*
** c_misuse_test
*/
static int c_misuse_test(
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int objc, /* Number of arguments */
Tcl_Obj *CONST objv[] /* Command arguments */
){
const char *zErrFunction = "N/A";
sqlite3 *db = 0;
sqlite3_stmt *pStmt;
int rc;
if( objc!=1 ){
Tcl_WrongNumArgs(interp, 1, objv, "");
return TCL_ERROR;
}
/* Open a database. Then close it again. We need to do this so that
** we have a "closed database handle" to pass to various API functions.
*/
rc = sqlite3_open(":memory:", &db);
if( rc!=SQLITE_OK ){
zErrFunction = "sqlite3_open";
goto error_out;
}
sqlite3_close(db);
rc = sqlite3_errcode(db);
if( rc!=SQLITE_MISUSE ){
zErrFunction = "sqlite3_errcode";
goto error_out;
}
pStmt = (sqlite3_stmt*)1234;
rc = sqlite3_prepare(db, 0, 0, &pStmt, 0);
if( rc!=SQLITE_MISUSE ){
zErrFunction = "sqlite3_prepare";
goto error_out;
}
assert( pStmt==0 ); /* Verify that pStmt is zeroed even on a MISUSE error */
pStmt = (sqlite3_stmt*)1234;
rc = sqlite3_prepare_v2(db, 0, 0, &pStmt, 0);
if( rc!=SQLITE_MISUSE ){
zErrFunction = "sqlite3_prepare_v2";
goto error_out;
}
assert( pStmt==0 );
#ifndef SQLITE_OMIT_UTF16
pStmt = (sqlite3_stmt*)1234;
rc = sqlite3_prepare16(db, 0, 0, &pStmt, 0);
if( rc!=SQLITE_MISUSE ){
zErrFunction = "sqlite3_prepare16";
goto error_out;
}
assert( pStmt==0 );
pStmt = (sqlite3_stmt*)1234;
rc = sqlite3_prepare16_v2(db, 0, 0, &pStmt, 0);
if( rc!=SQLITE_MISUSE ){
zErrFunction = "sqlite3_prepare16_v2";
goto error_out;
}
assert( pStmt==0 );
#endif
return TCL_OK;
error_out:
Tcl_ResetResult(interp);
Tcl_AppendResult(interp, "Error testing function: ", zErrFunction, 0);
return TCL_ERROR;
}
/*
** Register commands with the TCL interpreter.
*/
int Sqlitetest9_Init(Tcl_Interp *interp){
static struct {
char *zName;
Tcl_ObjCmdProc *xProc;
void *clientData;
} aObjCmd[] = {
{ "c_misuse_test", c_misuse_test, 0 },
{ "c_realloc_test", c_realloc_test, 0 },
{ "c_collation_test", c_collation_test, 0 },
};
int i;
for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
Tcl_CreateObjCommand(interp, aObjCmd[i].zName,
aObjCmd[i].xProc, aObjCmd[i].clientData, 0);
}
return TCL_OK;
}
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+150
View File
@@ -0,0 +1,150 @@
/*
** 2009 January 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 test logic for the sqlite3_backup() interface.
**
*/
#include "tcl.h"
#include <sqlite3.h>
#include <assert.h>
/* These functions are implemented in main.c. */
extern const char *sqlite3ErrName(int);
/* These functions are implemented in test1.c. */
extern int getDbPointer(Tcl_Interp *, const char *, sqlite3 **);
static int backupTestCmd(
ClientData clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *const*objv
){
enum BackupSubCommandEnum {
BACKUP_STEP, BACKUP_FINISH, BACKUP_REMAINING, BACKUP_PAGECOUNT
};
struct BackupSubCommand {
const char *zCmd;
enum BackupSubCommandEnum eCmd;
int nArg;
const char *zArg;
} aSub[] = {
{"step", BACKUP_STEP , 1, "npage" },
{"finish", BACKUP_FINISH , 0, "" },
{"remaining", BACKUP_REMAINING , 0, "" },
{"pagecount", BACKUP_PAGECOUNT , 0, "" },
{0, 0, 0, 0}
};
sqlite3_backup *p = (sqlite3_backup *)clientData;
int iCmd;
int rc;
rc = Tcl_GetIndexFromObjStruct(
interp, objv[1], aSub, sizeof(aSub[0]), "option", 0, &iCmd
);
if( rc!=TCL_OK ){
return rc;
}
if( objc!=(2 + aSub[iCmd].nArg) ){
Tcl_WrongNumArgs(interp, 2, objv, aSub[iCmd].zArg);
return TCL_ERROR;
}
switch( aSub[iCmd].eCmd ){
case BACKUP_FINISH: {
const char *zCmdName;
Tcl_CmdInfo cmdInfo;
zCmdName = Tcl_GetString(objv[0]);
Tcl_GetCommandInfo(interp, zCmdName, &cmdInfo);
cmdInfo.deleteProc = 0;
Tcl_SetCommandInfo(interp, zCmdName, &cmdInfo);
Tcl_DeleteCommand(interp, zCmdName);
rc = sqlite3_backup_finish(p);
Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
break;
}
case BACKUP_STEP: {
int nPage;
if( TCL_OK!=Tcl_GetIntFromObj(interp, objv[2], &nPage) ){
return TCL_ERROR;
}
rc = sqlite3_backup_step(p, nPage);
Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
break;
}
case BACKUP_REMAINING:
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_backup_remaining(p)));
break;
case BACKUP_PAGECOUNT:
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_backup_pagecount(p)));
break;
}
return TCL_OK;
}
static void backupTestFinish(ClientData clientData){
sqlite3_backup *pBackup = (sqlite3_backup *)clientData;
sqlite3_backup_finish(pBackup);
}
/*
** sqlite3_backup CMDNAME DESTHANDLE DESTNAME SRCHANDLE SRCNAME
**
*/
static int backupTestInit(
ClientData clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *const*objv
){
sqlite3_backup *pBackup;
sqlite3 *pDestDb;
sqlite3 *pSrcDb;
const char *zDestName;
const char *zSrcName;
const char *zCmd;
if( objc!=6 ){
Tcl_WrongNumArgs(
interp, 1, objv, "CMDNAME DESTHANDLE DESTNAME SRCHANDLE SRCNAME"
);
return TCL_ERROR;
}
zCmd = Tcl_GetString(objv[1]);
getDbPointer(interp, Tcl_GetString(objv[2]), &pDestDb);
zDestName = Tcl_GetString(objv[3]);
getDbPointer(interp, Tcl_GetString(objv[4]), &pSrcDb);
zSrcName = Tcl_GetString(objv[5]);
pBackup = sqlite3_backup_init(pDestDb, zDestName, pSrcDb, zSrcName);
if( !pBackup ){
Tcl_AppendResult(interp, "sqlite3_backup_init() failed", 0);
return TCL_ERROR;
}
Tcl_CreateObjCommand(interp, zCmd, backupTestCmd, pBackup, backupTestFinish);
Tcl_SetObjResult(interp, objv[1]);
return TCL_OK;
}
int Sqlitetestbackup_Init(Tcl_Interp *interp){
Tcl_CreateObjCommand(interp, "sqlite3_backup", backupTestInit, 0, 0);
return TCL_OK;
}
+62
View File
@@ -0,0 +1,62 @@
/*
** 2007 May 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.
**
*************************************************************************
** Code for testing the btree.c module in SQLite. This code
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
*/
#include "btreeInt.h"
#include <tcl.h>
/*
** Usage: sqlite3_shared_cache_report
**
** Return a list of file that are shared and the number of
** references to each file.
*/
int sqlite3BtreeSharedCacheReport(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
#ifndef SQLITE_OMIT_SHARED_CACHE
extern BtShared *sqlite3SharedCacheList;
BtShared *pBt;
Tcl_Obj *pRet = Tcl_NewObj();
for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
const char *zFile = sqlite3PagerFilename(pBt->pPager, 1);
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj(zFile, -1));
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(pBt->nRef));
}
Tcl_SetObjResult(interp, pRet);
#endif
return TCL_OK;
}
/*
** Print debugging information about all cursors to standard output.
*/
void sqlite3BtreeCursorList(Btree *p){
#ifdef SQLITE_DEBUG
BtCursor *pCur;
BtShared *pBt = p->pBt;
for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){
MemPage *pPage = pCur->apPage[pCur->iPage];
char *zMode = pCur->wrFlag ? "rw" : "ro";
sqlite3DebugPrintf("CURSOR %p rooted at %4d(%s) currently at %d.%d%s\n",
pCur, pCur->pgnoRoot, zMode,
pPage ? pPage->pgno : 0, pCur->aiIdx[pCur->iPage],
(pCur->eState==CURSOR_VALID) ? "" : " eof"
);
}
#endif
}
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+128
View File
@@ -0,0 +1,128 @@
/*
** 2009 November 10
**
** 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 is the C-language interface definition for the "intarray" or
** integer array virtual table for SQLite.
**
** The intarray virtual table is designed to facilitate using an
** array of integers as the right-hand side of an IN operator. So
** instead of doing a prepared statement like this:
**
** SELECT * FROM table WHERE x IN (?,?,?,...,?);
**
** And then binding indivdual integers to each of ? slots, a C-language
** application can create an intarray object (named "ex1" in the following
** example), prepare a statement like this:
**
** SELECT * FROM table WHERE x IN ex1;
**
** Then bind an ordinary C/C++ array of integer values to the ex1 object
** to run the statement.
**
** USAGE:
**
** One or more intarray objects can be created as follows:
**
** sqlite3_intarray *p1, *p2, *p3;
** sqlite3_intarray_create(db, "ex1", &p1);
** sqlite3_intarray_create(db, "ex2", &p2);
** sqlite3_intarray_create(db, "ex3", &p3);
**
** Each call to sqlite3_intarray_create() generates a new virtual table
** module and a singleton of that virtual table module in the TEMP
** database. Both the module and the virtual table instance use the
** name given by the second parameter. The virtual tables can then be
** used in prepared statements:
**
** SELECT * FROM t1, t2, t3
** WHERE t1.x IN ex1
** AND t2.y IN ex2
** AND t3.z IN ex3;
**
** Each integer array is initially empty. New arrays can be bound to
** an integer array as follows:
**
** sqlite3_int64 a1[] = { 1, 2, 3, 4 };
** sqlite3_int64 a2[] = { 5, 6, 7, 8, 9, 10, 11 };
** sqlite3_int64 *a3 = sqlite3_malloc( 100*sizeof(sqlite3_int64) );
** // Fill in content of a3[]
** sqlite3_intarray_bind(p1, 4, a1, 0);
** sqlite3_intarray_bind(p2, 7, a2, 0);
** sqlite3_intarray_bind(p3, 100, a3, sqlite3_free);
**
** A single intarray object can be rebound multiple times. But do not
** attempt to change the bindings of an intarray while it is in the middle
** of a query.
**
** The array that holds the integers is automatically freed by the function
** in the fourth parameter to sqlite3_intarray_bind() when the array is no
** longer needed. The application must not change the intarray values
** while an intarray is in the middle of a query.
**
** The intarray object is automatically destroyed when its corresponding
** virtual table is dropped. Since the virtual tables are created in the
** TEMP database, they are automatically dropped when the database connection
** closes so the application does not normally need to take any special
** action to free the intarray objects.
*/
#include "sqlite3.h"
#ifndef _INTARRAY_H_
#define _INTARRAY_H_
/*
** Make sure we can call this stuff from C++.
*/
#ifdef __cplusplus
extern "C" {
#endif
/*
** An sqlite3_intarray is an abstract type to stores an instance of
** an integer array.
*/
typedef struct sqlite3_intarray sqlite3_intarray;
/*
** Invoke this routine to create a specific instance of an intarray object.
** The new intarray object is returned by the 3rd parameter.
**
** Each intarray object corresponds to a virtual table in the TEMP table
** with a name of zName.
**
** Destroy the intarray object by dropping the virtual table. If not done
** explicitly by the application, the virtual table will be dropped implicitly
** by the system when the database connection is closed.
*/
int sqlite3_intarray_create(
sqlite3 *db,
const char *zName,
sqlite3_intarray **ppReturn
);
/*
** Bind a new array array of integers to a specific intarray object.
**
** The array of integers bound must be unchanged for the duration of
** any query against the corresponding virtual table. If the integer
** array does change or is deallocated undefined behavior will result.
*/
int sqlite3_intarray_bind(
sqlite3_intarray *pIntArray, /* The intarray object to bind to */
int nElements, /* Number of elements in the intarray */
sqlite3_int64 *aElements, /* Content of the intarray */
void (*xFree)(void*) /* How to dispose of the intarray when done */
);
#ifdef __cplusplus
} /* End of the 'extern "C"' block */
#endif
#endif /* _INTARRAY_H_ */
File diff suppressed because it is too large. Load diff
+122
View File
@@ -0,0 +1,122 @@
/*
** 2006 June 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.
**
*************************************************************************
** Test extension for testing the sqlite3_load_extension() function.
*/
#include <string.h>
#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1
/*
** The half() SQL function returns half of its input value.
*/
static void halfFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
sqlite3_result_double(context, 0.5*sqlite3_value_double(argv[0]));
}
/*
** SQL functions to call the sqlite3_status function and return results.
*/
static void statusFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
int op, mx, cur, resetFlag, rc;
if( sqlite3_value_type(argv[0])==SQLITE_INTEGER ){
op = sqlite3_value_int(argv[0]);
}else if( sqlite3_value_type(argv[0])==SQLITE_TEXT ){
int i;
const char *zName;
static const struct {
const char *zName;
int op;
} aOp[] = {
{ "MEMORY_USED", SQLITE_STATUS_MEMORY_USED },
{ "PAGECACHE_USED", SQLITE_STATUS_PAGECACHE_USED },
{ "PAGECACHE_OVERFLOW", SQLITE_STATUS_PAGECACHE_OVERFLOW },
{ "SCRATCH_USED", SQLITE_STATUS_SCRATCH_USED },
{ "SCRATCH_OVERFLOW", SQLITE_STATUS_SCRATCH_OVERFLOW },
{ "MALLOC_SIZE", SQLITE_STATUS_MALLOC_SIZE },
};
int nOp = sizeof(aOp)/sizeof(aOp[0]);
zName = (const char*)sqlite3_value_text(argv[0]);
for(i=0; i<nOp; i++){
if( strcmp(aOp[i].zName, zName)==0 ){
op = aOp[i].op;
break;
}
}
if( i>=nOp ){
char *zMsg = sqlite3_mprintf("unknown status property: %s", zName);
sqlite3_result_error(context, zMsg, -1);
sqlite3_free(zMsg);
return;
}
}else{
sqlite3_result_error(context, "unknown status type", -1);
return;
}
if( argc==2 ){
resetFlag = sqlite3_value_int(argv[1]);
}else{
resetFlag = 0;
}
rc = sqlite3_status(op, &cur, &mx, resetFlag);
if( rc!=SQLITE_OK ){
char *zMsg = sqlite3_mprintf("sqlite3_status(%d,...) returns %d", op, rc);
sqlite3_result_error(context, zMsg, -1);
sqlite3_free(zMsg);
return;
}
if( argc==2 ){
sqlite3_result_int(context, mx);
}else{
sqlite3_result_int(context, cur);
}
}
/*
** Extension load function.
*/
int testloadext_init(
sqlite3 *db,
char **pzErrMsg,
const sqlite3_api_routines *pApi
){
int nErr = 0;
SQLITE_EXTENSION_INIT2(pApi);
nErr |= sqlite3_create_function(db, "half", 1, SQLITE_ANY, 0, halfFunc, 0, 0);
nErr |= sqlite3_create_function(db, "sqlite3_status", 1, SQLITE_ANY, 0,
statusFunc, 0, 0);
nErr |= sqlite3_create_function(db, "sqlite3_status", 2, SQLITE_ANY, 0,
statusFunc, 0, 0);
return nErr ? SQLITE_ERROR : SQLITE_OK;
}
/*
** Another extension entry point. This one always fails.
*/
int testbrokenext_init(
sqlite3 *db,
char **pzErrMsg,
const sqlite3_api_routines *pApi
){
char *zErr;
SQLITE_EXTENSION_INIT2(pApi);
zErr = sqlite3_mprintf("broken!");
*pzErrMsg = zErr;
return 1;
}
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+99
View File
@@ -0,0 +1,99 @@
/*
** 2011 March 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 a VFS "shim" - a layer that sits in between the
** pager and the real VFS.
**
** This particular shim enforces a multiplex system on DB files.
** This shim shards/partitions a single DB file into smaller
** "chunks" such that the total DB file size may exceed the maximum
** file size of the underlying file system.
**
*/
#ifndef _TEST_MULTIPLEX_H
#define _TEST_MULTIPLEX_H
/*
** CAPI: File-control Operations Supported by Multiplex VFS
**
** Values interpreted by the xFileControl method of a Multiplex VFS db file-handle.
**
** MULTIPLEX_CTRL_ENABLE:
** This file control is used to enable or disable the multiplex
** shim.
**
** MULTIPLEX_CTRL_SET_CHUNK_SIZE:
** This file control is used to set the maximum allowed chunk
** size for a multiplex file set. The chunk size should be
** a multiple of SQLITE_MAX_PAGE_SIZE, and will be rounded up
** if not.
**
** MULTIPLEX_CTRL_SET_MAX_CHUNKS:
** This file control is used to set the maximum number of chunks
** allowed to be used for a mutliplex file set.
*/
#define MULTIPLEX_CTRL_ENABLE 214014
#define MULTIPLEX_CTRL_SET_CHUNK_SIZE 214015
#define MULTIPLEX_CTRL_SET_MAX_CHUNKS 214016
#ifdef __cplusplus
extern "C" {
#endif
/*
** CAPI: Initialize the multiplex VFS shim - sqlite3_multiplex_initialize()
**
** Use the VFS named zOrigVfsName as the VFS that does the actual work.
** Use the default if zOrigVfsName==NULL.
**
** The multiplex VFS shim is named "multiplex". It will become the default
** VFS if makeDefault is non-zero.
**
** An auto-extension is registered which will make the function
** multiplex_control() available to database connections. This
** function gives access to the xFileControl interface of the
** multiplex VFS shim.
**
** SELECT multiplex_control(<op>,<val>);
**
** <op>=1 MULTIPLEX_CTRL_ENABLE
** <val>=0 disable
** <val>=1 enable
**
** <op>=2 MULTIPLEX_CTRL_SET_CHUNK_SIZE
** <val> int, chunk size
**
** <op>=3 MULTIPLEX_CTRL_SET_MAX_CHUNKS
** <val> int, max chunks
**
** THIS ROUTINE IS NOT THREADSAFE. Call this routine exactly once
** during start-up.
*/
extern int sqlite3_multiplex_initialize(const char *zOrigVfsName, int makeDefault);
/*
** CAPI: Shutdown the multiplex system - sqlite3_multiplex_shutdown()
**
** All SQLite database connections must be closed before calling this
** routine.
**
** THIS ROUTINE IS NOT THREADSAFE. Call this routine exactly once while
** shutting down in order to free all remaining multiplex groups.
*/
extern int sqlite3_multiplex_shutdown(void);
#ifdef __cplusplus
} /* End of the 'extern "C"' block */
#endif
#endif /* _TEST_MULTIPLEX_H */
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+84
View File
@@ -0,0 +1,84 @@
/*
** 2008 September 1
**
** 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.
**
*************************************************************************
**
** The code in this file contains sample implementations of the
** sqlite3_wsd_init() and sqlite3_wsd_find() functions required if the
** SQLITE_OMIT_WSD symbol is defined at build time.
*/
#if defined(SQLITE_OMIT_WSD) && defined(SQLITE_TEST)
#include "sqliteInt.h"
#define PLS_HASHSIZE 43
typedef struct ProcessLocalStorage ProcessLocalStorage;
typedef struct ProcessLocalVar ProcessLocalVar;
struct ProcessLocalStorage {
ProcessLocalVar *aData[PLS_HASHSIZE];
int nFree;
u8 *pFree;
};
struct ProcessLocalVar {
void *pKey;
ProcessLocalVar *pNext;
};
static ProcessLocalStorage *pGlobal = 0;
int sqlite3_wsd_init(int N, int J){
if( !pGlobal ){
int nMalloc = N + sizeof(ProcessLocalStorage) + J*sizeof(ProcessLocalVar);
pGlobal = (ProcessLocalStorage *)malloc(nMalloc);
if( pGlobal ){
memset(pGlobal, 0, sizeof(ProcessLocalStorage));
pGlobal->nFree = nMalloc - sizeof(ProcessLocalStorage);
pGlobal->pFree = (u8 *)&pGlobal[1];
}
}
return pGlobal ? SQLITE_OK : SQLITE_NOMEM;
}
void *sqlite3_wsd_find(void *K, int L){
int i;
int iHash = 0;
ProcessLocalVar *pVar;
/* Calculate a hash of K */
for(i=0; i<sizeof(void*); i++){
iHash = (iHash<<3) + ((unsigned char *)&K)[i];
}
iHash = iHash%PLS_HASHSIZE;
/* Search the hash table for K. */
for(pVar=pGlobal->aData[iHash]; pVar && pVar->pKey!=K; pVar=pVar->pNext);
/* If no entry for K was found, create and populate a new one. */
if( !pVar ){
int nByte = ROUND8(sizeof(ProcessLocalVar) + L);
assert( pGlobal->nFree>=nByte );
pVar = (ProcessLocalVar *)pGlobal->pFree;
pVar->pKey = K;
pVar->pNext = pGlobal->aData[iHash];
pGlobal->aData[iHash] = pVar;
pGlobal->nFree -= nByte;
pGlobal->pFree += nByte;
memcpy(&pVar[1], K, L);
}
return (void *)&pVar[1];
}
#endif