【问题标题】:Print sqlite query to logCat将 sqlite 查询打印到 logCat
【发布时间】:2016-03-25 01:49:02
【问题描述】:

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

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

【问题讨论】:

  • @beetlej @FarbodSalamat-Zadeh:如果我没有光标,而是使用了getContentResolver().delete(...),该怎么办?我不是在寻找结果的日志。我正在寻找 SQLite 字符串本身。 @tinysunlight 明白了。

标签: android sqlite android-sqlite logcat


【解决方案1】:

您可以尝试添加

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

对于奥氏体

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() {
    }
 }

【讨论】:

  • 我没有用这种方法得到任何结果。由于我使用的是 sqlite,因此我使用标签 Help >> Configure Debug Log Settings 之后的前两行
  • 据我所知,这个类今天不存在?尝试引用android.database.sqlite.SQLiteDebug,没有解决
【解决方案2】:

Android 有一个实用程序类来转储光标!如下所示:

while(!cursor.isAfterLast()) {
    Log.e(TAG,DatabaseUtils.dumpCurrentRowToString(cursor));
    cursor.moveToNext();
}

【讨论】:

    【解决方案3】:

    我会通读查询读取的每一行,并使用以下命令将每一行的值打印到 logcat:

    while (!cursor.isAfterLast()) {
        /* Reading values from the current line, putting them into variables */
        ...
    
        /* Print the log message */
        Log.d("Log message", value1 + " and " + value2 + " and " + ... );
    
        cursor.moveToNext();
    }
    cursor.close();
    

    【讨论】:

      【解决方案4】:

      用这一行显示

      Log.d(TAG, DatabaseUtils.dumpCursorToString(cursor));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-09
        • 1970-01-01
        • 2020-05-20
        • 2019-05-17
        相关资源
        最近更新 更多