Skip to content
cnnaik edited this page Feb 15, 2018 · 22 revisions

Building MariaDB Connector/ODBC

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

  • RHEL (7.3, 7.4)
  • SLES (12 SP2, 12 SP3)
  • Ubuntu (16.04, 17.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 writeable directory anywhere you'd like to place it.

1. Install dependencies

  • RHEL (7.3, 7.4)

    sudo yum install -y git wget cmake gcc gcc-c++ make ncurses-devel bison hostname tar boost-devel check-devel openssl-devel perl-CPAN 'perl(Test::More)' unixODBC unixODBC-devel
    
  • SLES (12 SP2, 12 SP3)

    sudo zypper install -y git wget tar cmake gcc gcc-c++ make ncurses-devel boost-devel check-devel openssl-devel bison scons glibc-locale unixODBC unixODBC-devel 
    
  • Ubuntu (16.04, 17.10)

    sudo apt-get update
    sudo apt-get install -y build-essential hostname libncurses-dev git wget cmake gcc make tar libpcre3-dev bison scons libboost-dev libboost-program-options-dev openssl dh-autoreconf libssl-dev unixodbc unixodbc-dev
    

2. Build and Install MariaDB

2.1 Get MariaDB source

     cd /<source_root>/
     wget https://github.com/MariaDB/server/archive/mariadb-10.2.12.tar.gz
     tar xzf mariadb-10.2.12.tar.gz

2.2 Get MariaDB Connector/C source into libmariadb folder

     cd /<source_root>/
     git clone https://github.com/MariaDB/mariadb-connector-c.git
     cd mariadb-connector-c
     git checkout v3.0.3
     cp -r /<source_root>/mariadb-connector-c/* /<source_root>/server-mariadb-10.2.12/libmariadb/

2.3 Build and install

     cd /<source_root>/server-mariadb-10.2.12
     BUILD/autorun.sh 
     ./configure
     make
     sudo make install

2.4 Create a user and group with name mysql

     sudo useradd mysql
     sudo groupadd mysql

2.5 Give owner permission to the mysql directory

     cd /usr/local/mysql                         
     sudo chmod -R o+rwx .

2.6 Create database and populate test data into database

     sudo scripts/mysql_install_db --user=mysql

2.7 Start MySQL server

     sudo cp support-files/mysql.server /etc/init.d/mysql
     sudo /usr/local/mysql/bin/mysqld_safe --user=mysql &
     sudo bin/mysqladmin version --user=mysql
     export PATH=$PATH:/usr/local/mysql/bin

2.8 Drop anonymous user before running test cases

      mysql -u root -e "DROP USER ''@'localhost';"

2.9 Run tests

     cd /<source_root>/server-mariadb-10.2.12/
     make test 

3. Build and install MariaDB Connector ODBC

3.1 Download MariaDB Connector ODBC source code

    cd /<source_root>/
    wget https://github.com/MariaDB/mariadb-connector-odbc/archive/3.0.3.tar.gz
    tar -xvf 3.0.3.tar.gz

3.2 Edit the source files

  • Make changes to /<source_root>/mariadb-connector-odbc-3.0.3/CMakeLists.txt to resolve linking error.
    @@ -207,6 +207,14 @@
    
    ENDIF()
    
    +find_package(ZLIB)
    +if (ZLIB_FOUND)
    +     MESSAGE(STATUS "Configuring to build with ZLIB")
    +     include_directories(${ZLIB_INCLUDE_DIRS})
    +     ADD_DEFINITIONS(-DHAVE_ZLIB)
    +     SET(PLATFORM_DEPENDENCIES ${PLATFORM_DEPENDENCIES} ${ZLIB_LIBRARIES})
    +endif()
    +
    IF(WIN32 OR WITH_OPENSSL)
       IF(WITH_OPENSSL)
         FIND_PACKAGE(OpenSSL)
    
  • Make changes to /<source_root>/mariadb-connector-odbc-3.0.3/ma_connection.c.
    @@ -556,7 +556,7 @@
    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-3.0.3/ma_odbc.h.
    @@ -301,7 +301,7 @@
       MYSQL_RES                 *metadata;
       MADB_List                 ListItem;
       MADB_QUERY                *Tokens;
    -  SQLSMALLINT               ParamCount;
    +  SQLINTEGER                ParamCount;
       enum MADB_DaeType         DataExecutionType;
       MYSQL_RES                 *DefaultsResult;
       int                       ArrayOffset;
  • Make changes to /<source_root>/mariadb-connector-odbc-3.0.3/test/basic.c.
    @@ -71,7 +71,7 @@
    {
       SQLRETURN rc= SQL_SUCCESS;
    
    -   SQLINTEGER value=3;
    +   SQLSMALLINT value=3;
       SQLWCHAR Buffer[20];
    
       char buffer[128];
  • Make changes to /<source_root>/mariadb-connector-odbc-3.0.3/test/param.c.
    @@ -1485,6 +1485,7 @@
    ODBC_TEST(odbc45)
    {
       SQLSMALLINT i;
    +  SQLCHAR value;
       SQLLEN      len= 0;
       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' } };
    @@ -1523,7 +1524,8 @@
      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));
    

3.3 Build MariaDB Connector ODBC

  • Only for RHEL : Create a soft link to libmysqlclient.a in /usr/local/mysql/lib/
  sudo ln -s /usr/local/mysql/lib/libmysqlclient.a /usr/local/mysql/lib/libmariadbclient.a 

3.3.1 Run cmake

  • For RHEL & SLES
  cd /<source_root>/mariadb-connector-odbc-3.0.3/
  cmake ../mariadb-connector-odbc-3.0.3/ -DWITH_OPENSSL=1
  make
  sudo make install
  • For Ubuntu
  cd /<source_root>/mariadb-connector-odbc-3.0.3/
  cmake -DWITH_OPENSSL=1 -DODBC_LIB_DIR=/usr/lib/s390x-linux-gnu/
  make
  sudo make install

4. Run Testcases

4.1 Setup test environment for Connector ODBC

  • Set Password for root user on localhost
   mysql -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'rootpass';CREATE USER 'root' IDENTIFIED BY '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

4.2 Configure Connector/ODBC DSN

4.2.1 Edit odbc.ini file with following configuration

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

[maodbc_test]
Driver      = maodbc_test
DESCRIPTION = MariaDB ODBC Connector Test
SERVER      = localhost
PORT        = 3306
DATABASE    = test
UID         = root
PASSWORD    = rootpass

4.2.2 Edit odbcinst.ini file with following configuration

Note: Edit /etc/unixODBC/odbcinst.ini on SLES and /etc/odbcinst.ini on RHEL & Ubuntu.

[ODBC]
# Change to "yes" to turn on tracing
Trace     = no
TraceFile = /tmp/maodbc_trace.log

[maodbc_test]
Driver      = /<source_root>/mariadb-connector-odbc-3.0.3/libmaodbc.so
DESCRIPTION = MariaDB ODBC Connector
Threading   = 0
IconvEncoding=UTF16

4.2.3 Run tests

cd /<source_root>/mariadb-connector-odbc-3.0.3/test
ctest

References:

MariaDB Connector/ODBC