Solved

Saving to BLOB field in dbExpress with a join

Posted on 2003-11-13
2
912 Views
Last Modified: 2008-01-16
Writing to and from Interbase BLOB fields in Delphi7 like this….

Memo.Text:=ClientDataset.FieldByName(‘NOTES’).AsString;
and
ClientDataset.FieldByName(‘NOTES’).AsString:=Memo.Text;

...works fine until the underlying dataset is a join and the fields need to be written explicitly to the joined tables by the providers BeforeUpdateRecord event.
Building SQL statements in this event from the fields to be updated works for non-blob field but doesn’t work for BLOB fields as there is no INSERT syntax allowable for BLOB fields.
The question is therefore what should the providers BeforeUpdateRecord event look like to handle this kind of field? Is it possible to do it this way or is there another way?
A solution involving the datasets provider is preferable as this nicely encapsulates updates to all affected tables.
0
Comment
Question by:RogerFroud
2 Comments
 

Accepted Solution

by:
RogerFroud earned 0 total points
ID: 9782120
This solution seems to work ok but is a bit clumsy. Any better solution gets the points....

Dataset Provider BeforeUpdateRecord event
var
    SQL: String;
    myParams: TParams;
    FileStream : TFileStream; //debug only
    StringStream : TStringStream;
......
code to save all other fields using INSERT statements in SQL then....

      if (DeltaDS.FieldByName('NOTES').NewValue<>Null) then
        begin
          myParams := TParams.Create;
          myParams.Clear;
          myParams.CreateParam(ftBlob, 'BlobParam', ptInput);
          StringStream:=TStringStream.Create(DeltaDS.FieldByname('NOTES').NewValue);
          myParams.ParamByName('BlobParam').LoadFromStream(StringStream, ftBlob);
          StringStream.Free;
          SQL:=Format('UPDATE STOCKSUPPLIERS SET NOTES = :BlobParam WHERE STOCKSUPPLIERID = %d', [ID]);
          Connection.Execute(SQL, myParams);
          myParams.Free;
        end;
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question