?
Solved

Saving to BLOB field in dbExpress with a join

Posted on 2003-11-13
2
Medium Priority
?
930 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

771 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