Is there a way to get the value of SQLITE_MAX_COMPOUND_SELECT of a SQLite database on Android? In the C sqlite3 API, this is sqlite3_limit(db, SQLITE_LIMIT_COMPOUND_SELECT, -1), but I don't see this interface exposed in the Android SQLite API.
The reason for this is that I'm inserting thousands of rows, and issuing a batch INSERT statement is faster than many single-row inserts, even when it's wrapped in a transaction. But the max number of rows that can be inserted per statement is limited by SQLITE_MAX_COMPOUND_SELECT, necessitating splitting it into several batches. And, for obvious reasons, I'd rather not hardcode the default limit of 500.
The SQLITE_LIMIT_COMPOUND_SELECT limit is not a means to prevent memory overflow (as least on Android systems), but just a sanity check.
Therefore, it is extremely unlikely that a vendor will reduce it from its default, so 500 should be safe.
Furthermore, as the number of inserted records in one command gets larger, the incremental speedup will get smaller; e.g., the speedup of going from 5 to 50 records will be larger than the speedup of going from 50 to 500. Therefore, just using 50 should not hurt too much.
Another way to speed up repeated executions is to use prepared statements, with SQLiteDatabase.compileStatement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With