尝试运行删除查询时,我遇到了一个奇怪的错误。
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)
但是可以注意到,删除查询中没有使用列ITEMS_LINK
。
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.
}
我之前已经包含了一些语句,因为相同的db
用于运行查询,其中提到了列db。 (我认为值得一提的是,我也试图关闭数据库并获得另一个writableDatabase
无效。
运行简单查询 在得到@MikeT的建议后,我尝试了一个简单的查询
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
记录的查询
D/Query: DELETE FROM ITEMS_CONTENT_TABLE WHERE PARENT_CATEGORY_LINK='_____' AND BASE_CATEGORY_NAME='_____' AND BASE_CATEGORY_SRC_PATH='_____';
这给出了大致相同的错误和堆栈跟踪,但现在PARENT_CATEGORY_LINK
也包含在错误记录的查询中,这在以前是丢失的。
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)
答案 0 :(得分:2)
因为与@MikeT的讨论告诉我在问题中发布DB的Schema,所以刚刚找到了最奇怪的错误的原因。在这样做的过程中,我意识到有一些未注释的假设评论TRIGGER
附加到ITEMS_CONTENT_TABLE
。
我不会删除此问题,如果其他人遇到此问题,请发布此答案以提供帮助。