0

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();
}

何か案は?ありがとう。

4

1 に答える 1

1

通常、CRUD 操作を実行する場合は、SQLiteDatabase.execSQL().

SQLiteDatabase.rawQuery()通常、選択Cursorクエリに使用され、結果セットとともに を返します。

ドキュメントrawQuery()によると、理論的には機能するはずですが

提供された SQL を実行し、結果セットに対して Cursor を返します。

しかし、更新クエリでは機能しないと他の人が報告しているので、それについては完全にはわかりません.

于 2013-10-20T11:02:26.770 に答える