2012-04-25 76 views
1

我只想問,如果這是使用選擇正確的方式,從等,如果我的條件是正確的:這是原始查詢的正確方法嗎? - Android電子

private Cursor delete(){ 
     calendarData = new CalendarData(this); 
     SQLiteDatabase db = calendarData.getWritableDatabase(); 
     String mySQL = " select"+ _ID+ "from " + TABLE_NAME + "where" + _ID + "==" + deleteAnAppointment.getText().toString(); 
     Cursor idToDelete = db.rawQuery(mySQL, null); 
     startManagingCursor(idToDelete); 
     return idToDelete; 
    } 

    private void selectToDelete(Cursor cursor){ 
     calendarData = new CalendarData(this); 
     SQLiteDatabase db = calendarData.getWritableDatabase(); 
     if(cursor.getCount() > 0){ 
      db.delete(TABLE_NAME, _ID+" = "+deleteAnAppointment.getText().toString(), null); 
     } 

    } 

我沒有得到任何結果,但無論如何只是想看看它正確的格式化SQL的方法,謝謝

回答

2

不,你的查詢有問題。

更改此:

String mySQL = " select"+ _ID+ "from " + TABLE_NAME + "where" + _ID + "==" + 
     deleteAnAppointment.getText().toString(); 
Cursor idToDelete = db.rawQuery(mySQL, null); 

要這樣:

String mySQL = "SELECT "+ _ID+ " FROM " + TABLE_NAME + " WHERE " + _ID + " = ?"; 
Cursor idToDelete = db.rawQuery(mySQL, 
    new String[]{deleteAnAppointment.getText().toString()}); 
+0

最新的問號? – a7omiton 2012-04-25 20:16:10

+0

你是什麼意思? – waqaslam 2012-04-25 20:20:37

+0

「=?」在sql – a7omiton 2012-04-25 20:27:05

相關問題