简体   繁体   English

SQLiteLog:(1)在“ *”附近:语法错误

[英]SQLiteLog﹕ (1) near “*”: syntax error

I am getting SQLiteLog﹕ (1) near "*": syntax error in the below code while deleting row from table.Whats wrong with the code and why i am getting this error? SQLiteLog﹕ (1) near "*": syntax error遇到SQLiteLog﹕ (1) near "*": syntax error从表中删除行时,以下代码中SQLiteLog﹕ (1) near "*": syntax error 。代码有什么问题,为什么我得到此错误?

 public void deleteVideo(String key){
            String selectQuery = "DELETE  * FROM " + TABLE_TOW + " WHERE " + KEY_ID + "= '"+key;

            SQLiteDatabase db = this.getWritableDatabase();
            db.rawQuery(selectQuery, null);
        }

It should be "Delete from........" and not "Delete * from........" . 应该是"Delete from........"而不是"Delete * from........" Because you have made a syntax issue 因为您犯了语法问题

Pass value in single quote (') and remove * from query single quote (')传递值并从查询中删除*

Final: 最后:

String selectQuery = "DELETE FROM " + TABLE_TOW + " WHERE " + KEY_ID + "='"+key+"'";

Remove * from your query. 从查询中删除*

Updated Code 更新的代码

public void deleteVideo(String key){
    String selectQuery = "DELETE  FROM " + TABLE_TOW + " WHERE " + KEY_ID + "= '"+key+"'";
    SQLiteDatabase db = this.getWritableDatabase();
    db.rawQuery(selectQuery, null);
}

Documentation 文献资料

The asterisk isn't necessary with DELETE . DELETE不需要使用星号。 In fact, it's invalid. 实际上,这是无效的。 The DELETE FROM function will delete the entire row. DELETE FROM函数将删除整个行。 There is no way to specify which columns are to be deleted, because the clause can only delete entire rows. 由于子句只能删除整行,因此无法指定要删除的列。

You can't really 'delete' a cell. 您无法真正“删除”一个单元格。 You can set to be empty ( '' ), or NULL . 您可以设置为空( '' ),或NULL

If you need to specifically edit the contents of certain columns I recommend the UPDATE table SET a = 'b' WHERE id = 'some number' clause 如果您需要专门编辑某些列的内容,建议使用UPDATE table SET a = 'b' WHERE id = 'some number'子句

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM