【openwrt】移植sqlite 交叉编译sqlite3
本帖最后由 sunsili 于 2024-1-23 11:45 编辑【openwrt】移植sqlite 交叉编译sqlite3
【前言】
SQLite是遵守ACID的关联式数据库管理系统,它包含在一个相对小的C库中, 是一款轻量轻级数据库。它是D.RichardHipp建立的公有领域项目。不像常见的客户-服务器范例,SQLite引擎不是个程序与之通信的独立进程,而是连接到程序中成为它的一个主要部分。所以主要的通信协议是在编程语言内的直接API调用。这在消耗总量、延迟时间和整体简单性上有积极的作用。整个数据库(定义、表、索引和数据本身)都在宿主主机上存储在一个单一的文件中。它的简单的设计是通过在开始一个事务的时候锁定整个数据文件而完成的。SQLite非常适合嵌入式系统应用。所以我们的openwrt用此数据库
【实操---交叉编译sqlite】
获取sqlite源码(如果是已经编译过的旧工程可跳过此步骤)
wget https://www.sqlite.org/2023/sqlite-autoconf-3410000.tar.gz
解压后进到sqite源码目录sqlite-autoconf-3410000
tar vzxf sqlite-autoconf-3410000.tar.gz
cd sqlite-autoconf-3410000/
查看编译说明
cat README.txt
查阅Makefile
cat Makefile
创建编译目标目录
mkdir mips_build
编译前配置
./configure CC=mipsel-openwrt-linux-gcc --host=mipsel-openwrt-linux --prefix=/home/fan/work/sqlite-autoconf-3410000/mips_build/
编译sqlite3
make
make install
编译结果
ls mips_build/
binincludelibshare
bin ---- 存放可以执行文件 sqilte3 可传到开发板执行
inlcude ---- 供外部调到的头文件,声明了相关sqlite库接口
lib ---- sqlite动态连接库
share -- sqtlie相关共享库
把库加入到用户源码工程,工程中就用使用sqlite接口了
cp -rf ./* ~/openwrt_21.02.0_mt76x8_jotale_source/package/omj_gateway/extra-libs/mips/sqlite3/
如果是cmake工程,在.cmake文件中添加sqlite3--include和lib目录路径
-- EXTRA_INC_PATH=../../extra-libs/mips/sqlite3/include
-- EXTRA_LIB_PATH=../../extra-libs/mips/sqlite3/lib
【实操--在开发板上运行】
确认开发板与电脑开发机在同一局域网下
scp bin/sqlite3 root@192.168.3.176:/root/
按提示输入开发板密码
root@192.168.3.176's password:
sqlite3 100% 7297KB 164.7KB/s 00:44//等待传输完成
在开发执行sqlite3
到root目录,因为刚才传入的是root目录
cd /root
查看sqlite3属性
ls -la
...
-rwxr-xr-x 1 root root 7472168 Jul4 13:47 sqlite3 //开发板用的root应用,可以看到在开发板,已经有了可执行权
...
运行sqlite3
./sqlite3
SQLite version 3.41.0 2023-02-21 18:09:37Enter ".help" for usage hints.Connected to a transient in-memory database.Use ".open FILENAME" to reopen on a persistent database.
查看sqlite使用方法, 数据库使用太多内容,本文是讲不完的,有用到sqlte朋友,自行补课吧。
sqlite> .help
.auth ON|OFF Show authorizer callbacks
.backup ?DB? FILE Backup DB (default "main") to FILE
.bail on|off Stop after hitting an error.Default OFF
.binary on|off Turn binary output on or off.Default OFF
.cd DIRECTORY Change the working directory to DIRECTORY
.changes on|off Show number of rows changed by SQL
.check GLOB Fail if output since .testcase does not match
.clone NEWDB Clone data into NEWDB from the existing database
.connection [#]Open or close an auxiliary database connection
.databases List names and files of attached databases
.dbconfig ?op? ?val? List or change sqlite3_db_config() options
.dbinfo ?DB? Show status information about the database
.dump ?OBJECTS? Render database content as SQL
.echo on|off Turn command echo on or off
.eqp on|off|full|... Enable or disable automatic EXPLAIN QUERY PLAN
.excel Display the output of next command in spreadsheet
.exit ?CODE? Exit this program with return-code CODE
.expert EXPERIMENTAL. Suggest indexes for queries
.explain ?on|off|auto? Change the EXPLAIN formatting mode.Default: auto
.filectrl CMD ... Run various sqlite3_file_control() operations
.fullschema ?--indent? Show schema and the content of sqlite_stat tables
.headers on|off Turn display of headers on or off
.help ?-all? ?PATTERN? Show help text for PATTERN
.import FILE TABLE Import data from FILE into TABLE
.imposter INDEX TABLE Create imposter table TABLE on index INDEX
.indexes ?TABLE? Show names of indexes
.limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT
.lint OPTIONS Report potential schema issues.
.load FILE ?ENTRY? Load an extension library
.log FILE|off Turn logging on or off.FILE can be stderr/stdout
.mode MODE ?OPTIONS? Set output mode
.nonce STRING Suspend safe mode for one command if nonce matches
.nullvalue STRING Use STRING in place of NULL values
.once ?OPTIONS? ?FILE? Output for the next SQL command only to FILE
.open ?OPTIONS? ?FILE? Close existing database and reopen FILE
.output ?FILE? Send output to FILE or stdout if FILE is omitted
.parameter CMD ... Manage SQL parameter bindings
.print STRING... Print literal STRING
.progress N Invoke progress handler after every N opcodes
.prompt MAIN CONTINUE Replace the standard prompts
.quit Stop interpreting input stream, exit if primary.
.read FILE Read input from FILE or command output
.recover Recover as much data as possible from corrupt db.
.restore ?DB? FILE Restore content of DB (default "main") from FILE
.save ?OPTIONS? FILE Write database to FILE (an alias for .backup ...)
.scanstats on|off|est Turn sqlite3_stmt_scanstatus() metrics on or off
.schema ?PATTERN? Show the CREATE statements matching PATTERN
.selftest ?OPTIONS? Run tests defined in the SELFTEST table
.separator COL ?ROW? Change the column and row separators
.sha3sum ... Compute a SHA3 hash of database content
.shell CMD ARGS... Run CMD ARGS... in a system shell
.show Show the current values for various settings
.stats ?ARG? Show stats or turn stats on or off
.system CMD ARGS... Run CMD ARGS... in a system shell
.tables ?TABLE? List names of tables matching LIKE pattern TABLE
.testcase NAME Begin redirecting output to 'testcase-out.txt'
.testctrl CMD ... Run various sqlite3_test_control() operations
.timeout MS Try opening locked tables for MS milliseconds
.timer on|off Turn SQL timer on or off
.trace ?OPTIONS? Output each SQL statement as it is run
.version Show source, library and compiler versions
.vfsinfo ?AUX? Information about the top-level VFS
.vfslist List all available VFSes
.vfsname ?AUX? Print the name of the VFS stack
.width NUM1 NUM2 ... Set minimum column widths for columnar output
sqlite> .exit // 退出
页:
[1]