移植Sqlite到Vxworks(2)
今天有空,继续Port Sqlite,这次用的OS没有文件系统,只有一块64M的Flash内存。所以,把Sqlite对文件操作的IO函数都改成对Flash内存地址的访问。然后,将一个Sqlite 测试用的数据库传到Flash内存中,
数据库很简单,只有一个Test表,有两个字段f1, f2,有两条数据1,123; 2,234
使用下面测试函数进行测试,
#include <stdio.h>
#include <sqlite3.h>
static int callback(void *NotUsed, int argc, char **argv, char **azColName){
int i;
for(i=0; i<argc; i++){
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
int test_sqlite(){
sqlite3 *db;
char *zErrMsg = 0;
int rc;
rc = sqlite3_open("sqlite_mem", &db);
if( rc ){
printf("Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
return 1;
}
rc = sqlite3_exec(db, "select * from test", callback, 0, &zErrMsg);
if( rc!=SQLITE_OK ){
printf("SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
sqlite3_close(db);
return 0;
}
运行LOG结果如下
sqlite3VxFullPathname sqlite_mem
sqlite3VxFullPathname sqlite_mem
OPEN R/W 0 "sqlite_mem"
268357892: OPEN 268427704 sqlite_mem
vxSeek 0
vxREAD 100 byte
>pBuf
>------------
>[0000-0007] 5351 4c69 7465 2066 6f72 6d61 7420 3300 <
>------------
sqlite3VxThreadSpecificData
LOCK
FileExists "sqlite_mem-journal"
vxFileSize 2048
vxSeek 0
vxREAD 1024 byte
>pBuf
>------------
>[0000-0007] 5351 4c69 7465 2066 6f72 6d61 7420 3300 <
>------------
268357892: FETCH 268427704 page 1
sqlite3VxThreadSpecificData
sqlite3VxThreadSpecificData
vxUnlock
sqlite3VxThreadSpecificData
sqlite3VxThreadSpecificData
LOCK
FileExists "sqlite_mem-journal"
vxFileSize 2048
vxSeek 0
vxREAD 1024 byte
>pBuf
>------------
>[0000-0007] 5351 4c69 7465 2066 6f72 6d61 7420 3300 <
>------------
268357892: FETCH 268427704 page 1
vxSeek 1024
vxREAD 1024 byte
>pBuf
>------------
>[0000-0007] 0d00 0000 0203 f000 03f8 03f0 0000 0000 <
>------------
268357892: FETCH 268427704 page 2
f1 = 1 <------- 哈哈,数据库查询结果OK
f2 = 123
f1 = 2
f2 = 234
vxUnlock
268357892: CLOSE 268427704
CLOSE 0