Chapter 12Database Access
by Michael Van Canneyt
Many applications (by no means only business applications) display andmanipulate data coming from various sources. The data may come from adatabase server or from regular files, and is commonly stored on the local harddisk.
12.1 Architecture12.1.1Database access
The Lazarus IDE and LCL do not provide their own database engine, nor do they offer acomplete database management system. All database systems have their peculiarities, andmost come with their own specialised tools to create and maintain their databases.General-purpose tools cannot hope to match that specialised functionality. Therefore when you develop database applications in Lazarus, you will also need whatever nativedatabase tools are available (for instance mysqladmin when working with MySQL, orFlameRobin when working with Firebird).Instead ofattempting to duplicate what the database engines and tools do best, Lazarusand its LCL offer two kinds ofsupport for creating database applications, which focuson connecting to as many database systems as possible. Access to different data sources in Lazarus is achieved through a unified databaseinterface, provided in the form ofcomponents. Most standard controls available for writing a user interface have a corresponding data-aware version. The data-aware controlknows how to get data from the data interface, and how to communicate any datachanges back to the database. Thanks to this unified architecture, you don't have to change your user interface todevelop it as a database application which can edit an underlying database. The databaselayer is not dependent on the visual controls, and therefore it can also be used in serviceor web applications. The database interface is written in pure Object Pascal–and is therefore fully accessible –and Lazarus contains ready-made components for access to many different databasetypes and file formats, regardless ofwhether they are open source or not: CSV data(comma-separated values), DBF files, Firebird and Interbase databases, MySQLdatabases (version 4.0, 4.1 or 5), Oracle databases, PostGreSQL databases, embeddedSQLite databases and any other database for which an ODBC driver is available. Additionally, Lazarus offers components to keep data in memory. The advantage ofthis Object Pascal approach is that data can be shown in the IDE, where it can be inspected at design time. You don't have to run your application just to view the data.
Lazarus - the complete guide