Page 1 of 1
Urgent - D7.1/MySQL/BLOB field problem
Posted: 20.10.2005, 02:35
by IgD
Please refer to
http://sourceforge.net/tracker/index.ph ... tid=415824
I ported an application to Zeoslib. I thought it worked but obviously didn't test it enough and the BLOB problem slipped through. I can't write to a BLOB. If I strip the Zeoslib components off the app and replace with dbExpress it works fine. Can anyone help me with this problem either a fix or workaround?
In the bug report I included detailed step by step instructions to replicate.
The problem occurs with both Zeoslib 6.15 stable and 6.51 alpha.
Posted: 21.10.2005, 23:23
by IgD
Anyone have any suggestions on this one? I'm really stumped. I had to revert back to dbExpress.
Posted: 22.10.2005, 15:36
by joupse
Here's how I read and write from/to a blobfield (with Zeoslib 5.5 though):
{------------------------------------------------}
Write a blob to a diskfile
{-----------------------------------------------}
var blob:TStream;
fs:TFilestream;
fname:string;
begin
fname:=Exedir+'\temp\'+
DataMod1.ZZMySqlQuery2Fnamn.asString;
try
blob := DataMod1.ZZMySqlQuery2.CreateBlobStream(DataMod1.ZZMySqlQuery2.FieldByName('xdok'), bmRead);
blob.Seek(0, soFromBeginning);
try
fs:=TFileStream.Create(fname, fmCreate);
fs.CopyFrom(blob, blob.Size);
finally
fs.Free
end;
finally
blob.Free
end;
{-------------------------------------------}
{--------------------------------------------------------------------------- }
Read from diskfile and insert into blobfield}
{----------------------------------------------------------------------------}
var
st:TFileStream;
blob:TStream;
try
st := TFileStream.Create(PBOpenPreviewDialog1.filename, fmOpenRead or
fmShareDenyWrite);
DataMod1.ZZMySqlQuery2.insert;
DataMod1.ZZMySqlQuery2.fieldbyname('Fnamn').asString:=
ExtractFilename(PBOpenPreviewDialog1.filename);
DataMod1.ZZMySqlQuery2.fieldbyname('Yr').asInteger:=wyear;
DataMod1.ZZMySqlQuery2.fieldbyname('Mnd').asInteger:=wmnd;
DataMod1.ZZMySqlQuery2.fieldbyname('Sign').asString:=Usign;
DataMod1.ZZMySqlQuery2.fieldbyname('Pnr').asInteger:=DataMod1.ZZMySqlTable2Pnr.asInteger;
DataMod1.ZZMySqlQuery2.fieldbyname('subnr').asInteger:=DataMod1.ZZMySqlQuery1dbnr.asInteger;
DataMod1.ZZMySqlQuery2.fieldbyname('Fnamn').asString:=
ExtractFilename(PBOpenPreviewDialog1.filename);
try
blob := DataMod1.ZZMySqlQuery2.Createblobstream(DataMod1.ZZMySqlQuery2.Fieldbyname('xdok'), bmWrite);
blob.Seek(0, soFromBeginning);
st.seek(0, soFromBeginning);
try
blob.CopyFrom(st, st.Size);
except
on exception do ;
end;
finally
blob.Free
end;
DataMod1.ZZMySqlQuery2.post;
DataMod1.ZZMySqlQuery2.refresh;
finally
st.free;
end;
Posted: 27.10.2005, 11:53
by IgD
Are there any ZeosLib developers here who could help me verify and fix the problem (if necessary)?
Posted: 04.11.2005, 00:43
by IgD
This problem is a real show stopper for me. Are there any members of the ZeosLib team who could help? Thanks!
Posted: 12.11.2005, 23:50
by IgD
Procedure for replicating this bug:
1. Create a MySQL 4.0 database:
a. Open up MySQL command line tool
b. Create database blobtest;
c. Create table blobtable (myblob blob, myedit varchar(80) );
2. Create a new application
3. Add TRichEdit and a TEdit
4. Add TButton
5. Add ZConnection and ZQuery.
a. OnZConnection set Protocol to MySql 4.0, appropriate
User, Password, Hostname and Database name to
"blobtest".
b. Set connection property on ZQuery.
6. Put some text in the rich edit and in the edit
7. In the TButton's OnClick event...
procedure TForm1.Button1Click(Sender:TObject);
var MyStringStream: TStringStream;
begin
ZConnection.Connected:=True;
with ZQuery do
begin
SQL.Clear;
Params.Clear;
MyStringStream:=TStringStream.Create('');
MyStringStream.Position:=0;
MyRichEdit.Lines.SavetoStream(MyStringStream);
SQL.Text:='insert into blobtable (myblob, myedit) values
(:myblob :myedit)';
Params[0].LoadFromStream(MyStringStream, ftFmtMemo);
Params[1].AsString:=Edit1.Text;
ExecSql;
end;
end;
8. Now run the application and click the button. The text
from the rich edit and edit should be saved in the BLOB field.
9. From the MySQL command line tool, do a SELECT * FROM
BLOBTABLE and see that the blob is NULL but the edit is okay.
10. Repeat the same testing using dbExpress with D7.1. It
works fine.
Posted: 15.11.2005, 09:32
by aperger
Hello,
I have no time to do your test, but maybe you read my previous notice
Problem
And you can see the solution to my problem. Maybe it will solve your problem too. Please take a short look into MySQL units which is similar then the PostgreSQL as the following:
Solution
Perger, Attila