Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.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
JDBC到android.sqlite:选择/删除…;其中字段在(?)_Android_Jdbc_Android Sqlite - Fatal编程技术网

JDBC到android.sqlite:选择/删除…;其中字段在(?)

JDBC到android.sqlite:选择/删除…;其中字段在(?),android,jdbc,android-sqlite,Android,Jdbc,Android Sqlite,我只是将一些JDBC代码(用于HSQLDB)移植到Android自己的SQLite实现中。我有一个代码片段,根据与Java代码中String[]数组中的一个值匹配的特定字段删除记录 以下是DELETE语句的JDBC代码: String[] ids = getIdsSomehow(); PreparedStatement stmtD = db.prepareStatement("delete from message where id in (unnest(?))"); Arr

我只是将一些JDBC代码(用于HSQLDB)移植到Android自己的SQLite实现中。我有一个代码片段,根据与Java代码中
String[]
数组中的一个值匹配的特定字段删除记录

以下是
DELETE
语句的JDBC代码:

String[] ids = getIdsSomehow();
PreparedStatement stmtD = db.prepareStatement("delete from message where id in (unnest(?))");
Array delIdArray = stmtD.getConnection().createArrayOf("VARCHAR", ids);
stmtD.setArray(1, delIdArray);
stmtD.execute();
stmtD.close();
另一个代码段执行
SELECT
而不是
DELETE
,并将值放在
列表中而不是数组中


我将如何使用
SQLiteDatabase
提供的方法来实现这一点,最好是不打开任何SQL注入漏洞?

通过JDBC使用HSQLDB实现这一点的主要“要素”,即DBMS的
unnest()
功能,以及将数组值传递给SQL语句的能力,android.sqlite
堆栈中不提供,因此需要解决以下问题:

String[] ids = getIdsSomehow();
String whereClause = "id in (" + TextUtils.join(",", Collections.nCopies(ids.size(), "?")) + ")";
db.delete("message", whereClause, ids);
这将在(?,,,?)中构建一个where子句a la
id,并带有正确数量的问号

对于选择,使用
rawQuery()
和以相同方式构建的
SELECT
语句。
列表
可以转换为如下数组:

ids.toArray(new String[]{})
输入来自及其评论