一、测试环境为:树莓派3B+
pi@raspberrypi:~/workfile/lorawan/lorawan-gw $ uname -a
Linux raspberrypi 6.1.21-v7+ #1642 SMP Mon Apr 3 17:20:52 BST 2023 armv7l GNU/Linux
测试过程中,请确保树莓派连接网络 ;
二、安装 sqlite及相关命令
2.1 安装命令
sudo apt install sqlite3
sudo apt install libsqlite3-dev
2.2 查看sqlite3的版本
查看安装的sqlite3的版本号的命令: sqlite3 -version
pi@raspberrypi:~ $ sqlite3 -version
3.34.1 2021-01-20 14:10:07 10e20c0b43500cfb9bbc0eaa061c57514f715d87238f4d835880cd846b9ealt1
三、测试
3.1 新建 sqlite_test.c ,代码如下:
pi@raspberrypi ~/code/sqlite $ vi test_sqlite.c
#include <stdio.h>
#include <stdlib.h>
#include <sqlite3.h>
int main()
{
int ret = 0;
sqlite3 *sql_db=NULL;
ret = sqlite3_open("sql_test.db",&sql_db);
printf("This is a test for sqlite3 \n,%d",ret );
return 0;
}
3.2 编译执行
编译脚本 compie.sh
gcc sqlite_test.c -o test_sqlite -lsqlite3
执行结果如下:
pi@raspberrypi:~/workfile/reference/sqlite_test/test2 $ ./compile.sh
pi@raspberrypi:~/workfile/reference/sqlite_test/test2 $ ls
compile.sh sqlite_test.c test_sqlite
pi@raspberrypi:~/workfile/reference/sqlite_test/test2 $ ./test_sqlite
This is a test for sqlite3,0
pi@raspberrypi:~/workfile/reference/sqlite_test/test2 $