【发布时间】:2019-02-07 09:02:27
【问题描述】:
我查看了一些不同的建议,但由于某种原因,以下解决方案都无法工作/仍然在表中重复数据。
"Category" 将是此 SQLite 表的唯一值。要更改的值为“spending_limit”。
到目前为止我已经尝试过:
public void writeToSpendingLimits(int sequence, double amount){
String sql = "INSERT OR REPLACE INTO spending_limits(category, spending_limit) "
+ "VALUES(" + sequence + ", " + amount + ");";
connection.executeSQL(sql);
}
.
public void writeToSpendingLimits(int sequence, double amount){
String sql = "INSERT INTO spending_limits (category, spending_limit) "
+ "VALUES(" + sequence + ", " + amount + ") "
+ "ON CONFLICT(category)"
+ "DO UPDATE SET spending_limit = " + amount + ";";
connection.executeSQL(sql);
.
public void writeToSpendingLimits(int sequence, double amount){
String sql = "INSERT INTO spending_limits (category, spending_limit) "
+ "VALUES (coalesce((select category from spending_limits where category = " + amount + "),"
+ "(select max(category) from spending_limits) + 1), " + amount + ");";
connection.executeSQL(sql);
.
public void writeToSpendingLimits(int sequence, double amount){
String sql = "UPDATE spending_limits "
+ "SET category = " + sequence + ", " + "spending_limit = " + amount + " "
+ "WHERE spending_limit = " + sequence + ";\n"
+ "INSERT INTO spending_limits(category, spending_limit) "
+ "SELECT " + sequence + ", " + amount + " "
+ "WHERE (Select Changes() = 0)";
connection.executeSQL(sql);
【问题讨论】:
-
你的表架构是什么?不工作是什么意思?
标签: sql database sqlite replace