【前言】
SQLite是遵守ACID的關(guān)聯(lián)式數(shù)據(jù)庫管理系統(tǒng),它包含在一個相對小的C庫中, 是一款輕量輕級數(shù)據(jù)庫。它是D.RichardHipp建立的公有領(lǐng)域項目。不像常見的客戶-服務(wù)器范例,SQLite引擎不是個程序與之通信的獨立進程,而是連接到程序中成為它的一個主要部分。
所以主要的通信協(xié)議是在編程語言內(nèi)的直接API調(diào)用。這在消耗總量、延遲時間和整體簡單性上有積極的作用。整個數(shù)據(jù)庫(定義、表、索引和數(shù)據(jù)本身)都在宿主主機上存儲在一個單一的文件中。它的簡單的設(shè)計是通過在開始一個事務(wù)的時候鎖定整個數(shù)據(jù)文件而完成的。SQLite非常適合嵌入式系統(tǒng)應(yīng)用。所以我們的openwrt用此數(shù)據(jù)庫
【實操---交叉編譯sqlite】
獲取sqlite源碼(如果是已經(jīng)編譯過的舊工程可跳過此步驟)
解壓
tar vzxf sqlite-autoconf-3410000.tar.gz
cd sqlite-autoconf-3410000/
查看編譯說明
cat README.txt
查閱Makefile
cat Makefile
創(chuàng)建編譯目標(biāo)目錄
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
編譯結(jié)果
ls mips_build/
binincludelibshare
bin ---- 存放可以執(zhí)行文件 sqilte3 可傳到開發(fā)板執(zhí)行
inlcude ---- 供外部調(diào)到的頭文件,聲明了相關(guān)sqlite庫接口
lib ---- sqlite動態(tài)連接庫
share -- sqtlie相關(guān)共享庫
把庫加入到用戶源碼工程,工程中就用使用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
【實操--在開發(fā)板上運行】
確認(rèn)開發(fā)板與電腦開發(fā)機在同一局域網(wǎng)下
scp bin/sqlite3root@192.168.3.176:/root/
按提示輸入開發(fā)板密碼
root@192.168.3.176's password:
等待傳輸完成sqlite3 100% 7297KB 164.7KB/s 00:44
在開發(fā)執(zhí)行sqlite3
到root目錄,因為剛才傳入的是root目錄
cd /root
查看sqlite3屬性
ls -la
...
-rwxr-xr-x 1 root root 7472168 Jul4 13:47 sqlite3 //開發(fā)板用的root應(yīng)用,可以看到在開發(fā)板,已經(jīng)有了可執(zhí)行權(quán)
...
運行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使用方法, 數(shù)據(jù)庫使用太多內(nèi)容,本文是講不完的,有用到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 // 退出
審核編輯:劉清
-
存儲器
+關(guān)注
關(guān)注
38文章
7492瀏覽量
163833 -
嵌入式系統(tǒng)
+關(guān)注
關(guān)注
41文章
3593瀏覽量
129472 -
SQlite
+關(guān)注
關(guān)注
0文章
78瀏覽量
15945 -
openwrt系統(tǒng)
+關(guān)注
關(guān)注
0文章
3瀏覽量
1555
原文標(biāo)題:【openwrt】移植sqlite 交叉編譯sqlite3
文章出處:【微信號:嵌入式加油站,微信公眾號:嵌入式加油站】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
相關(guān)推薦
評論