openwrt之mariadb odbc

There are already unixODBC and mariadb modules in openwrt, but the 19.07.04 version does not have the mariadb-odbc driver, so mariadb and mysql databases cannot be operated through odbc.

  • In feeds/packages/libs, add the libmaodbc directory and create a Makefile
eric@eric-PC:~/Documents/work/openwrt_1907/feeds/packages/libs/libmaodbc$ ls
Makefile

Makefile:

#
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

# https://downloads.mariadb.org/interstitial/connector-odbc-3.0.2/mariadb-connector-odbc-3.0.2-ga-src.tar.gz/from/https%3A//archive.mariadb.org/

include $(TOPDIR)/rules.mk

PKG_NAME:=libmaodbc
PKG_VERSION:=3.0.2
PKG_RELEASE:=1

PKG_SOURCE:=mariadb-connector-odbc-$(PKG_VERSION)-ga-src.tar.gz
PKG_SOURCE_URL:=https://downloads.mariadb.org/interstitial/connector-odbc-$(PKG_VERSION)/mariadb-connector-odbc-$(PKG_VERSION)-ga-src.tar.gz/from/https%3A//archive.mariadb.org/
PKG_HASH:=eba4fbda21ae9d50c94d2cd152f0ec14dde3989522f41ef7d22aa0948882ff93
PKG_BUILD_DIR:=$(BUILD_DIR)/mariadb-connector-odbc-$(PKG_VERSION)-ga-src

PKG_MAINTAINER:=
PKG_LICENSE:=LGPL-2.1-or-later
PKG_LICENSE_FILES:=license.txt

PKG_BUILD_DEPENDS:=unixodbc/host
PKG_BUILD_PARALLEL:=1
PKG_INSTALL:=1

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/cmake.mk

define Package/$(PKG_NAME)/Default
  SUBMENU:=Database
  SECTION:=libs
  CATEGORY:=Libraries
  URL:=https://mariadb.org/
  TITLE:=mariadb driver for ODBC
  DEPENDS:=+unixodbc +libmariadb
endef

define Package/$(PKG_NAME)
$(call Package/$(PKG_NAME)/Default)
  TITLE:=MariaDB oddbc library
  MENU:=1
  PROVIDES:=libmaodbc
endef

define Package/$(PKG_NAME)/description
    MariaDB ODBC Driver.
    It is released under the Library General Public Licence, or LGPL.
endef

CMAKE_OPTIONS += -DMARIADB_INCLUDE_DIR=$(BUILD_DIR)/mariadb-connector-c-3.1.10-src/include
CMAKE_OPTIONS += -DMARIADB_LIBRARY_DIR=$(BUILD_DIR)/mariadb-connector-c-3.1.10-src/libmariadb
# cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo 
# -DCONC_WITH_UNIT_TESTS=Off -DCONC_WITH_MSI=OFF -DCMAKE_INSTALL_PREFIX=/usr/local .
CMAKE_OPTIONS += -DCONC_WITH_UNIT_TESTS=Off \
		-DCONC_WITH_MSI=OFF \
		-DCMAKE_INSTALL_PREFIX=/usr


define Package/$(PKG_NAME)/install
  $(INSTALL_DIR) $(1)/usr/lib
	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/lib/libmaodbc.so $(1)/usr/lib
endef

$(eval $(call BuildPackage,$(PKG_NAME)))

  • Update link files (re-create index files, install symlinks)
./scripts/feeds update -i
./scripts/feeds install -a
  • Enter menuconfig, check the libmaodbc directory just added
 .config - OpenWrt Configuration                                                        
 > Libraries > Database ─────────────────────────────────────────────────────────────── 
  ┌─────────────────────────────────── Database ────────────────────────────────────┐   
  │  Arrow keys navigate the menu.  <Enter> selects submenus ---> (or empty         │   
  │  submenus ----).  Highlighted letters are hotkeys.  Pressing <Y> includes, <N>
  │  excludes, <M> modularizes features.  Press <Esc><Esc> to exit, <?> for Help,   │   </> for Search.  Legend: [*] built-in  [ ] excluded  <M> module  < > module    │   
  │ ┌─────────────────────────────────────────────────────────────────────────────┐ │   
  │ │    <*> libmaodbc.......................................... MariaDB oddbc lib│ │   
  │ │    -*- libmariadb............................... MariaDB database client lib│ │   
  │ │    < > libpq.......................................... PostgreSQL client lib│ │   
  │ │    < > libpqxx........................ PostgreSQL client library (C++ interf│ │   
  │ │    < > libsqlite3....................... SQLite (v3.x) database engine (libr│ │   
  │ │    < > pgsqlodbc..................................... Postgresql driver for │ │   
  │ │    < > psqlodbca...................... psqlODBC - PostgreSQL ODBC driver (AS│ │   
  │ │    < > psqlodbcw...................... psqlODBC - PostgreSQL ODBC driver (UT│ │   
  │ │    < > redis-cli...................................................... Redis│ │   
  │ │    < > redis-server................................................ Redis se│ │   
  │ │    < > redis-utils.............................................. Redis utili│ │   
  │ │    < > tdb..................................................... Trivial Data│ │   
  │ │    -*- unixodbc............................................ unixODBC (librar│ │   
  │ │                                                                             │ │   
  │ └─────────────────────────────────────────────────────────────────────────────┘ │   
  ├─────────────────────────────────────────────────────────────────────────────────┤   <Select>    < Exit >    < Help >    < Save >    < Load >
  └─────────────────────────────────────────────────────────────────────────────────┘   
  • make, generate the corresponding libmaodbc.so
eric@eric-PC:~/Documents/work/openwrt_1907/build_dir/target-mipsel_24kc_musl/mariadb-connector-odbc-3.0.2-ga-src/ipkg-install$ tree
.
└── usr
    ├── lib
    │   └── libmaodbc.so
    └── share
        └── doc
            └── mariadb_connector_odbc
                ├── COPYING
                └── README

5 directories, 3 files
  • Enter the openwrt system and set the configuration file as follows:
root@Openwrt:/etc# cat odbcinst.ini
[ODBC]
Trace = off
TraceFile =


[mariadb]
Driver=/usr/lib/libmaodbc.so
Setup=/usr/lib/libmaodbc.so
UsageCount=1


root@Openwrt:/etc# cat odbc.ini
[mariadb]
Description = The Database for mariadb
Trace = On
TraceFile = stderr
Driver = mariadb
SERVER = 192.168.16.101
USER = root
PASSWORD = 1234
PORT = 3306
DATABASE = test
charset = UTF8
ioption = 3


  • Use the test program main to test the database connected to the server 192.168.16.101 address
root@Openwrt:/# ./main
[main](49)start...
[unixodbc_test](340)
[connect_database](192) Database Connected !
[OD_ListDSN](214)
[query_database](224)
[query_database](227)
[query_database](236)
[query_database](264) Number of Columns 3
[query_database](278) Number of Rows 2
[query_database](282) Result: haha 1
[query_database](282) Result: xixi 2
[close_database](204)
^C

Guess you like

Origin blog.csdn.net/pyt1234567890/article/details/112395053