Skip to content

Commit

Permalink
Added logging of sqlite statements.
Browse files Browse the repository at this point in the history
  • Loading branch information
BoD committed Apr 19, 2014
1 parent 1b3fb26 commit 95b2faa
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ${header}
</#if>
package ${config.providerJavaPackage};

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
Expand Down Expand Up @@ -59,6 +60,23 @@ public class ${config.providerClassName} extends ContentProvider {

@Override
public boolean onCreate() {
if (BuildConfig.DEBUG) {
// Enable logging of SQL statements as they are executed.
try {
Class<?> sqliteDebugClass = Class.forName("android.database.sqlite.SQLiteDebug");
Field field = sqliteDebugClass.getDeclaredField("DEBUG_SQL_STATEMENTS");
field.setAccessible(true);
field.set(null, true);

// Uncomment the following block if you also want logging of execution time (more verbose)
// field = sqliteDebugClass.getDeclaredField("DEBUG_SQL_TIME");
// field.setAccessible(true);
// field.set(null, true);
} catch (Throwable t) {
if (BuildConfig.DEBUG) Log.w(TAG, "Could not enable SQLiteDebug logging", t);
}
}

m${config.sqliteOpenHelperClassName} = ${config.sqliteOpenHelperClassName}.newInstance(getContext());
return true;
}
Expand Down

0 comments on commit 95b2faa

Please sign in to comment.