Moving BLOB fields from one SQL Database into InterBase database using FireDAC

Posted by on in Blogs

In general, there is no difference between moving non-BLOB and BLOB fields into an InterBase database, so any technique may be used, depending on your needs:

1. One technique is to use two regular TFDQuery components; one TFDQuery will read with SELECT, and another will write with INSERT / UPDATE. The process is as follows:

1) Read the data from a FireDAC query into a RAD Studio, Delphi or C++ Builder application from a SQL Database.

2) Push the data via a FireDAC connection into an InterBase database.

This sample shows the support for BLOB (Binary Large Object) streaming in FireDAC using the CreateBlobStream method of TFDQuery.

2. Another technique is to use FireDAC TFDBatchMove.  See some FireDAC TFDBatchMove examples here:

3. A third technique is to use "real BLOB streaming" that is optimized for BLOB values and two TFDQuery components like in the first option above.  Real BLOB streaming is useful when BLOB values are large.  For examples on how to use FireDAC Real Blob Streaming (to read / write blobs), see Support for Blob Streaming in FireDAC

4. For loading Images into an InterBase database, I wrote in this How to insert an InterBase blob with RAD Studio using FireDAC and LoadFromFile post, describing how you can use FireDAC and load the Images into an InterBase database at design time using the FDQuery1IMAGE_FIELD_NAME technique:


And you should also be able to do the same to load .movs, .pdfs, audio files, etc.

Some have commented that using the technique in 4, you need to create persistent fields, but you may also use dynamic fields to do the same, for example, by using this sample C++ Builder code:

5. In addition, to load images from a database into TImage, you may use TDBImage, in a VCL application, which will be connected to TDataSource + TFDQuery that returns a field with an image. 

 In RAD Studio 10.2 Tokyo, TDBImage is capable of handling not only BMP but also JPG, PNG, etc.

For example, for TImage, you can use this sample code:
TStream * str = FDQuery1->CreateBlobStream(FDQuery1->FieldByName("Image_Field_Name"), bmRead);
TBitmap * bmp = new TBitmap();
delete str;
delete bmp;

Another Code Example on how to use TDBImage can be found here .

6. Lastly, as mentioned in 3, for effective BLOB reading / writing you should consider using FireDAC Real Blob Streaming as described here:

Hope this helps and gives you some ideas on how you can move BLOB fields from one SQL Database into InterBase database using FireDAC.



Gold User, Rank: 90, Points: 4
Al Mannarino has 25+ years of software development experience, including object-oriented analysis and design (OOAD) and developing and deploying production applications. He is currently a Principal Software Consultant and Evangelist for Embarcadero Technologies. Prior to joining Embarcadero, Al spent three years working with CodeGear, a division of Borland that was acquired by Embarcadero in 2008. He also worked for five years as a lead systems engineer for Borland supporting application lifecycle management, software delivery optimization and developer tools solutions. Prior to Borland, Al served as a systems engineer for companies including Objectivity, Versant, Red Brick Systems, Information Builders, and was an electrical engineer for Grumman Aerospace performing application implementations on complex electrical-mechanical systems. Al has a bachelor's of science degree in electrical engineering from Manhattan College.


Check out more tips and tricks in this development video: