1

我只想问这是否是使用 select、from 等的正确方法,以及我的条件是否正确:

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 的正确方法,谢谢

4

1 回答 1

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()});
于 2012-04-25T20:08:10.567 回答