Sign in Join

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

Mailing lists / lazarus / 2010-11

Database access and thread-safety

7 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

Can anybody say whether a TSQLQuery can be activated in a thread, provided that the portions of the app which activate it and the portions which read data from it are protected by critical sections?

I'm trying to increase the responsiveness of a program that I'm using as a testbed before moving onto anything critical. Backend is PostgreSQL accessed via a TPQConnection.

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

Graeme Geldenhuys
to Mark Morgan Lloyd

Op 2010-11-08 09:19, Mark Morgan Lloyd het geskryf:

Can anybody say whether a TSQLQuery can be activated in a thread, provided that the portions of the app which activate it and the portions which read data from it are protected by critical sections?

In our company we use tiOPF with the SqlDB components as our persistence layer, and our commercial apps do data access via multiple threads without problems (specially now that I fixed some of the Thread.WaitFor problems in FPC+tiOPF+Linux). An example usage: While the user sits at the login prompt of our application, our app loads up some commonly used lookup list data in a separate thread. Reporting queries also gets done in a separate thread.

We primarily talk to a Firebird RDBMS, but I have tested PostgreSQL for a short while too, to see if that DB works.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net:8080/fpgui/

Reply by email

Michael Van Canneyt
to Mark Morgan Lloyd: Can anybody say whether a TSQLQuery can be activated in a thread, provided that the…
Mark Morgan Lloyd wrote 7 lines
Can anybody say whether a TSQLQuery can be activated in a thread, provided that the portions of the app which activate it and the portions which read data from it are protected by critical sections? I'm trying to increase the responsiveness of a program that I'm using as a testbed before moving onto anything critical. Backend is PostgreSQL accessed via a TPQConnection.

If the postgres client library is thread safe, then SQLDB (and in particular TSQLQuery) should also be thread safe.

Michael.

Reply by email

Mark Morgan Lloyd
to Michael Van Canneyt
Michael Van Canneyt wrote 13 lines
On Mon, 8 Nov 2010, Mark Morgan Lloyd wrote: > Can anybody say whether a TSQLQuery can be activated in a thread, > provided that the portions of the app which activate it and the > portions which read data from it are protected by critical sections? > > I'm trying to increase the responsiveness of a program that I'm using > as a testbed before moving onto anything critical. Backend is > PostgreSQL accessed via a TPQConnection. If the postgres client library is thread safe, then SQLDB (and in particular TSQLQuery) should also be thread safe.

Thanks Graeme and Michael, that's encouraging. I'm not planning to use any graphical DB-aware controls, or if I do I'll have an in-memory database as a buffer.

My normal preference would have been to use ODBC or similar to improve portability. However in the current case I want to use the PostgreSQL-specific LISTEN/NOTIFY facility to save having to poll the database for changes, I haven't yet worked out whether I can get at that easily but I'm pretty sure that using a generic connection layer would complicate things.

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

Martin Schreiber
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 6 lines
My normal preference would have been to use ODBC or similar to improve portability. However in the current case I want to use the PostgreSQL-specific LISTEN/NOTIFY facility to save having to poll the database for changes, I haven't yet worked out whether I can get at that easily but I'm pretty sure that using a generic connection layer would complicate things.

MSEgui has tdbevent component (tab DBf) which works with PostgreSQL.

Martin

Reply by email

Mark Morgan Lloyd
to Martin Schreiber
Martin Schreiber wrote 10 lines
On Monday, 8. November 2010 10.19:31 Mark Morgan Lloyd wrote: > My normal preference would have been to use ODBC or similar to improve > portability. However in the current case I want to use the > PostgreSQL-specific LISTEN/NOTIFY facility to save having to poll the > database for changes, I haven't yet worked out whether I can get at that > easily but I'm pretty sure that using a generic connection layer would > complicate things. MSEgui has tdbevent component (tab DBf) which works with PostgreSQL.

[Googles] Thanks Martin, that's useful to know. It's also useful to know that Postgres isn't the only database that offers NOTIFY-style functionality. For the moment I'm trying to stick with "standard" components, but I'm not ruling anything out.

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 Mark Morgan Lloyd
Mark Morgan Lloyd wrote 16 lines
Martin Schreiber wrote: > On Monday, 8. November 2010 10.19:31 Mark Morgan Lloyd wrote: > >> My normal preference would have been to use ODBC or similar to improve >> portability. However in the current case I want to use the >> PostgreSQL-specific LISTEN/NOTIFY facility to save having to poll the >> database for changes, I haven't yet worked out whether I can get at that >> easily but I'm pretty sure that using a generic connection layer would >> complicate things. > > MSEgui has tdbevent component (tab DBf) which works with PostgreSQL. [Googles] Thanks Martin, that's useful to know. It's also useful to know that Postgres isn't the only database that offers NOTIFY-style functionality. For the moment I'm trying to stick with "standard" components, but I'm not ruling anything out.

For anybody else using or considering PostgreSQL, LISTEN/NOTIFY works well provided that the calls are against TPQConnection.Handle. The ExecuteDirect() method uses a different handle which does not have the extended lifetime required.

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