SQLdb Package

This is an old revision of SQLdb Package, edited by Lacak at . The current revision is 43031.

/* TXXXConnection */

The SQLdb package contains FPC units to access a number of SQL databases. It is "packaged" as sqldblaz.lpk in Lazarus, and the components can be found on the "SQLdb" tab.

Components

The SQLdb package provides the following components:

TSQLQuery

This is a descendant of TDataset, and provides the data as a table from the SQL query that you submit. But can also be used to execute SQL-queries that don't return any data. See Working With TSQLQuery for more details.

TSQLTransaction

This encapsulates the transaction on the database server. I am not going to say much about it as I haven't quite worked out the details myself! The important bit is that it has the commit and rollback methods to finish or cancel your transaction on the database.

TXXXConnection

where XXX is the flavour of the database you are connecting to. Each one of these components takes the "standard" requests of the SQLQuery and SQLTransaction components and translates them into database requests, allowing for the idiosyncrasies of the specific database you are using.

The actual components are:

Using the SQLdb Package

To use the SQLdb package, you need a TSQLQuery component, a TSQLTransaction component, and one of the connection components.

Here is a quick tutorial:

From here on, adding controls is the same as for any database, but just to recap:

OF course, this is just the beginning, but getting some data in a grid is usually the first step to ensure the database connection is working. More detailed explanations will be found at Working With TSQLQuery.

Notes

More details will be found in SQLdb Programming Reference

The pages related to the SQLdb package were initially written from explorations done using TPQConnection, using a PostgreSQL 8.1 database on Win XP O/S. They are expected to be true for the other databases and OSes as well. If you can confirm this, please leave a note here.

There are some notes and documentation started: http://z505.com/cgi-bin/powtils/docs/1.6/idx.cgi?file=fcldbnotes

An interface view of the classes is availble: http://z505.com/cgi-bin/powtils/docs/1.6/idx.cgi?file=index-4&unit=sqldb