KarlisB
asked on
bytea get data from postgre
Greetings!
Am stuck on a bit tricky problem.
I am using ado components to access postgre database.
Same old problem everyone is experiencing, problems to store files into postgre database and retrieve them.
I have managed to store file into table in bytea field.
but main problem, i dont know how to retrieve files, since its not a really a blob.
i have managed to get down data 255 byte long, but not greater, cant figure out whats the problem.
any ideas?
Am stuck on a bit tricky problem.
I am using ado components to access postgre database.
Same old problem everyone is experiencing, problems to store files into postgre database and retrieve them.
I have managed to store file into table in bytea field.
but main problem, i dont know how to retrieve files, since its not a really a blob.
i have managed to get down data 255 byte long, but not greater, cant figure out whats the problem.
any ideas?
procedure TForm1.Button1Click(Sender: TObject);
var
ByteCount: integer;
EncodedStr: WideString;
MemStream: TMemoryStream;
//// DecodeStream: TBase64DecodingStream;
//Signal: array of byte;
begin
q.sql.Clear;
q.SQL.Add('select by from aaa');
q.Open;
q.last;
EncodedStr := q.FieldByName('by').asstring;
MemStream := TMemoryStream.Create;
ByteCount := length(q.FieldByName('by').AsString);
showmessage(inttostr(ByteCount)); // returns 255 only, why???
MemStream.Write((EncodedStr[1]), ByteCount);
MemStream.Seek(0, soFromBeginning);
MemStream.SaveToFile('01.jpg');
end;
ASKER
well, my mistake. but postgre is quite 'smart' and query works without problem.
my problem is how to get result into stream.
field[].asstring is wrong data type,
how can i get that bytea result into a stream???
my problem is how to get result into stream.
field[].asstring is wrong data type,
how can i get that bytea result into a stream???
instead of deleting a question you could accept your own comment
this way you have it for your own reference
and for others too
this way you have it for your own reference
and for others too
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> order by
select [by] from aaa