Does anyone have any success running mysql ODBC connector with QSqlQuery and mac osx 10.7 ?
-
My application running correctly in Linux and Windows but I have no success with Mac ocx 10.7. I use Qt Libraries 2.5 and Qt Creator 4.8.2. I tried the mysql ODBC 5.1.11 for mac osx 10.6 (Maybe is the problem). I'am able to connect to my database but query.next() return no values. I got this error :QODBC3: Unable to fetch first. I tried to set query.setForwardOnly(true). Someone has an idea
-
Phil,
It appears that there is a bug with query.next() using ODBC in Mac OS X. The bug report for 4.8.0 with a temporary work around is here: https://bugreports.qt-project.org/browse/QTBUG-25260
I know that this bug still exists in 4.8.1, but I've not looked at 4.8.2's source so I can't verify. Hopefully this bug is fixed in Qt 5.0.
I had to recompile the ODBC sql driver plugin from source making the modifications suggested in the work around in qsql_odbc.cpp in the QODBCResult::fetchNext() function on line 1043. The class file, qsql_odbc.cpp, can be found at /Users/[you]/QtSources/4.8.[x]/src/sql/drivers/odbc/qsql_odbc.cpp.
Note: If you downloaded the source outside of Qt Creator, you'll need to browse to where you extracted the source. This applies to all paths supplied in this post.
I commented out the conditional part, beginning on line 1033, where SQLFetchScroll is called so that it looks like this:
@// if (d->hasSQLFetchScroll)
// r = SQLFetchScroll(d->hStmt,
// SQL_FETCH_NEXT,
// 0);
// else
r = SQLFetch(d->hStmt);@Then I opened up /Users/you/QtSources/4.8.x/src/plugins/sqldrivers/odbc/odbc.pro within Qt Creator and built the source. The outputted dylibs are put in the sqldrivers directory in their respective release and debug folders.
When building the plugin, it's very important that you use the correct version of Qt to build. For instance, if you're targeting Qt 4.8.2, make sure you have Qt 4.8.2 configured in your Qt versions from Qt Creator.
After you build the ODBC plugin, you're ready to replace your Qt installation's dylibs with the newly built dylibs. First, make a back up of libqsqlodbc.dylib and libqsqlodbc_debug.dylib from your Qt installation. This is typically in /Users/you/QtSDK/Desktop/Qt/4.8.x/gcc/plugins/sqldrivers. Then you can overwrite your Qt installation's dylibs.
Now you should be able to get results from query.next() within your application.