Database.FireDAC.AddOn.SQLiteIniFile Sample
This sample uses FireDAC to connect to a IniFile using SQLite.
Contents
Location
You can find SQLiteIniDemo project at:
- Start | Programs | Embarcadero RAD Studio 10.1 Berlin | Samples and then navigate to:
- Object Pascal\Database\FireDAC\Samples\AddOn\SQLiteIniFile\Demo
- Subversion Repository for Delphi:
Description
- This application reads and writes data to an IniFile using a FireDAC database connection.
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 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 TFDQuey, a TDataSource and a TFDPhysSQLiteDriverLink.
- The data will be displayed in a TDBGrid.
- You can navigate through the data with a TDBNavigator.
- The TFDQuey 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 in the TFDQuey code says, when the "LENGTH(A.KEY_VALUE) > 32" the TDBGrid will display "(blob)" in the Value column.
- 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