SQLite3 移植到 ARM

前端之家收集整理的这篇文章主要介绍了SQLite3 移植到 ARM前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:Verdana; panose-1:2 11 6 4 3 5 4 4 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:536871559 0 0 0 415 0;} @font-face {font-family:Fixedsys; panose-1:0 0 0 0 0 0 0 0 0 0; mso-font-alt:方正舒体; mso-font-charset:134; mso-generic-font-family:auto; mso-font-format:other; mso-font-pitch:fixed; mso-font-signature:1 135135232 16 0 262144 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"DejaVu Sans"; mso-font-alt:"MS Gothic"; mso-font-charset:128; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} @font-face {font-family:OpenSymbol; mso-font-alt:"MS Gothic"; mso-font-charset:128; mso-generic-font-family:auto; mso-font-pitch:auto; mso-font-signature:0 0 0 0 0 0;} @font-face {font-family:"/@DejaVu Sans"; mso-font-charset:128; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} @font-face {font-family:"/@Fixedsys"; panose-1:0 0 0 0 0 0 0 0 0 0; mso-font-charset:134; mso-generic-font-family:auto; mso-font-format:other; mso-font-pitch:fixed; mso-font-signature:1 135135232 16 0 262144 0;} @font-face {font-family:"/@OpenSymbol"; mso-font-charset:128; mso-generic-font-family:auto; mso-font-pitch:auto; mso-font-signature:0 0 0 0 0 0;} /* Style Definitions */ p.MsoNormal,li.MsoNormal,div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:none; mso-hyphenate:none; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"DejaVu Sans"; mso-font-kerning:.5pt; mso-fareast-language:#00FF;} h1 {mso-style-next:正文文本; margin-top:12.0pt; margin-right:0cm; margin-bottom:6.0pt; margin-left:21.6pt; text-indent:-21.6pt; mso-pagination:none; page-break-after:avoid; mso-outline-level:1; mso-list:l0 level1 lfo1; mso-hyphenate:none; tab-stops:list 0cm; font-size:24.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"DejaVu Sans"; mso-bidi-font-family:"DejaVu Sans"; mso-font-kerning:.5pt; mso-fareast-language:#00FF;} p.MsoHeader,li.MsoHeader,div.MsoHeader {margin:0cm; margin-bottom:.0001pt; mso-pagination:no-line-numbers; mso-hyphenate:none; tab-stops:center 249.3pt right 498.6pt; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"DejaVu Sans"; mso-font-kerning:.5pt; mso-fareast-language:#00FF;} p.MsoBodyText,li.MsoBodyText,div.MsoBodyText {margin-top:0cm; margin-right:0cm; margin-bottom:6.0pt; margin-left:0cm; mso-pagination:none; mso-hyphenate:none; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"DejaVu Sans"; mso-font-kerning:.5pt; mso-fareast-language:#00FF;} a:link,span.MsoHyperlink {mso-style-parent:""; color:navy; mso-ansi-language:#00FF; mso-fareast-language:#00FF; mso-bidi-language:#00FF; text-decoration:underline; text-underline:single;} a:visited,span.MsoHyperlinkFollowed {color:purple; text-decoration:underline; text-underline:single;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:2.0cm 2.0cm 2.0cm 2.0cm; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-page-numbers:num-in-dash; mso-paper-source:0;} div.Section1 {page:Section1;} /* List Definitions */ @list l0 {mso-list-id:1; mso-list-template-ids:1;} @list l0:level1 {mso-level-number-format:none; mso-level-suffix:none; mso-level-text:""; mso-level-tab-stop:0cm; mso-level-number-position:left; margin-left:21.6pt; text-indent:-21.6pt;} @list l0:level2 {mso-level-number-format:none; mso-level-suffix:none; mso-level-text:""; mso-level-tab-stop:0cm; mso-level-number-position:left; margin-left:28.8pt; text-indent:-28.8pt;} @list l0:level3 {mso-level-number-format:none; mso-level-suffix:none; mso-level-text:""; mso-level-tab-stop:0cm; mso-level-number-position:left; margin-left:36.0pt; text-indent:-36.0pt;} @list l0:level4 {mso-level-number-format:none; mso-level-suffix:none; mso-level-text:""; mso-level-tab-stop:0cm; mso-level-number-position:left; margin-left:43.2pt; text-indent:-43.2pt;} @list l0:level5 {mso-level-number-format:none; mso-level-suffix:none; mso-level-text:""; mso-level-tab-stop:0cm; mso-level-number-position:left; margin-left:50.4pt; text-indent:-50.4pt;} @list l0:level6 {mso-level-number-format:none; mso-level-suffix:none; mso-level-text:""; mso-level-tab-stop:0cm; mso-level-number-position:left; margin-left:57.6pt; text-indent:-57.6pt;} @list l0:level7 {mso-level-number-format:none; mso-level-suffix:none; mso-level-text:""; mso-level-tab-stop:0cm; mso-level-number-position:left; margin-left:64.8pt; text-indent:-64.8pt;} @list l0:level8 {mso-level-number-format:none; mso-level-suffix:none; mso-level-text:""; mso-level-tab-stop:0cm; mso-level-number-position:left; margin-left:72.0pt; text-indent:-72.0pt;} @list l0:level9 {mso-level-number-format:none; mso-level-suffix:none; mso-level-text:""; mso-level-tab-stop:0cm; mso-level-number-position:left; margin-left:79.2pt; text-indent:-79.2pt;} @list l1 {mso-list-id:2; mso-list-template-ids:2; mso-list-name:WW8Num2;} @list l1:level1 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:35.35pt; mso-level-number-position:left; margin-left:35.35pt; text-indent:-14.15pt; mso-ascii-font-family:Symbol; mso-hansi-font-family:Symbol; mso-bidi-font-family:OpenSymbol;} @list l1:level2 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:70.7pt; mso-level-number-position:left; margin-left:70.7pt; text-indent:-14.15pt; mso-ascii-font-family:Symbol; mso-hansi-font-family:Symbol; mso-bidi-font-family:OpenSymbol;} @list l1:level3 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:106.05pt; mso-level-number-position:left; margin-left:106.05pt; text-indent:-14.15pt; mso-ascii-font-family:Symbol; mso-hansi-font-family:Symbol; mso-bidi-font-family:OpenSymbol;} @list l1:level4 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:141.4pt; mso-level-number-position:left; margin-left:141.4pt; text-indent:-14.15pt; mso-ascii-font-family:Symbol; mso-hansi-font-family:Symbol; mso-bidi-font-family:OpenSymbol;} @list l1:level5 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:176.75pt; mso-level-number-position:left; margin-left:176.75pt; text-indent:-14.15pt; mso-ascii-font-family:Symbol; mso-hansi-font-family:Symbol; mso-bidi-font-family:OpenSymbol;} @list l1:level6 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:212.1pt; mso-level-number-position:left; margin-left:212.1pt; text-indent:-14.15pt; mso-ascii-font-family:Symbol; mso-hansi-font-family:Symbol; mso-bidi-font-family:OpenSymbol;} @list l1:level7 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:247.45pt; mso-level-number-position:left; margin-left:247.45pt; text-indent:-14.15pt; mso-ascii-font-family:Symbol; mso-hansi-font-family:Symbol; mso-bidi-font-family:OpenSymbol;} @list l1:level8 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:282.8pt; mso-level-number-position:left; margin-left:282.8pt; text-indent:-14.15pt; mso-ascii-font-family:Symbol; mso-hansi-font-family:Symbol; mso-bidi-font-family:OpenSymbol;} @list l1:level9 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:318.15pt; mso-level-number-position:left; margin-left:318.15pt; text-indent:-14.15pt; mso-ascii-font-family:Symbol; mso-hansi-font-family:Symbol; mso-bidi-font-family:OpenSymbol;} ol {margin-bottom:0cm;} ul {margin-bottom:0cm;} -->

Table of Contents

1. sqlite Porting porting to arm step by step

2. Appendix A – Features Of sqlite

3. Appendix B – sqlite command

1. sqlite Porting

1. Download sqlite source

URL: http://www.sqlite.org/download.html

Package src: sqlite3-3.6.23.1.bin.gz

Package doc: sqlite_docs_3_6_23.zip

2. Decompression package

$ tar -zxvf sqlite-amalgamation-3.6.23.1.tar.gz

3. Confirm your Cross compiler is arm-linux-gcc,in my notebook,version is 3.4.5

$ echo $PATH

/crosstool/gcc-3.4.5-glibc-2.3.6/arm-softfloat-linux-gnu/bin:

$ arm-linux-gcc --version

arm-linux-gcc (GCC) 3.4.5

4. Configure

I installed sqlite3 under sqlite_build:

$ mkdir sqlite_build

See more information: ./configure --help

/sqlite-3.6.23.1$ ./configure --host=arm-linux --prefix /

=/home/furtherchan/work/sqlite_porting/sqlite_build

5. make and make install,then you’ll find some files in the sqlite_build dir

(1). view file

furtherchan@further:~/work/sqlite_porting/sqlite_build$ ls

bin include lib share

(2). In embedded system,file size,the smaller the better,u sing arm-linux-strip to remove symbols and sections from files.

furtherchan@further:~/work/sqlite_porting/sqlite_build/lib$ arm-linux-strip libsqlite3.so.0.8.6

furtherchan@further:~/work/sqlite_porting/sqlite_build/lib$ file libsqlite3.so.0.8.6

libsqlite3.so.0.8.6: ELF 32-bit LSB shared object,ARM,version 1,dynamically linked,stripped

(3). if you don’t have follow symbol link,use “ln -s” command to create it.

furtherchan@further:~/work/sqlite_porting/sqlite_build/lib$ ll libsqlite3.so.0

lrwxrwxrwx 1 furtherchan furtherchan 19 2010-06-22 20:59 libsqlite3.so.0 -> libsqlite3.so.0.8.6

(4). copy /bin/sqlite3 into target board /usr/bin/ directory, /lib/ibsqlite3.so.0.8.6 and libsqlite3.so.0 into /lib directory,

6. Start testing,the follow codes are come from: sqlite-3_6_23-docs/quickstart.html

//test.c

#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 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,&zErrMsg);

if ( rc!=sqlITE_OK ){

fprintf(stderr,"sql error: %s/n",zErrMsg);

sqlite3_free(zErrMsg);

}

sqlite3_close(db);

return 0;

}

7. Compiling test.c

$ arm-linux-gcc -I/home/furtherchan/work/sqlite_porting/sqlite_build//

include -L/home/furtherchan/work/sqlite_porting/sqlite_build/lib -o test test.c -lsqlite3

$ file test

test: ELF 32-bit LSB executable,dynamically linked (uses shared libs),for GNU/Linux 2.4.3,not stripped

8. Test sqlite3 in target board:

# echo $PATH

/sbin:/usr/sbin:/bin:/usr/bin

# echo $LD_LIBRARY_PATH

/Qtopia/lib:/lib:

# which sqlite3

/usr/bin/sqlite3

# sqlite3

sqlite version 3.6.23.1

Enter ".help" for instructions

Enter sql statements terminated with a ";"

sqlite> create table gps(pos_x varchar(20),pos_y varchar(20));

sqlite> insert into gps values('123.4','567.8');

sqlite> select * from gps;

123.4|567.8

sqlite>./test

Usage: ./test DATABASE sql-STATEMENT

2. Appendix A

Features Of sqlite

· Transactions are atomic,consistent,isolated,and durable (ACID) even after system crashes and power failures.

· Zero-configuration - no setup or administration needed.

· Implements most of sql92. ( Features not supported )

· A complete database is stored in a single cross-platform disk file .

· Supports terabyte-sized databases and gigabyte-sized strings and blobs. (See limits.html .)

· Small code footprint: less than 300KiB fully configured or less than 180KiB with optional features omitted.

· Faster than popular client/server database engines for most common operations.

· Simple,easy to use API .

· Written in ANSI-C. TCL bindings included. Bindings for dozens of other languages available separately.

· Well-commented source code with 100% branch test coverage .

· Available as a single ANSI-C source-code file that you can easily drop into another project.

· Self-contained : no external dependencies.

· Cross-platform: Unix (Linux and Mac OS X),OS/2,and Windows (Win32 and WinCE) are supported out of the Box. Easy to port to other systems.

· Sources are in the public domain . Use for any purpose.

· Comes with a standalone command-line interface (CLI) client that can be used to administer sqlite databases.

3. Appendix B

sqlite command: from help

sqlite> .help

.backup ?DB? FILE Backup DB (default "main") to FILE

.bail ON|OFF Stop after hitting an error. Default OFF

.databases List names and files of attached databases

.dump ?TABLE? ... Dump the database in an sql text format

If TABLE specified,only dump tables matching

LIKE pattern TABLE.

.echo ON|OFF Turn command echo on or off

.exit Exit this program

.explain ?ON|OFF? Turn output mode suitable for EXPLAIN on or off.

With no args,it turns EXPLAIN on.

.header(s) ON|OFF Turn display of headers on or off

.help Show this message

.import FILE TABLE Import data from FILE into TABLE

.indices ?TABLE? Show names of all indices

If TABLE specified,only show indices for tables

matching LIKE pattern TABLE.

.load FILE ?ENTRY? Load an extension library

.log FILE|off Turn logging on or off. FILE can be stderr/stdout

.mode MODE ?TABLE? Set output mode where MODE is one of:

csv Comma-separated values

column Left-aligned columns. (See .width)

html HTML <table> code

insert sql insert statements for TABLE

line One value per line

list Values delimited by .separator string

tabs Tab-separated values

tcl TCL list elements

.nullvalue STRING Print STRING in place of NULL values

.output FILENAME Send output to FILENAME

.output stdout Send output to the screen

.prompt MAIN CONTINUE Replace the standard prompts

.quit Exit this program

.read FILENAME Execute sql in FILENAME

.restore ?DB? FILE Restore content of DB (default "main") from FILE

.schema ?TABLE? Show the CREATE statements

If TABLE specified,only show tables matching

LIKE pattern TABLE.

.separator STRING Change separator used by output mode and .import

.show Show the current values for varIoUs settings

.tables ?TABLE? List names of tables

If TABLE specified,only list tables matching

LIKE pattern TABLE.

.timeout MS Try opening locked tables for MS milliseconds

.width NUM1 NUM2 ... Set column widths for "column" mode

.timer ON|OFF Turn the cpu timer measurement on or off

原文链接:https://www.f2er.com/sqlite/202921.html

猜你在找的Sqlite相关文章