Android的SQLite的更新/插入 [英] android SQLite update/insert

查看:109
本文介绍了Android的SQLite的更新/插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要的更新一排在我的表,其中key = LastSelected
如果某行与该键不存在,我想为 INSERT 吧。

我可以在更新工作,如果该行已经存在,但不会插入如果它丢失了。

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

 的String.Format(UPDATE TABLE_1设定值='%s'的其中key ='LastSelected',S);

的String.Format(REPLACE TABLE_1设定值='%s'的其中key ='LastSelected',S);

的String.Format(插入或更换成TABLE_1设定值='%s'的其中key ='LastSelected',S);
 

解决方案

语法是插入或更换成<表> (小于列>)VALUES(小于值>),如可在的文档

在你的情况,这将是这样的:

 插入或更换成TABLE_1(键,值)
VALUES('LastSelected','...')
 

I want to UPDATE a row in my table, WHERE key = LastSelected
If a row with that key does not exist, I want to INSERT it.

I can get the UPDATE to work if the row already exists, but it will not INSERT if it is missing.

I have tried these (the first one correctly updates, but does not 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);

解决方案

The syntax is INSERT OR REPLACE INTO <table> (<columns>) VALUES (<values>), as can be seen in the documentation.

In your case, it would be something like this:

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

这篇关于Android的SQLite的更新/插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆