QSqlQuery / bindValue syntax
Hello, this code is working OK :
Code:
query.prepare("SELECT name FROM mytable");
if( ! query.exec() )
cout << "error SQL= " << query.lastError().text().toStdString() << endl;
else
cout << "Ok" << endl;
But if I change the 3 lines :
Code:
query.prepare("SELECT :tag_array FROM :tag_table");
query.bindValue(":tag_array","name");
query.bindValue(":tag_table","mytable");
if( ! query.exec() )
cout << "error SQL= " << query.lastError().text().toStdString() << endl;
else
cout << "Ok" << endl;
I have this error at execution time :
Code:
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 ':tag_array FROM :tag_table' at line 1 QMYSQL: Unable to execute query
Did I did a mistake ?
Re: QSqlQuery / bindValue syntax
Check the documentation for MySQL if the table name in a prepared statement can be a parameter.
Re: QSqlQuery / bindValue syntax
You're totaly right Lesiok ! it is not a Qt problem, it is a Mysql problem.
Here is 2 good docs :
http://rpbouman.blogspot.fr/2005/11/...yntax-and.html
http://dev.mysql.com/doc/refman/5.0/fr/sqlps.html
You have lightened my light, thanks a lot !