Androidデータベースの挿入速度を改善しようとしています。私が現在行っているのは、次のような文字列を生成することです。
SELECT ? as title, ? as musician_id, ? as album_id, ? as genre
UNION SELECT ?, ?, ?, ?
UNION SELECT ?, ?, ?, ?
UNION SELECT ?, ?, ?, ?
UNION SELECT ?, ?, ?, ?
UNION SELECT ?, ?, ?, ?
そしてそれを実行します
SQLiteDatabase database = //initialized in some way
String insertQuery; // the string of the query above
String [] parameters; // the parameters to use in the insertion.
database.execSQL(insertQuery.toString(), parameters);
約2000行を挿入しようとすると、次のエラーが発生します。
Caused by: android.database.sqlite.SQLiteException: too many SQL variables (code 1): , while compiling: INSERT INTO songs (title, musician_id, album_id, genre)
SELECT ? as title, ? as musician_id, ? as album_id, ? as genre
UNION SELECT ?, ?, ?, ?
UNION SELECT ?, ?, ?, ?
約200行を挿入しようとすると、すべてが正常に機能します。
当たり前のことだと思います。1つの変数に渡そうとしている変数が多すぎますexecSQL
。挿入した行を適切なバッチに分割できるようにするための制限を知っている人はいますか?