Computing: Free Pascal Programming

Database access with Lazarus/Free Pascal on Windows.

This page contains details concerning the access of various SQL databases from a Lazarus/Free Pascal application. The tutorials cover only the basics and are primarily intended for beginners. The most complete tutorial is the one concerning MySQL with connection, read and write examples. The tutorials for the other databases just show how to do to connect to the database server. Reading and writing data is essentially the same as described for MySQL.

1. SQLite.

The tutorial shows how to connect to SQLite 3.44 using a TSQLite3Connection object, or, as an alternative, using a TODBCConnection object. Connections to other 3.x versions of SQLite should be quite the same. I suppose that reading and writing data is similar to the description given below for MySQL.

2. MySQL.

The tutorial describes how to connect to MySQL 5.7 and MySQL 8.0. It is divided into 3 parts:

3. MariaDB.

The tutorial shows how to connect to MariaDB 10.6 using a TMySQLConnection object, or, as an alternative, using a TODBCConnection object. Connections to other versions of MariaDB should be quite the same. Reading and writing data is the same as described above for MySQL.

4. PostgreSQL.

The tutorial shows how to connect to PostgreSQL 15 using a TPQConnection object. The tutorial should also apply to others versions of PostgreSQL.

5. Firebird.

The tutorial shows how to connect to Firebird 4.0 using a TIBConnection object. To note that the tutorial supposes that you have installed Firebird in client/server mode (not in embedded mode).

6. Microsoft SQL Server.

The tutorial shows how to connect to SQL Server 2017 using a TMSSQLConnection object. The tutorial should also apply to newer versions of SQL Server.

7. IBM DB2.

The tutorial shows how to connect to DB2 11.5.8 using a TODBCConnection object. The tutorial should also apply to other versions of the database server.

8. Connector-type independent database access.

The tutorial shows how to connect to different database servers using one single TSQLConnector object. The sample application uses MySQL, MariaDB, PostgreSQL, MSSQLServer and Firebird. The way to proceed should also apply to other database connectors (in particular to ODBC access).

9. Connecting to MySQL/MariaDB using Zeos components.

The tutorial shows how to connect to a MySQL resp. a MariaDB database server, without using the standard SQLdb components shipped with Lazarus. Instead of those, the sample applications in the tutorial use the components of the (freeware and open source) Lazarus Zeos package.


If you find this text helpful, please, support me and this website by signing my guestbook.