android - 当 SqLite 中特定值的计数大于 1 时更新表

标签 android sqlite sql-update

我有一个表,我想在计数大于 1 时更新现有值。

这是我的代码:

  public int getCount(String clues) {
    Cursor c = null;
    try {
        db = this.getReadableDatabase();

        String query = "select count(*) from " + TABLE_NAME + "where CLUES_VALUES = ?";
        c = db.rawQuery(query, new String[] {clues});
        if (c.moveToFirst()) {
            return c.getInt(0);
        }
        return 0;
    }
    finally {
        if (c != null) {
            c.close();
        }
        if (db != null) {
            db.close();
        }
    }
}

我正在根据“CLUES_VALUES”列进行检查。我从数据库中获取值并检查它是否在 "CLUES_VALUES"列中包含多个相似值。如果它包含那么它将更新整行否则它不会。 当我执行代码时,出现以下错误

     android.database.sqlite.SQLiteException: near "=": syntax error (code 1): , while compiling: select count(*) from puzzl_tablewhere CLUES_VALUES = ?

Clues_values 列包含“字符串值” 我不知道我在哪里失踪。请帮忙。

最佳答案

你在“where”前面少了一个空格。

String query = "select count(*) from " + TABLE_NAME + " where CLUES_VALUES = ?";

关于android - 当 SqLite 中特定值的计数大于 1 时更新表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37019333/

相关文章:

python - 对 GROUP BY 查询进行排序

c# - Xamarin.iOS 上的 sqlite 中的缓慢 SELECT

mysql - 如果其他表中的数据不匹配,则更新表

java - 使用 eclipse 更改应用程序主题?

android - 视频录制到 Android 上的循环缓冲区

java - 执行末尾添加空格且不带空格的删除查询

mysql - SQL 获取、编辑和更新数据

sql-server-2008 - 如何处理SQL更新语句中的单引号和双引号

android - 限制发送可以向我的应用发送 ACTION_SEND Intent 的应用

android - "Theming Icons"功能崩溃 Android 12 上的动态壁纸