Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用queryWithFactory绑定空参数_Android_Sql - Fatal编程技术网

Android 使用queryWithFactory绑定空参数

Android 使用queryWithFactory绑定空参数,android,sql,Android,Sql,我正在编写一个需要写入SQLite数据库的Android应用程序。目前,它正在使用rawquerywhithstring来构建更新查询,而我正在查询中使用?占位符并结合selectionArgs参数来传递实际值 但是,有时我确实想将我的列(类型为Date)更新为NULL,但如果我在我的selectionArgs中传入NULL,则会出现以下错误: IllegalArgumentException: the bind value at index 1 is null 当值实际为空时,我真的看不出应

我正在编写一个需要写入SQLite数据库的Android应用程序。目前,它正在使用
rawquerywhithstring
来构建更新查询,而我正在查询中使用
占位符并结合
selectionArgs
参数来传递实际值

但是,有时我确实想将我的列(类型为
Date
)更新为
NULL
,但如果我在我的
selectionArgs
中传入
NULL
,则会出现以下错误:

IllegalArgumentException: the bind value at index 1 is null
当值实际为空时,我真的看不出应该如何使它工作。我想我可以传入一个空字符串,在像这样的
Date
列的情况下,这可能会起作用,但是假设它是一个字符串列,我确实想表示
NULL
,而不是空字符串(或者它们在SQLite中被认为是等效的?)

代码如下:

String timestampStr = null; // Obviously not really set like this
SQLiteDatabase d = getWritableDatabase();
DBCursor c = (DBCursor) d.rawQueryWithFactory(
        new DBCursor.Factory(),
        "Update subject set schedulingTimestamp = ? where identifier = ?",
        new String[] { timestampStr, subjId.toString() },
        null);
d.close();
该列是使用以下查询添加的,因此我假定它是可为null的列,因为我没有另外指定:

ALTER TABLE subject ADD schedulingTimestamp DATE;

通配符不用于在SQL、AFAIK中插入/更新值。在Android中,您可以将
ContentValues
update()
方法结合使用,而不是试图将其固定在原始查询方法中。

我假设您的列可以为空……谢谢,添加了一条注释以澄清