sqlite:下载数据库
我是新的 Android 开发人员,首先感谢所有每天对我有帮助的答案。 我的问题是: 我想使用 sqlite 来拥有一个包含数千行的数据库,但是插入每行平均需要一秒:太慢了; 我的数据库必须每天更新,所以我想压缩这个数据库,下载到一个文件夹中 我的应用程序(资产或原始数据)。 Android sdk允许这样做吗?我查看了很多答案,但一无所获。 谢谢大家。 (原谅我的英语)
I'm new android developer, first thank's for all the answers which helps me every day.
My question is:
I'm want to use a sqlite to have a db with many thousand rows but inserting this takes in average one second per line : it's too slow;
my db must be updated every day so I want to zip this db, downloading in a folder
of my application(assets ou raws).
Android sdk allows this? I look in many answers but i found nothing.
Thank's for all.
(excuse my English)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决您的问题的方法是使用事务。您对 SQLite 说
“BEGIN TRANSACTION”
,然后运行所有INSERT
,然后说“COMMIT TRANSACTION”
。这要快得多,因为除非已经启动了事务,否则 SQLite 会在单独的事务(所谓的自动提交)中运行每个查询,并且在内部为每个INSERT
执行"COMMIT TRANSACTION"
非常耗时慢的。The solution to your problem is to use transactions. You say
"BEGIN TRANSACTION"
to SQLite, then run all yourINSERT
s, then say"COMMIT TRANSACTION"
. This is much faster because unless there's started transaction already SQLite runs every query inside a separate transaction (so-called autocommit) and doing"COMMIT TRANSACTION"
internall for eachINSERT
is very slow.不知道android部分,但是插入花费1秒是不正常的。如果要插入大量行,请在事务中执行。
这将比一次只执行一个插入快得多。
No idea about the android part, but inserts taking 1s is abnormal. If you're going to insert a large number of rows, do it in a transaction.
This will be much faster than just doing the inserts one at a time.