Android的:如何找到SQLITE_MAX_COMPOUND_SELECT [英] Android: how to find SQLITE_MAX_COMPOUND_SELECT
问题描述
有没有办法让 SQLITE_MAX_COMPOUND_SELECT
Android上的SQLite数据库的?在C sqlite3的API,这是 sqlite3_limit(DB,SQLITE_LIMIT_COMPOUND_SELECT,-1)
,但我没有看到这个接口的的 Android的SQLite的API 。
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.
这样做的原因是,我插入数千行,并发出一个批次INSERT语句是比许多单行插入更快,甚至当它包裹在一个交易。但是,可以为每个语句插入的行的最大数量是由 SQLITE_MAX_COMPOUND_SELECT
的限制,迫使其拆分成几个批次。而且,由于显而易见的原因,我宁愿不硬code 500的默认限制。
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.
推荐答案
的 SQLITE_LIMIT_COMPOUND_SELECT
限制是不是prevent内存溢出的手段(如至少在Android系统),而只是一个全面的检查。
因此,这是极不可能的厂商会的降低的它从默认的,所以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.
此外,由于插入的记录在一个命令的数目越大,所述的增量的加速比将变得更小;例如,从5至50个记录打算的加速会比的去从50至500的加速比更大。
因此,仅仅使用50不应该伤害太大。
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.
加快重复执行的另一种方法是使用prepared陈述,与<一href=\"http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#compileStatement%28java.lang.String%29\"相对=nofollow> SQLiteDatabase.compileStatement
。
Another way to speed up repeated executions is to use prepared statements, with SQLiteDatabase.compileStatement
.
这篇关于Android的:如何找到SQLITE_MAX_COMPOUND_SELECT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!