I have a query that is just a simple INSERT into MySQL. When I use DBQuery.Params
to add my value to query I get ??????(or E?? E?E???) in the MySQL side(if I perform a SELECT I get this results too ). But when I directly add my value to query everything is fine.
The problematic way:
procedure TfrmMain.Button1Click(Sender: TObject);
var
Title: widestring;
begin
Title:='سلام';
DBQuery.SQL.Text:=
'INSERT INTO tblintersection '+
'( '+
' Address, '+
' Title, '+
' InsertDate '+
') '+
'VALUES '+
'( '+
' :Address /*Address*/, '+
' :Title /*Title*/, '+
' NOW() /*InsertDate*/ '+
')';
DBQuery.Params.ParamValues['Address']:='100';
DBQuery.Params.ParamValues['Title']:=Title;
DBQuery.ExecSQL;
end;
If I change :Title
to "'+Title+'"
(and removing it's parameter also) the problem will be solved, but I want to use parameters to avoid problems like injection.
DB CharacterSet is Latin1. But everything is fine when I used values directly inside query
I also tested this but no result:
DBQuery.ParamByName('Title').DataType:= ftWideString;
DBQuery.ParamByName('Title').Value:= Title;
I've used Zeos
ZSqlMonitor
and saved log show this:
2013-09-25 11:18:24 cat: Execute, proto: mysql-5, msg: INSERT INTO tblintersection ( Address, Title, InsertDate ) VALUES ( 'sd45' , '? ??? ??? ???' , NOW() )
How to use parameter and avoid this problem?