gpt4 book ai didi

android - ContentValues 将值作为 sql 条件

转载 作者:行者123 更新时间:2023-11-29 02:09:49 24 4
gpt4 key购买 nike

当我尝试将某些条件值放入 ContentValues 变量时,会插入为字符串。

contentValues = new ContentValues();
contentValues.put("DLM", "julianday('now', 'localtime')");

执行后

count = db.update(TABLE_NAME, contentValues, selection, selectionArgs);

字段已更新,但值不正确。我需要在字段中包含数字日期,而不是字符串。

另一个问题,如果我需要用计算值更新现有字段:

UPDATE tbl SET field=field*2

当我把值写成

contentValues.put("field", "field*2");

它已将值设置为字符串。我如何才能获得我真正需要的值(value)?

最佳答案

我认为您应该使用 execSQL 而不是 update() 方法允许您完全控制查询语法的方法。此外,您可以考虑 creating triggers 而不是计算查询中的字段.

关于android - ContentValues 将值作为 sql 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8119857/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com