免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1192 | 回复: 0
打印 上一主题 下一主题

sqlite 移植到arm平台 和测试 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-02-26 20:30 |只看该作者 |倒序浏览


文件:
sqlite笔记和例子.rar
大小:
5KB
下载:
下载
1.============================================
交叉编译sqlite
首先备份configure文件
cp configure configure.old
1).修改configure文件,主要是出错了的地方(可以看config.log文件查找到第几行对应删除即可)
./configure --host=arm-linux --disable-tcl --prefix=/usr/local/arm/3.3.2/arm-linux
2).
修改Makefile
#BCC = arm-linux-gcc -g -O2
BCC = gcc -g -O2
因为生成的 lemon 可执行文件需要在主机上执行
2.============================================
建立数据库
chmod 775 sqlite3
and then run sqlite3 like this
sqlite3 ex2
,if you see the following messages:
SQLite version 3.3.6
Enter ".help" for instructions
sqlite>
input some commands to do something,
sqlite> create table tbl(one varchar(10),two smallint);
sqlite> insert into tbl values('hello',10);
sqlite> insert into tbl values('goodbye',20);
sqlite> .quit
more commands , please visit
www.sqlite.org
for details
then use 'ls ex2' to list files in currect directory,
if you see 'ex2' file,
congratulations,you have successfully making a standalone 'sqlite3'.
next step we should compile the example code on
www.sqlite.org
's quickstart page
3.=============================================
运用测试
make a 'test.c' file in 'build' directory, content as showed:
#include
#include "sqlite3.h" /* orignal is  */
static int callback(void *NotUsed, int argc, char **argv, char **azColName){
int i;
for(i=0; i
int main(int argc, char **argv){
sqlite3 *db;
char *zErrMsg = 0;
int rc;
if( argc!=3 ){
fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]);
exit(1);
}
rc = sqlite3_open(argv[1], &db);
if( rc ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
sqlite3_close(db);
return 0;
}
arm-linux-gcc test.c -L.libs -lsqlite3 -static  //arm-linux-gcc test.c -L.libs -lsqlite3 动态
explaination: -L.libs show that the lib searching path is '.libs'
'-lsqlite3 -static' show that the lib name is libsqlite3.a,the 'lib' and '.a' is added by linker.
with the above command ,we can compile a standalone application with sql databse supported.
use arm-linux-strip to decrease its size:
arm-linux-strip a.out
upload to ARM9 board, make it runable and test it:
[root@fa fa]# a.out ex2 "select * from tbl"      
one = hello
two = 10
one = goodbye
two = 20
[root@fa fa]#
if you see the above result , ok you make it.
over.
wish the article is usefull for you!
4.==============================================
sql语法
sqlite3 *db=NULL;
char *zErrMsg = 0;
打开:
sqlite3_open() 打开数据库
sqlite3_close()关闭数据库连接
sqlite3_exec( db , sql , 0 , 0 , &zErrMsg );
创建并插入:CREATE INSERT
char *sql  =  "CREATE TABLE SensorData( ID INTEGER PRIMARY KEY, SensorID INTEGER,SiteNum INTEGER,Time VARCHAR(12),SensorParameter REAL);" ;
char *sql1 = "INSERT INTO \"SensorData\" VALUES( NULL , 1 , 1 , '200605011206', 18.9 );" ;
char *sql2 = "INSERT INTO \"SensorData\" VALUES( NULL , 1 , 1 , '200605011306', 16.4 );" ;
可以调用这个函数(sqlite3_exec( db , sql , 0 , 0 , &zErrMsg );)来执行sql语句sqlite3_exec( db , sql , 0 , 0 , &zErrMsg );
查询: SELECT
char **azResult;
sql = "SELECT * FROM SensorData ";
sqlite3_get_table( db , sql , &azResult , &nrow , &ncolumn , &zErrMsg );
int i = 0 ;
printf( "row:%d column=%d \n" , nrow , ncolumn );
printf( "\nThe result of querying is : \n" );
for( i=0 ; i
删除:delete
sql = "DELETE FROM SensorData WHERE SensorID = 1 ;" ;
sqlite3_exec( db , sql , 0 , 0 , &zErrMsg );


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/33226/showart_484220.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP