Search code examples
androidsqlitekotlindelete-row

sqlite delete code not working in database_handeler


db!!.rawQuery("DELETE FROM $Cards_TABLE WHERE $Card_Parent_Board_Id='$CardParnt_boardId' AND $Card_Parent_Swimlane_Id='$CardParnt_SwimlaneId' AND $Card_Parent_List_Id='$CardParnt_ListId' ", null)

this code doesn't work in app but the result string (sql code ) works in sql


Solution

  • The rawQuery method expects output, that is it returns a Cursor, and should therefore only be used for SELECT queries.

    Other queries, such as DELETE, INSERT, DELETE, UPDATE or CREATE queries should instead use the execSQL method.

    It should also be noted that the conveniences methods, such as delete, insert and update not only generate SQL but they also return the a useful value.

    • The insert returns the rowid of the inserted row as a longm
    • The update and delete methods return the number of affected rows as an int.

    You may wish to refer to SQLiteDatabase