Discussion:
Store and Retrieving Blob Field problem.
(too old to reply)
Ahmadi
2008-07-19 07:20:08 UTC
Permalink
Hi
Im using following code to store and retrieve blob field:

procedure TCEngineForm.SaveButtonClick(Sender: TObject);
var
mem:TMemoryStream;
begin
SQLQuery1.SQL.Clear;
SQLQuery1.SQL.Add('Insert into myTable(ID,image) values (1,:p1);');
mem:=TMemoryStream.create;
mem.LoadFromFile('c:\ali.bmp');
SQLQuery1.Params.Clear;
SQLQuery1.Params.CreateParam(ftBlob,'p1',ptInput);
SQLQuery1.Params.ParamByName('p1').SetBlobData(mem.Memory,mem.Size);
SQLQuery1.ExecSQL;
end;

procedure TCEngineForm.LoadButtonClick(Sender: TObject);
var
mem:TMemoryStream;
stream:TStream;
begin
SQLQuery1.SQL.Clear;
SQLQuery1.SQL.Add('select * from myTable where id='+QuotedStr('1')+';');
SQLQuery1.ExecSQL;
SQLQuery1.open;
TBlobField(SQLQuery1.FieldByName('image')).SaveToFile('c:\ali2.bmp');
end;

After saving, only first bytes(approximately 1000 bytes) of "ali2.bmp" is
equal to "ali.bmp", and seems that DMBS don't send whole of my Blob field
data !
I tested the above code and some other blob save & retrieve methods from
internet, all return only a few of Blob field data correctly !!!
This mean that DBMS can not return rest of field data, and return
zero(#0).im confused!
Im using D2007, SQL Server (my blob field type in SQL is varbinary(Max),
other types also have same problem),and dbx for driver
Thanks for any help
--
~~~~~~~~~~~
Best Regards
H.Ahmadi
Ahmadi
2008-07-19 08:10:41 UTC
Permalink
I have new information that explore the problem.
1)im sure that write operation work fine, because my DBMS Manager show me
that "image" field contain correct data. also my query result contain whole
of ali.bmp data.
2)SQLQuery only fetch 1024 bytes of my blob data, this mean that i must say
it that fetch whole of data.
SQLQuery only fetch 1024 bytes of my blob data! really why? how can i say it
to fetch all of my blob data?

Thank you for your attention.
--
~~~~~~~~~~~
Best Regards
H.Ahmadi
Post by Ahmadi
Hi
procedure TCEngineForm.SaveButtonClick(Sender: TObject);
var
mem:TMemoryStream;
begin
SQLQuery1.SQL.Clear;
SQLQuery1.SQL.Add('Insert into myTable(ID,image) values (1,:p1);');
mem:=TMemoryStream.create;
mem.LoadFromFile('c:\ali.bmp');
SQLQuery1.Params.Clear;
SQLQuery1.Params.CreateParam(ftBlob,'p1',ptInput);
SQLQuery1.Params.ParamByName('p1').SetBlobData(mem.Memory,mem.Size);
SQLQuery1.ExecSQL;
end;
procedure TCEngineForm.LoadButtonClick(Sender: TObject);
var
mem:TMemoryStream;
stream:TStream;
begin
SQLQuery1.SQL.Clear;
SQLQuery1.SQL.Add('select * from myTable where id='+QuotedStr('1')+';');
SQLQuery1.ExecSQL;
SQLQuery1.open;
TBlobField(SQLQuery1.FieldByName('image')).SaveToFile('c:\ali2.bmp');
end;
After saving, only first bytes(approximately 1000 bytes) of "ali2.bmp" is
equal to "ali.bmp", and seems that DMBS don't send whole of my Blob field
data !
I tested the above code and some other blob save & retrieve methods from
internet, all return only a few of Blob field data correctly !!!
This mean that DBMS can not return rest of field data, and return
zero(#0).im confused!
Im using D2007, SQL Server (my blob field type in SQL is varbinary(Max),
other types also have same problem),and dbx for driver
Thanks for any help
--
~~~~~~~~~~~
Best Regards
H.Ahmadi
Loading...