Markus Markus - 26 days ago 10
Objective-C Question

SQLite on iPhone - Get final query string with parameters after binding

I would like to get the final SQL query, with parameter values bound (replaced) for debugging. It is a rather large and complex query (some joins, and about 20 parameters). Just wondered if it was possible to access the final query passed to the sqlite db.

//PSEUDO CODE

theSQL = "SELECT a,b,c FROM myTable where aField = ?";
sqlite3_prepare_v2(myDb, theSQL, -1, &compiledStatement, NULL);
sqlite3_bind_text(compiledStatement, 1, myUTF8stringParam, -1, SQLITE_STATIC);

theSQLwithBoundParams = //<<<--- here is missing what I look for ;)
NSLog(@"Perpared Statement with params: %@", theSQLwithBoundParams);

...


I already looked around on the web and the sqlite documentation without luck.
For reference, I found a similar question here on stackoverflow. It is almost a year old - so I thought asking again should be ok…

Thanks in advance,

Markus

Answer

You migth want to take a look at this question. Basically, you can write your own sqlite3_trace to record the latest query.