4

I want to see the SQL statements generated by SQLiteDatabase, to understand why something is wrong. Is there a way to make SQLiteDatabase log to logcat?

Thanks, Itay.

EDIT: This is not the same as Logging SQL queries in android, as I'm trying to log insert and update statements - I don't have a cursor.

2
  • Seems that you are asking the same as stackoverflow.com/questions/5966584/… Commented Nov 20, 2011 at 8:35
  • No, not exactly, I don't have a cursor, I want to log insert and update statements (although logging queries is also a good idea...). I'll update to make sure. Commented Nov 20, 2011 at 8:36

1 Answer 1

2

You have to implement it by yourself using trace API,so you can implement the callback of SQLite Trace :

The callback function registered by sqlite3_trace() is invoked at various times when an SQL statement is being run by sqlite3_step(). The sqlite3_trace() callback is invoked with a UTF-8 rendering of the SQL statement text as the statement first begins executing. Additional sqlite3_trace() callbacks might occur as each triggered subprogram is entered. The callbacks for triggers contain a UTF-8 SQL comment that identifies the trigger.

The callback function registered by sqlite3_profile() is invoked as each SQL statement finishes. The profile callback contains the original statement text and an estimate of wall-clock time of how long that statement took to run. The profile callback time is in units of nanoseconds, however the current implementation is only capable of millisecond resolution so the six least significant digits in the time are meaningless. Future versions of SQLite might provide greater resolution on the profiler callback. The sqlite3_profile() function is considered experimental and is subject to change in future versions of SQLite.

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

2 Comments

Ahhh, now I need to find out how to implement those when I can't write C functions. Any ideas? A preliminary Google search wasn't very helpful.
The SQLite C API is not available in Android, unless you use the NDK.

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.