用过libmysql.dll高手请帮忙, mysql_escape_string出错!
程序:
procedure TForm1.Button1Click(Sender: TObject);
type
PArrinteger=PMYSQL_LENGTHS;
var
presultsLocal: PMYSQL_RES; //results structure *pointer
presultsServer: PMYSQL_RES; //results structure *pointer
i, j,n: Integer; //Counter vars
query1,query2: String;
row
MYSQL_ROW;
num_fields:integer;
pmyfield
MYSQL_FIELD;
plengths
Arrinteger;
tempStr
char;
ttt:longword;
retval: Integer;
BinStream:TMemoryStream;
StrStream:TStringStream;
s: string;
begin
mysql_connect(@mysqlrecServer, '18.1.1.2', 'easyweb', 'easyweb');
mysql_connect(@mysqlrecLocal, 'localhost', 'easyweb', 'easyweb');
retval:= mysql_select_db(@mysqlrecServer, 'test');
retval:= mysql_select_db(@mysqlrecLocal, 'test');
BinStream:=TMemoryStream.Create;
StrStream := TStringStream.Create(s);
query1:= 'SELECT * FROM image order by id'; //Query text
presultsServer:= nil;
try
mysql_real_query(@mysqlrecServer, pchar(query1),Length(query1)); //Send Query to server
presultsServer:= mysql_store_result(@mysqlrecServer); //Store results locally
//num_fields:= mysql_num_fields(results_Server);
for i:= 0 to presultsServer.row_count-1 do begin
row:=mysql_fetch_row(presultsServer);
plengths:=PArrinteger(mysql_fetch_lengths(presultsServer));
BinStream.Clear;
BinStream.Write(row[4]^,plengths[4]);
BinStream.SaveToFile(row[1]);//保存到文件
BinStream.SaveToStream(StrStream);
StrStream.Seek(0, soFromBeginning);
ttt:= plengths[4];
mysql_escape_string(tempStr,pchar(StrStream.Datastring),StrStream.size);
query2:='insert into image(filename,filetype,filesize,filedata)values(''' + row[1] + ''',''' + row[2] + ''',''' + row[3] + ''',''' + StrStream.DataString + ''')';
mysql_real_query(@mysqlrecLocal,pchar(query2),length(query2));
end; // i
finally
BinStream.Free;
StrStream.Free;
//mysql_free_result(presultsLocal); //release the stored results from memory
mysql_free_result(presultsServer);
end;
end;
程序执行到mysql_escape_string时出错。