2016-03-25 15 views
2

Gibt es eine Möglichkeit, meine SQL-Abfrage auf logCat zu drucken? Hier ist meine AbfrageDrucken sqlite Abfrage zu logCat

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

@beetlej @ FarbodSalamat-Zadeh angezeigt werden: Was passiert, wenn ich nicht einen Cursor haben, sondern hat eine 'getContentResolver() gelöscht werden (.. ..) '? Ich suche nicht nach dem Protokoll des Ergebnisses. Ich suche nach der SQLite-Zeichenfolge selbst. @tinysunlight hat die Idee. –

Antwort

2

ich durch jede Zeile von der Abfrage lesen lesen würde, und Druckwert aus jeder Zeile zum logcat mit:

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(); 
6

Sie können versuchen, hinzuzufügen

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

Für 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 

Yo Möglicherweise müssen Sie Android Studio neu starten.

Bearbeiten 1: Ich sqlite auf Mobile testen, scheinen die Konfigurationen nutzlos.Ich weiß nicht den Grund. Es funktioniert nicht, wie der Quellcode sagen:

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

+0

Ich bekomme mit diesem Ansatz keine Ergebnisse. Da ich sqlite benutze, benutze ich die ersten beiden Zeilen nach dem Reiter 'Hilfe >> Debug Log Einstellungen konfigurieren ' –

+0

Soweit ich sehen konnte, existiert diese Klasse heute nicht? Versuchen Sie, android.database.sqlite.SQLiteDebug zu referenzieren, es wird nicht aufgelöst – OlivierM

3

Android eine Utility-Klasse hat Cursor-Dump! Genau wie unten:

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

Verwendung dieser Linie

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