Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 12 total
Thread How to save binary data using sql...
Mon, Jan 26 2009 6:06 PMPermanent Link

Uli Becker
Hi,

I am using this code to save an email-attachment in a table:

dm.AttachmentsTable.append;
dm.AttachmentsTableFilename.asString := MessagePart.FileName;
try
  SaveStream := TEDBBlobStream.create(dm.AttachmentsTableBinary, bmWrite);
  MessagePart.SaveToStream(SaveStream);
finally
  SaveStream.free;
end;
dm.AttachmentsTable.post;

How can I do the same by using a query?

Regards Uli
Sun, Feb 8 2009 9:24 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Uli,

<< How can I do the same by using a query? >>

You would need to use a parameterized UPDATE statement to do so, or use one
big literal UPDATE statement with the binary data as a constant.  If you can
tell me your preference, I can offer some code.

--
Tim Young
Elevate Software
www.elevatesoft.com

Sun, Feb 8 2009 2:48 PMPermanent Link

Ulrich Becker
Tim

> You would need to use a parameterized UPDATE statement to do so, or use one
> big literal UPDATE statement with the binary data as a constant.  If you can
> tell me your preference, I can offer some code.

I'd prefer a parameterized update statement. Thanks for a code snippet.

Uli
Mon, Feb 9 2009 5:59 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Uli,

<< I'd prefer a parameterized update statement. Thanks for a code snippet.
>>

This should do it (I noticed that you were doing an INSERT, not an UPDATE,
but they both work the same way in terms of the parameters):

with MyEDBQuery do
   begin
   SQL.Text:='INSERT INTO Attachments (FileName, Contents) VALUES
(:FileName, :Contents)';
   Prepare;
   ParamByName('FileName').AsString:=MessagePart.FileName;
   TempStream:=TMemoryStream.Create;
   try
       MessagePart.SaveToStream(TempStream);
       ParamByName('Contents').LoadFromStream(TempStream,ftBlob);
   finally
       FreeAndNil(TempStream);
   end;
   ExecSQL;
   end;

--
Tim Young
Elevate Software
www.elevatesoft.com

Tue, Feb 10 2009 1:34 AMPermanent Link

Uli Becker
Tim,

thank you for the code!

Regards Uli
Tue, Feb 10 2009 4:04 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Tim

>with MyEDBQuery do
> begin
> SQL.Text:='INSERT INTO Attachments (FileName, Contents) VALUES
>(:FileName, :Contents)';
> Prepare;
> ParamByName('FileName').AsString:=MessagePart.FileName;
> TempStream:=TMemoryStream.Create;
> try
> MessagePart.SaveToStream(TempStream);
> ParamByName('Contents').LoadFromStream(TempStream,ftBlob);
> finally
> FreeAndNil(TempStream);
> end;
> ExecSQL;
> end;

Out of interest could you do something like ParamByName('Contents').AsString := ' X''01F21028'';

Roy Lambert
Tue, Feb 10 2009 8:17 AMPermanent Link

Uli Becker
Roy
> Out of interest could you do something like ParamByName('Contents').AsString := ' X''01F21028'';

I am using the idMessage component by Indy and it allows .SaveToFile or
..SaveToStream.

Uli
Tue, Feb 10 2009 8:40 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Uli

>I am using the idMessage component by Indy and it allows .SaveToFile or
>.SaveToStream.

Fair enough - but I'm still interested.

Roy Lambert
Tue, Feb 10 2009 12:12 PMPermanent Link

Uli Becker
Roy ,

> Fair enough - but I'm still interested.

Probably my English is not good enough - but I don't understand what you
mean.

Uli
Tue, Feb 10 2009 1:15 PMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Uli

>> Fair enough - but I'm still interested.
>
>Probably my English is not good enough - but I don't understand what you
>mean.

OK - fuller version.

I'm pleased that Tim's answer solved your query (that's "fair enough"). It could also mean that you've stated a fact that is of little or no interest to me - not in any nasty way though.

The second bit "but I'm still interested" means that even though Tim's answer has satisfied your query and hence Tim doesn't need to answer my question to help you I'd still like to know the answer out of general interest.

Hope that helps.

Roy Lambert
Page 1 of 2Next Page »
Jump to Page:  1 2
Image