POP Article V2.0 设为主页
收藏本站
首 页交流论坛留 言
您现在的位置:首 页 >> 开发文档 >> 经验技巧 >> 查看文章
移植Sqlite到Vxworks
作者:tamsyn  来源:http://blog.sharpplus.com/node/149  时间:2008-3-27  【 字体: 】 〖 双击滚屏 〗

今天有空,继续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

浏览次数:   【 打 印 】【 关 闭
上一篇:用 Psyco 让 Python 运行得像 C 一样快
下一篇:在Ruby On Rail中使用memory方式的SQLite数据库
 论坛登陆
用户名:
密  码:
验证码: 
Cookie 选项:
正常登陆 隐身登陆
   
没有注册?
 文章搜索
 推荐文章
 酷站推荐
 热门文章
 网站统计
关于我们 | 网站地图 | 联系我们 | 网站历史 | 友情链接 | TOP
Copyright© 2006 Sqlite中文社区  程序开发: mistletoe  站长: 林轩 陈文成