[DUG] Blob primer
Phil Middlemiss
phil at tumonz.co.nz
Fri Jul 1 10:24:13 NZST 2005
Very useful, thankyou.
Phil.
Robert martin wrote:
> Hi.
>
> Dont know if this helps but here is how we load and seve data (cut
> from code messily). We are using IBO and Firebird.
>
> with zMainDM.GeneralIB_Query do begin
> IB_Transaction.StartTransaction;
> try
> SQL.Text := 'SELECT r.FileName, ra.FileBlob ' +
> 'FROM ReportActivity ra ' +
> 'JOIN Report r ON r.ReportRef = ra.ReportRef ' +
> 'WHERE ra.ActivityRef = :ActivityRef;';
> Prepare;
>
> //Extract Archived file
> FileStream := TFileStream.Create(FileName +
> 't', fmCreate);
> try
> DBStream :=
> CreateBlobStream(FieldByName('FileBlob'), bsmRead);
> try
> FileStream.CopyFrom(DBStream, 0);
> finally
> DBStream.Free;
> end;
> finally
> FileStream.Free;
> end;
> ...
>
> //The above runs an SQL to select the desire blob and saves it to a
> file (with an extra 't' in the name for obscure reasons :) )
>
>
>
>
>
>
> zMainDM.InsertActivityIB_Query.SQL.Text := 'INSERT
> INTO ReportActivity ' +
>
> '(ActivityRef, ReportRef, VersionNo, rDate, rTime, Comment, UserRef,
> Activity, FileBlob, Approved, Canceled) ' +
> 'VALUES
> ' +
>
> '(:ActivityRef, :ReportRef, :VersionNo, :rDate, :rTime, :Comment,
> :UserRef, :Activity, :FileBlob, :Approved, ''F'');';
> zMainDM.InsertActivityIB_Query.Prepare;
>
> .....
>
> //Compress Report and insert into query
> CompLHA.ForceUpperCase := False;
> CompLHA.FilesToProcess.Clear;
> CompLHA.FilesToProcess.Add(InEdit.Text);
> CompLHA.ArchiveName := ExtractFileName(InEdit.Text);
> CompLHA.CompressionMethod := colh5;
>
> SList := TStringList.Create;
> Stream := TMemoryStream.Create;
> try
> SList.Add(InEdit.Text);
>
> CompLHA.CompressFilesToStream(Stream, SList, colh5);
>
> //Stream now contains compressed file, copy to
> insert statement
> DBStream :=
> zMainDM.InsertActivityIB_Query.CreateBlobStream(zMainDM.InsertActivityIB_Query.ParamByName('FileBlob'),
> bsmWrite);
>
> DBStream.CopyFrom(Stream, 0);
> finally
> Stream.Free;
> SList.Free;
> end;
>
>
> The above has an insert SQL to load the blob. It compresses the file
> and loads it into the query to insert. You could replace the CompLHA
> stuff with a std stream load.
>
>
>
> It is really quite simple to use, just a mix of SQL and TStreams.
>
>
>
> Rob Martin
> Software Engineer
>
> phone +64 03 377 0495
> fax +64 03 377 0496
> web www.chreos.com
>
> Wild Software Ltd
>
>
>
> Phil Middlemiss wrote:
>
>> Could anyone give me a link to a "how-to" about blobs? I'm using D6
>> with firebird - there is no GUI (it's a service) so I would like to
>> just use SQL if possible.
>>
>> Having not used blobs before I'm wondering:
>> - what is a subtype? The Interbase documentation assumes you know
>> - what is a good size for the segment length
>> - how to specify binary data in a sql - if it's actually possible.
>> - if I can't just use sql then what's the best way?
>>
>> Phil.
>>
>> _______________________________________________
>> Delphi mailing list
>> Delphi at ns3.123.co.nz
>> http://ns3.123.co.nz/mailman/listinfo/delphi
>>
> _______________________________________________
> Delphi mailing list
> Delphi at ns3.123.co.nz
> http://ns3.123.co.nz/mailman/listinfo/delphi
>
>
>
More information about the Delphi
mailing list