How can I store a TMemoryStream to a BLOBB Field and read from it using Accuracer DB / SQL. With SQL I mean ABSQuery..
Thanks
How can I store a TMemoryStream to a BLOBB Field and read from it using Accuracer DB / SQL. With SQL I mean ABSQuery..
Thanks
The following example reads the data from a memo field into a blob stream and displays it in a memo control.
procedure TForm1.Button2Click(Sender: TObject);
var
Buffer: PChar;
MemSize: Integer;
Stream: TACRBlobStream;
begin
Stream := TACRBlobStream.Create(MyAccuracer.FieldByName('Notes') as TBlobField, bmRead);
try
MemSize := Stream.Size;
Inc(MemSize); //Make room for the buffer's null terminator.
Buffer := AllocMem(MemSize); //Allocate the memory.
try
Stream.Read(Buffer^, MemSize); //Read Notes field into buffer.
Memo1.SetTextBuf(Buffer);// Display the buffer's contents.
finally
FreeMem(Buffer, MemSize);
end;
finally
Stream.Free;
end;
end;
from here:
The documentation for BLOB fields shows you how. The code there demonstrates storing a file into a BLOB field, but you can adapt it to store the contents of any kind stream, not just TFileStream. The key is to create a BLOB stream, and then call CopyFrom
, which copies the contents of one stream into another.
ABSTable1.Edit;
try
BlobStream := ABSTable1.CreateBlobStream(Field, bmWrite) as TABSBlobStream;
try
BlobStream.CopyFrom(Stream, 0);
finally
BlobStream.Free;
end;
ABSTable1.Post;
except
ABSTable1.Cancel;
raise;
end;
Your question is not very clear to me (and looking at the answers and your comments it's the same to all other). So this is just a shot in the dark ...
Absolute Database has a conversion function
MimeToBin
to convert a MIME-encoded (string) value to a binary data type.Sample for
MimeToBin
(The sample Data is justHello World
)To get such a
Base64
encoded string from a stream useABSDecUtil.TStringFormat_MIME64
.As this is all just a little abstract, you can get a sample project from Component Ace