Page 1 of 1

Could the ParamByName function be used for column and table?

Posted: 02.01.2014, 08:42
by detective0922
Hello,

sorry for my poor english :oops: . I am using C++ builder 6.0+ZEOSDBO-6.6.6-stable+mysql 5.0 and not familiar with zeosdbo, when i just use ParamByName function in sql for WHERE clause just like:
FMain->ZQuery1->SQL->Add("select slot from board where eqpid=:id");
FMain->ZQuery1->ParamByName("id")->AsInteger=1;
FMain->ZQuery1->Open();

That works fine.
But when I try to use ParamByName function for column and table name, it returned error. The code is below:
FMain->ZQuery1->SQL->Add("select :col from :tab where eqpid=:id");
FMain->ZQuery1->ParamByName("col")->AsString="slot;
FMain->ZQuery1->ParamByName("tab")->AsString="board";
FMain->ZQuery1->ParamByName("id")->AsInteger=1;
FMain->ZQuery1->Open();

it will return error:
SQL Error: 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 ''board' where eqpid=1' at line 1.

The sql I expected should be "select slot from board where eqpid=1", but the real sql seems not like that. Could someone help me?
Any replies will be appreciated. :D

Re: Could the ParamByName function be used for column and ta

Posted: 02.01.2014, 20:31
by marsupilami
Hello detective0922,

you canot use parameters for column names and table names. Parameters can only be used for sending values to the RDBMS. This is a limitation of SQL and Zeos doesn't replace the parameters by itself - it only transports them to the RDBMS which in turn has to process it.
Best regards,

Jan

Re: Could the ParamByName function be used for column and ta

Posted: 03.01.2014, 17:03
by detective0922
marsupilami wrote:Hello detective0922,

you canot use parameters for column names and table names. Parameters can only be used for sending values to the RDBMS. This is a limitation of SQL and Zeos doesn't replace the parameters by itself - it only transports them to the RDBMS which in turn has to process it.
Best regards,

Jan

Hi, marsupilami, thank you very much for your reply, it is helpful.