-1
此代碼只刪除我表中的單個記錄,我想要實現的是刪除具有給定字符串電話值的所有記錄。 Im新的SQlite,一點幫助,非常感謝。先謝謝你。SQlite刪除所有具有特定字符串值的行
此代碼成功地刪除記錄單:
public void delSmsData(int id){
String deleteQuery = "DELETE FROM "+TABLE_LO_SMSDATA+" WHERE _id="+id+"";
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL(deleteQuery); //delete single row by ID in a table
db.execSQL("vacuum");
db.close();
Log.e("Debug", "Successful delete of message with id no. " + id);
}
我successfuly刪除所有記錄,此代碼。感謝那些幫助過的人。
public void delAllSmsByPhone(String phone){
String deleteQuery = "DELETE FROM "+TABLE_LO_SMSDATA+" WHERE _phone='"+phone+"'";
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL(deleteQuery);
db.execSQL("vacuum");
db.close();
}
這是我的表結構:
String CREATE_LO_SMSDATA_TABLE = "CREATE TABLE "
+TABLE_LO_SMSDATA+"("
+KEY_ID+" INTEGER PRIMARY KEY AUTOINCREMENT,"
+KEY_EMAIL+" TEXT,"
+KEY_TARGETNAME+" TEXT,"
+KEY_SMSTYPE+" TEXT,"
+KEY_PHONE+" TEXT,"
+KEY_CONTACTNAME+" TEXT,"
+KEY_SMSBODY+" TEXT,"
+KEY_DATE+" TEXT"+")";
db.execSQL(CREATE_LO_SMSDATA_TABLE);
什麼是你的表結構? '_phone'是主鍵嗎? –
@AdamForbis我更新了這個問題。 – Draeko
'... WHERE _phone ='「+ phone +」'「' –