I’m doing an insert:
QSqlQuery myQuery(db);
myQuery.prepare("INSERT INTO mytable VALUES (:val1, :val2)");
myQuery.bindValue(":val1", 1);
myQuery.bindValue(":val2", 2);
myQuery.exec();
Then I need to get the executed SQL query for logging purposes.
myQuery.executedQuery() returns "INSERT INTO mytable VALUES (?, ?)".
How do I to get executed query with the actual binded values that were used?
An alternative to what lightstep suggested, is to prepare query strings and then call a function that first writes the query to the log and only then calls real execute(). I personally use QString::arg() and “%number” for arguments to make a query string instead of bindValue().
Let’s sum things up:
Solution #1 (lightstep)
Solution #2 (me):