Results 1 to 3 of 3

Thread: QSqlQuery / bindValue syntax

  1. #1
    Join Date
    Apr 2013
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    1

    Default QSqlQuery / bindValue syntax

    Hello, this code is working OK :
    Qt Code:
    1. QSqlQuery query(mybase);
    2. query.prepare("SELECT name FROM mytable");
    3.  
    4. if( ! query.exec() )
    5. cout << "error SQL= " << query.lastError().text().toStdString() << endl;
    6. else
    7. cout << "Ok" << endl;
    To copy to clipboard, switch view to plain text mode 

    But if I change the 3 lines :
    Qt Code:
    1. QSqlQuery query(mybase);
    2. query.prepare("SELECT :tag_array FROM :tag_table");
    3. query.bindValue(":tag_array","name");
    4. query.bindValue(":tag_table","mytable");
    5.  
    6. if( ! query.exec() )
    7. cout << "error SQL= " << query.lastError().text().toStdString() << endl;
    8. else
    9. cout << "Ok" << endl;
    To copy to clipboard, switch view to plain text mode 

    I have this error at execution time :

    Qt Code:
    1. 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
    To copy to clipboard, switch view to plain text mode 

    Did I did a mistake ?
    Last edited by dsant; 24th April 2013 at 12:58.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 284 Times in 279 Posts

    Default Re: QSqlQuery / bindValue syntax

    Check the documentation for MySQL if the table name in a prepared statement can be a parameter.

  3. The following user says thank you to Lesiok for this useful post:

    dsant (27th April 2013)

  4. #3
    Join Date
    Apr 2013
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    1

    Default 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 !

Similar Threads

  1. QSqlQuery::bindValue does not work
    By l0ud in forum Newbie
    Replies: 3
    Last Post: 23rd September 2012, 23:42
  2. QSqlQuery bindValue and SELECT WHERE IN
    By helloworld in forum Qt Programming
    Replies: 5
    Last Post: 6th November 2010, 16:45
  3. QSqlQuery::bindValue
    By viglu in forum Newbie
    Replies: 3
    Last Post: 29th March 2010, 21:13
  4. QSqlQuery, bindValue and Sqlite
    By cydside in forum Qt Programming
    Replies: 4
    Last Post: 5th April 2009, 17:53
  5. QSqlQuery::bindValue problem
    By segfault in forum Qt Programming
    Replies: 6
    Last Post: 11th March 2009, 08:27

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.