Bug 103077 - Can't connect to an existing Mariadb data base with ODBC (unixODBC or iODBC) using Mariadb ODBC connector
Summary: Can't connect to an existing Mariadb data base with ODBC (unixODBC or iODBC) ...
Status: RESOLVED NOTOURBUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Base (show other bugs)
Version:
(earliest affected)
5.2.2.2 release
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: haveBacktrace
Depends on:
Blocks:
 
Reported: 2016-10-10 03:12 UTC by Howard Johnson
Modified: 2016-10-24 09:29 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
gdbtrace.log of trying to register and open a new LO ODBC database (20.43 KB, text/x-log)
2016-10-12 03:58 UTC, Howard Johnson
Details
LO Base ODBC setup trace (9.03 KB, text/plain)
2016-10-21 20:33 UTC, Howard Johnson
Details
results of ldd and apt-file commands on libmaodbc.so (2.49 KB, text/plain)
2016-10-21 22:25 UTC, Howard Johnson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Howard Johnson 2016-10-10 03:12:41 UTC
Description:
I can't seem to get LibreOffice Base to open a database with ODBC without crashing.

I have unixODBC and iODBC installed and working. I have 2 ODBC drivers (one for MariaDB and one for MDBTools).  I have 4 data sources (DSN's Data Source Names) that I'm testing and they all work when tested with the isql command.

I'm using:
* Debian 8.6, Jessie-Stable 
* MariaDB 10.1  (the latest version)
* unixODBC v. 2.3.1-3  (the latest version)


----------------------------------------------------------
My /etc/odbcinst.ini is as follows (and there is no ~/.odbcinst.ini):

[mariadb]
Description	 = Maria DB
Driver 		 = /usr/lib/x86_64-linux-gnu/odbc/libmaodbc.so
Setup		 = /usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so
UsageCount  	 = 1

[mdbtools]
Description	 = MDBTools Driver
Driver		 = /usr/lib/x86_64-linux-gnu/odbc/libmdbodbc.so
Setup 		 = /usr/lib/x86_64-linux-gnu/odbc/libmdbodbc.so
UsageCount	 = 1



###############################################################
My /etc/odbc.ini is as follows (and there is no ~/.odbc.ini):

#=== For unixODBC =====================================
[mariadb-bigbase]
Description	 = Bigbase - tests ok with isql: show tables
Driver  	 = mariadb
Server           = localhost
Port 		 = 3306
Socket		 = /var/run/mysqld/mysqld.sock
Option		 = 
Stmt 		 = 
User 		 = root
Password 	 = test
Database	 = bigbase

[mdbtools-db]
Description 	 = test ok with isql: select * from m  -- fails on show tables
Driver 		 = mdbtools
Database	 = /home/howard/Documents/db.mdb


#=== For iODBC =========================================
[ODBC Data Sources]
i-mariadb-bigbase	= Mariadb
i-mdbtools-db		= MDB Tools

[i-mariadb-bigbase]
Driver		 = /usr/lib/x86_64-linux-gnu/odbc/libmaodbc.so
Description	 = Bigbase - tests ok with isql: show tables
Server		 = localhost
Port		 = 3306
Socket		 = /var/run/mysqld/mysqld.sock
Option		 = 
Stmt		 = 
User		 = root
Password	 = test
Database 	 = bigbase

[i-mdbtools-db]
Description	= test ok with isql: select * from m
Driver		= /usr/lib/x86_64-linux-gnu/odbc/libmdbodbc.so
Database	= /home/howard/Documents/db.mdb



###############################################################
An example of confirming that the ODBC driver is working with isql is as follows:

#> isql mariadb-bigbase
SQL> show tables
+--------------------------------------------------------------------------+
| Tables_in_bigbase                                                        |
+--------------------------------------------------------------------------+
| locations-all-old0                                                       |
| us-zip-codes                                                             |
+--------------------------------------------------------------------------+
SQLRowCount returns 2
2 rows fetched




Steps to Reproduce:
Open LibreOffice and select: File | New | Database --> opens Database Wizard

From here I have tried two methods of connecting as follows:

attempted method A:

Wizard step 1) * Connect to an existing database: MySQL

Wizard step 2) * Connect using ODBC (Open Database Connectivity) 

Wizard step 3) Name of the ODBC data source on your system: mariadb-bigbase

Wizard step 4) Enter user name, click Test Connection and enter password gives: 
  The connection was established successfully.

Wizard step 5) Select: 
    * Yes, register the database for me.
    X Open the database for editing.

Then click finish and save 'New Database' in ~/Documents.

Result:  "Due to an unexpected error, LibreOffice crashed. ...

and

attempted method B:

Wizard step 1) Connect to an existing database: ODBC

Wizard step 2) Name of the ODBC data source on your system: mariadb-bigbase

Wizard step 3) Enter user name, click Test Connection and enter password gives: 
  The connection was established successfully.

Wizard step 4) Select: 
    * Yes, register the database for me.
    X Open the database for editing.

Then click finish and save 'New Database1' in ~/Documents.

Result:  "Due to an unexpected error, LibreOffice crashed. ...


Actual Results:  
Due to an unexpected error, LibreOffice crashed. ...

Expected Results:
(I could open the connected data base).


Reproducible: Always

User Profile Reset: No

Additional Info:
Cinnamon GUI 2.2.16
Linux Kernel 3.16.0-4-amd64
Memory 7.8 GiB
Graphics Card  AMD RV710/M92


User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0
Comment 1 Joel Madero 2016-10-10 05:09:53 UTC
debug log would be nice: https://wiki.documentfoundation.org/Development/How_to_debug
Comment 2 Robert Großkopf 2016-10-10 10:03:14 UTC
Have connected to MariaDB on OpenSUSE Leap 42.1 64bit rpm Linux.
Installed the packages
MyODBC
unixODBC

In odbcinst.ini I set this:
[MySQL]
Description = ODBC Driver for MySQL
Driver = /usr/lib64/libmyodbc5.so

In odbc.ini I set this
[MySQL-test]
Description = MySQL database test
Driver = MySQL
Server = localhost
Database = libotest
Port = 3306
Socket =
Option = 3
Charset = UTF8

Only error: LO is looking for libodbc.so.1, but there is only a libodbc.so.2 on my system. So I put a link from usr/lib64/libodbc.so.1 to usr/lib64/libodbc.so.2.

Have tried this, could input data - so I couldn't confirm this bug.
Comment 3 Howard Johnson 2016-10-10 14:53:18 UTC
You wrote,

"Have connected to MariaDB ... In odbcinst.ini ... Driver = /usr/lib64/libmyodbc5.so"

Thanks, but I think this is the MySQL driver you're pointing to above, not the MariaDB driver (i.e. "lib my odbc..").

The MariaDB driver is named: libmaodbc.so  (lib ma odbc..).

---

FYI, I tried to use the MySQL driver here but it crashed when I tried to Test the connection.

Which database engine are you using, MariaDB or MySQL?

(In reply to robert from comment #2)
> Have connected to MariaDB on OpenSUSE Leap 42.1 64bit rpm Linux.
> Installed the packages
> MyODBC
> unixODBC
> 
> In odbcinst.ini I set this:
> [MySQL]
> Description = ODBC Driver for MySQL
> Driver = /usr/lib64/libmyodbc5.so
> 
> In odbc.ini I set this
> [MySQL-test]
> Description = MySQL database test
> Driver = MySQL
> Server = localhost
> Database = libotest
> Port = 3306
> Socket =
> Option = 3
> Charset = UTF8
> 
> Only error: LO is looking for libodbc.so.1, but there is only a libodbc.so.2
> on my system. So I put a link from usr/lib64/libodbc.so.1 to
> usr/lib64/libodbc.so.2.
> 
> Have tried this, could input data - so I couldn't confirm this bug.
Comment 4 Howard Johnson 2016-10-10 14:57:36 UTC
(In reply to Joel Madero from comment #1)
> debug log would be nice:
> https://wiki.documentfoundation.org/Development/How_to_debug

Ok, I read thru this a bit.  I might need some help getting this.  I tried to start these but all of them just printed usage:

libreoffice5.2 --base --enable-debug 
libreoffice5.2 --base --enable-debug --enable-selective-debuginfo="sw/ xmloff/"
libreoffice5.2 --base --enable-dbgutil

And I tried this but got "No such file or directory"

./autogen.sh --enable-debug


Do I need to try and build LibreOffice from source?
Comment 5 Robert Großkopf 2016-10-10 15:26:32 UTC
(In reply to Howard Johnson from comment #3)
> "Have connected to MariaDB ... In odbcinst.ini ... Driver =
> /usr/lib64/libmyodbc5.so"
> 
> Thanks, but I think this is the MySQL driver you're pointing to above, not
> the MariaDB driver (i.e. "lib my odbc..").
> 
> The MariaDB driver is named: libmaodbc.so  (lib ma odbc..).

There is no special libmaodbc available for my system (OepnSUSE 42.1 64bit rpm Linux). I use MyODBC-unixODBC instead. Compiled nothing here by myself.
> 
> ---
> 
> FYI, I tried to use the MySQL driver here but it crashed when I tried to
> Test the connection.
> 
> Which database engine are you using, MariaDB or MySQL?

MariaDB 10.0.27-12.1
UnixODBC 2.3.1-3.2

So there must be something special with your installed ODBC-configuration.
Comment 6 Howard Johnson 2016-10-10 15:48:31 UTC
(In reply to robert from comment #5)
> (In reply to Howard Johnson from comment #3)
> > "Have connected to MariaDB ... In odbcinst.ini ... Driver =
> > /usr/lib64/libmyodbc5.so"
> > 
> > Thanks, but I think this is the MySQL driver you're pointing to above, not
> > the MariaDB driver (i.e. "lib my odbc..").
> > 
> > The MariaDB driver is named: libmaodbc.so  (lib ma odbc..).
> 
> There is no special libmaodbc available for my system (OepnSUSE 42.1 64bit
> rpm Linux). I use MyODBC-unixODBC instead. Compiled nothing here by myself.
> > 
> > ---
> > 
> > FYI, I tried to use the MySQL driver here but it crashed when I tried to
> > Test the connection.
> > 
> > Which database engine are you using, MariaDB or MySQL?
> 
> MariaDB 10.0.27-12.1
> UnixODBC 2.3.1-3.2
> 
> So there must be something special with your installed ODBC-configuration.

Thanks.  

I have tried to use the MySQL ODBC driver, but with it I could not get ODBC to work at all, i.e. isql would not connect.  

To solve this I got the libmaodbc MariaDB ODBC connector here:

  https://mariadb.com/products/connectors-plugins
     click <Download MariaDB ODBC driver>

  https://mariadb.com/my_portal/download/connector-odbc
     Then I selected for Debian/Ubuntu, and:
       mariadb-connector-odbc-2.0.12-ga-linux-x86_64.tar.gz
         Inside is:
            /lib
              libmaodbc.so

So I copied the libmaodbc.so file into /usr/lib/x86_64-linux-gnu/odbc/libmaodbc.so, and set Driver=/usr/lib/x86_64-linux-gnu/odbc/libmaodbc.so in odbcinst.ini.  Then isql began to work.

Perhaps there is something special about this connector driver, but it is the one from MariaDB, and I could not get ODBC to work with MariaDB until I installed it.

I'm also working on trying to get some sort of debug log, but am stalled because at the moment I don't know how to do this.  Will keep working on it.  Thanks for your help.
Comment 7 Howard Johnson 2016-10-10 18:54:28 UTC
I just upgraded to unixODBC 2.3.4.  But the results are the same: crash.

Also I'm using Maria 10.1 which could have changed something I suppose.

  your Maria version: 10.0.27-12.1
  mine, via this command:
    mysql --version 
       Ver 15.1 Distrib 10.1.18-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Previously, our unixODBC versions were very close:

  yours  2.3.1-3.2
  mine   2.3.1-3
Comment 8 Robert Großkopf 2016-10-11 07:52:08 UTC
Have tried it a little bit more.

libmaodbc.so: 
I couldn't get it work with the binaries. 
One version (2.0.12, libmadoc.so 1.6 MB) gives the error: file not found
Other version (2.0.12, libmadoc.so 2.0 MB) gives the error: memory allocation error.
I won't install it through the source-code.

Tested all the special differences in our odbcinst.ini and odbc.ini. Worked with all the parameters you have given - but always the same way as without these parameters.

Couldn't reproduce any error here with OpenSUSE 42.1 64bit rpm Linux.
Comment 9 Julien Nabet 2016-10-11 17:39:53 UTC
To retrieve a backtrace on Linux, you can use this link:
https://wiki.documentfoundation.org/QA/BugReport/Debug_Information#GNU.2FLinux:_How_to_get_a_backtrace
Comment 10 Howard Johnson 2016-10-12 03:58:20 UTC
Created attachment 127958 [details]
gdbtrace.log  of trying to register and open a new LO ODBC database

Hope this is the right thing for you.  I've never done this before.
Comment 11 Julien Nabet 2016-10-12 05:13:57 UTC
bt is ok, thank you for your feedback.
Comment 12 Alex Thurgood 2016-10-12 08:23:13 UTC
I have edited the title to mention that Mariadb is the environment, because this is WFM in a mysql and mysql odbc connector environment.
Comment 13 Alex Thurgood 2016-10-12 08:36:26 UTC
@Howard :

- you might have more luck trying to ask for help on the Debian forums as there probably aren't many of us in Base QA using Mariadb over ODBC (with the exception of perhaps Julien)?

You don't state whether the LibreOffice you are using is the Jesse-provided one, or else the TDF-distributed DEBs ?

My immediate suspicion would be that the version of LO you are using has not been compiled against the same version of the mariadb connector client library source code. The only way to know this is to see if there is a log of the compile options somewhere in the LO packages you have installed.

This should not be in NEW status without independent QA confirmation, resetting to NEEDINFO, please set back to UNCONFIRMED once you have provided the requested information.
Comment 14 Julien Nabet 2016-10-12 08:53:49 UTC
(In reply to Alex Thurgood from comment #13)
> @Howard :
> 
> - you might have more luck trying to ask for help on the Debian forums as
> there probably aren't many of us in Base QA using Mariadb over ODBC (with
> the exception of perhaps Julien)?
>...

I'm dealing far less than before Base bugs because:
1) for this case specifically, it seems we're still in transition between Mysql and MariaDB (I don't remember details with C and C++ driver and license)
2) we don't upgrade to a newer hsqlDB version because target is Firebird
3) Firebird is still experimental because of some bugs even with Firebird 3.0 (eg: building in MacOS)
4) Reports components are also obsolete
Comment 15 Alex Thurgood 2016-10-12 08:59:20 UTC
@Juilen : Thanks for the update, and quite agree, the whole mysql/mariadb support is all a bit of a mess at the moment (as indeed are other parts of Base as you mention).


@Howard : my inexpert reading of your trace log would seem to show that there is an incompatibility in the ODatabaseMetaData.cxx code with what the driver is expecting, or announcing, as to its capabilities.
Comment 16 Alex Thurgood 2016-10-12 09:02:27 UTC
FWIW, bug 46259 is still opne, i.e. nothing has progressed so far on the rewrite of the connector C++ to use mariadb connector C code instead. Perhaps the ODBC connector shares some common ancestry here ?
Comment 17 Alex Thurgood 2016-10-12 09:07:49 UTC
For an example of the potential for an compatibility with Mariadb client library, see also bug 83656
Comment 18 Julien Nabet 2016-10-12 20:36:30 UTC
Just some thoughts.
Since you didn't install MariaDb odbc driver from Debian repo with apt but with tar.gz file from official website, perhaps there's something lacking.

I didn't try to reproduce the problem but on my system, ldd mariadb-connector-odbc-2.0.12-ga-linux-x86_64/lib/libmaodbc.so 
gives this:
	linux-vdso.so.1 (0x00007ffdf37fb000)
	libodbcinst.so.2 => /usr/lib/x86_64-linux-gnu/libodbcinst.so.2 (0x00007eff25701000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007eff253fd000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007eff2505f000)
	libltdl.so.7 => /usr/lib/x86_64-linux-gnu/libltdl.so.7 (0x00007eff24e55000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007eff24c38000)
	/lib64/ld-linux-x86-64.so.2 (0x0000557394653000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007eff24a32000)

if you apt-file all of these referenced files, you'll find a package for them except for linux-vdso.so.1 which is a bit specific

apt-file search libodbcinst.so.2 gives odbcinst1debian2
apt-file search libm.so.6 gives libc6
idem for libc.so.6, libpthread.so.0, ld-linux-x86-64.so.2 and libdl.so.2
apt-file search libltdl.so.7 gives libltdl7

To sum up, do you confirm these packages are installed:
odbcinst1debian2, libc6 and libltdl7 ?
Comment 19 Lionel Elie Mamane 2016-10-14 12:29:59 UTC
(In reply to Alex Thurgood from comment #16)
> FWIW, bug 46259 is still opne, i.e. nothing has progressed so far on the
> rewrite of the connector C++ to use mariadb connector C code instead.
> Perhaps the ODBC connector shares some common ancestry here ?

(In reply to Julien Nabet from comment #14)
> 1) for this case specifically, it seems we're still in transition between
> Mysql and MariaDB (I don't remember details with C and C++ driver and
> license)

Since this is about connecting through an ODBC driver, this is completely unrelated to the idea of rewriting the NATIVE SDBC driver to not use the GPLed MySQL C++ connector.
Comment 20 Lionel Elie Mamane 2016-10-14 12:39:20 UTC
I wouldn't be too surprised if the MariaDB libmaodbc didn't implement
 SQLGetInfo(... SQL_FILE_USAGE ...)
or did it incorrectly. Cannot be sure until I take a good look at it, though. isql likely doesn't care about SQL_FILE_USAGE

(In reply to Howard Johnson from comment #0)

> [mariadb]
> Description	 = Maria DB
> Driver 		 = /usr/lib/x86_64-linux-gnu/odbc/libmaodbc.so
> Setup		 = /usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so
> UsageCount  	 = 1

The "Driver" and "Setup" entries are inconsistent: you use driver from MariaDB, but setup from MySQL; I wonder it that's not the source of the crash. Please try to use *both* from MariaDB, no mixing.

The backtrace would be far more useful if you installed the libreoffice-dbg package (same version as your installed LibreOffice), or used a debug version of libreoffice, e.g. from one of the directories that ends with "-dbg" at http://dev-builds.libreoffice.org/daily/master/ (since these are builds of master / alpha versions, exercice care and caution).
Comment 21 Julien Nabet 2016-10-14 17:13:52 UTC
Lionel:
I retrieved sources of MariaDB odbc.
In file ma_connection.c, in this function::
SQLRETURN MADB_DbcGetInfo(MADB_Dbc *Dbc, SQLUSMALLINT InfoType, SQLPOINTER InfoValuePtr,
                          SQLSMALLINT BufferLength, SQLSMALLINT *StringLengthPtr, my_bool isWChar)

I noticed this:
   1169   case SQL_FILE_USAGE:
   1170     MADB_SET_NUM_VAL(SQLUINTEGER, InfoValuePtr, SQL_FILE_NOT_SUPPORTED, StringLengthPtr);
   1171     break;
...
Comment 22 Julien Nabet 2016-10-14 17:34:19 UTC
Would this patch help?
diff --git a/connectivity/source/drivers/odbc/ODatabaseMetaData.cxx b/connectivity/source/drivers/odbc/ODatabaseMetaData.cxx
index 65336c2..992f3b5 100644
--- a/connectivity/source/drivers/odbc/ODatabaseMetaData.cxx
+++ b/connectivity/source/drivers/odbc/ODatabaseMetaData.cxx
@@ -50,6 +50,16 @@ ODatabaseMetaData::ODatabaseMetaData(const SQLHANDLE _pHandle,OConnection* _pCon
         try
         {
             m_bUseCatalog   = !(usesLocalFiles() || usesLocalFilePerTable());
+        }
+        catch(SQLException& )
+        { // doesn't matter here
+        }
+        catch(RuntimeException& )
+        {
+            m_bUseCatalog = true;
+        }
+        try
+        {
             OUString sVersion = getDriverVersion();
             m_bOdbc3        =  sVersion != "02.50" && sVersion != "02.00";
         }
Comment 23 Lionel Elie Mamane 2016-10-14 18:59:32 UTC
(In reply to Julien Nabet from comment #21)
> Lionel:
> I retrieved sources of MariaDB odbc.
> In file ma_connection.c, in this function::
> SQLRETURN MADB_DbcGetInfo(MADB_Dbc *Dbc, SQLUSMALLINT InfoType, SQLPOINTER
> InfoValuePtr,
>                           SQLSMALLINT BufferLength, SQLSMALLINT
> *StringLengthPtr, my_bool isWChar)
> 
> I noticed this:
>    1169   case SQL_FILE_USAGE:
>    1170     MADB_SET_NUM_VAL(SQLUINTEGER, InfoValuePtr,
> SQL_FILE_NOT_SUPPORTED, StringLengthPtr);
>    1171     break;
> ...

Try changing on this line 1170 "SQLUINTEGER" to "SQLUSMALLINT". If my guess is right, it will solve the problem.
Comment 24 Julien Nabet 2016-10-14 19:29:37 UTC
I don't know how to build MariaDB odbc driver since there's no instructions about building
Here's the output of cmake:
julien@debian:~/lo/bugs/103077_mariadb/mariadb-connector-odbc-2.0.12-ga-src$ cmake ./
-- The C compiler identification is GNU 6.1.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Looking for floor
-- Looking for floor - not found
-- Looking for floor in m
-- Looking for floor in m - found
CMake Error at CMakeLists.txt:118 (MESSAGE):
  MariaDB not found

However, I can propose this patch on https://github.com/MariaDB/mariadb-connector-odbc
Comment 25 Julien Nabet 2016-10-16 12:48:29 UTC
I submitted a request here:
https://github.com/MariaDB/mariadb-connector-odbc/pull/12
Comment 26 Julien Nabet 2016-10-17 05:16:24 UTC
The Lionel's fix has been pushed!
See https://github.com/MariaDB/mariadb-connector-odbc/pull/12

A test case has been created by the maintener, see https://jira.mariadb.org/browse/ODBC-61?jql=
In this page, we can read:
Fix Version/s:
3.0.0, 2.0.13

So FIXED in the odbc connector and NOTOURBUG.

Thank you Lionel!
Comment 27 Howard Johnson 2016-10-21 20:33:53 UTC
Created attachment 128140 [details]
LO Base ODBC setup trace
Comment 28 Howard Johnson 2016-10-21 20:36:45 UTC
Today I discovered that I could get a trace of the ODBC calls as they were occurring leading up to this crash.  From this I think Base might be crashing inside LO BASE, and not inside of the ODBC manager nor inside the ODBC driver.  

To trace: In the unixODBC gui turn on Tracing from the driver manager, or add the following lines to odbcinit.ini:

[ODBC]
Trace=1
ForceTrace=1
TraceFile=/tmp/Trace.txt
TraceLibrary=libodbctrac.so


From my trace just now (which I will attach) it appears the crash is happening after ODBC call originating in LGetInfo.c line # 554.  Here is the very last entry from the trace showing that the ODBC call completed successfully:

-----------------------------------------------------
[ODBC][3715][1477058411.956470][SQLGetInfo.c][554]
                Entry:
                        Connection = 0x3808a20
                        Info Type = SQL_FILE_USAGE (84)
                        Info Value = 0x7ffc36990c4e
                        Buffer Length = 2
                        StrLen = 0x7ffc36990c06

[ODBC][3715][1477058411.956513][SQLGetInfo.c][617]
                Exit:[SQL_SUCCESS]
------------------------------------------------------

(Sorry if I've been quiet for awhile.  I've been working on trying to follow your leads as quickly as I could, but I'm slow because I have to do a lot of extra reading because of how new to Linux I am, e.g. I had to read a bunch about shared libraries, and learn about cmake and how to use it (especially when it fails), and also freshen my rusty knowledge of c, and scant knowledge of ODBC. 

I figured out how to get the ODBC connector code, and have been going through it to try and understand it.
Comment 29 Howard Johnson 2016-10-21 22:25:14 UTC
Created attachment 128142 [details]
results of ldd and apt-file commands on libmaodbc.so

In my non-expert analysis it appears that everything is in place as you asked me to check.  Attached is the information I collected for you.

(In reply to Julien Nabet from comment #18)
> ... ldd
> mariadb-connector-odbc-2.0.12-ga-linux-x86_64/lib/libmaodbc.so 
> gives this:
> 	linux-vdso.so.1 (0x00007ffdf37fb000)
> 	libodbcinst.so.2 => /usr/lib/x86_64-linux-gnu/libodbcinst.so.2
> (0x00007eff25701000)
> 	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007eff253fd000)
> 	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007eff2505f000)
> 	libltdl.so.7 => /usr/lib/x86_64-linux-gnu/libltdl.so.7 (0x00007eff24e55000)
> 	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
> (0x00007eff24c38000)
> 	/lib64/ld-linux-x86-64.so.2 (0x0000557394653000)
> 	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007eff24a32000)
> 
> if you apt-file all of these referenced files, you'll find a package for
> them except for linux-vdso.so.1 which is a bit specific
> 
> apt-file search libodbcinst.so.2 gives odbcinst1debian2
> apt-file search libm.so.6 gives libc6
> idem for libc.so.6, libpthread.so.0, ld-linux-x86-64.so.2 and libdl.so.2
> apt-file search libltdl.so.7 gives libltdl7
> 
> To sum up, do you confirm these packages are installed:
> odbcinst1debian2, libc6 and libltdl7 ?
Comment 30 Howard Johnson 2016-10-21 22:56:48 UTC
A couple of answers to your comments:

(In reply to Lionel Elie Mamane from comment #20)
> I wouldn't be too surprised if the MariaDB libmaodbc didn't implement
>  SQLGetInfo(... SQL_FILE_USAGE ...)
> or did it incorrectly. 

It's in odbc_3_api.c:

SQLRETURN SQL_API SQLGetInfo(SQLHDBC ConnectionHandle,
    SQLUSMALLINT InfoType,
    SQLPOINTER InfoValuePtr,
    SQLSMALLINT BufferLength,
    SQLSMALLINT *StringLengthPtr)
{
  MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;
  SQLRETURN ret;
  if (!Dbc)
    return SQL_INVALID_HANDLE;
  MADB_CLEAR_ERROR(&Dbc->Error);

  MDBUG_C_ENTER(Dbc, "SQLGetInfo");
  MDBUG_C_DUMP(Dbc, InfoType, d);
  ret= Dbc->Methods->GetInfo(Dbc, InfoType, InfoValuePtr, BufferLength, StringLengthPtr, FALSE);

  MDBUG_C_RETURN(Dbc, ret, &Dbc->Error);
}


> The "Driver" and "Setup" entries are inconsistent: you use driver from
> MariaDB, but setup from MySQL; I wonder it that's not the source of the
> crash. Please try to use *both* from MariaDB, no mixing.

Good point.  I found that MariaDB doesn't offer a ODBC setup driver.

I apologize for neglecting to mention that LO Base is also crashing when trying to connect with MDBTools ODBC driver.  I didn't focus on this because I thought it might just make things too complicated and perhaps we should just deal with one crash at a time.  Note that MDBTools uses the exact same library (one library) as both the driver and setup library.  

Later today I hope to take an ODBC call trace of the similar MDBTools crash, and compare it with the MariaDB ODBC call trace crash.

Anyway this setup library you mention appears to only be used by the unixODBC tools to setup/configure odbc.ini and odbcinst.ini.  (But I'm not 100% sure.)  In other words, if it's missing I can't use those tools, (the gui ODBC configuration tools, or odbcinst).  But that notwithstanding isql works when the setup library is missing.  

I wasn't sure what to do when I found the setup library missing but decided a reasonable idea was to use the mysql one, and it worked.  So I'm not 100% sure, but I think the setup libaray only helps setup the configuration parameters in these two confiburation files (/etc/odbc.ini and /etc/odbcinst.ini).  I think that would also make sense because ALL of the setup libraries (except for MDTTools) are named something like: xxxxxS.lo.  (With a "S").


> The backtrace would be far more useful if you installed the libreoffice-dbg
> package (same version as your installed LibreOffice), or used a debug
> version of libreoffice, e.g. from one of the directories that ends with
> "-dbg" at http://dev-builds.libreoffice.org/daily/master/ (since these are
> builds of master / alpha versions, exercice care and caution).

I will work on this.  Sorry I am slow in responding.  I am new to Linux and having to learn much to proceed little.  Thanks for your help!
Comment 31 Lionel Elie Mamane 2016-10-24 09:29:41 UTC
(In reply to Howard Johnson from comment #28)
> Today I discovered that I could get a trace of the ODBC calls as they were
> occurring leading up to this crash.  From this I think Base might be
> crashing inside LO BASE, and not inside of the ODBC manager nor inside the
> ODBC driver.

While what you write is technically true, I think the ODBC driver overwrites LibreOffice memory when  SQLGetInfo(... SQL_FILE_USAGE ...) is called. Namely it writes, into a LibreOffice-provided pointer (buffer),  4 bytes instead of 2. A patch correcting this was accepted in the driver.

So technically it crashes in LibreOffice code, but it is caused by the ODBC driver.

So please, try with a version of the ODBC driver that is recent enough to include the above accepted patch.

> From my trace just now (which I will attach) it appears the crash is
> happening after ODBC call originating in LGetInfo.c line # 554.  Here is the
> very last entry from the trace showing that the ODBC call completed
> successfully:
> 
> -----------------------------------------------------
> [ODBC][3715][1477058411.956470][SQLGetInfo.c][554]
>                 Entry:
>                         Connection = 0x3808a20
>                         Info Type = SQL_FILE_USAGE (84)
>                         Info Value = 0x7ffc36990c4e
>                         Buffer Length = 2
>                         StrLen = 0x7ffc36990c06
> 
> [ODBC][3715][1477058411.956513][SQLGetInfo.c][617]
>                 Exit:[SQL_SUCCESS]
> ------------------------------------------------------

As I wrote above, it successfully overwrote LibreOffice memory it is not supposed to :)