IBDAC

BLOB Data Types

BLOB field can be used to store large amounts of data of different types.For BLOB  data type only BLOB IDs (pointers to data) are stored in table columns; actual  BLOBdata is stored separately. When accessing a BLOB column, it is the ID which is returned, not the value itself. InterBase supports two types of blobs, stream and segmented. Segmented BLOBs are usual InterBase BLOBs and are stored in chunks. Stream BLOBs are stored as a continuous array of data bytes.

IBDAC components provide following features for working with BLOBs:

IBDAC components support InterBase BLOB datatype. You can retrieve values of BLOB fields using TIBCQuery component the same way as you do for another fields.

It is possible to control the way BLOB objects are handled while the application fetches records from the database. BLOBs can be fetched either with other fields to the application or on demand.This is determined by DeferredBlobRead option in TCustomIBCDataSet component. Setting TCustomIBCDataSet.Options.DeferredBlobRead to false allows to reduce traffic over the network since BLOBs are only transferred on demand and to use less memory on the client side because returned record sets do not hold contents of BLOB fields.

IBDAC components support InterBase streamed BLOBs. To enable streamed BLOBs handling set TCustomIBCDataSet.Options.StreamedBlobs to True. Setting this option to True makes all edited BLOBs to be saved as streamed BLOBs and all streamed BLOBs to be handled as streamed. Otherwise streamed BLOBs are handled as usual segmented BLOBs and all edited BLOBs are saved as segmented BLOBs. Setting this option to True also allows to use benefits of server side access to BLOB fields.

Set TCustomIBCDataSet.Options.CacheBlobs to False to access streamed BLOB values on server side without caching BLOBs on the client side. Only requested portions of data are fetched in that case. Setting CacheBlobs to False may bring up the following benefits for time-critical applications: reduced traffic over the network since only required data are fetched, less memory is needed on the client side because BLOB data are not cached on the client side. This feature is available only for streamed BLOBs and only if StreamedBlobs option is set to True. This option doesn't make sense if DefferedBlobRead is set to False because all BLOB values are fetched to the dataset in that case.

IBDAC components provides easy usage of InterBase BLOB subtype conversion, using BLOB filters. It allows to set BLOB parameter buffer (BPB), that is needed whenever a filter will be used when writing to or reading from a BLOB. BPB contains source and target subtype and charset (for text BLOBs). These parameters are set in TIBCBlob component by setting TIBCBlob.CharsetID, TIBCBlob.ConversionCharsetID, TIBCBlob.ConversionSubType, TIBCBlob.SubType properties. In retrieval operations, when you set them before reading BLOB, SubType and Charset properties are considered actual subtype and charset of database BLOB data. Application will get data converted to ConversionSubType subtype and ConversionCharset charset.

In upload operations, SubType and Charset properties mean actual subtype and charset of BLOB data in the application. ConversionSubType and ConversionCharset properties must contain desired subtype and charset to save BLOB to database with.

To avoid unwanted conversions do not set these properties, or make sure that Charset equals to ConversionCharset and SubType equals to ConversionSubType.

Note that if there is no filter for pair of source and target subtype, no conversion is provided and BLOB data remains unconverted.

Executing TIBCQuery or TIBCSQL with BLOB parameter requires live transaction after execute. To execute such statement you should explicitly start the transaction or set AutoCommit property to False.

Use P:Devart.Dac.TDADataSetOptions.CompressBlobMode for managing BLOB compression. BLOBs can be stored compressed on the client side, on the server side (in database) or on the both sides. By default it has value cbNone, that means no compression is provided. Use cbClient value to store compressed blobs on client side. This saves client memory. BLOB data is stored unchanged in database, other application can read these BLOBs as usual. If cbServer value is used, BLOB data is stored compressed in database. It's decompressed on the client side. This saves server disk space and network traffic. Other application can't process compressed BLOB data as usual. To use compressed BLOB data both on the client and server side use cbClientServer value. To use cbClient, cbServer, cbClientServer and cbNone constants you should add MemData unit to uses clause.

Note: Internal compression functions are available in Delphi 2007, Borland Developer Studio 2006, and Delphi 7. To use  BLOBcompression under Delphi 6 and C++Builder you should use your own compression functions. To use them set CompressProc and UncompressProc variables declared in MemUtils unit.

type
TCompressProc = function(dest: IntPtr; destLen: IntPtr; const source:
      IntPtr; sourceLen: longint): longint;
TUncompressProc = function(dest: IntPtr; destlen: IntPtr; source:
      IntPtr; sourceLne: longint): longint;

var
CompressProc: TCompressProc;
UncompressProc: TUncompressProc; 

You can compress and decompress a single BLOB. To do it set P:Devart.Dac.TCompressedBlob.Compressed property. Set it to True to compress BLOB data and to False to decompress BLOB data.

Note that using compression and decompression operations will raise CPU usage and can reduce application performance.

See Also

© 1997-2024 Devart. All Rights Reserved. Request Support DAC Forum Provide Feedback