This chapter introduces how to port sqlite3 to the ARM development board and operate sqlite3 in C language on the development board. The relevant supporting materials are in the online disk "iTOP-i.MX6 development board information summary (excluding CD information)\08_iTOP-i.MX6 development board Linux system development information\25-QT system Sqlite3 porting and use" directory. Operation source code download address:
We directly download the latest version (version 3.32.3), and we put the downloaded compressed package under the document directory:
1 Unzip the downloaded compressed package sqlite-autoconf-3320300.tar.gz and create the installation directory mkdir install, as shown in the figure below:
2 Enter the unzipped directory and configure the compilation options: ./configure --host=arm-none-linux-gnueabi
--prefix=/home/topeet/iMX6Q/sqlite3/install/ .
--host: Specifies the cross-compilation tool, which is the same as the compiler for compiling Linux.
--prefix: specifies the installation directory. The files generated after compilation are placed in this directory. It must be an absolute path.
3 Execute make. After completion, it will be as shown in the following figure:
3 Execute make. After completion, it will be as shown in the following figure:
5 Check whether the required files are generated in the install directory.
6 Copy the library files in the lib directory to the /lib/ directory of the development board, and copy the sqlite3 in the bin directory to the /bin/ directory of the development board.
7 Enter sqlite3 in the terminal command line of the development board, and the following figure will be displayed:
8 Test:
1 Create a new table, enter create table user (id int, name char, age int); Then query the table, enter .table, and you can find the user table you just created, as shown in Figure 83.9:
2 Create a .db file
Enter sqlite3 /path/filename.db Be sure to enter .databases after the operation.
3 Write C code test:
Now create a table in the database and insert data:
create table demo (id int,name char,age int);
insert into demo values(100,'WangWu',23);
insert into demo values(101,'Tommm',25);
select * from demo;
The C code is as follows. For details, please refer to the demo source code in the directory.
Enter the following command to cross-compile: arm-none-linux-gnueabi-gcc -I/home/topeet/iMX6Q/sqlite3/install/include/ -L /home/topeet/iMX6Q/sqlite3/install/lib/ -o sql
testSql.c -lsqlite3 -ldl
-I specifies the path where sqlite3.h is located, and
-L specifies the lib library path of sqlite3.
Copy the generated executable file sql to the root directory of the development board
After execution, you can see the query results:
This concludes the introduction to the porting and simple use of sqlite3. Xunwei IMX6Q development board