gpt4 book ai didi

android SQLite 更新/插入

转载 作者:搜寻专家 更新时间:2023-11-01 09:12:35 25 4
gpt4 key购买 nike

我想UPDATE我表中的一行,WHERE key = LastSelected
如果不存在具有该键的行,我想插入它。

如果该行已经存在,我可以让 UPDATE 工作,但如果它丢失,它不会INSERT

我试过这些(第一个正确更新,但不插入):

String.format("UPDATE table_1 SET value = '%s' WHERE key = 'LastSelected'", s);

String.format("REPLACE table_1 SET value = '%s' WHERE key = 'LastSelected'", s);

String.format("INSERT OR REPLACE INTO table_1 SET value = '%s' WHERE key = 'LastSelected'", s);

最佳答案

语法是INSERT OR REPLACE INTO <table> (<columns>) VALUES (<values>) , 可以在 the documentation 中看到.

在你的情况下,它会是这样的:

INSERT OR REPLACE INTO table_1 (key, value)
VALUES ('LastSelected', '...')

关于android SQLite 更新/插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7180441/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com