sasa
sasa

Reputation: 31

Params sql false

i tried this code

source := 'prénom';
FDQuery4.SQL.Add ('INSERT INTO  name(:pSource) Values ("kkkkk")');
FDQuery4.Params.ParamByName('pSource').Value := source;
FDQuery4.execSQL;

but it shows me this exception.

Exception 'first chance' à $75B2845D. Classe d'exception EMySQLNativeException avec un message '[FireDAC][Phys][MySQL] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''prénom') Values ("kkkkk")' at line 1'.

i don't understand why prénom is read like this ''prénom')

Upvotes: 0

Views: 109

Answers (1)

GuidoG
GuidoG

Reputation: 12014

You cannot use parameters for field names. Construct the query before executing like this

source := 'prénom';
FDQuery4.SQL.Add ('INSERT INTO  name(' + source + ') Values ("kkkkk")');
FDQuery4.execSQL;

And better is to use parameters for your value

source := 'prénom';
FDQuery4.SQL.Add ('INSERT INTO  name(' + source + ') Values (:pValue)');
FDQuery4.Params.ParamByName('pValue').Value := 'kkkk';
FDQuery4.execSQL;

As suggested by Victoria you can also do it like this when using FireDAC:
This does solves your first problem.

FDQuery4.SQL.Add('INSERT INTO name (&TheColumn) VALUES ("TheValue")');     
FDQuery4.MacroByName('TheColumn').AsIdentifier := 'prénom';

Upvotes: 1

Related Questions