无法更新 SQLite 上的最后一行
public public udpateNoteInfo(String text){
ContentValues val = new ContentValues();
val.put(KEY_CONTENT5, text);
sqLiteDatabase.update(MYDATABASE_TABLE, val,"ORDER_BY("+KEY_ID+") DESC LIMIT 0,1", new String[]{text});
}
我尝试更新 SQLite 中 KEY_CONTENT5 列的最后一行,但出现错误。 我猜它的错误在 "ORDER_BY("+KEY_ID+") DESC LIMIT 0,1"
但我不知道如何使其正确。如果你知道的话请告诉我。谢谢。
ERROR:
09-05 11:47:54.769 E/Database( 4386): Error updating note=Test using UPDATE PERSONAL_TABLE SET note=? WHERE _id = (SELECT max(_id) FROM PERSONAL_TABLE)
活动类:
public void updateNote(String txt) {
mySQLiteAdapter = new PersonalSQLiteAdapter(this);
mySQLiteAdapter.openToWrite();
cursor = mySQLiteAdapter.queueAll();
if (cursor != null) {
mySQLiteAdapter.udpateNoteInfo(txt);
}
mySQLiteAdapter.close();
}
SQLiteAdapter 类(不是活动):
public void udpateNoteInfo(String text) {
ContentValues val = new ContentValues();
val.put(KEY_CONTENT5, text);
sqLiteDatabase.update(MYDATABASE_TABLE, val, KEY_ID + " = (SELECT max("
+ KEY_ID + ") FROM " + MYDATABASE_TABLE + ")",
new String[] { text });
}
public public udpateNoteInfo(String text){
ContentValues val = new ContentValues();
val.put(KEY_CONTENT5, text);
sqLiteDatabase.update(MYDATABASE_TABLE, val,"ORDER_BY("+KEY_ID+") DESC LIMIT 0,1", new String[]{text});
}
I try to update the last row of the KEY_CONTENT5 column in my SQLite, but it's error.
I guess its mistake at "ORDER_BY("+KEY_ID+") DESC LIMIT 0,1"
but I don't know how to make it correct. Please tell me if you know that. Thank you.
ERROR:
09-05 11:47:54.769 E/Database( 4386): Error updating note=Test using UPDATE PERSONAL_TABLE SET note=? WHERE _id = (SELECT max(_id) FROM PERSONAL_TABLE)
Activity class:
public void updateNote(String txt) {
mySQLiteAdapter = new PersonalSQLiteAdapter(this);
mySQLiteAdapter.openToWrite();
cursor = mySQLiteAdapter.queueAll();
if (cursor != null) {
mySQLiteAdapter.udpateNoteInfo(txt);
}
mySQLiteAdapter.close();
}
SQLiteAdapter class (not activity):
public void udpateNoteInfo(String text) {
ContentValues val = new ContentValues();
val.put(KEY_CONTENT5, text);
sqLiteDatabase.update(MYDATABASE_TABLE, val, KEY_ID + " = (SELECT max("
+ KEY_ID + ") FROM " + MYDATABASE_TABLE + ")",
new String[] { text });
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您无法在更新前下订单。
你可以尝试这样的事情:
WHERE id=(SELECT max(id) FROM TABLE) 如果你想更新最后一个 id,假设你的序列没有被修改。
You can't put an order by in an update.
You can try something like this:
WHERE id=(SELECT max(id) FROM TABLE) if you want to update the last id, assuming your sequences aren't modified.
我的最终答案。
My final answer.
您可以查询 ID,然后更新这一行...如果您的 key_id 值不唯一,则需要使用主键列而不是这一列...
You can query the ID, and then, update this row... if your key_id values are not unique, you'll need to use your primary key column(s) instead of this one...
UPDATE 表集 col = 1 WHERE id = (SELECT MAX(id) FROM 表)
UPDATE table set col = 1 WHERE id = (SELECT MAX(id) FROM table)