Connecting to ODBC (Pervasive SQL) database
-
Hello,
I need a way to work with Pervasive Database. I've been searching and testing for hours, trying to find a way to do it.. I'm not a complite stranger to C++ and Qt, but I would count myself a beginner and I'm struggling very much with this. I have managed to build the ODBC driver (atleast I think I did), as my C:\Qt\Qt5.0.1\5.0.1\Src\qtbase\plugins\sqldrivers -folder now has four files:
libsqlodbc.a
libsqlodbcd.a
qsqlobdc.dll
qsqlodbcd.dllSo, the problem is, that whenever I search the internet for solutions, most of the answers are based on earlier versions of Qt. I'm not with Qt5.0.1, and for example, all of the examples I have found, just include #include <QtSql>. If I start with that, I just get:
"QtSql: No such file or directory".
So, with a little improvising, this is my very basic ODBC test code so far:
@
#include <QCoreApplication>
#include <QtSql/QODBCDriver>int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString servername = "LOCALHOST" ;
QString dbname = "DEMODATA";
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setConnectOptions();
QString dsn = QString("DRIVER={Pervasive ODBC Engine Interface);SERVER=%1;DATABASE=%2;Trusted_Connection=Yes;").arg(servername).arg(dbname);
db.setDatabaseName(dsn);return a.exec();
}@These things I'm not sure about:
- Is that include right?
- If the database files are in my local computer, is it right to use LOCALHOST as Servername?
- I've gotten that driver name from ODBC Management. I can access the database from Pervasive Control Center just fine, and that driver name is presented in the settings of the database (in Pervasive Control Center).
Anyway, with this code I get the following errors:
F:\Arkisto\Qt\test_bench\main.cpp:35: error: variable 'QSqlDatabase db' has initializer but incomplete type
F:\Arkisto\Qt\test_bench\main.cpp:35: error: incomplete type 'QSqlDatabase' used in nested name specifierThank you in advance, I really hope I find a solution to get this thing started, I'm usually good at learning things from examples and stuff, when I get the basic code working.. But this one really seems hard for me :P
-
Okay, thanks, that got me forward!
I now compiled and ran the program. At first, I got errors:
QSqlDtabase: QODBC driver not loaded
QSqlDatabase: available drivers: QSQLITEAfter that, I copied the files I from C:\Qt\Qt5.0.1\5.0.1\Src\qtbase\plugins\sqldrivers to C:\Qt\Qt5.0.1\5.0.1\mingw47_32\plugins\sqldrivers (is this right?) and now the program runs without errors!
What would be the next step? If you can provide me with a good tutorial, that would be even better, I can just ask here again if I have too much trouble ;)
EDIT: I've managed to connect to the demodata -database now, and made some basic queries based on this example:
http://www.easysoft.com/developer/libraries/qt/example.cpp
I'll keep trying stuff. Thank you so much Konstantin Podsvirov for your help so far, I'll post more questions if I face problems that I cannot solve myself..
-
Typically, the driver ODBC comes pre-assembled for windows.
In the version of "Qt 5.0.2 for Windows 32-bit":http://download.qt-project.org/official_releases/qt/5.0/5.0.2/qt-windows-opensource-5.0.2-mingw47_32-x86-offline.exe is it just there (I checked).
Separate assembly and manually copying is also possible, if necessary.
Books can be found "here":http://qt-project.org/books.
At the time I was reading "Max Schlee":http://qt-project.org/books/view/qt_4_professional_programming_with_c.