分类: SQLite/嵌入式数据库
2015-04-17 15:18:38
这两天在搞OBDC的移植,支持sqlite驱动, 搞得头都大了,不过最终还是搞定了,还是比较欣慰,在这做个笔记与大家分享
首先要下载SQLite数据库源码
下载地址:
本文下载的是 sqlite3.8.3
li007lee@li007lee: tar xvf SQLite-e816dd92.tgz
li007lee@li007lee: cd SQLite-e816dd92
li007lee@li007lee: ./configure --host=mipsel-linux --prefix=/home/li007lee/local/unixODBC-2.3.2 --includedir=/home/li007lee/include --libdir=/home/li007lee/lib --bindir=/home/li007lee/bin --sysconfdir=/home/li007lee/etc
--host 指定编译工具
--prefix 指定安装目录
--includedir头文件安装目录
--libdir 库安装目录
--bindir 可执行文件安装目录
--sysconfdir 配置文件位置
等待配置结束后
li007lee@li007lee: make
li007lee@li007lee: make install
然后要下载ODBC源码
下载地址:
本文下载的是
li007lee@li007lee: tar xvf unixODBC-2.3.2.tar.gz
li007lee@li007lee: cd unixODBC-2.3.2
li007lee@li007lee: ./configure --host=mipsel-linux --prefix=/home/li007lee/local/unixODBC-2.3.2 --includedir=/home/li007lee/include --libdir=/home/li007lee/lib --bindir=/home/li007lee/bin --sysconfdir=/home/li007lee/etc --enable-gui=no
--enable-gui=no 是关闭QT图形界面
li007lee@li007lee:make
li007lee@li007lee:make install
最后要下载SQLite 驱动程序
下载地址:
本文下载的是: (当前最新)
li007lee@li007lee: tar xvf sqliteodbc-0.9992.tar.gz
li007lee@li007lee: cd sqliteodbc-0.9992
li007lee@li007lee: ./configure --host=mipsel-linux --prefix=/home/li007lee/local/unixODBC-2.3.2 --includedir=/home/li007lee/include --libdir=/home/li007lee/lib --bindir=/home/li007lee/bin
li007lee@li007lee: make
li007lee@li007lee: make install
三部都完成后,将生成的库文件拷贝到板子的/lib目录下,并创建相应的硬链接
我在一直之前先做成了X86版,通过x86版看到了sqliteobdc需要的链接库如下:li007lee@li007lee:~/bin$ ldd ../lib/libsqlite3odbc.so
linux-gate.so.1 => (0xb7794000)
libsqlite3.so.0 => /home/li007lee/lib/ libsqlite3.so.0
libodbcinst.so.2 => /home/ li007lee /lib/libodbcinst.so.2
(0xb7740000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb7590000)
libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xb758b000)
libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0
(0xb756f000)
/lib/ld-linux.so.2 (0xb7795000)
所以在板子中创建相应的硬链接:
#: ln -s /lib/libodbc.so.2.0.0 /lib/libodbc.so.2 (使用时会用到)
#:ln –s /lib/libsqlite3odbc-0.9992.so /lib/libsqlite3odbc.so
#: ln –s /lib/libsqlite3.so.0.8.6 /lib/libsqlite3.so.0
#: ln –s /lib/libodbcinst.so.2.0.0 /lib/libodbcinst.so.2
libsqlite3odbc.so需求的libc.so.6 和 libdl.so.2 两个库板子中没有,所以:
#:ls –l /lib/libc*
-rw-r--r-- 1 root root 284 Nov 4 08:27 /lib/libc.so
lrwxrwxrwx 1 root root 21 Nov 4 08:27 /lib/libc.so.0 -> libuClibc-0.9.32.1.so
lrwxrwxrwx1 root root 26 Apr 17 13:13 /lib/libc.so.6 -> /lib/libuClibc-0.9.32.1.so
发现所有libc相关的库连接到了libuClibc-0.9.32.1.so
所以:
#:ln –s /lib/libuClibc-0.9.32.1.so /lib/ libc.so.6
同理,将libdl.so.2也做相应操作创建连接
#:ln –s /lib/libdl-0.9.32.1.so /lib/libdl.so.2
将/home/li007lee/etc/ 下的 odbc.ini 和 odbcinst.ini拷贝到板子的/home/li007lee/etc/ 没有就创建 否则会找不到DSN(数据源名称)
添加配置:
1. Add the driver to /home/li007lee/etc/odbcinst.ini:
[SQLite]
Description=SQLite ODBC Driver
Driver=/lib/libsqlite3odbc.so
Setup=/lib/libsqlite3odbc.so
2. Add a DSN to your private odbc.ini:
[mysqlitedb]
Description = My
SQLite test database
Trace = On
TraceFile = stderr
Driver = SQLite
Database=…/***.db (要访问的数据库)
将/home/li007lee/bin/下的工具拷贝到 板子/bin目录下
测试:
# dltest /lib/libodbc.so SQLConnect
SUCCESS: Loaded /lib/libodbc.so
SUCCESS: Found SQLConnect
# isql mysqlitedb -v
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>