PDA

View Full Version : PostgreSQL and Windows Community Version



graeme
17th April 2006, 16:30
Hi,

I have been developing an Open Source program in Linux using psotgreSQL and the community version of QT. I am at a stage when I wish to test in in Windows, for that I require the psql plugin.

The commands I used are as follows:


qmake -o Makefile "INCLUDEPATH+=C:\psql\include" "LIBS+=C:\psql\lib\ms\libpq.lib" psql.pro
make

This generated .a and .dll files in the C:\Qt\4.1.1\plugins\sqldrivers directory.

However when I run my program I am unable to load the drivers.

I had also tried to generate the dlls using the configue approach suggesting in an earlier post, again the files were created but I was unable to load the drivers.

Using the File Monitor program (as suggested in an earlier thread) my program is reading this dll. I ask my program to display the available drivers, so I can see it access qsqlite, qsqlodbc and qsqlpsql, teh request and results appear to match in all cases, but the result is that I stil fail to have access to the psql driver from withn my program, so sad.

Does anyone have any suggestion on what else to try?

Many thanks for you time,

graeme.

jacek
17th April 2006, 16:52
Use Dependency Walker (http://www.dependencywalker.com) to check if you have all DLLs required by the PostgreSQL driver.

graeme
17th April 2006, 17:40
Hi,

I tried that. I profiled my app and got the dialog box that I put in to dispaly the number of drivers. I then tried to connect (even though the psql driver is not listed) the connection obviously failed. I then closed the app.

Looking at the output generated by Dependency Walker, it gave references to QTSQLD4.dll, but none of the driver specific dlls.

It flagged a number of dlls in error:
CCL30.DLL, EFSADU.DLL, MSJAVA.DLL and WINTAB32.DLL
And some warning were generated:
KERNEL32.DLL, MPR.DLL, MIDIMAP.DLL and MSCTFIME.DLL

Any suggestions on where I should go next?

cheers,

graeme.

jacek
17th April 2006, 18:58
Looking at the output generated by Dependency Walker, it gave references to QTSQLD4.dll, but none of the driver specific dlls.
Have you tried the Dependency Walker on your application or on the plugin?


It flagged a number of dlls in error:
CCL30.DLL, EFSADU.DLL, MSJAVA.DLL and WINTAB32.DLL
And some warning were generated:
KERNEL32.DLL, MPR.DLL, MIDIMAP.DLL and MSCTFIME.DLL
Don't worry about these DLLs.


Any suggestions on where I should go next?
Do you have a debug version of the plugin? Did you try compiling your application in release mode?

graeme
17th April 2006, 19:29
I ran Dependency Walker on the application, when I run it on the dll I get the following error:

At least one required implicit or forward dependency was not found.

This was for, I believe, LIBPQ.DLL, I do not get this error when I try the other plugins. So I guess this is teh problem, but I'm still unceratn where to go from here, although it does give me something to Google.

The application was origianlly in debug mode, I now have it in release mode, but no difference.

jacek
17th April 2006, 20:03
This was for, I believe, LIBPQ.DLL, I do not get this error when I try the other plugins.
It looks like it can't find the PostgreSQL client library. Find that file and copy it to the same directory where your executable is (you might need other DLLs too, so check it with Dependency Walker).

graeme
17th April 2006, 20:26
Just done that and whilst Dependency Walker is now happy, my app refuses to play ball :mad:

I have now put the driver along with the dlls in the plugin directory and in an sqldrivers directory in the same direcotiry as the executable but no joy.

jacek
17th April 2006, 20:38
I have now put the driver along with the dlls in the plugin directory and in an sqldrivers directory in the same direcotiry as the executable but no joy.
Are you 100% sure that both the plugin and the application were built in the same mode (i.e. both in debug mode or both in release mode)?

graeme
17th April 2006, 20:48
I have both versions of the plugin qsqlpsql.dll & qsqlpsqld.dll.
I tried with a release version of my app, followed by a debug version. I currently have a debug version.
The postgresql dll are (I believe) release versions (no *d.dll)

Should I just revert to the release version of the app?

jacek
17th April 2006, 21:06
Should I just revert to the release version of the app?
No, since you have both versions of the plugin.

What does exactly QSqlDatabase::drivers() return when you invoke it from your application? What parameters do you pass to QSqlDatabase::addDatabase()?

graeme
17th April 2006, 21:19
drivers returns:

QSQLITE
QODBC3
QODBC

The code you requested is:

// Get the connection, if it exists
QSqlDatabase dbConn = QSqlDatabase::database(connName,false);
// Check that the driver is available
if (!QSqlDatabase::isDriverAvailable(connType))
throw sqlE(dbConn, QObject::tr("The Database driver ")+ connType + QObject::tr("is not available"));

followed by:


// Okay the connection doesn't exist so let's add it using the appropriate driver type
dbConn = QSqlDatabase::addDatabase(connType,connName);
The result is "... The Database driver QPSQLis not available"

jacek
17th April 2006, 21:51
This is weird. I've never had any problems with QPSQL driver on windows.


qmake -o Makefile "INCLUDEPATH+=C:\psql\include" "LIBS+=C:\psql\lib\ms\libpq.lib" psql.pro
...
This generated .a and .dll files in the C:\Qt\4.1.1\plugins\sqldrivers directory.
What compiler do you use? I guess you use MinGW, if you got an .a file, but then you shouldn't be able to use the libpq.lib file.

Try:
qmake -o Makefile "INCLUDEPATH+=C:\psql\include" "LIBS+=C:\psql\lib" psql.pro

graeme
17th April 2006, 22:09
I'm using Mingw32

The switch you suggest gives an error:

C:\psql\lib: No such file

following you line of thought (I believe) I tried

qmake -o Makefile "INCLUDEPATH+=C:\psql\include" "LIBS+=C:\psql\lib\libpq.a" psql.pro

that created the files but still nothing when I run the program

jacek
17th April 2006, 22:27
following you line of thought (I believe) I tried
qmake -o Makefile "INCLUDEPATH+=C:\psql\include" "LIBS+=C:\psql\lib\libpq.a" psql.pro
Yes, or "LIBS+= -LC:\psql\lib\ -lpq".


that created the files but still nothing when I run the program
I hope you have removed all copies of the old driver.

I always configure Qt like this:
configure -L C:\...\psql\lib -I C:\...\psql\include -plugin-sql-psql ...
Which Qt version do you use exactly? In one of the older versions one had to remove some keys from the registry in case of problems with plugins. It was something around HKEY_CURRENT_USER\Software\Trolltech\OrganizationD efaults\Qt Plugin Cache...

graeme
17th April 2006, 22:35
I'm using 4.1.1

I removed the old drivers, in fact I renamed the old file ran my program - no drivers. Copied the qsqlited.dll into the sqldrivers folder of my app it found that driver. Removed it - no drivers.

Then ran the make. It created a new sqldrivers directory with the new psql driver. I copied it into my program sqldrivers directory and deleted it from the qt directory. But alas...

I'll look for the registry entry.

graeme
17th April 2006, 22:39
The registry only has the default value

jacek
17th April 2006, 22:42
I'm using 4.1.1
...
I'll look for the registry entry.
If there was a problem with loading the driver Qt marked such plugin as invalid in the registry and then just ignored it (even after the problem was fixed), but AFAIR this was Qt 4.0.0 or 4.0.1.

graeme
17th April 2006, 22:54
Okay I'm running out of ideas.

From all of this I believe that the problem lies with how the dll is being created. So would getting an MS compiler help? I guess that I could download their C++ compiler and try it out. Or would it be better to configue and rebuild Qt?

jacek
17th April 2006, 23:06
Okay I'm running out of ideas.
Unfortunately, me too. One more thing you could try is to add "CONFIG += console" to your .pro file and check if there are any warnings on the console.


So would getting an MS compiler help?
The problem is that Open Source edition supports only MinGW.


Or would it be better to configue and rebuild Qt?
You could try to compile the driver into Qt. This way if there is some problem with linking, it might be easier to find it.

graeme
17th April 2006, 23:12
I'm downloading 4.1.2 How do I link psql into QT? Woudl taht be with the configure switch you gave earlier?


configure -L C:\...\psql\lib -I C:\...\psql\include -plugin-sql-psql

or would it be (essentailly a modification of what I did on Linux):


configure -qt-sql-psql -I C:/pgsql/include -L C:/pgsql/lib

jacek
17th April 2006, 23:17
configure -L C:\...\psql\lib -I C:\...\psql\include -plugin-sql-psql
This will compile the QPSQL driver as a plugin.


configure -qt-sql-psql -I C:/pgsql/include -L C:/pgsql/lib
And this should compile it into the Qt library.

graeme
18th April 2006, 17:40
It works :D Quite why I'm still a little perplexed but here is what I have done:


Downloaded 4.1.2 src - previously I have 4.1.1 mingw installer
Configured with: configure -debug-and-release -plugin-sql-sqlite -plugin-sql-odbc -qt-libpng -qt-libjpeg -qt-sql-psql -L C:\psql\lib
Recompiled my app: placed the pgsql dlls in the same directory as the exe


I had also done the following prior to configure

set QTDIR=C:\Qt\4.1.2
set PATH=C:\Qt\4.1.2\bin
set PATH=%PATH%;C:\psql\include
set PATH=%PATH%;C:\psql\lib
set PATH=%PATH%;C:\MinGW\bin

So the differences are:


Slightly newer version of Qt - doubt if that makes any difference
I have the src rather than the installer - might make a difference
I have compiled it into Qt rather than as a plugin - might make a difference, although I doubt it.


When I get time I will compile Qt with pgsql as a plug in. I can't think of any difference at the moment.

jacek, thank you very much for your support and your valuable ideas.

graeme.

dimitri
18th April 2006, 18:47
Recompiled my app: placed the pgsql dlls in the same directory as the exe
Most probably there used to be an issue with the PostgreSQL DLL's, which is why you were asked to run the Dependency Walker on the plugin. Unfortunately that didn't help.

I have compiled it into Qt rather than as a plugin - might make a difference, although I doubt it.
Yes, that might make a difference, although it shouldn't.

GreyGeek
20th April 2006, 20:29
Have you installed an ODBC driver for PostgreSQL?

Try: psqlodbc-08_00_0101.zip

Then set up an ODBC connection. I run PostgreSQL on a Linux server and connect to it from this W2K workstation using an ODBC driver setup through the ODBC Manager on the Control Panel.


To compile PostgreSQL plugins.
1) Install PostgreSQL and be careful to select the libraries for installation. (I installed every feature)
2) Install QT4 for windows and use the following configure command:
(In place of "C:\Progra~1\PostgreSQL...." point to where you installed PostgreSQL.)

configure -plugin-sql-psql -qt-sql-psql
-I C:\Progra~1\PostgreSQL\8.1\include
-L C:\Progra~1\PostgreSQL\8.1\lib
-L C:\Progra~1\PostgreSQL\8.1\lib\libpq.a

cd E:\Qt\4.1.0\src\plugins\sqldrivers\psql
qmake -o Makefile "INCLUDEPATH+=C:\Progra~1\PostgreSQL\8.1\include" "LIBS+=C:\Progra~1\PostgreSQL\8.1\lib C:\Progra~1\PostgreSQL\8.1\lib\ms\libpq.lib" psql.pro
qmake
make or nmake

and the plugins were installed in:
E:\Qt\4.1.0\plugins\sqldrivers

I use PostgreSQL 8.1.x as a standin for our Oracle server. IF I had my way we'd use PostgreSQL and not Oracle. :)