Boa+php+sqlite's SQLite

Source: Internet
Author: User
Tags sql error sqlite sqlite database

Third, SQLite




Migrating SQLite on the Arm-linux platform

(Chenyunchuan 200620603001 [email protected] Chengdu, Sichuan)
Absrtact: Firstly, this paper introduces the embedded database SQLite, and makes a simple description of the software and hardware platform used in the transplant. Then the details of the transplant process are described in detail by SQLite3, and the SQLite3 database is tested. The test results show that the transplant method adopted in this paper is effective.
Keywords: arm-linux, embedded, SQLite

Port SQLite to Arm-linux Platform
(Yun Chuan Chen, 200620603001, [email protected], Chengdu Sichuan)
Abstract:this Paper first give a brief introduction to SQLite database and the hardware and software platform to port. Then demonstrate SQLite3 's porting process to arm-linux in detail and test the ported SQLite3. The testing result states the porting method This paper proposed is effective.
Keywords:arm-linux, embedded, SQLite

1. Introduction
This article will briefly describe how to migrate the SQLite embedded database on the Arm-linux platform. SQLite is an embedded database engine developed with C language. The latest version of SQLite is 3.3.8, without causing confusion, this article also referred to it as SQLite3.
The goal of the database is to realize the storage, retrieval and other functions of the data. Traditional database products, in addition to providing basic query, add, delete and other functions, but also provides a lot of advanced features, such as triggers, stored procedures, data backup recovery and so on. But in fact, the use of these advanced features is not much, the application is frequently used in the basic function of the database. Therefore, in some special applications, the traditional database appears to be too bloated. In this case, the embedded database begins to emerge. Embedded database is a kind of data file with basic database characteristics, which differs from traditional database: Embedded database is driven directly by program, while traditional database is driven by engine response. Embedded databases are often small in size, which makes embedded databases often used on mobile devices. Because of its excellent performance, embedded databases are often seen in high-performance applications.
SQLite is an embedded database. The goal of SQLite is to be as simple as possible, so it discards the complexities of traditional enterprise-class databases and only implements those features that are essential to the database. Although simplicity is the primary goal of SQLite's quest, its functionality and performance are excellent. It has some features [1]: Support for acid transactions (acid is atomic, consistent, Isolated, durable abbreviation), 0 configuration, no administrative configuration process is required, and most SQL92 standards are implemented All data is stored in a single file, supporting a file size of up to 2TB; The database can be shared between machines of different byte-order, small size, in the case of removing optional function, the code volume is less than 150KB, even if all optional functions are added, the code size is not more than 250KB; low system overhead , the retrieval efficiency is high, the normal database operation is faster than the client/server type database, simple and easy to use API interface, and TCL, Python, C + +, Java, Ruby, Lua, Perl, PHP and other languages binding; self-contained, independent of external support ; Good annotated code; Code test coverage of more than 95%; Open source can be used for any lawful purpose. Due to these outstanding advantages, SQLite was given the 2005 Open Source award! hosted by Google and O ' Reilly
Because of its powerful features, simple interface, fast speed and small footprint, SQLite is particularly suitable for applications in embedded environments. SQLite has been widely used in mobile phones, PDAs, set-top boxes and other devices. This article explains how to migrate SQLite3 based on the Arm-linux kernel.
2. Hardware and software platform
The hardware platform used in this paper is Sitsang embedded evaluation board. The core of the Sitsang Evaluation Board is the PXA255 embedded processor, the PXA255 is a high performance, low power embedded processor based on Intel XScale microarchitecture. Sitsang Evaluation Board is equipped with flash memory, LCD, touch screen, USB interface, Ethernet interface, full-featured serial port (Ffuart), Bluetooth serial (Btuart), audio interface and many other hardware resources.
The underlying software system is based on the Arm-linux kernel. The arm-linux used in the Sitsang evaluation Board was compiled after a patch-2.4.19-sitsang2 patch was made on the linux-2.4.19 kernel.
To port the SQLite3 to the Sitsang evaluation Board, you must have a corresponding cross-compilation toolchain in addition to the support of the underlying operating system. Since the Sitsang evaluation Board uses arm-linux as the underlying operating system, the Arm-linux tool chain needs to be installed first. The installation of the Arm-linux tool chain can be found in literature [4]. The Arm-linux tool chain is typically installed in the/usr/local/arm-linux/bin/directory, usually beginning with arm-linux-. This article will cover the main ARM-LINUX-GCC, Arm-linux-ar, arm-linux-ranlib such as three tools.
3. Transplant process
First download SQLite 3.3.8 from http://sqlite.org. This article assumes that the sqlite-3.3.8.tar.gz is downloaded to the/root directory. Then, unzip the sqlite-3.3.8.tar.gz with the following command and extract the files and directories from the archive:
# tar ZXVF sqlite-3.3.8.tar.gz
After the extraction is complete, a sqlite-3.3.8/subdirectory will be generated in the/root directory containing all the source files and configuration scripts required for compilation. All source code files for SQLite3 are located in the sqlite-3.3.8/src/directory.
Unlike compiling SQLite3 in a PC environment, makefile files cannot be generated from configure scripts under the sqlite-3.3.8/directory. Instead, you must manually modify the makefile file. There is a Makefile sample file MAKEFILE.LINUX-GCC under the sqlite-3.3.8/directory. First copy this file and rename it to makefile with the following command:
# CP MAKEFILE.LINUX-GCC Makefile
Next, open the makefile file with vim and manually modify the contents of the makefile file. First find the following line in the makefile file:
TOP =.. /sqlite
Modify it to:
TOP =.
Find the following line:
TCC = Gcc-o6
Modify it to:
TCC = Arm-linux-gcc-o6
Find the following line:
AR = ar cr
Modify it to:
AR = Arm-linux-ar cr
Find the following line:
Ranlib = Ranlib
Modify it to:
Ranlib = Arm-linux-ranlib
Find the following line:
Mkshlib = gcc-shared
Modify it to:
Mkshlib = arm-linux-gcc-shared
Comment out the following line:
Tcl_flags =-i/home/drh/tcltk/8.4linux
Comment out the following line:
LIBTCL =/HOME/DRH/TCLTK/8.4LINUX/LIBTCL8.4G.A-LM-LDL
In principle, the modification of makefile mainly consists of two aspects: first, the compiler, archiving tools and other tools in the cross-tool chain, for example, the GCC replaced with Arm-linux-gcc,ar for Ar-linux-ar,ranlib exchange into Arm-linux-ranlib and so on, followed by the removal of TCL-related compilation options, because by default, the SQLite3 Tcl language bindings will be compiled, but not required when porting to Arm-linux, so two TCL-related lines are commented out. A summary of the changes to makefile is shown in table 1.
Table 1 Makefile Modification position original value changed to
17 Row top =. /sqlitetop =.
73 rows TCC = GCC-O6TCC = Arm-linux-gcc-o6
81 line ar = ar crar = arm-linux-ar cr
83 rows Ranlib = Ranlibranlib = Arm-linux-ranlib
86 rows mkshlib = Gcc-sharedmkshlib = arm-linux-gcc-shared
96 rows tcl_flags =-i/home/drh/tcltk/8.4linux#tcl_flags =-i/home/drh/tcltk/8.4linux
103 rows libtcl =/HOME/DRH/TCLTK/8.4LINUX/LIBTCL8.4G.A-LM-LDL#LIBTCL =/home/drh/tcltk/8.4linux/libtcl8.4g.a-lm-ldl


Next, one of the files that needs to be modified is MAIN.MK, because makefile contains this file. Locate the following line in this file:
SELECT.O table.o TCLSQLITE.O TOKENIZE.O trigger.o
Replace it with:
SELECT.O TABLE.O TOKENIZE.O TRIGGER.O
That is to remove the TCLSQLITE.O on the line. This compilation will not compile SQLite3 's Tcl language bindings.
Since then, the modifications have been completed and the SQLite3 is ready to be compiled, which can be done with the make command:
# make
Once the compilation is complete, the library function file libsqlite3.a and header file Sqlite3.h will be generated under the sqlite3.3.8/directory, which is the required two files.
4. Testing
This is the example of a test procedure in the Quick Start document http://sqlite.org The official SQLite site to test the SQLite3 ported to Arm-linux. The program list is as follows:
1 #include
2 #include
3
4 static int
5 callback (void *notused, int argc, char **argv, char **azcolname)
6 {
7 int i;
8
9 for (i = 0; i < argc; i++) {
printf ("%s =%s\n", Azcolname[i], argv[i], Argv[i]: "NULL");
11}
printf ("\ n");
return 0;
14}
15
+ int
Main (int argc, char **argv)
18 {
Sqlite3 *db;
char *zerrmsg = 0;
int RC;
22
if (argc! = 3) {
fprintf (stderr, "Usage:%s DATABASE sql-statement\n", argv[0]);
Exit (1);
26}
rc = Sqlite3_open (argv[1], &db);
if (RC) {
fprintf (stderr, "Can ' t Open database:%s\n", sqlite3_errmsg (db));
Sqlite3_close (DB);
To exit (1);
32}
rc = sqlite3_exec (db, Argv[2], callback, 0, &zerrmsg);
if (rc! = SQLITE_OK) {
fprintf (stderr, "SQL Error:%s\n", zerrmsg);
Sqlite3_free (ZERRMSG);
37}
Sqlite3_close (DB);
0;
40}
Save the source program as TEST.C, and then compile the program with the following command:
# arm-linux-gcc-i/root/sqlite-3.3.8/-l/root/sqlite-3.3.8-o Test Test.c-lsqlite3
In the above compilation command,-i/root/sqlite-3.3.8 indicates the directory where the header file Sqlite3.h is located,-l/root/sqlite3.3.8 specifies the directory where the library function file libsqlite3.a is located,-O TEST specifies that the compiled generated file name test,test.c is the source program file,-lsqlite3 indicates that you want to link the static library file libsqlite3.a. After compiling, the test can be downloaded to the Sitsang Evaluation Board via NFS or FTP, with the LS command to see that the test size is only about 300K:
[[email protected] root] $ll-h test
-rwxr-xr-x 1 root root 323.5k Jan 1 00:07 test
The test program can then be tested. The test program accepts two parameters: the first parameter is the database file name, and the second parameter is the SQL statement to execute. There are four main areas associated with SQLite3 APIs in the program: the 27th line of Sqlite3_open (), the 33rd line of Sqlite3_exec (), the 30th line and the 38th row of Sqlite3_close (), the sqlite3_free of the 36th line ( )。 Refer to the documentation [1] for the API interface for SQLite3.
The following is the complete process of testing the test program, and it is important to note that because the commands are long, each command is divided into multiple lines of input, which seems to be clearer:
[Email protected] root]$./test xyz.db "CREATE table
> tbl0 (name varchar (ten), number smallint); "
[Email protected] root]$./test xyz.db "INSERT INTO
> Tbl0 values (' Cyc ', 1); "
[Email protected] root]$./test xyz.db "INSERT INTO
> Tbl0 values (' Dzy ', 2); "
[Email protected] root]$./test xyz.db "SELECT *
> from tbl0; "
Name = Cyc
Number = 1

Name = Dzy
Number = 2
Explain the test command used above: The first command creates a tbl0 table in the Xyz.db database file, which contains two fields, the field name is a variable-length string, the field number is of type smallint, and the second The command inserts a record into the database's tbl0 table (' Cyc ', 1), the third command inserts a record into the Tbl0 table of the database (' Dzy ', 2), and the fourth command is all the contents of the query table Tbl0, as expected, This command prints two newly inserted records in addition to the database. It can be concluded that these commands have indeed been working as expected.
Also, after inserting the data shown above into the database, you can see that the xyz.db size of the database file has changed:
[[email protected] root] $ll-h xyz.db
-rw-r--r--1 root root 2.0k Jan 1 00:18 xyz.db
The size of the database file xyz.db at this time is 2K. Since then, the SQLite3 database has been migrated on the Sitsang evaluation Board. The test results indicate that the database can work properly.
5. Conclusion
SQLite is an excellent embedded database. This article describes in detail how to transplant SQLite3 to the Arm-linux platform and tests the transplanted SQLite3 in a simple way. With its powerful features, high efficiency, 0 configuration, and small size, SQLite makes it ideal for embedded mobile devices. Therefore, the details of transplant SQLite3 in this paper are of positive significance. Because SQLite3 is developed in C language, portability is very good. The methods discussed in this paper can also be applied to other operating system platforms with slight modification.
Reference documents
[1] The definitive guide to SQLite. Beauty Michael Owens. apress,2006
[2] Http://sqlite.org
[3] SQLite transplant notes. Hily Jiang. WWW.SQLITE.COM.CN,2006 year November
[4] sitsang/pxa255 Evaluation Platform Linux User ' s Guide. Intel ltd,sep. 2003 Read (2178) | Comments (0) | Forwards (0) | 0

Previous: Boa+php+sqlite PHP

Next post: Grub boot Win 7

Related Popular articles
    • Welcome to Phplearner in Chinaunix bo ...
    • About PHP Slow.log is not effective ...
    • Welcome to Phpsuper in Chinaunix blog ...
    • Welcome to xuefeiphp in Chinaunix blog ...
    • Welcome to xcc_4php in Chinaunix blog ...
    • sHTML is what _ssi have what use ...
    • String manipulation in the shell
    • The principle of Kalman filter explains ...
    • About "Error in Java: Not found or ...
    • Special characters in the shell
    • Linux DHCP Peizhi ROC
    • Soft links to Unix files
    • What does this command mean, I'm new ...
    • What does sed-e "/grep/d" mean ...
    • Who can help me solve Linux 2.6 10 ...
Leave something to the owner! ~~ Comment on the hot topic

Boa+php+sqlite's SQLite

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.