Results 1 to 2 of 2

Thread: QSqlQuery::prepare() and executed sql command after bound values

  1. #1
    Join Date
    Jul 2011
    Location
    Brasil
    Posts
    39
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSqlQuery::prepare() and executed sql command after bound values

    Hi,

    I tried to search all documentation of QSqlQuery and QSqlResult, but I didn't find a way to output the query that Qt executed in my database.

    I'm using a prepared statement, and binding the values, but I can't get the whole query(prepared with the placeholders replaced by their bound values).

    QSqlQuery::lastQuery() and QSqlQuery::executedQuery() both give me the original prepared statement, with the placeholders...

    There is a way to get the sql command?

    I'm using QMYSQL...

  2. #2
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQuery::prepare() and executed sql command after bound values

    Post your sample code, please. But, the basic is:

    Qt Code:
    1. int i = 10;
    2. q.prepare(QString::fromUtf8(" SELECT ID_EXAMPLE, FIELD_EXAMPLE FROM TABLE_EXAMPLE WHERE ID_EXAMPLE = ? ");
    3. q.addBindValue(i);
    4. q.exec();
    5. r = q.record();
    6. QString s = q.value(r.indexOf("FIELD_EXAMPLE")).toString();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Why does QSqlQuery::prepare() return false?
    By NotANoob in forum Qt Programming
    Replies: 2
    Last Post: 20th April 2011, 19:05
  2. QSqlQuery::prepare() - placeholder as table name
    By dawwin in forum Qt Programming
    Replies: 2
    Last Post: 7th March 2011, 21:40
  3. Replies: 1
    Last Post: 1st August 2010, 14:06
  4. QSqlQuery prepare() bindValue() broken badly
    By RolandHughes in forum Qt Programming
    Replies: 4
    Last Post: 14th November 2008, 18:25
  5. Database and QSqlQuery::prepare problem
    By fengtian.we in forum Qt Programming
    Replies: 1
    Last Post: 31st October 2007, 23:17

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.