这是原始查询的正确方法吗? - Android

时间:2012-04-25 20:04:42

标签: android sql

我只是想问一下,如果这是使用select的正确方法,等等,如果我的条件是正确的:

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

1 个答案:

答案 0 :(得分: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()});