谷动谷力

 找回密码
 立即注册
查看: 2287|回复: 0
打印 上一主题 下一主题
收起左侧

【openwrt】移植sqlite 交叉编译sqlite3

[复制链接]
跳转到指定楼层
楼主
发表于 2023-7-4 15:27:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 sunsili 于 2024-1-23 11:45 编辑

【openwrt】移植sqlite 交叉编译sqlite3


【前言】
SQLite是遵守ACID的关联式数据库管理系统,它包含在一个相对小的C库中, 是一款轻量轻级数据库。它是D.RichardHipp建立的公有领域项目。不像常见的客户-服务器范例,SQLite引擎不是个程序与之通信的独立进程,而是连接到程序中成为它的一个主要部分。所以主要的通信协议是在编程语言内的直接API调用。这在消耗总量、延迟时间和整体简单性上有积极的作用。整个数据库(定义、表、索引和数据本身)都在宿主主机上存储在一个单一的文件中。它的简单的设计是通过在开始一个事务的时候锁定整个数据文件而完成的。SQLite非常适合嵌入式系统应用。所以我们的openwrt用此数据库

【实操---交叉编译sqlite】
获取sqlite源码(如果是已经编译过的旧工程可跳过此步骤)
  1. wget https://www.sqlite.org/2023/sqlite-autoconf-3410000.tar.gz
复制代码

解压后进到sqite源码目录sqlite-autoconf-3410000
  1. tar vzxf sqlite-autoconf-3410000.tar.gz
  2. cd sqlite-autoconf-3410000/
复制代码

查看编译说明
  1. cat README.txt
复制代码

查阅Makefile
  1. cat Makefile
复制代码

创建编译目标目录
  1. mkdir mips_build
复制代码

编译前配置
  1. ./configure CC=mipsel-openwrt-linux-gcc --host=mipsel-openwrt-linux --prefix=/home/fan/work/sqlite-autoconf-3410000/mips_build/
复制代码

编译sqlite3
  1. make
  2. make install
复制代码


编译结果
  1. ls mips_build/
  2. bin  include  lib  share
复制代码

bin ---- 存放可以执行文件 sqilte3 可传到开发板执行
inlcude ---- 供外部调到的头文件,声明了相关sqlite库接口
lib ---- sqlite动态连接库
share -- sqtlie相关共享库
把库加入到用户源码工程,工程中就用使用sqlite接口了
  1. cp -rf ./* ~/openwrt_21.02.0_mt76x8_jotale_source/package/omj_gateway/extra-libs/mips/sqlite3/
复制代码

如果是cmake工程,在.cmake文件中添加sqlite3--include和lib目录路径
  1. -- EXTRA_INC_PATH=../../extra-libs/mips/sqlite3/include
  2. -- EXTRA_LIB_PATH=../../extra-libs/mips/sqlite3/lib
复制代码


【实操--在开发板上运行】
确认开发板与电脑开发机在同一局域网下
  1. scp bin/sqlite3 root@192.168.3.176:/root/  
复制代码

按提示输入开发板密码
  1. root@192.168.3.176's password:
  2. sqlite3 100% 7297KB 164.7KB/s 00:44  //等待传输完成
复制代码


在开发执行sqlite3
到root目录,因为刚才传入的是root目录
  1. cd /root
复制代码

查看sqlite3属性
  1. ls -la
  2. ...
  3. -rwxr-xr-x    1 root     root       7472168 Jul  4 13:47 sqlite3 //开发板用的root应用,可以看到在开发板,已经有了可执行权
  4. ...
复制代码

运行sqlite3
  1. ./sqlite3
  2. 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朋友,自行补课吧。
  1. sqlite> .help
  2. .auth ON|OFF             Show authorizer callbacks
  3. .backup ?DB? FILE        Backup DB (default "main") to FILE
  4. .bail on|off             Stop after hitting an error.  Default OFF
  5. .binary on|off           Turn binary output on or off.  Default OFF
  6. .cd DIRECTORY            Change the working directory to DIRECTORY
  7. .changes on|off          Show number of rows changed by SQL
  8. .check GLOB              Fail if output since .testcase does not match
  9. .clone NEWDB             Clone data into NEWDB from the existing database
  10. .connection [close] [#]  Open or close an auxiliary database connection
  11. .databases               List names and files of attached databases
  12. .dbconfig ?op? ?val?     List or change sqlite3_db_config() options
  13. .dbinfo ?DB?             Show status information about the database
  14. .dump ?OBJECTS?          Render database content as SQL
  15. .echo on|off             Turn command echo on or off
  16. .eqp on|off|full|...     Enable or disable automatic EXPLAIN QUERY PLAN
  17. .excel                   Display the output of next command in spreadsheet
  18. .exit ?CODE?             Exit this program with return-code CODE
  19. .expert                  EXPERIMENTAL. Suggest indexes for queries
  20. .explain ?on|off|auto?   Change the EXPLAIN formatting mode.  Default: auto
  21. .filectrl CMD ...        Run various sqlite3_file_control() operations
  22. .fullschema ?--indent?   Show schema and the content of sqlite_stat tables
  23. .headers on|off          Turn display of headers on or off
  24. .help ?-all? ?PATTERN?   Show help text for PATTERN
  25. .import FILE TABLE       Import data from FILE into TABLE
  26. .imposter INDEX TABLE    Create imposter table TABLE on index INDEX
  27. .indexes ?TABLE?         Show names of indexes
  28. .limit ?LIMIT? ?VAL?     Display or change the value of an SQLITE_LIMIT
  29. .lint OPTIONS            Report potential schema issues.
  30. .load FILE ?ENTRY?       Load an extension library
  31. .log FILE|off            Turn logging on or off.  FILE can be stderr/stdout
  32. .mode MODE ?OPTIONS?     Set output mode
  33. .nonce STRING            Suspend safe mode for one command if nonce matches
  34. .nullvalue STRING        Use STRING in place of NULL values
  35. .once ?OPTIONS? ?FILE?   Output for the next SQL command only to FILE
  36. .open ?OPTIONS? ?FILE?   Close existing database and reopen FILE
  37. .output ?FILE?           Send output to FILE or stdout if FILE is omitted
  38. .parameter CMD ...       Manage SQL parameter bindings
  39. .print STRING...         Print literal STRING
  40. .progress N              Invoke progress handler after every N opcodes
  41. .prompt MAIN CONTINUE    Replace the standard prompts
  42. .quit                    Stop interpreting input stream, exit if primary.
  43. .read FILE               Read input from FILE or command output
  44. .recover                 Recover as much data as possible from corrupt db.
  45. .restore ?DB? FILE       Restore content of DB (default "main") from FILE
  46. .save ?OPTIONS? FILE     Write database to FILE (an alias for .backup ...)
  47. .scanstats on|off|est    Turn sqlite3_stmt_scanstatus() metrics on or off
  48. .schema ?PATTERN?        Show the CREATE statements matching PATTERN
  49. .selftest ?OPTIONS?      Run tests defined in the SELFTEST table
  50. .separator COL ?ROW?     Change the column and row separators
  51. .sha3sum ...             Compute a SHA3 hash of database content
  52. .shell CMD ARGS...       Run CMD ARGS... in a system shell
  53. .show                    Show the current values for various settings
  54. .stats ?ARG?             Show stats or turn stats on or off
  55. .system CMD ARGS...      Run CMD ARGS... in a system shell
  56. .tables ?TABLE?          List names of tables matching LIKE pattern TABLE
  57. .testcase NAME           Begin redirecting output to 'testcase-out.txt'
  58. .testctrl CMD ...        Run various sqlite3_test_control() operations
  59. .timeout MS              Try opening locked tables for MS milliseconds
  60. .timer on|off            Turn SQL timer on or off
  61. .trace ?OPTIONS?         Output each SQL statement as it is run
  62. .version                 Show source, library and compiler versions
  63. .vfsinfo ?AUX?           Information about the top-level VFS
  64. .vfslist                 List all available VFSes
  65. .vfsname ?AUX?           Print the name of the VFS stack
  66. .width NUM1 NUM2 ...     Set minimum column widths for columnar output
  67. sqlite> .exit // 退出
复制代码


+10

本帖被以下淘专辑推荐:

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|深圳市光明谷科技有限公司|光明谷商城|Sunshine Silicon Corpporation ( 粤ICP备14060730号|Sitemap

GMT+8, 2024-5-19 16:22 , Processed in 0.080911 second(s), 42 queries .

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表