Solved

Saving to BLOB field in dbExpress with a join

Posted on 2003-11-13
2
902 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now