2016-08-17 1 views
0

値が「完了」のときにデータベース内のすべてのオブジェクトを取得しようとしていますが、例外が発生します。私は別のメソッドで同じクエリを使用してオブジェクトのみを回復するため、クエリが正しいと思います。データベースのすべてのオブジェクトを取得しようとするとエラーが発生する

public List<DownloadProfile> getAllDownloadProfile(String state) { 
    List<DownloadProfile> downloadProfiles = new ArrayList<>(); 
    Cursor cursor = db.rawQuery("SELECT * FROM " + DownloadEntry.TABLE_NAME 
      + " WHERE " + DownloadEntry.COLUMN_NAME_DL_STATE + " = " + state + "", null); 

    if (cursor.getCount() > 0) { 
     cursor.moveToFirst(); 
     do { 
      DownloadProfile downloadProfile = new DownloadProfile(-1, "", "", ""); 
      downloadProfile.path = cursor.getString(cursor.getColumnIndex(DownloadEntry.COLUMN_NAME_DL_PATH)); 
      downloadProfile.extension = cursor.getString(cursor.getColumnIndex(DownloadEntry.COLUMN_NAME_DL_EXTENSION)); 
      downloadProfile.downloadId = cursor.getInt(cursor.getColumnIndex(DownloadEntry.COLUMN_NAME_DL_ID)); 
      downloadProfiles.add(downloadProfile); 

     } while (cursor.moveToNext()); 
    } 
    cursor.close(); 
    return downloadProfiles; 
} 

マイ例外:SQLで

Caused By : SQL(query) error or missing database. 
(no such column: completed (code 1): , while compiling: SELECT * FROM download WHERE download_state = completed) 
################################################################# 
    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) 
    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1058) 
    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:623) 
    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 
    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59) 
    at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37) 
    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44) 
    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1454) 
    at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1393) 
    at com.samsung.sidia.rio360.database.DownloadDatabase.getAllDownloadProfile(DownloadDatabase.java:47) 
    at com.samsung.sidia.rio360.model.DownloadModel.getVideoIDsAtState(DownloadModel.java:82) 
    at sidia.rio360app.MainActivity.resumeDl(MainActivity.java:54) 
+0

あなたがクラス全体をください投稿することができますか? – sumandas

答えて

1

文字列リテラルは'single quotes'に行きます。引用符で囲まれていない文字列は、列名などの識別子として解釈されます。

しかし、それは?変数を使用して値をバインドすると良いでしょう:

Cursor cursor = db.rawQuery("SELECT * FROM " + DownloadEntry.TABLE_NAME 
     + " WHERE " + DownloadEntry.COLUMN_NAME_DL_STATE + " = ?", new String[] { state }); 
+0

それはそれです:)。ありがとうございました。 –

関連する問題