Reputation: 279
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
Upvotes: 0
Views: 1009
Reputation: 4577
Starting on SQLite 3.14 there is the sqlite3_expanded_sql()
function.
You can call it inside a callback registered with the sqlite3_trace_v2()
function.
Upvotes: 0
Reputation: 40721
You migth want to take a look at this question. Basically, you can write your own
sqlite3_trace
to record the latest query.
Upvotes: 1