Qt – SQL Drivers

Prerequisites

Change the working directory to [Path2QtSdk]/Src/qtbase/src/plugins/sqldrivers and if necessary clean previous build files.

# Clean working directory.
# The base directory.
rm -rf config
rm Makefile

# The MySQL directory.
rm mysql/Makefile*

# The SQLite directory.
rm sqlite/Makefile*

(Optional) Install Spatialite

If wanted to support Spatialite module within SQLite.

MacOSX

# Install using port.
sudo port install spatialite

[1] System SQLite with Spatialite Support

(1) Edit sqlite/sqlite.pro

(Optional) Replace static linking with dynamic library.
MacOsx: /opt/local/spatialite.dynlib => /opt/local/lib/libspatialite.a

== sqlite/sqlite.pro ==
....
qtConfig(system-sqlite) {
    QMAKE_USE += sqlite
    LIBS += /opt/local/lib/libspatialite.a
} else {
....
=======================

(2) Edit configure.json

Add the following lines under features, due to missing zlib.

== configure.json (sqlite3) ==
....
,
"system-zlib": {
    "label": " Using system provided zLib",
    "autoDetect": false,
    "condition": "",
    "output": [ "privateFeature" ]
}
....
==============================

(3) Build Plugin

# Configure.
# MacOSX
[Path2QtSdk]/bin/qmake -- -system-sqlite SQLITE_PREFIX=/opt/local

# Build.
make sub-sqlite

[2] Qt 3rdParty SQLite with Spatialite Support

(1) Modify sqlite.pri

Edit [Path2Qt]/Src/qtbase/src/3rdparty/sqlite.pri

# (1) Remove following: 
SQLITE_OMIT_LOAD_EXTENSION from DEFINES or add the following line:
DEFINES -= SQLITE_OMIT_LOAD_EXTENSION

# (2) Add following:
DEFINES += SQLITE_ENABLE_LOAD_EXTENSION

(2) Edit configure.json

Edit [Path2Qt]/Src/qtbase/src/plugins/sqldrivers/configure.json
Remove zlib condition from the libraries of sqlite3.

== configure.json (sqlite3) ==
,
"use": [
    { "lib": "zlib", "condition": "!config.win32 && features.system-zlib" }
]
==============================

(3) Build Plugin

# Configure.
[Path2QtSdk]/bin/qmake

# Build.
make

Install Spatialite Module under Usage

Copy or create a symbolic link of mod_spatialite into the respective directory of the application.

MacOSX:
/opt/local/lib/mod_spatialite.so -> [Application]/mod_spatialite.dylib

[3] MySQL

(1) Create Makefiles

Run the following to create the Makefiles.

[Path2QtSdk]/bin/qmake -- MYSQL_PREFIX=[Path2MySQL]
make sub-mysql

(Optional) Edit Makefile.Debug & Makefile.Release (Static Only)

If wanted to static linking the MySQL Client library (provided from MySQL), then search and replace libmysqlclient.dylib with libmysqlclient.a in generated make files.

(2) Build Plugin

Run make sub-mysql again.

Install Plugins

Copy files from plugins/* into [Path2SDK]/[Prefix]/plugins/sqldrivers/