增加的android / SQLite数据库记录的值 [英] Increase the value of a record in android/sqlite database

查看:85
本文介绍了增加的android / SQLite数据库记录的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着在我的表增加一列整数键的值。然而,没有什么似乎发生。

I try to increase the value of an integer key in a row in my table. However, nothing really seems to happen.

db.rawQuery("UPDATE table SET key = key + 1 WHERE name=?", new String[] {name});

然而,这code正常工作(只是设置的关键硬codeD值):

However, this code works fine (just sets the key to a hard-coded value):

    ContentValues values = new ContentValues();
    values.put("key", 2);
    db.update("table", values, "name=?", new String[] {name});

也试过'?而不是只?,但它只是导致在运行时错误。

Also tried '?' instead of just ?, but it resulted just in a run-time error.

推荐答案

从的http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html:

公开光标rawQuery(SQL字符串,字符串[] selectionArgs两个)

public Cursor rawQuery (String sql, String[] selectionArgs)

运行提供的SQL和返回游标在结果集。返回一个光标对象,它位于第一条目之前

Runs the provided SQL and returns a Cursor over the result set. Returns a Cursor object, which is positioned before the first entry

公共无效execSQL(SQL字符串,对象[] bindArgs)

public void execSQL (String sql, Object[] bindArgs)

执行一个SQL语句不是一个查询。例如, CREATE TABLE 删除插入

Execute a single SQL statement that is not a query. For example, CREATE TABLE, DELETE, INSERT, etc.

在换句话说,SQL查询这些数据将与 rawQuery 运行返回表,而那些不回表要与 execSQL 。

In other words, SQL queries which return a table are to be run with rawQuery, and those that do not return tables are to be run with execSQL.

这篇关于增加的android / SQLite数据库记录的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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