提交 d47febdc 编写于 作者: xpxyr's avatar xpxyr 提交者: geniusgogo

port complete SQLite-3.8.1 to RT-Thread

上级 993374d8
......@@ -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,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)
......
/* 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 */
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
/*
** 2001 September 15
**
** 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 utf.c module in SQLite. This code
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library. Specifically, the code in this file
** is used for testing the SQLite routines for converting between
** the various supported unicode encodings.
*/
#include "sqliteInt.h"
#include "vdbeInt.h"
#include "tcl.h"
#include <stdlib.h>
#include <string.h>
/*
** The first argument is a TCL UTF-8 string. Return the byte array
** object with the encoded representation of the string, including
** the NULL terminator.
*/
static int binarize(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
int len;
char *bytes;
Tcl_Obj *pRet;
assert(objc==2);
bytes = Tcl_GetStringFromObj(objv[1], &len);
pRet = Tcl_NewByteArrayObj((u8*)bytes, len+1);
Tcl_SetObjResult(interp, pRet);
return TCL_OK;
}
/*
** Usage: test_value_overhead <repeat-count> <do-calls>.
**
** This routine is used to test the overhead of calls to
** sqlite3_value_text(), on a value that contains a UTF-8 string. The idea
** is to figure out whether or not it is a problem to use sqlite3_value
** structures with collation sequence functions.
**
** If <do-calls> is 0, then the calls to sqlite3_value_text() are not
** actually made.
*/
static int test_value_overhead(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
int do_calls;
int repeat_count;
int i;
Mem val;
if( objc!=3 ){
Tcl_AppendResult(interp, "wrong # args: should be \"",
Tcl_GetStringFromObj(objv[0], 0), " <repeat-count> <do-calls>", 0);
return TCL_ERROR;
}
if( Tcl_GetIntFromObj(interp, objv[1], &repeat_count) ) return TCL_ERROR;
if( Tcl_GetIntFromObj(interp, objv[2], &do_calls) ) return TCL_ERROR;
val.flags = MEM_Str|MEM_Term|MEM_Static;
val.z = "hello world";
val.type = SQLITE_TEXT;
val.enc = SQLITE_UTF8;
for(i=0; i<repeat_count; i++){
if( do_calls ){
sqlite3_value_text(&val);
}
}
return TCL_OK;
}
static u8 name_to_enc(Tcl_Interp *interp, Tcl_Obj *pObj){
struct EncName {
char *zName;
u8 enc;
} encnames[] = {
{ "UTF8", SQLITE_UTF8 },
{ "UTF16LE", SQLITE_UTF16LE },
{ "UTF16BE", SQLITE_UTF16BE },
{ "UTF16", SQLITE_UTF16 },
{ 0, 0 }
};
struct EncName *pEnc;
char *z = Tcl_GetString(pObj);
for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
if( 0==sqlite3StrICmp(z, pEnc->zName) ){
break;
}
}
if( !pEnc->enc ){
Tcl_AppendResult(interp, "No such encoding: ", z, 0);
}
if( pEnc->enc==SQLITE_UTF16 ){
return SQLITE_UTF16NATIVE;
}
return pEnc->enc;
}
/*
** Usage: test_translate <string/blob> <from enc> <to enc> ?<transient>?
**
*/
static int test_translate(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
u8 enc_from;
u8 enc_to;
sqlite3_value *pVal;
char *z;
int len;
void (*xDel)(void *p) = SQLITE_STATIC;
if( objc!=4 && objc!=5 ){
Tcl_AppendResult(interp, "wrong # args: should be \"",
Tcl_GetStringFromObj(objv[0], 0),
" <string/blob> <from enc> <to enc>", 0
);
return TCL_ERROR;
}
if( objc==5 ){
xDel = sqlite3_free;
}
enc_from = name_to_enc(interp, objv[2]);
if( !enc_from ) return TCL_ERROR;
enc_to = name_to_enc(interp, objv[3]);
if( !enc_to ) return TCL_ERROR;
pVal = sqlite3ValueNew(0);
if( enc_from==SQLITE_UTF8 ){
z = Tcl_GetString(objv[1]);
if( objc==5 ){
z = sqlite3_mprintf("%s", z);
}
sqlite3ValueSetStr(pVal, -1, z, enc_from, xDel);
}else{
z = (char*)Tcl_GetByteArrayFromObj(objv[1], &len);
if( objc==5 ){
char *zTmp = z;
z = sqlite3_malloc(len);
memcpy(z, zTmp, len);
}
sqlite3ValueSetStr(pVal, -1, z, enc_from, xDel);
}
z = (char *)sqlite3ValueText(pVal, enc_to);
len = sqlite3ValueBytes(pVal, enc_to) + (enc_to==SQLITE_UTF8?1:2);
Tcl_SetObjResult(interp, Tcl_NewByteArrayObj((u8*)z, len));
sqlite3ValueFree(pVal);
return TCL_OK;
}
/*
** Usage: translate_selftest
**
** Call sqlite3UtfSelfTest() to run the internal tests for unicode
** translation. If there is a problem an assert() will fail.
**/
void sqlite3UtfSelfTest(void);
static int test_translate_selftest(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
#ifndef SQLITE_OMIT_UTF16
sqlite3UtfSelfTest();
#endif
return SQLITE_OK;
}
/*
** Register commands with the TCL interpreter.
*/
int Sqlitetest5_Init(Tcl_Interp *interp){
static struct {
char *zName;
Tcl_ObjCmdProc *xProc;
} aCmd[] = {
{ "binarize", (Tcl_ObjCmdProc*)binarize },
{ "test_value_overhead", (Tcl_ObjCmdProc*)test_value_overhead },
{ "test_translate", (Tcl_ObjCmdProc*)test_translate },
{ "translate_selftest", (Tcl_ObjCmdProc*)test_translate_selftest},
};
int i;
for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
Tcl_CreateObjCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
}
return SQLITE_OK;
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
/*
** 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;
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册