Reputation: 3331
I am getting a weird error when trying to run a delete query.
android.database.sqlite.SQLiteException: no such column: ITEMS_LINK (Sqlite code 1): , while compiling: DELETE FROM ITEMS_CONTENT_TABLE WHERE BASE_CATEGORY_NAME=? AND BASE_CATEGORY_SRC_PATH=?, (OS error - 2:No such file or directory)
W/System.err: at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
W/System.err: at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:910)
W/System.err: at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:521)
W/System.err: at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:603)
W/System.err: at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:63)
W/System.err: at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
W/System.err: at android.database.sqlite.SQLiteDatabase.delete(SQLiteDatabase.java:1759)
But as can be noted column ITEMS_LINK
is not used in the delete query.
private boolean deleteChildContentFor(SQLiteDatabase db, String parentCategoryLink, String baseCategoryName, String baseCategorySrcPath)
{
String columns[] = {ITEMS_LINK};
String selection = PARENT_CATEGORY_LINK + "=? AND " + BASE_CATEGORY_NAME + "=? AND " + BASE_CATEGORY_SRC_PATH + "=?";
String selectionArgs[] = {parentCategoryLink.trim(), baseCategoryName.trim(), baseCategorySrcPath.trim()};
Cursor cursor = db.query(ITEMS_CONTENT_TABLE, columns, selection, selectionArgs, null, null, null);
if (cursor != null && cursor.getCount() > 0) {
cursor.moveToFirst();
do {
String itemsLink = cursor.getString(0);
if (itemsLink != null && !itemsLink.isEmpty()) {
deleteChildContentFor(db, itemsLink, baseCategoryName, baseCategorySrcPath);
}
} while (cursor.moveToNext());
}
if (cursor != null)
cursor.close();
String whereClause = PARENT_CATEGORY_LINK + "=? AND " + BASE_CATEGORY_NAME + "=? AND "
+ BASE_CATEGORY_SRC_PATH + "=?";
String whereArgs[] = {parentCategoryLink.trim(), baseCategoryName.trim(), baseCategorySrcPath.trim()};
db.delete(ITEMS_CONTENT_TABLE, whereClause, whereArgs); // Where the error occurs.
}
I've included some statements from before since same db
is used to run query where a column db is mentioned. (I think it is also worth mentioning that I also tried to close the db and obtained another writableDatabase
to no avail).
Running Simple Query After a suggestion from @MikeT I tried a simple query
String query = "DELETE FROM " + ITEMS_CONTENT_TABLE + " WHERE " + PARENT_CATEGORY_LINK + "='"
+ parentCategoryLink.trim() + "' AND " + BASE_CATEGORY_NAME + "='"
+ baseCategoryName.trim() + "' AND " + BASE_CATEGORY_SRC_PATH + "='" + baseCategorySrcPath.trim() + "';";
Log.d("Query", query);
db.execSQL(query); // Error on this line
The logged Query
D/Query: DELETE FROM ITEMS_CONTENT_TABLE WHERE PARENT_CATEGORY_LINK='_____' AND BASE_CATEGORY_NAME='_____' AND BASE_CATEGORY_SRC_PATH='_____';
This gave mostly the same error and stack trace but now PARENT_CATEGORY_LINK
is included in the error-logged query too, which was previously missing.
W/System.err: android.database.sqlite.SQLiteException: no such column: ITEMS_LINK (Sqlite code 1): , while compiling: DELETE FROM ITEMS_CONTENT_TABLE WHERE PARENT_CATEGORY_LINK='_______' AND BASE_CATEGORY_NAME='_______' AND BASE_CATEGORY_SRC_PATH='_______';, (OS error - 2:No such file or directory)
W/System.err: at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
W/System.err: at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:910)
W/System.err: at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:521)
W/System.err: at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:603)
W/System.err: at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:63)
W/System.err: at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
W/System.err: at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1960)
W/System.err: at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1885)
Upvotes: 0
Views: 977
Reputation: 3331
So just found the reason for the strangest of errors thanks to a discussion with @MikeT who told me to post DB's Schema in the question. While doing that I realized that there was some uncommented suppose-to-be-commented TRIGGER
attached to ITEMS_CONTENT_TABLE
.
I am not deleting this question and posting this answer to help if anyone else face this issue.
Upvotes: 2