【前言】
SQLite是遵守ACID的關聯式數據庫管理系統,它包含在一個相對小的C庫中, 是一款輕量輕級數據庫。它是D.RichardHipp建立的公有領域項目。不像常見的客戶-服務器范例,SQLite引擎不是個程序與之通信的獨立進程,而是連接到程序中成為它的一個主要部分。
所以主要的通信協議是在編程語言內的直接API調用。這在消耗總量、延遲時間和整體簡單性上有積極的作用。整個數據庫(定義、表、索引和數據本身)都在宿主主機上存儲在一個單一的文件中。它的簡單的設計是通過在開始一個事務的時候鎖定整個數據文件而完成的。SQLite非常適合嵌入式系統應用。所以我們的openwrt用此數據庫
【實操---交叉編譯sqlite】
獲取sqlite源碼(如果是已經編譯過的舊工程可跳過此步驟)
解壓
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/sqlite3root@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
./sqlite3SQLite version 3.41.0 2023-02-21 1837Enter ".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 [close] [#]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 // 退出
審核編輯:劉清
-
存儲器
+關注
關注
38文章
7528瀏覽量
164194 -
嵌入式系統
+關注
關注
41文章
3620瀏覽量
129655 -
SQlite
+關注
關注
0文章
78瀏覽量
15983 -
openwrt系統
+關注
關注
0文章
3瀏覽量
1561
原文標題:【openwrt】移植sqlite 交叉編譯sqlite3
文章出處:【微信號:嵌入式加油站,微信公眾號:嵌入式加油站】歡迎添加關注!文章轉載請注明出處。
發布評論請先 登錄
相關推薦
評論