我想在 SQLite 中做这个查询:
update table1 set col1 = (? || substr (col1, col2))
where table1.id in (select id from table2 where condition);
我不知道该怎么做。SQLiteDatabase.rawQuery 不起作用。我见过的所有其他 API 都不允许“set”部分中的表达式。如果我可以使用 SQLiteStatement,它会起作用。但是该构造函数仅在其包中可见,对我的代码不可见:(
理想情况下,我会做这样的事情:
String query =
"update Table1 set " +
" col1 = (? || substr (col1, col2)), " +
" col2 = ? " +
"where Table1.id in " +
" (select id from Table2 where col3 = ?)";
String[] args = new String[3];
args[0] = arg0;
args[1] = arg1;
args[2] = arg2;
SQLiteStatement statement = new SQLiteStatement (getDb(), query, args);
int rowsUpdated = 0;
try
{
rowsUpdated = statement.executeUpdateDelete();
} finally {
statement.close();
}
有任何想法吗?谢谢。