Skip to content

Building MariaDB Connector ODBC

aborkar-ibm edited this page Dec 5, 2019 · 33 revisions

Building MariaDB Connector/ODBC

Below versions of MariaDB Connector/ODBC are available in respective distributions at the time of creation of these build instructions:

  • SLES (15, 15 SP1) has 3.0.2
  • RHEL 8.0 has 3.0.7

The instructions provided below specify the steps to build MariaDB Connector/ODBC version 3.1.4 on Linux on IBM Z for following distributions:

  • RHEL (7.5, 7.6, 7.7, 8.0)
  • SLES (12 SP4, 15, 15 SP1)
  • Ubuntu (16.04, 18.04, 19.04, 19.10)

General Notes:

  • When following the steps below, please use a standard permission user unless otherwise specified.

  • A directory /<source_root>/ will be referred to in these instructions, this is a temporary writable directory anywhere you'd like to place it.

Building and Installing MariaDB Connector/ODBC

Step 1: Build using script

If you want to build MariaDB Connector/ODBC using manual steps, go to Step 2.

Use the following commands to build MariaDB Connector ODBC using the build script. Please make sure you have wget installed.

wget -q https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/MariaDB-Connector-ODBC/3.1.4/build_mariadb_connector_odbc.sh
# Build MariaDB Connector/ODBC
bash build_mariadb_connector_odbc.sh   [Provide -t option for executing build with tests]

In case of error, check logs for more details or go to STEP 2 to follow manual build steps.

Step 2: Install dependencies

  • RHEL (7.5, 7.6, 7.7, 8.0)

    sudo yum install -y mariadb mariadb-server unixODBC unixODBC-devel git cmake gcc openssl-devel openssl wget tar curl libcurl-devel krb5-devel make
    
  • SLES (12 SP4, 15, 15 SP1)

    sudo zypper install -y mariadb unixODBC unixODBC-devel git cmake gcc libopenssl-devel openssl glibc-locale wget tar curl libcurl-devel krb5-devel pcre-devel
    
  • Ubuntu (16.04, 18.04, 19.04, 19.10)

    sudo apt-get update
    sudo apt-get install -y mariadb-server unixodbc-dev git cmake gcc libssl-dev wget tar curl libcurl4-openssl-dev libkrb5-dev
    

Step 3: Build and install MariaDB Connector/ODBC

  • Download MariaDB Connector/ODBC source code

    export SOURCE_ROOT=/<source_root>/
    cd $SOURCE_ROOT
    git clone https://github.com/MariaDB/mariadb-connector-odbc.git
    cd mariadb-connector-odbc
    git checkout 3.1.4
    git submodule init
    git submodule update
  • Make changes to $SOURCE_ROOT/mariadb-connector-odbc/libmariadb/libmariadb/mariadb_stmt.c.

diff --git a/libmariadb/mariadb_stmt.c b/libmariadb/mariadb_stmt.c
index cf35e37..ff2df66 100644
--- a/libmariadb/mariadb_stmt.c
+++ b/libmariadb/mariadb_stmt.c
@@ -1120,7 +1120,7 @@ my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type a
       stmt->state= MYSQL_STMT_INITTED;
       stmt->params= 0;
     }
-    stmt->prebind_params= *(unsigned int *)value;
+    stmt->prebind_params= *(unsigned int *)value >> 16;
     break;
   case STMT_ATTR_ARRAY_SIZE:
     stmt->array_size= *(unsigned int *)value;
  • Make changes to $SOURCE_ROOT/mariadb-connector-odbc/ma_connection.c.
diff --git a/ma_connection.c b/ma_connection.c
index 80c2e36..593e8d8 100644
--- a/ma_connection.c
+++ b/ma_connection.c
@@ -584,7 +584,7 @@ SQLRETURN MADB_DbcConnectDB(MADB_Dbc *Connection,
     MADB_Dsn *Dsn)
 {
   char StmtStr[128];
-  unsigned ReportDataTruncation= 1;
+  my_bool ReportDataTruncation= 1;
   unsigned int i;
   unsigned long client_flags= 0L;
   my_bool my_reconnect= 1;
  • Make changes to $SOURCE_ROOT/mariadb-connector-odbc/test/basic.c.
diff --git a/test/basic.c b/test/basic.c
index d9d6f3a..2a81e07 100644
--- a/test/basic.c
+++ b/test/basic.c
@@ -71,7 +71,7 @@ ODBC_TEST(simple_test)
 {
   SQLRETURN rc= SQL_SUCCESS;

-  SQLINTEGER value=3;
+  SQLSMALLINT value=3;
   SQLWCHAR Buffer[20];

   char buffer[128];
  • Make changes to $SOURCE_ROOT/mariadb-connector-odbc/test/param.c.
diff --git a/test/param.c b/test/param.c
index fff913a..902021f 100644
--- a/test/param.c
+++ b/test/param.c
@@ -1491,6 +1491,7 @@ ODBC_TEST(odbc45)
 {
   SQLSMALLINT i;
   SQLLEN      len= 0;
+SQLCHAR     value;
   SQLCHAR     val[][4]=        {"0",            "1"};//, "4", "-1", "0.5", "z"},
   SQLWCHAR    valw[][4]=       { { '0', '\0' }, { '1', '\0' }, { '4', '\0' }, { '-', '1', '\0' }, { '0', '.', '5', '\0' }, { 'z', '\0' } };
   SQLRETURN   XpctdRc[]=       {SQL_SUCCESS,    SQL_SUCCESS, SQL_ERROR, SQL_ERROR, SQL_ERROR, SQL_ERROR};
@@ -1528,7 +1529,8 @@ ODBC_TEST(odbc45)
   for (i= 0; i<sizeof(XpctdValue); ++i)
   {
     CHECK_STMT_RC(Stmt, SQLFetch(Stmt));
-    is_num(my_fetch_int(Stmt, 1), XpctdValue[i]);
+SQLGetData(Stmt, 1, SQL_C_BIT, &value, sizeof(value), 0);
+is_num(value, XpctdValue[i]);
   }

   CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));
  • Build and install

    • For RHEL and SLES
    cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONC_WITH_UNIT_TESTS=Off  -DWITH_SSL=OPENSSL -DCMAKE_INSTALL_PREFIX=/usr/local
    make
    sudo make install
    • For Ubuntu
    cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONC_WITH_UNIT_TESTS=Off  -DWITH_SSL=OPENSSL -DCMAKE_INSTALL_PREFIX=/usr/local  -DODBC_LIB_DIR=/usr/lib/s390x-linux-gnu/
    make
    sudo make install

Step 4: Testing (Optional)

4.1) Start MariaDB server and configure for testing

  • Start MariaDB server

    sudo mysql_install_db --user=mysql
    sudo mysqld_safe --user=mysql &
  • Create the following softlink

    • RHEL
    sudo ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
    • SLES
    sudo ln -s /run/mysql/mysql.sock /tmp/mysql.sock
    • Ubuntu
    sudo ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
  • Update root plugin and create test database (Only Ubuntu)

    sudo mysql -u root -e "USE mysql; UPDATE user SET plugin='mysql_native_password' WHERE User='root'; FLUSH PRIVILEGES;"
    mysql -u root -e "CREATE DATABASE IF NOT EXISTS test;"

4.2) Run Connector/ODBC test cases

  • Set password for root@localhost

    mysql -u root -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('rootpass');"
  • Set the environment variables

    export TEST_DRIVER=maodbc_test
    export TEST_SCHEMA=test
    export TEST_DSN=maodbc_test
    export TEST_UID=root
    export TEST_PASSWORD=rootpass
  • Edit odbc.ini file and append the following text

    Note: Edit /etc/odbc.ini on RHEL, Ubuntu and /etc/unixODBC/odbc.ini on SLES.

    [maodbc_test]
    Driver      = maodbc_test
    DESCRIPTION = MariaDB ODBC Connector Test
    SERVER      = localhost
    PORT        = 3306
    DATABASE    = test
    UID         = root
    PASSWORD    = rootpass
    
  • Edit odbcinst.ini file and append the following text

    • For SLES and RHEL

    Note:Edit /etc/unixODBC/odbcinst.ini on SLES, /etc/odbcinst.ini on RHEL.

    [ODBC]
    # Change to "yes" to turn on tracing
    Trace     = no
    TraceFile = /tmp/maodbc_trace.log
    
    [maodbc_test]
    Driver      = /usr/local/lib64/libmaodbc.so
    DESCRIPTION = MariaDB ODBC Connector
    Threading   = 0
    IconvEncoding=UTF16
    
    • For Ubuntu

    Note:Edit /etc/odbcinst.ini on Ubuntu.

    [ODBC]
    # Change to "yes" to turn on tracing
    Trace     = no
    TraceFile = /tmp/maodbc_trace.log
    
    [maodbc_test]
    Driver      = /usr/local/lib/libmaodbc.so
    DESCRIPTION = MariaDB ODBC Connector
    Threading   = 0
    IconvEncoding=UTF16
    
  • Run tests

    cd $SOURCE_ROOT/mariadb-connector-odbc/test
    ctest

Note: odbc_connstring is expected to fail for RHEL (7.5, 7.6, 7.7), Ubuntu 16.04. This failure is not specific to IBM Z and can be ignored.
Note: odbc_prepare may fail based on your --secure-file-priv option in your MariaDB configuration.

References:

MariaDB Connector/ODBC

Clone this wiki locally