android - 将 sqlite 查询打印到 logCat

标签 android sqlite android-sqlite logcat

有没有办法将我的 sqlite 查询打印到 logCat?这是我的查询

db.query(TABLE, projection, selection, selectionArgs, null, null, null)

最佳答案

你可以尝试添加

adb shell setprop log.tag.SQLiteLog V
adb shell setprop log.tag.SQLiteStatements V

对于 ormlite

adb shell setprop log.tag.StatementExecutor VERBOSE 
adb shell setprop log.tag.BaseMappedStatement VERBOSE 
adb shell setprop log.tag.MappedCreate VERBOSE 
adb shell setprop log.tag.ORMLite DEBUG

您可能需要重启 Android Studio。

编辑 1: 我在 Mobile 上测试了 sqllite,配置似乎没用。我不知道原因。 它不像源代码所说的那样工作:

public final class SQLiteDebug {
    private static native void nativeGetPagerStats(PagerStats stats);

    /**
     * Controls the printing of informational SQL log messages.
     *
     * Enable using "adb shell setprop log.tag.SQLiteLog VERBOSE".
     */
    public static final boolean DEBUG_SQL_LOG =
            Log.isLoggable("SQLiteLog", Log.VERBOSE);

    /**
     * Controls the printing of SQL statements as they are executed.
     *
     * Enable using "adb shell setprop log.tag.SQLiteStatements VERBOSE".
     */
    public static final boolean DEBUG_SQL_STATEMENTS =
            Log.isLoggable("SQLiteStatements", Log.VERBOSE);

    /**
     * Controls the printing of wall-clock time taken to execute SQL statements
     * as they are executed.
     *
     * Enable using "adb shell setprop log.tag.SQLiteTime VERBOSE".
     */
    public static final boolean DEBUG_SQL_TIME =
            Log.isLoggable("SQLiteTime", Log.VERBOSE);

    /**
     * True to enable database performance testing instrumentation.
     * @hide
     */
    public static final boolean DEBUG_LOG_SLOW_QUERIES = Build.IS_DEBUGGABLE;

    private SQLiteDebug() {
    }
 }

enter image description here enter image description here

关于android - 将 sqlite 查询打印到 logCat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36212847/

相关文章:

ruby-on-rails - ruby rails : "cannot load such file" eventmachine

java - Android SQLiteOpenHelper : Why onCreate() method is not called?

android - 使用 ViewPager 实现类似 iOS 应用关闭垂直滑动关闭的功能

javascript - 无法访问cordova SQLite存储插件

python - 从 sqlite 数据库中获取多行,合并共享相同日期的行,然后在表中打印

sql - 用外键计算行数

android - 无法在 SQLiteOpenHelper.onCreate(SQLiteDatabase) 中插入数据

android - 在 Retrofit Interceptor 中访问 sharedPreferences

android - requestLocationUpdates 花费的时间太长

java - 服务器发送消息给客户端