SQLiteStatement执行SELECT /插入/删除/更新 [英] SQLiteStatement execute a SELECT / INSERT / DELETE / UPDATE
问题描述
我使用的是编译 SQLiteStatement
与优化SQLite的交易事务,但我读的文档<一href="http://developer.android.com/reference/android/database/sqlite/SQLiteStatement.html#execute%28%29"><$c$c>execute$c$c>功能:
I'm using a compiled SQLiteStatement
with transactions in optimizing SQLite transactions but I'm reading the documentation for the execute
function:
执行这条SQL语句,,如果它不是一个SELECT /插入/删除/更新的,例如CREATE / DROP表,视图,触发器,索引等。
Execute this SQL statement, if it is not a SELECT / INSERT / DELETE / UPDATE, for example CREATE / DROP table, view, trigger, index etc.
这似乎在暗示,这个功能不应该与 SELECT /插入/删除/更新
语句中使用,但我有一个使用它插入code和作品。
This seems to imply that this function should not be used with SELECT / INSERT / DELETE / UPDATE
statements, but I have code that uses it with an insert and works.
我知道 executeInsert
和其他方法,但 executeUpdateDelete
是不是在我的API级别可用,这样我就可以使用执行
?
I'm aware of executeInsert
and the other methods, but executeUpdateDelete
is not available in my API level, so can I use execute
?
另外,如果我不需要最后插入身份证或受影响我应该使用的行数执行
而不是 executeInsert
等,换句话说就是它更有效率?
Also if I don't need the last insert id or the number of rows affected should I use execute
instead of executeInsert
and etc., in other words is it more efficient?
推荐答案
执行
很可能并不比 executeInsert
更快,甚至可能会比较慢(在ICS <一href="https://github.com/android/platform_frameworks_base/blob/ics-mr1-release/core/java/android/database/sqlite/SQLiteStatement.java#L69"相对=nofollow> 执行
电话 executeUpdateDelete
并丢弃的返回值)。你需要测试,但我怀疑你会在这里找到真正的作用。
execute
is probably not faster than executeInsert
, could even be slower (on ICS execute
calls executeUpdateDelete
and discards the return value). You need to test that but I doubt you will find a real difference here.
AFAIK,它是安全的只使用执行
如果你不需要返回值,但我不会指望,持有真正的未来的Android版本。该文件说没有,所以也许有人会去改变,以反映这一点。旧的实现似乎使用执行
太(如<一个href="https://github.com/android/platform_frameworks_base/blob/eclair-release/core/java/android/database/sqlite/SQLiteDatabase.java#L1475"相对=nofollow> 2.1 删除()
源$ C $ C )。果冻豆例如改变<一href="https://github.com/android/platform_frameworks_base/blob/jb-release/core/java/android/database/sqlite/SQLiteSession.java"相对=nofollow>背后的SQLite的场景很多,但它应该使用时仍能正常工作执行
AFAIK, It is safe to use just execute
if you don't need return values but I would not count on that holding true in future Android versions. The documentation says no, so maybe someone is going to change the behavior to reflect that. Older implementations seem to use execute
too (e.g. 2.1 delete()
sourcecode). Jelly Bean for example changed a lot behind the scenes of SQLite, but it should still work when using execute
另外,如果你不 SQLiteStatement
一遍又一遍使用相同的,而刚刚重新绑定的args它可能不值得使用它。每次通话时间建设一个新的常规插入
,更新
,...方法是比较快的实际数据库访问和所需的磁盘I / O。在另一方面交易有很大的帮助,因为磁盘上的每个语句同步数据库状态实在是太慢了。
Besides, if you don't use the same SQLiteStatement
over and over again while just rebinding the args it's probably not worth using it. Building a new one each time you call the regular insert
, update
, ... methods is fast compared to the actual database access and the required disk I/O. Transactions on the other hand help a lot, since synchronizing database state on the disk for each statement is really slow.
这篇关于SQLiteStatement执行SELECT /插入/删除/更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!