2016-03-25 22 views
2

sqlite sorgumu logCat'e yazdırmanın bir yolu var mı? İşte benim sorgusqlite sorgusunu logCat'e yazdır

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

gösterilecek. Ben 'getContentResolver() sildin yerine imleç var ama yok ne olur (. ..) '? Sonuçların günlüğünü aramıyorum. SQLite dizesinin kendisini arıyorum. @tinysunlight fikrini aldı. –

cevap

2

kullanıyorum LogCat her satırından her sorgu tarafından okunan çizgi ve baskı değeri üzerinden okurdum:

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

ekleyebilir deneyin yapabilirsiniz

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 

Yo için

Android Studio’yu yeniden başlatmanız gerekebilir.

Düzenleme 1: Mobilde sqllite'ı test ederim, yapılandırmalar yararsız görünüyor. Nedeni bilmiyorum. Bu kaynak kodu olarak çalışmıyor ki:

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

Bu yaklaşımla hiç sonuç alamıyorum. Sqlite kullanıyorum beri ben ilk iki satır kullanın 'sekme >> Hata ayıklama günlüğü ayarları yapılandırmak ' –

+0

görebildiğim kadarıyla, bu sınıf bugün yok mu? Android.database.sqlite.SQLiteDebug'a başvurmayı deneyin, çözülmez – OlivierM

3

Android imleci dökümü bir yardımcı sınıf var! Bunun için aşağıdaki gibi:

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

kullanımı bu hat @ FarbodSalamat-Zadeh @beetlej

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