Solved

Saving to BLOB field in dbExpress with a join

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Mdi application Child forms get behind control 7 208
Delphi Form ownership 4 85
Adoquery sql  left join does not work 25 89
Delphi problems to abort a printjob 9 18
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

785 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