Sign in Join
Wiki copytemporary

SQLdb Programming Reference: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11## Documentation
22
33Please see the official documentation at [SQLDB documentation](http://www.freepascal.org/docs-html/fcl/sqldb/index.html).
44
55This article attempts to give some more detail about SQLDb; however the official documentation is authorative.
66
77## Class Structure
88
99The following diagram attempts to show the hierarchy and required links of the MAIN components involved in SQLdb. It is certainly not exhaustive, nor does it use any "proper" diagram structure, so please don't try to read too much into it. I hope it will make it easier to work out which bits of the source code you need to look at to really work out what is happening.
1010
11-<figure>
12-<img src="Laz_SqlDB_components.png" title="Laz_SqlDB_components.png" />
13-<figcaption>Laz_SqlDB_components.png</figcaption>
14-</figure>
11+![](/wiki-images/1/17/Laz_SqlDB_components.png)
1512
1613#### Notes
1714
1815- The link from TDatabase to TTransaction is Transactions, and is a list, implying many transactions are possible for the one database. However, a new link is defined from TSQLConnection to TSQLTransaction which is Transaction - a single transaction per database. This does not actually hide the previous link, but only the new link is published, and it is probably inadvisable to use the ancestor's link.
1916- Some of the inherited links need to be typecast to the new types to be useful. You can't call SQLQuery.Transaction.Commit, as Commit is only defined in TSQLTransaction. Call SQLTransaction.Commit, or "(SQLQuery.Transaction as TSQLTransaction).Commit"
2017
2118## Interaction
2219
2320### TConnection
2421
2522Documentation: [TSQLConnection documentation](http://www.freepascal.org/docs-html/fcl/sqldb/tsqlconnection.html)
2623
2724A [[TConnection]] represents a connection to an SQL database. In daily use, you will use the descendent for a specific database (e.g. TIBConnection for Interbase/Firebird), but it is possible to use TConnection if you are trying to write database factory/database independent applications (note: it's probably more advisable to use [TSQLConnector](http://www.freepascal.org/docs-html/fcl/sqldb/tsqlconnector.html)). In this object, you specify connection-related items such as hostname, username and password. Finally, you can connect or disconnect (using the .Active or .Connected property)
2825
2926Most database allow muliple concurrent connections from the same program/user.
3027
3128### TSQLTransaction
3229
3330Documentation: [TSQLTransaction](http://www.freepascal.org/docs-html/fcl/sqldb/tsqltransaction.html)
3431
3532This object represents a transaction on the database. In practice, at least one transaction needs to be active for a database, even if you only use it for reading data. When using a single transaction, set the TConnection.Transaction property to the transaction to set the default transaction for the database; the corresponding TSQLTransaction.Database property should then automatically point to the connection.
3633
3734Setting a [[TSQLTransaction]] to .Active/calling .StartTransaction starts a transaction; calling .Commit or .RollBack commits (saves) or rolls back (forgets/aborts) the transaction. You should surround your database transactions with these unless you use .Autocommit or CommitRetaining.
3835
3936### TSQLQuery
4037
4138Documentation: [TSQLQuery documentation](http://www.freepascal.org/docs-html/fcl/sqldb/tsqlquery.html)
4239
4340See [[Working With TSQLQuery]] for more details.
4441
4542[[TSQLQuery]] is an object that embodies a dataset from a connection/transaction pair using its SQL property to determines what data is retrieved from the database into the dataset.
4643
4744When working with it, you therefore need to at least specify the transaction, connection amd SQL properties. The TSQLQuery is an important part in the chain that links databound controls to the database. As said, the SQL property determines what SELECT query is run against the database to get data. FPC will try to determine what corresponding SQL INSERT, UPDATE and DELETE statements should be used in order to process user/program generated data changes. If necessary, the programmer can fine tune this and manually specify the InsertSQL, UpdateSQL and DeleteSQL properties.
4845
4946### DataSource
5047
5148A [[TDataSource]] object keeps track of where in a dataset (such as TSQLQuery) data bound components are. The programmer should specify the corresponding TSQLQuery object for this to work.
5249
5350### Databound controls such as DBGrid
5451
5552These controls must be linked to a DataSource. They will often have properties that indicate what fields in the DataSource they show.
5653
5754## Data modules
5855
5956[[Data module|Data modules]] can be used to store non-visual components such as **T*Connection**, **TSQLTransaction**, **TSQLQuery** etc. Data modules also let you share components between forms.
6057
6158See [[SQLdb Tutorial4]].
6259
6360---
6461*From the Free Pascal wiki, page "SQLdb Programming Reference", as it stood on 2017-04-04 after a change by E-ric, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history