I have been learning SQLite, and I am running into a snag when trying to delete entries. I am being told that the table I am trying to reference is not correct, however, I have data added to it. I must be missing something small.
I delete records using the following method in my DBHelper.java class
public long deleteRecord(String table, String condition) {
mDatabase = getWritableDatabase();
if (mDatabase.isOpen()) {
return mDatabase.delete(table, condition, null);
}
return 0;
}
I am using the method as such:
final DBHelper db = new DBHelper(mContext);
db.deleteRecord(EntryTable.TABLE_NAME, "Test=hardcoded");
db.close();
Here is my EntryTable.java class if this helps.
public class EntryTable {
public static final String TABLE_NAME = "entry";
public static final String PATH = "entry";
public static final int PATH_TOKEN = 2015;
public static final Uri CONTENT_URI = ContentDescriptor.BASE_URI.buildUpon().appendPath(PATH).build();
public static class Cols {
// Table column names
public static final String COLUMN_ID = "_id";
public static final String COLUMN_ENTRY = "Entry";
public static final String COLUMN_TEST = "Test";
}
}
I thought that deleting entries from a table is done in this format:
DELETE FROM table_name WHERE some_column=some_value
Nearly every row will have "hardcoded" under the test column. My table looks like this:
_id Entry Test
0 a hardcoded
1 b hardcoded
2 c hardcoded
3 d hardcoded
4 e hardcoded
5 f hardcoded
My error log is
03-16 16:32:45.224: E/AndroidRuntime(18790): FATAL EXCEPTION: main
03-16 16:32:45.224: E/AndroidRuntime(18790): Process: com.example.sqlitedemo, PID: 18790
03-16 16:32:45.224: E/AndroidRuntime(18790): android.database.sqlite.SQLiteException: no such table: entry (code 1): , while compiling: DELETE FROM entry WHERE Test=hardcoded
03-16 16:32:45.224: E/AndroidRuntime(18790): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
03-16 16:32:45.224: E/AndroidRuntime(18790): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1113)
03-16 16:32:45.224: E/AndroidRuntime(18790): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:690)
03-16 16:32:45.224: E/AndroidRuntime(18790): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
03-16 16:32:45.224: E/AndroidRuntime(18790): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
03-16 16:32:45.224: E/AndroidRuntime(18790): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
03-16 16:32:45.224: E/AndroidRuntime(18790): at android.database.sqlite.SQLiteDatabase.delete(SQLiteDatabase.java:1610)
03-16 16:32:45.224: E/AndroidRuntime(18790): at com.example.sqlitedemo.helper.DBHelper.deleteRecord(DBHelper.java:206)
03-16 16:32:45.224: E/AndroidRuntime(18790): at com.example.sqlitedemo.activity.MainActivity.onClick(MainActivity.java:67)
03-16 16:32:45.224: E/AndroidRuntime(18790): at android.view.View.performClick(View.java:4630)
03-16 16:32:45.224: E/AndroidRuntime(18790): at android.view.View$PerformClick.run(View.java:19331)
03-16 16:32:45.224: E/AndroidRuntime(18790): at android.os.Handler.handleCallback(Handler.java:733)
03-16 16:32:45.224: E/AndroidRuntime(18790): at android.os.Handler.dispatchMessage(Handler.java:95)
03-16 16:32:45.224: E/AndroidRuntime(18790): at android.os.Looper.loop(Looper.java:157)
03-16 16:32:45.224: E/AndroidRuntime(18790): at android.app.ActivityThread.main(ActivityThread.java:5356)
03-16 16:32:45.224: E/AndroidRuntime(18790): at java.lang.reflect.Method.invokeNative(Native Method)
03-16 16:32:45.224: E/AndroidRuntime(18790): at java.lang.reflect.Method.invoke(Method.java:515)
03-16 16:32:45.224: E/AndroidRuntime(18790): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
03-16 16:32:45.224: E/AndroidRuntime(18790): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
03-16 16:32:45.224: E/AndroidRuntime(18790): at dalvik.system.NativeStart.main(Native Method)
What am I missing? Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire