Hardware platform: IMX6Q
kernel version: kernel3.0.35
Transplant to ARM board
Step:
1 download source codesqlite-3.6.16.tar.gz
2 Compile the source code and execute the following instructions
cp sqlite-3.6.16.tar.gz /home/liuhaobi/sqlite3
tar -zxvf sqlite-3.6.16.tar.gz
cd /home/liuhaobi/sqlite3/sqlite-3.6.16
./configure –host=arm-linux –prefix=/home/liuhaobi/sqlite3
make
make install
After executing the above instructions, in/home/liuhaobi/sqlite3 will generate BIN, Include, lib folder
In order to prevent errors when copying the soft link file, the lib file is packaged and executed
cd /home/liuhaobi/sqlite3
tar -zcvf lib.tar.gz lib/
3 Copy the executable file and library file to the ARM board
Copy the executable files in the bin file SQLite3 and lib.tar.gz to the SD card, insert the SD card into the development board, execute the following instructions
cp /sddisk/sqlite3 /bin
cp /sddisk/lib.tar.gz /opt
cd /opt
tar -zxvf lib.tar.gz
cp lib/* /lib -rf
4 Test transplantation effect
execute SQLite3, and can enter the SQLite command line, that is, the transplantation is completed
Use C language to operate SQLite database
1 New database test.db
sqlite3 *db = NULL;
sqlite3_open(“test.db”,&db);
2 Turn off the database test.db
sqlite3_close(db);
3 database report error information output
sqlite3_errmsg(db);
4 New database table
char *zErrMsg;
char *sql = ” CREATE TABLE my_table (ID INTEGER PRIMARY KEY,SersorID INTE GER,SiteNum INTEGER,Time VARCHAR(12),SensorParameter REAL);”;
sqlite3_exec(db,sql,0,0,&zErrMsg);
sqlite3_exec(db,sql,0,0,&zErrMsg);
5 Insert data
sql = “INSERT INTO \”my_table\” VALUES(NULL,1,1,’20061685′,18.9)”;
sqlite3_exec(db,sql,0,0,&zErrMsg);
sqlite3_exec(db,sql,0,0,&zErrMsg);
6 query data
int nrow = 0,ncolumn = 0;
char ** azresult; // The two -dimensional array is used to store results
char ** azresult; // The two -dimensional array is used to store results
char *sql = “SELECT * FROM my_table”;
sqlite3_get_table(db,sql,&azResult,&nrow,&ncolumn,&zErrMsg);
sqlite3_get_table(db,sql,&azResult,&nrow,&ncolumn,&zErrMsg);
sqlite3_free_table(azResult);
// Clear the buffer data
// Clear the buffer data
7 Delete data
char *sql = “DELETE FROM my_table WHERE SersorID = 1;”;
sqlite3_exec(db,sql,0,0,&zErrMsg);
sqlite3_exec(db,sql,0,0,&zErrMsg);
8 Update data
char *sql = “UPDATE my_table set SersorID = 5;”;
sqlite3_exec(db,sql,0,0,&zErrMsg);
sqlite3_exec(db,sql,0,0,&zErrMsg);
Specific instance can refer tosqlite3_test.tar
Executive order OpenDBSQLite-> Insert-> Query-> Delete-> Update
Note: When compiling, add the database path and header file path, otherwise an error will be reported
arm-linux-gcc insert.c -o insert_arm -lsqlite3 -I/home/liuhaobi/sqlite3/include -L/home/liuhaobi/sqlite3/lib