add test/test10.c
This commit is contained in:
parent
7d88b753d6
commit
7e7f0fb5f5
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
测试方法:
|
测试方法:
|
||||||
1.
|
1.
|
||||||
在rtconfig.h中定义一下宏
|
在rtconfig.h中定义一下宏,并打开newlib组件
|
||||||
/*
|
/*
|
||||||
* SQLite compile macro
|
* SQLite compile macro
|
||||||
*/
|
*/
|
||||||
|
@ -19,12 +19,13 @@
|
||||||
#define SQLITE_THREADSAFE 1
|
#define SQLITE_THREADSAFE 1
|
||||||
#define HAVE_READLINE 0
|
#define HAVE_READLINE 0
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
|
#define SQLITE_TEST
|
||||||
#define _HAVE_SQLITE_CONFIG_H
|
#define _HAVE_SQLITE_CONFIG_H
|
||||||
#define BUILD_sqlite
|
#define BUILD_sqlite
|
||||||
#define SQLITE_OS_OTHER 1
|
#define SQLITE_OS_OTHER 1
|
||||||
#define SQLITE_OS_RTT 1
|
#define SQLITE_OS_RTT 1
|
||||||
2.
|
2.
|
||||||
在test目录下找一个测试样例来加入工程进行测试.
|
用test目录下的test10.c来进行测试.
|
||||||
推荐用mini2440bsp,因为板子的ram较大。
|
推荐用mini2440bsp,因为板子的ram较大。
|
||||||
|
|
||||||
注意shell.c还没有移植的。请不要使用。
|
注意shell.c还没有移植的。请不要使用。
|
||||||
|
|
|
@ -5,6 +5,7 @@ from building import *
|
||||||
cwd = GetCurrentDir()
|
cwd = GetCurrentDir()
|
||||||
src = Split("""
|
src = Split("""
|
||||||
sqlite3.c
|
sqlite3.c
|
||||||
|
test/test10.c
|
||||||
""")
|
""")
|
||||||
CPPPATH = [cwd, str(Dir('#'))]
|
CPPPATH = [cwd, str(Dir('#'))]
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,7 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
#include <rtconfig.h>
|
#include <rtconfig.h>
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Add the ability to override 'extern'
|
** Add the ability to override 'extern'
|
||||||
*/
|
*/
|
||||||
|
@ -36913,6 +36914,76 @@ static struct rtt_syscall {
|
||||||
#define osAccess ((int(*)(const char*, int))aSyscall[12].pCurrent)
|
#define osAccess ((int(*)(const char*, int))aSyscall[12].pCurrent)
|
||||||
}; /* End of the overrideable system calls */
|
}; /* End of the overrideable system calls */
|
||||||
|
|
||||||
|
/*
|
||||||
|
**
|
||||||
|
** This function - unixLogError_x(), is only ever called via the macro
|
||||||
|
** unixLogError().
|
||||||
|
**
|
||||||
|
** It is invoked after an error occurs in an OS function and errno has been
|
||||||
|
** set. It logs a message using sqlite3_log() containing the current value of
|
||||||
|
** errno and, if possible, the human-readable equivalent from strerror() or
|
||||||
|
** strerror_r().
|
||||||
|
**
|
||||||
|
** The first argument passed to the macro should be the error code that
|
||||||
|
** will be returned to SQLite (e.g. SQLITE_IOERR_DELETE, SQLITE_CANTOPEN).
|
||||||
|
** The two subsequent arguments should be the name of the OS function that
|
||||||
|
** failed (e.g. "unlink", "open") and the associated file-system path,
|
||||||
|
** if any.
|
||||||
|
*/
|
||||||
|
#define rttLogError(a,b,c) rttLogErrorAtLine(a,b,c,__LINE__)
|
||||||
|
static int rttLogErrorAtLine(
|
||||||
|
int errcode, /* SQLite error code */
|
||||||
|
const char *zFunc, /* Name of OS function that failed */
|
||||||
|
const char *zPath, /* File path associated with error */
|
||||||
|
int iLine /* Source line number where error occurred */
|
||||||
|
){
|
||||||
|
char *zErr; /* Message from strerror() or equivalent */
|
||||||
|
int iErrno = errno; /* Saved syscall error number */
|
||||||
|
|
||||||
|
/* If this is not a threadsafe build (SQLITE_THREADSAFE==0), then use
|
||||||
|
** the strerror() function to obtain the human-readable error message
|
||||||
|
** equivalent to errno. Otherwise, use strerror_r().
|
||||||
|
*/
|
||||||
|
#if SQLITE_THREADSAFE && defined(HAVE_STRERROR_R)
|
||||||
|
char aErr[80];
|
||||||
|
memset(aErr, 0, sizeof(aErr));
|
||||||
|
zErr = aErr;
|
||||||
|
|
||||||
|
/* If STRERROR_R_CHAR_P (set by autoconf scripts) or __USE_GNU is defined,
|
||||||
|
** assume that the system provides the GNU version of strerror_r() that
|
||||||
|
** returns a pointer to a buffer containing the error message. That pointer
|
||||||
|
** may point to aErr[], or it may point to some static storage somewhere.
|
||||||
|
** Otherwise, assume that the system provides the POSIX version of
|
||||||
|
** strerror_r(), which always writes an error message into aErr[].
|
||||||
|
**
|
||||||
|
** If the code incorrectly assumes that it is the POSIX version that is
|
||||||
|
** available, the error message will often be an empty string. Not a
|
||||||
|
** huge problem. Incorrectly concluding that the GNU version is available
|
||||||
|
** could lead to a segfault though.
|
||||||
|
*/
|
||||||
|
#if defined(STRERROR_R_CHAR_P) || defined(__USE_GNU)
|
||||||
|
zErr =
|
||||||
|
# endif
|
||||||
|
strerror_r(iErrno, aErr, sizeof(aErr)-1);
|
||||||
|
|
||||||
|
#elif SQLITE_THREADSAFE
|
||||||
|
/* This is a threadsafe build, but strerror_r() is not available. */
|
||||||
|
zErr = "";
|
||||||
|
#else
|
||||||
|
/* Non-threadsafe build, use strerror(). */
|
||||||
|
zErr = strerror(iErrno);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if( zPath==0 ) zPath = "";
|
||||||
|
sqlite3_log(errcode,
|
||||||
|
"os_rtt.c:%d: (%d) %s(%s) - %s",
|
||||||
|
iLine, iErrno, zFunc, zPath, zErr
|
||||||
|
);
|
||||||
|
|
||||||
|
return errcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Do not accept any file descriptor less than this value, in order to avoid
|
** Do not accept any file descriptor less than this value, in order to avoid
|
||||||
** opening database file using file descriptors that are commonly used for
|
** opening database file using file descriptors that are commonly used for
|
||||||
|
@ -37236,75 +37307,6 @@ static int sqliteErrorFromPosixError(int posixError, int sqliteIOErr) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
**
|
|
||||||
** This function - unixLogError_x(), is only ever called via the macro
|
|
||||||
** unixLogError().
|
|
||||||
**
|
|
||||||
** It is invoked after an error occurs in an OS function and errno has been
|
|
||||||
** set. It logs a message using sqlite3_log() containing the current value of
|
|
||||||
** errno and, if possible, the human-readable equivalent from strerror() or
|
|
||||||
** strerror_r().
|
|
||||||
**
|
|
||||||
** The first argument passed to the macro should be the error code that
|
|
||||||
** will be returned to SQLite (e.g. SQLITE_IOERR_DELETE, SQLITE_CANTOPEN).
|
|
||||||
** The two subsequent arguments should be the name of the OS function that
|
|
||||||
** failed (e.g. "unlink", "open") and the associated file-system path,
|
|
||||||
** if any.
|
|
||||||
*/
|
|
||||||
#define rttLogError(a,b,c) rttLogErrorAtLine(a,b,c,__LINE__)
|
|
||||||
static int rttLogErrorAtLine(
|
|
||||||
int errcode, /* SQLite error code */
|
|
||||||
const char *zFunc, /* Name of OS function that failed */
|
|
||||||
const char *zPath, /* File path associated with error */
|
|
||||||
int iLine /* Source line number where error occurred */
|
|
||||||
){
|
|
||||||
char *zErr; /* Message from strerror() or equivalent */
|
|
||||||
int iErrno = errno; /* Saved syscall error number */
|
|
||||||
|
|
||||||
/* If this is not a threadsafe build (SQLITE_THREADSAFE==0), then use
|
|
||||||
** the strerror() function to obtain the human-readable error message
|
|
||||||
** equivalent to errno. Otherwise, use strerror_r().
|
|
||||||
*/
|
|
||||||
#if SQLITE_THREADSAFE && defined(HAVE_STRERROR_R)
|
|
||||||
char aErr[80];
|
|
||||||
memset(aErr, 0, sizeof(aErr));
|
|
||||||
zErr = aErr;
|
|
||||||
|
|
||||||
/* If STRERROR_R_CHAR_P (set by autoconf scripts) or __USE_GNU is defined,
|
|
||||||
** assume that the system provides the GNU version of strerror_r() that
|
|
||||||
** returns a pointer to a buffer containing the error message. That pointer
|
|
||||||
** may point to aErr[], or it may point to some static storage somewhere.
|
|
||||||
** Otherwise, assume that the system provides the POSIX version of
|
|
||||||
** strerror_r(), which always writes an error message into aErr[].
|
|
||||||
**
|
|
||||||
** If the code incorrectly assumes that it is the POSIX version that is
|
|
||||||
** available, the error message will often be an empty string. Not a
|
|
||||||
** huge problem. Incorrectly concluding that the GNU version is available
|
|
||||||
** could lead to a segfault though.
|
|
||||||
*/
|
|
||||||
#if defined(STRERROR_R_CHAR_P) || defined(__USE_GNU)
|
|
||||||
zErr =
|
|
||||||
# endif
|
|
||||||
strerror_r(iErrno, aErr, sizeof(aErr)-1);
|
|
||||||
|
|
||||||
#elif SQLITE_THREADSAFE
|
|
||||||
/* This is a threadsafe build, but strerror_r() is not available. */
|
|
||||||
zErr = "";
|
|
||||||
#else
|
|
||||||
/* Non-threadsafe build, use strerror(). */
|
|
||||||
zErr = strerror(iErrno);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if( zPath==0 ) zPath = "";
|
|
||||||
sqlite3_log(errcode,
|
|
||||||
"os_rtt.c:%d: (%d) %s(%s) - %s",
|
|
||||||
iLine, iErrno, zFunc, zPath, zErr
|
|
||||||
);
|
|
||||||
|
|
||||||
return errcode;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int robust_ftruncate(int h, sqlite3_int64 sz){
|
static int robust_ftruncate(int h, sqlite3_int64 sz){
|
||||||
int rc;
|
int rc;
|
||||||
rc = -1;
|
rc = -1;
|
||||||
|
@ -37455,6 +37457,12 @@ static int nolockClose(sqlite3_file *id) {
|
||||||
*/
|
*/
|
||||||
#define DOTLOCK_SUFFIX ".lock"
|
#define DOTLOCK_SUFFIX ".lock"
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Only set the lastErrno if the error code is a real error and not
|
||||||
|
** a normal expected return code of SQLITE_BUSY or SQLITE_OK
|
||||||
|
*/
|
||||||
|
#define IS_LOCK_ERROR(x) (((x) != SQLITE_OK) && ((x) != SQLITE_BUSY))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** This routine checks if there is a RESERVED lock held on the specified
|
** This routine checks if there is a RESERVED lock held on the specified
|
||||||
** file by this or any other process. If such a lock is held, set *pResOut
|
** file by this or any other process. If such a lock is held, set *pResOut
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sqlite3.h>
|
||||||
|
#include "finsh.h"
|
||||||
|
|
||||||
|
static int callback(void *NotUsed, int argc, char **argv, char **azColName){
|
||||||
|
int i;
|
||||||
|
for(i=0; i<argc; i++){
|
||||||
|
rt_kprintf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
|
||||||
|
}
|
||||||
|
rt_kprintf("\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test10_main(int argc, char **argv){
|
||||||
|
sqlite3 *db;
|
||||||
|
char *zErrMsg = 0;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
if( argc!=3 ){
|
||||||
|
rt_kprintf("Usage: %s DATABASE SQL-STATEMENT\n", argv[0]);
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
rc = sqlite3_open(argv[1], &db);
|
||||||
|
if( rc ){
|
||||||
|
rt_kprintf("Can't open database: %s\n", sqlite3_errmsg(db));
|
||||||
|
sqlite3_close(db);
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);
|
||||||
|
if( rc!=SQLITE_OK ){
|
||||||
|
rt_kprintf("SQL error: %s\n", zErrMsg);
|
||||||
|
sqlite3_free(zErrMsg);
|
||||||
|
}
|
||||||
|
sqlite3_close(db);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
FINSH_FUNCTION_EXPORT(test10_main, sqlite test)
|
Loading…
Reference in New Issue