FireDAC.SQLiteIniFile Demo Sample
This sample uses FireDAC to connect to an SQLite database that emulates the structure and the operations of an INI File.
Contents
Location
You can find the SQLiteIniDemo project at:
- Start | Programs | Embarcadero RAD Studio Athens | Samples and then navigate to:
- Object Pascal\Database\FireDAC\Samples\AddOn\SQLiteIniFile\Demo
- Subversion Repository:
- You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
Description
- This application reads and writes data to an INI file using a FireDAC database connection as its storage medium, instead of a plain text file.
Note: The connection to the database does not require authentication.
How to Use the Sample
- Navigate to the location given above and open SQLiteIniDemo.dproj.
- Press F9 or choose Run > Run.
- Click the Write to IniFile button and the program will create a database (IniFile.db) and fill it with data.
- The data from the database that was just created is displayed in a TDBGrid.
- You can manipulate the data with a TDBNavigator.
- Click the Read from IniFile button to display the data from the database in a TMemo and the image from the database in a TImage.
Files
File | Contains |
---|---|
Demo\data\ winmacmachine.bmp |
Contains the image that is diplayed in the TImage. |
Demo\SQLiteIniDemo.dproj |
Contains the project itself. |
Demo\Unit1.dfm |
Contains the code of the main form. |
Demo\Unit1.pas |
Contains the main form and the main code. |
FireDAC.Phys.SQLiteIniFile.pas |
Contains the code for the SQLiteIniFile class used for writting/reading to/from the IniFile.db. |
ReadMe.txt |
Contains information about FireDAC.Phys.SQLiteIniFile.pas. |
Implementation
- The project uses a TFDConnection to establish a connection with a database (IniFile.db), which will be used to write or read data.
- In order to display the data from the database, the project uses a TFDQuery, a TDataSource, and a TFDPhysSQLiteDriverLink.
- The data will be displayed in a TDBGrid.
- You can navigate through the data with a TDBNavigator.
- The TFDQuery uses the following query:
SELECT B.SECTION_NAME AS "Section::varchar(32)", A.KEY_NAME AS "Name::varchar(32)", CASE WHEN LENGTH(A.KEY_VALUE) <= 32 THEN A.KEY_VALUE ELSE '(blob)' END AS "Value::varchar(32)" FROM KEYS A LEFT JOIN SECTIONS B ON B.SECTION_ID = A.SECTION_ID
- In the FireDAC.Phys.SQLiteIniFile.pas unit, several classes (TFDSQLiteIniFileDB and TFDSQLiteIniFile) are defined for interacting with the database.
- Click the Write to IniFile button on the main form to create and initialize a TFDSQLiteIniFile instance (the oIniFile code variable) and to create the "IniFile.db" database. After this, a string (abcd...), an integer (123), a float (567.89), a date time (Now), and an image (the image from the data folder) are added to the database. The data that was just inserted in the database is displayed in a TDBGrid.
Note: As shown by the TFDQuery SQL command, when "LENGTH(A.KEY_VALUE) > 32", TDBGrid will display "(blob)" instead of the actual value.
- Click the Read from Inifile button on the main form to read from the database and display the string, the integer, the float, and the date time in a TMemo and the image will be displayed in a TImage.
- Click the Write to IniFile button on the main form to create and initialize a TFDSQLiteIniFile instance (the oIniFile code variable) and to create the "IniFile.db" database. After this, a string (abcd...), an integer (123), a float (567.89), a date time (Now), and an image (the image from the data folder) are added to the database. The data that was just inserted in the database is displayed in a TDBGrid.
Uses
- FireDAC.Comp.Client.TFDConnection
- FireDAC.Comp.Client.TFDQuery
- FireDAC.Phys.SQLite.TFDPhysSQLiteDriverLink
- Data.DB.TDataSource
- Vcl.DBGrids.TDBGrid
- Vcl.DBCtrls.TDBNavigator
- Vcl.ExtCtrls.TImage
- Vcl.StdCtrls.TMemo