What is the best way of load and read BLOB field?

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
tanghz
Posts: 23
Joined: Wed 17 Jan 2007 02:40

What is the best way of load and read BLOB field?

Post by tanghz » Wed 29 Sep 2010 16:15

As the title. I saw your picture demo. However, that one only demoed insert blob filed. The title field is still empty. How to insert a real record e.g insert ID, title, filesize, blobfile
all in one go?

I also read you have TBlob method, and AsBlob. How to use them?
Can I use it directly like

dataset.insert;
dataset.fieldbyname('title').asstring:=title;
dataset.fieldbyname('blobfile').asblob.loadfromfile('filename');
dataset.post;

or with the UniSQL, what is the best way to do it?


thanks,

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Thu 30 Sep 2010 08:58

Hello,

The asBlob property is implemented only in TDAParam class, you can use this property
to set and read the value of the BLOB parameter as string, for example

blob:TBlobData;
blob:= 'data';
TUniQuery.ParamByName('BLOB_PARAM_NAME').asBlob:=blob;

To insert the blob data you can use type casts, for example

TBlobField(TUniQuery.FieldByName('BLOB_FIELD_NAME')).LoadFrom.....

or

(TUniQuery.FieldByName('BLOB_FIELD_NAME') as TBlobField).LoadFrom....

or

BlobField: TblobField;
BlobField:=TUniQuery.FieldByName('BLOB_FIELD_NAME') as TBlobField;
BlobField.LoadFrom;

You can use this code to insert all field values including the Blob fields

TUniQuery.Insert;
TUniQuery.FieldByName('FIELD_1').asInteger:= 1;
TUniQuery.FieldByName('FIELD_2').asString:= 'test';
.......
TBlobField(TUniQuery.FieldByName('BLOB_FIELD_NAME')).LoadFromFile('File');
TUniQuery.Post;

tanghz
Posts: 23
Joined: Wed 17 Jan 2007 02:40

Post by tanghz » Thu 30 Sep 2010 12:27

Hi , thanks for your clear answer. It shines some advantages of the UniDAC features. If you can provide some updated demos in your future release to highlight the difference between your way and the triditional Delphi way, we will all be glad to read them thro. I belive some of them same a lot of coding time.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Mon 04 Oct 2010 07:02

Hello,

Our products have many different possibilities, but unfortunately we can't include all of them in the demo project, if you have any specific questions you can post them to our forum or send by e-mail, and we will help you to resolve the issue.

Post Reply