当前位置:数据库 > SQLite >>

ucLinux下sqlite嵌入式数据库移植全攻略(3)

答案:四、修改sqlite/src/shell.c

  1、struct previous_mode_data 结构定义项:

  将 int colWidth[100];

  用 int colWidth[20];

  替换。

  2、struct callback_data 结构定义项

  将:

int colWidth[100];
int actualWidth[100];
char outfile[FILENAME_MAX];


  用:

int colWidth[20];
int actualWidth[20];
char *outfilep;


  对应替换。

  再在结构下面增加:

#ifndef FILENAME_MAX
#define FILENAME_MAX 4095
#endif
char outfilename[FILENAME_MAX]; /* Filename for *out */


  即

struct callback_data
{
...
};
#ifndef FILENAME_MAX
#define FILENAME_MAX 4095
#endif
char outfilename[FILENAME_MAX]; /* Filename for *out */


  3、函数do_meta_command(...)

  找到类似这样的一句:

sqlite_exec(p->db, "PRAGMA database_list; ", callback, &data, &zErrMsg);


  在它的前面有一句

memcpy(&data, p, sizeof(data));


  现在在memcpy下面增加一行

data.cnt = 0;


  即将结构中cnt的值赋为0 ;

  现在代码会被修改成类似:

open_db(p);
memcpy(&data, p, sizeof(data));
data.cnt = 0;


  再继续。

  找到类似这样的一句:

strcmp(azArg[1],"stdout")==0


  在它的下面的括号中:

  将 strcpy(p->outfile,"stdout");

  用 p->outfilep = "stdout";

  来替换。

  再在它下面的5-6行处

  将:

strcpy(p->outfile,azArg[1]);


  用:

strcpy(outfilename,azArg[1]);
p->outfilep = outfilename;


  替换。

  再继续,找到类似这样的一句:

fprintf(p->out,"%9.9s: %s\n","output",


  将:

fprintf(p->out,"%9.9s: %s\n","output", strlen(p->outfile) ? p->outfile : "stdout");


  用:

fprintf(p->out,"%9.9s: %s\n","output", p->outfilep && strlen(p->outfilep) ? p-> ;outfilep : "stdout");

替换。

  完成修改。

  上面的所有的对sqlite的修改完成后,你就可以make dep;make lib_only;make user_only;make romfs;make image了。

  如果你对sqlite的修改,在make user_only过程中出现错误的话,你可以忽略make dep;make lib_only命令,直接再次进行make user_only;make romfs;make image;就可以了,而不用重复make dep;make lib_only。

  make image会帮你生成romfs文件系统。现在在uClinux-dist/images下面就有编译生成的romfs文件系统了。这个就是我们需要的包含有sqlite的romfs了。

  在上面的过程中,你可以不用在“make image”后再去“make”生成kernel内核,因为你只需要生成romfs就可以了,它里面已经有sqlite了。

  现在你就可以把你生成的含有sqlite应用程序的romfs下载到开发板上运行一下。

Welcome to
____ _ _
/ __| ||_|
_ _| | | | _ ____ _ _ _ _
| | | | | | || | _ \| | | |\ \/ /
| |_| | |__| || | | | | |_| |/ \
| ___\____|_||_|_| |_|\____|\_/\_/
| |
|_|

GDB/ARMulator support by
For further information check:
http://www.uclinux.org/

Command: /bin/ifconfig eth0 up 10.0.0.2
Execution Finished, Exiting
init: Booting to single user mode

Sash command shell (version 1.1.1)
/> cd bin
/bin> ls -l sqlite
-rwxr-xr-x 1 0 0 327072 Jan 01 00:00 sqlite
/bin >cd /tmp
/tmp>sqlite test.sqlite
sqlite> create table my(name varchar(80), num smallint);
sqlite> insert into my values('yutao', 100);
sqlite> insert into my values('uclinux', 99);
sqlite> select * from my;
yutao|100
uclinux|99
sqlite> .tables
my
sqlite> .schema
create table my(name varchar(80), num smallint);
sqlite> .q
/tmp>ls –l test.sqlite


  你要保证你的/tmp是可写的目录。

  好,现在你的sqlite就已经在uclinux运行起来了,感觉如何呀,在uclinux也可以玩玩“select * from”,感觉很爽吧。

上一个:sqlite简明教程
下一个:ucLinux下sqlite嵌入式数据库移植全攻略(2)

Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,