简体   繁体   English

Android 更新 SQLite 表项

[英]Android update SQLite table entry

I have a local SQLite Database in may App.我在 May App 中有一个本地 SQLite 数据库。 I create and open the Database like this:我像这样创建并打开数据库:

CookieClickerBase = getBaseContext().openOrCreateDatabase(CookieBase, MODE_PRIVATE, null);
CookieClickerBase.execSQL("CREATE TABLE IF NOT EXISTS cookiedata(what TEXT, data LONG)");

I insert some thin into the table link this:我在表格链接中插入了一些细线:

CookieClickerBase.execSQL("INSERT INTO cookiedata VALUES ('Image','3')");

But now I wont to change the data from 3 to 9 in the table entry, where what = Image.但现在我不会将表条目中的数据从 3 更改为 9,其中 what = Image. How can I do that?我怎样才能做到这一点?

THANKS!谢谢!

You could use an UPDATE statement with execSQL() :您可以将UPDATE语句与execSQL()一起使用:

CookieClickerBase.execSQL("UPDATE cookiedata SET data = 9 WHERE what ='Image'");

or use the recommended method which is update() with ContentValues :或使用推荐的方法,即update()ContentValues

ContentValues cv = new ContentValues();
cv.put("data", "9");
int rows = CookieClickerBase.update("cookiedata", cv, "what = ?", new String[] {"Image"});

The variable rows will contain the number of updated rows.变量rows将包含更新的行数。

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

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