insert blob and read blob error!

Forum related to SQLite

Moderators: gto, cipto_kh, EgonHugeist

leatarget
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 02.01.2011, 12:31

insert blob and read blob error!

Postby leatarget » 07.01.2011, 04:59

env is delphi2010+preview-ZEOSDBO-7.0.1-alpha
Table structure is create table test(aa integer,ss char(50),b blob)
Into the blob field, insert three or more than three records, reading will be a problem, it should be an error led to the current record number.
Specific code as follows:

insert :
var
sql: string;
str: string;
fileStream : TStream;
zqry1: TZQuery;

fileStream := TFileStream.Create(ExtractFilePath(Application.ExeName)+ '\test.docx',fmOpenRead);
zqry1:= TZQuery.Create(self);
zqry1.Connection := con1;
zqry1.sql.Clear;
sql := 'insert into test(aa,ss,b)values('+FormatDateTime('mmsszzz',now)+',%s,:b)';
//sql := 'insert into test(aa,ss)values('+FormatDateTime('mmsszzz',now)+',%s)';

str := '中文服务请按1,Zemra ime kineze ah historinë tuaj私の中国語心はあなたの話をああ';
sql := Format(sql, [Quotedstr(str)]);
zqry1.sql.Add(sql);
zqry1.Params.ParamByName('b').DataType := ftBlob;
fileStream.Position := 0;
zqry1.Params.ParamByName('b').LoadFromStream(fileStream,ftBlob);
zqry1.ExecSQL;
filestream.Free;
zqry1.Close;
zqry1.Free;

read:
zqry1:= TZQuery.Create(self);
zqry1.Connection := con1;
zqry1.sql.Clear;
zqry1.sql.Add(Format('select * from test where ss like %s',
[QuotedStr('%服务%')]));
zqry1.Open;
ShowMessage(IntToStr(zqry1.RecordCount));
while not zqry1.Eof do
begin
ShowMessage(zqry1.FieldByName('ss').AsString);
//blobStream := zqry1.CreateBlobStream(zqry1.FieldByName('b'),bmRead);
//fileStream := TFileStream.Create('d:\temp\ddd.docx',fmCreate);
//filestream.CopyFrom(blobStream,blobStream.Size);

zqry1.Next; //===========error here
//filestream.free;
//blobStream.Free;
end;
zqry1.Close;
zqry1.Free;

Return to “SQLite”

Who is online

Users browsing this forum: No registered users and 1 guest