Sto cercando di migliorare la velocità dei miei inserimenti nel database di Android. Quello che sto facendo attualmente è di generare una stringa del tipo:Qual è il limite delle variabili SQL che è possibile specificare in una singola query execSQL
SELECT ? as title, ? as musician_id, ? as album_id, ? as genre
UNION SELECT ?, ?, ?, ?
UNION SELECT ?, ?, ?, ?
UNION SELECT ?, ?, ?, ?
UNION SELECT ?, ?, ?, ?
UNION SELECT ?, ?, ?, ?
E poi eseguirla con
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);
sto ottenendo il seguente errore quando provo ad inserire circa 2000 righe:
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 ?, ?, ?, ?
Quando provo a inserire circa 200 righe, tutto funziona correttamente.
Suppongo che sia ovvio: sto tentando di inserire troppe variabili in un singolo execSQL
. Qualcuno sa qual è il limite in modo da poter dividere le righe che inserisco nei lotti appropriati?
si dovrebbe avere uno sguardo alla documentazione qui: http://www.sqlite.org/limits.html – ebarrenechea
@ebarrenchea Sono quasi certo il limite non è imposto da SQLite piuttosto dall'API SQLite Android. Hai trovato qualche indicazione del contrario? –
Si potrebbe avvicinarsi a questo con una ricerca binaria: 2000 non funziona, quindi prova 1000, poi 500 (o 1500) ... – Sam