PDA

View Full Version : QSqlQuery::prepare() and executed sql command after bound values



NullPointer
5th August 2011, 04:04
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...

estanisgeyer
8th August 2011, 01:21
Post your sample code, please. But, the basic is:



int i = 10;
QSqlQuery q;
QSqlRecord r;
q.prepare(QString::fromUtf8(" SELECT ID_EXAMPLE, FIELD_EXAMPLE FROM TABLE_EXAMPLE WHERE ID_EXAMPLE = ? ");
q.addBindValue(i);
q.exec();
r = q.record();
QString s = q.value(r.indexOf("FIELD_EXAMPLE")).toString();