Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-12

Searching for database libraries

9 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mark Morgan Lloyd

When using something like InitialisePostgres3(), if the approximate location of the database library (.so or .dll) is known, what's the most effective way of finding the exact file? Is there a single routine that does a recursive search?

The reason that I ask is that it appears that the most efficient way of getting libpq.dll for Windows is to install the ODBC drivers, and they go into a directory typically named like C:\Program Files\psql\ODBC\xxxx\bin where xxxx is a version number.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Michael Van Canneyt
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote
When using something like InitialisePostgres3(), if the approximate location of the database library (.so or .dll) is known, what's the most effective way of finding the exact file? Is there a single routine that does a recursive search?

No.

The reason that I ask is that it appears that the most efficient way of getting libpq.dll for Windows is to install the ODBC drivers, and they go into a directory typically named like C:\Program Files\psql\ODBC\xxxx\bin where xxxx is a version number.

Maybe the installer writes something in the registry, in which case you could try that first.

Michael.

Reply by email

Mark Morgan Lloyd
to Michael Van Canneyt
Michael Van Canneyt wrote 16 lines
On Fri, 7 Dec 2012, Mark Morgan Lloyd wrote: > When using something like InitialisePostgres3(), if the approximate > location of the database library (.so or .dll) is known, what's the > most effective way of finding the exact file? Is there a single > routine that does a recursive search? No. > The reason that I ask is that it appears that the most efficient way > of getting libpq.dll for Windows is to install the ODBC drivers, and > they go into a directory typically named like C:\Program > Files\psql\ODBC\xxxx\bin where xxxx is a version number. Maybe the installer writes something in the registry, in which case you could try that first.

There's a problem with this on (at least some versions of) Windows: if you use InitialisePostgres3() it will find libpq.dll but not other libraries such as ssleay. A workable hack appears to be to cd to the directory that contains the DLLs before attempting to establish the database connection.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Michael Van Canneyt
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 22 lines
Michael Van Canneyt wrote: > On Fri, 7 Dec 2012, Mark Morgan Lloyd wrote: > >> When using something like InitialisePostgres3(), if the approximate >> location of the database library (.so or .dll) is known, what's the most >> effective way of finding the exact file? Is there a single routine that >> does a recursive search? > > No. > >> The reason that I ask is that it appears that the most efficient way of >> getting libpq.dll for Windows is to install the ODBC drivers, and they go >> into a directory typically named like C:\Program Files\psql\ODBC\xxxx\bin >> where xxxx is a version number. > > Maybe the installer writes something in the registry, in which case you > could try that first. There's a problem with this on (at least some versions of) Windows: if you use InitialisePostgres3() it will find libpq.dll but not other libraries such as ssleay. A workable hack appears to be to cd to the directory that contains the DLLs before attempting to establish the database connection.

I consider this an installation problem, not something that must be catered for in FPC.

Michael.

Reply by email

Marco van de Voort
to Michael Van Canneyt

In our previous episode, Michael Van Canneyt said:

Show quoted text 9 lines
>> Maybe the installer writes something in the registry, in which case you >> could try that first. > > There's a problem with this on (at least some versions of) Windows: if you > use InitialisePostgres3() it will find libpq.dll but not other libraries such > as ssleay. A workable hack appears to be to cd to the directory that contains > the DLLs before attempting to establish the database connection. I consider this an installation problem, not something that must be catered for in FPC.

That's what I thought too. They are installed in a way that they are only easily usable via odbc.

Anyway, a workaround could be to try to add the filedir of the dll found via the registry to the path. (on shell level, not FPC rtl level)

Reply by email

Mark Morgan Lloyd
to Michael Van Canneyt: I consider this an installation problem, not something that must be catered for in FPC.…
Michael Van Canneyt wrote 16 lines
>>> The reason that I ask is that it appears that the most efficient way >>> of getting libpq.dll for Windows is to install the ODBC drivers, and >>> they go into a directory typically named like C:\Program >>> Files\psql\ODBC\xxxx\bin where xxxx is a version number. >> >> Maybe the installer writes something in the registry, in which case >> you could try that first. > > There's a problem with this on (at least some versions of) Windows: if > you use InitialisePostgres3() it will find libpq.dll but not other > libraries such as ssleay. A workable hack appears to be to cd to the > directory that contains the DLLs before attempting to establish the > database connection. I consider this an installation problem, not something that must be catered for in FPC.

I'm inclined to agree with you. However I think it's noteworthy that passing a library name to InitialisePostgres3() is an incomplete solution since (a) at least on Windows it can't provide a path to libpq's prerequisites and (b) if built to be able to use SSL then libpq requires that it be available, even if it isn't being used for the session being established.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Mark Morgan Lloyd
to Marco van de Voort: In our previous episode, Michael Van Canneyt said: That's what I thought too. They are…
Marco van de Voort wrote 14 lines
In our previous episode, Michael Van Canneyt said: >>> Maybe the installer writes something in the registry, in which case you >>> could try that first. >> There's a problem with this on (at least some versions of) Windows: if you >> use InitialisePostgres3() it will find libpq.dll but not other libraries such >> as ssleay. A workable hack appears to be to cd to the directory that contains >> the DLLs before attempting to establish the database connection. > I consider this an installation problem, not something that must be catered for in FPC. That's what I thought too. They are installed in a way that they are only easily usable via odbc. Anyway, a workaround could be to try to add the filedir of the dll found via the registry to the path. (on shell level, not FPC rtl level)

Does Windows use the standard path for searching DLLs? I can confirm that inside a program temporarily changing the current directory has the desired effect, and this can obviously be done with reference to the registry.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Michael Van Canneyt
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 20 lines
Marco van de Voort wrote: > In our previous episode, Michael Van Canneyt said: >>>> Maybe the installer writes something in the registry, in which case you >>>> could try that first. >>> There's a problem with this on (at least some versions of) Windows: if >>> you use InitialisePostgres3() it will find libpq.dll but not other >>> libraries such as ssleay. A workable hack appears to be to cd to the >>> directory that contains the DLLs before attempting to establish the >>> database connection. >> I consider this an installation problem, not something that must be >> catered for in FPC. > > That's what I thought too. They are installed in a way that they are only > easily usable via odbc. > > Anyway, a workaround could be to try to add the filedir of the dll found > via > the registry to the path. (on shell level, not FPC rtl level) Does Windows use the standard path for searching DLLs?

Yes, after the current working directory, and possibly the location of the binary itself.

Michael.

Reply by email

Reinier Olislagers
to Mark Morgan Lloyd: Does Windows use the standard path for searching DLLs? I can confirm that inside a…
Mark Morgan Lloyd wrote
Does Windows use the standard path for searching DLLs? I can confirm that inside a program temporarily changing the current directory has the desired effect, and this can obviously be done with reference to the registry.

For the authorative answer, see:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx#search_order_for_desktop_applications

Reply by email