Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How use the insert query using parameters?

When i try with this query i get an error says that Perameter email doesn't exist, i am sure that the variables : email, login_pass, payment_method,operateur are valid and exists.

SQLQuery2.sql.Text := 'INSERT INTO registered (email,login_pass,payment_method,operateur) VALUES (":email",":login_pass",":payment_method",":avecpuce")';
SQLQuery2.ParamByName('email').AsString := email;
SQLQuery2.ParamByName('login_pass').AsString := login_pass;
SQLQuery2.ParamByName('payment_method').AsString := payment_method;
SQLQuery2.ParamByName('avecpuce').AsString := avecpuce;
SQLQuery2.ExecSQL(true);

I tried removing the quotation, but i get

You have an error in your Sql syntax, check the manual that corresponds to your SQL server for the right syntax to use near ':email,:login_pass,:payment_method,:avecpuce)' at line 1

How to use the insert query above using parameters?

like image 524
Rafik Bari Avatar asked Dec 01 '22 07:12

Rafik Bari


1 Answers

From the TSQLQuery.ExecSQL documentation:

ExecDirect indicates that the query does not need to be prepared before it is executed. This parameter can be set to true if the query does not include any parameters.

So if the code uses

SQLQuery2.ExecSQL(true);

this means that there will be no support for parameters.

But because you use parameters, just use

SQLQuery2.ExecSQL;

and also remove the quotes around parameters.

like image 108
mjn Avatar answered Dec 06 '22 18:12

mjn