To build ODBC plugin I need the whole source code?
-
I'm quite confused about the building of the ODBC plugin (to connect to a MySQL database).
Here I read:The ODBC driver is build by default
Instead, here it seems I need to build it.
I have already installed unixODBC. Now, if I need to build the ODBC plugin the docs say:
cd $QTDIR/qtbase/src/plugins/sqldrivers
Dumb question: do I need to download the whole Qt source repository? Or is it possible to find and download only the
sqldrivers
sub-module? -
@Mark81 said in To build ODBC plugin I need the whole source code?:
do I need to download the whole Qt source repository?
No, just QtBase. Also not the repository but the source code matching your Qt version.
Or is it possible to find and download only the sqldrivers sub-module?
No, this is not possible
-
@Mark81 said in To build ODBC plugin I need the whole source code?:
do I need to download the whole Qt source repository?
No, just QtBase. Also not the repository but the source code matching your Qt version.
Or is it possible to find and download only the sqldrivers sub-module?
No, this is not possible
@Christian-Ehrlicher I did what you suggested, but when I issued the following commands (link updated to Qt6) I get errors:
qt-cmake --build . qt-cmake --install
Actually, I had to type:
cmake --build . cmake --install .
But I'm pretty sure I can't be right and the official docs wrong. Anyway, the build was completed successfully.
I cannot findlibodbcHDB.so
in the output directory. I only findlibqsqlodbc.so
. -
Hi, you're sure you want the odbc driver file libodbcHDB.so?
I think that file is for SAP HANA and not for MySQL. -
@Christian-Ehrlicher I did what you suggested, but when I issued the following commands (link updated to Qt6) I get errors:
qt-cmake --build . qt-cmake --install
Actually, I had to type:
cmake --build . cmake --install .
But I'm pretty sure I can't be right and the official docs wrong. Anyway, the build was completed successfully.
I cannot findlibodbcHDB.so
in the output directory. I only findlibqsqlodbc.so
.@Mark81 said in To build ODBC plugin I need the whole source code?:
I cannot find libodbcHDB.so in the output directory. I only find libqsqlodbc.so.
Qt does not build a plugin named libodbcHDB.so - it only creates the libqsqlodbc.so for ODBC access. Don't know why you think you need the other one though.
-
@Mark81 said in To build ODBC plugin I need the whole source code?:
I cannot find libodbcHDB.so in the output directory. I only find libqsqlodbc.so.
Qt does not build a plugin named libodbcHDB.so - it only creates the libqsqlodbc.so for ODBC access. Don't know why you think you need the other one though.
@Christian-Ehrlicher I was my fault then. I saw this code in the link above. I assumed the example was for ODBC.
Anyway, I was able to compile this test application:#include <QCoreApplication> #include <QSqlDatabase> #include <QSqlError> #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QSqlDatabase db = QSqlDatabase::addDatabase("QODBC"); QString connectString = QStringLiteral( "DRIVER=/home/mark/Qt/6.2.0/gcc_64/plugins/sqldrivers/libqsqlodbc.so;" "SERVERNODE=192.168.1.28:3306;" "UID=admin;" "PWD=<password>;" "SCROLLABLERESULT=true"); db.setDatabaseName(connectString); qDebug() << db.open(); qDebug() << db.lastError().text(); return a.exec(); }
but it does not connect:
false
"[unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed QODBC: Unable to connect"Using
mysql
I confirm it works:mysql -h 192.168.1.28 -u admin -p
Maybe I still got it wrong?
-
@Christian-Ehrlicher I was my fault then. I saw this code in the link above. I assumed the example was for ODBC.
Anyway, I was able to compile this test application:#include <QCoreApplication> #include <QSqlDatabase> #include <QSqlError> #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QSqlDatabase db = QSqlDatabase::addDatabase("QODBC"); QString connectString = QStringLiteral( "DRIVER=/home/mark/Qt/6.2.0/gcc_64/plugins/sqldrivers/libqsqlodbc.so;" "SERVERNODE=192.168.1.28:3306;" "UID=admin;" "PWD=<password>;" "SCROLLABLERESULT=true"); db.setDatabaseName(connectString); qDebug() << db.open(); qDebug() << db.lastError().text(); return a.exec(); }
but it does not connect:
false
"[unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed QODBC: Unable to connect"Using
mysql
I confirm it works:mysql -h 192.168.1.28 -u admin -p
Maybe I still got it wrong?
@Mark81 said in To build ODBC plugin I need the whole source code?:
"DRIVER=/home/mark/Qt/6.2.0/gcc_64/plugins/sqldrivers/libqsqlodbc.so;"
This is wrong. You have to pass the correct odbc driver name for your MySQL odbc connection.
But why do you want to use the ODBC plugin to access a mysql database? Wouldn't it be better to directly use the Qt MySQL plugin then? -
@Mark81 said in To build ODBC plugin I need the whole source code?:
"DRIVER=/home/mark/Qt/6.2.0/gcc_64/plugins/sqldrivers/libqsqlodbc.so;"
This is wrong. You have to pass the correct odbc driver name for your MySQL odbc connection.
But why do you want to use the ODBC plugin to access a mysql database? Wouldn't it be better to directly use the Qt MySQL plugin then?@Christian-Ehrlicher I apologize, I'm not an expert of database. This morning the database developer said me: "please connect to our MySql database using an ODBC connection on address x and port y".
You have to pass the correct odbc driver name for your MySQL odbc connection
I'm not sure to understand. Which are the possible names? I mean, in the
plugins/sqldrivers/
I see:But I'm sure they are not using SQLite.
I'm going to try withQtMySQL
, but - be patient - where does the ODBC connection go then? -
It seems I was able to connect!
#include <QCoreApplication>
#include <QSqlDatabase>
#include <QSqlError>
#include <QDebug>int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setHostName("192.168.1.28"); db.setPort(3306); db.setDatabaseName("<db>"); db.setUserName("admin"); db.setPassword("<password>"); qDebug() << db.open(); qDebug() << db.lastError().text(); return a.exec();
}
Still I don't understand why he asked my for ODBC while here I didn't use it...
-
@Mark81 said in To build ODBC plugin I need the whole source code?:
Still I don't understand why he asked my for ODBC while here I didn't use it...
You did use it
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
-
@Mark81 said in To build ODBC plugin I need the whole source code?:
Still I don't understand why he asked my for ODBC while here I didn't use it...
You did use it
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
@Christian-Ehrlicher Sorry, perhaps I explained it wrong.
The code above that begins with:QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
does not connect, while the code that begins with:
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
does connect.
I understand you can say: "well, if it works why still questioning?". I'm afraid about the request of the developer to connect using ODBC. I don't know in detail how it works under the hood, so I'm not sure if I fit the constraints. -
Because, as I said above you're passing a wrong driver string to the ODBC driver.
-
Because, as I said above you're passing a wrong driver string to the ODBC driver.
@Christian-Ehrlicher I will be happy if you would help me to understand how to select the correct string.
-
@Christian-Ehrlicher I will be happy if you would help me to understand how to select the correct string.
@Mark81 I don't know the correct ODBC string for you and would need to google around. But it's the same as you want to open an odbc connection on windows and at least not a path to a qt plugin.