S
swhl
Unregistered / Unconfirmed
GUEST, unregistred user!
用delphi+libmysql.dll+blob时,使用ObjectBinaryToText函数出错。程序如下:
var
BinStream:TMemoryStream;
StrStream: TStringStream;
s: string;
BinStream:=TMemoryStream.Create;
StrStream := TStringStream.Create(s);
row:=mysql_fetch_row(presultsServer);
plengths:=PArrinteger(mysql_fetch_lengths(presultsServer));
BinStream.Clear;
BinStream.Write(row[4]^,plengths[4]);//将blob字段读取到BinStream
BinStream.SaveToFile(row[1]);//保存到文件文件名为row[1]
BinStream.Seek(0, soFromBeginning);
ObjectBinaryToText(BinStream, StrStream);//程序运行到此,出错“Invalid stream format”
StrStream.Seek(0, soFromBeginning);
mysql_escape_string(tempStr,pchar(StrStream.DataString),length(pchar(StrStream.DataString)));
query2:='insert into image(filename,filetype,filesize,filedata)values(''' + row[1] + ''',''' + row[2] + ''',''' + row[3] + ''',''' + tempStr + ''')';
mysql_real_query(@mysqlrecLocal,pchar(query2),length(query2));//将数据插入到另一个数据库中
delphi的帮助中的例子为:
function ComponentToString(Component: TComponent): string;
var
BinStream:TMemoryStream;
StrStream: TStringStream;
s: string;
begin
BinStream := TMemoryStream.Create;
try
StrStream := TStringStream.Create(s);
try
BinStream.WriteComponent(Component);
BinStream.Seek(0, soFromBeginning);
ObjectBinaryToText(BinStream, StrStream);
StrStream.Seek(0, soFromBeginning);
Result:= StrStream.DataString;
finally
StrStream.Free;
end;
finally
BinStream.Free
end;
end;
请高手帮忙!!!!小弟学delphi刚两个星期菜鸟一个。
var
BinStream:TMemoryStream;
StrStream: TStringStream;
s: string;
BinStream:=TMemoryStream.Create;
StrStream := TStringStream.Create(s);
row:=mysql_fetch_row(presultsServer);
plengths:=PArrinteger(mysql_fetch_lengths(presultsServer));
BinStream.Clear;
BinStream.Write(row[4]^,plengths[4]);//将blob字段读取到BinStream
BinStream.SaveToFile(row[1]);//保存到文件文件名为row[1]
BinStream.Seek(0, soFromBeginning);
ObjectBinaryToText(BinStream, StrStream);//程序运行到此,出错“Invalid stream format”
StrStream.Seek(0, soFromBeginning);
mysql_escape_string(tempStr,pchar(StrStream.DataString),length(pchar(StrStream.DataString)));
query2:='insert into image(filename,filetype,filesize,filedata)values(''' + row[1] + ''',''' + row[2] + ''',''' + row[3] + ''',''' + tempStr + ''')';
mysql_real_query(@mysqlrecLocal,pchar(query2),length(query2));//将数据插入到另一个数据库中
delphi的帮助中的例子为:
function ComponentToString(Component: TComponent): string;
var
BinStream:TMemoryStream;
StrStream: TStringStream;
s: string;
begin
BinStream := TMemoryStream.Create;
try
StrStream := TStringStream.Create(s);
try
BinStream.WriteComponent(Component);
BinStream.Seek(0, soFromBeginning);
ObjectBinaryToText(BinStream, StrStream);
StrStream.Seek(0, soFromBeginning);
Result:= StrStream.DataString;
finally
StrStream.Free;
end;
finally
BinStream.Free
end;
end;
请高手帮忙!!!!小弟学delphi刚两个星期菜鸟一个。