0

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

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.