The BlobStreams sample shows you how to use the BLOB streaming techniques of FireDAC. To this end, this sample implements both the external streaming and the internal streaming.
You can find the BlobStreams sample project at:
- Start | Programs | Embarcadero RAD Studio Sydney | Samples and then navigate to:
Object PascalDatabaseFireDACSamplesComp LayerTFDQueryBlobStreams
- Subversion Repository:
- You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
How to Use the Sample
- Navigate to the location given above and open
- Press F9 or choose Run > Run.
|File in Delphi||Contains|
|The project itself.|
|The main form.|
Before running the sample, the main components are configured at design time using the Object Inspector as follows:
- Two TFDQuery objects named qSelect and qInsert. These components are used to implement the datasets capable of executing SQL queries. The following setup is needed:
- Configure the Connection property of both objects to specify the FireDAC connection object that is used to connect to a DBMS. In both cases it is set to
- Set the SQL property for both objects. It specifies the SQL statement to execute for the query.
- Configure the qInsert.Param:
- The Name property is se to
- The DataType property is set to one of the BLOB data types. In this sample
- The ParamType property is set to
ptInput. It means that the stream will be read and written to a database BLOB value.
- The StreamMode property is set to
smOpenRead. This is the default value. It means that the stream is used to read the database BLOB value.
- The Name property is se to
- A TDataSource object named DataSource1. This component provides an interface between a dataset component and data-aware controls on a form. In this sample, it is used to provide communication between the dataset and a TDBMemo object named DBMemo1. DBMemo1 is used to display the blobdata field of the dataset. To this end, the following setup is needed:
- The DataSet property of DataSource is set to
- The DataSource property of DBMemo1 to
- The DataField property of DBMemo1 to
Once the main components are configured at design time you can run the application and interact with the sample in run time. To this end, the sample offers three buttons:
- Prepare data. This button creates an OnClick event that uses the TFileStream.Create method to instantiate the file stream in order to write a string into the file.
- Insert (external stream). This button creates an OnClick event that implements an external streaming. An external stream is provided by the application to FireDAC (external to FireDAC). Then, FireDAC reads this stream.
See the code below:
- Insert (internal stream). This button creates an OnClick event that implements an internal streaming. An internal stream is provided by FireDAC to the application (internal to FireDAC). Then, the application reads this stream. To this end, the sample does the following:
- Use the StarTransaction method to start a mandatory transaction.
- Set the parameter DataType to
- Set the parameter StreamMode to
smOpenWritein order to write the database BLOB value.
- Use the ExecSQL method to execute the SQL command. This will return the internal stream reference.
- Write the internal stream reference.
- Call the CloseStreams method to flush database API buffers and close internal streams.
- Use the Commint method to finish the transaction.
For more information about this sample, please refer to the link below: