如何填充在第一次运行一个大型SQLite数据库数据库、SQLite

2023-09-05 09:54:38 作者:深海映星辰

我基于与超过300,000行SQLite数据库上一本字典应用程序正在正常工作。

I'm working on a dictionary app based on an SQLite database with well over 300,000 rows.

现在的问题是,在其最终形式的数据库文件包含全文索引的表和过重以及 150MB

The problem is that the database file in its final form consists of full-text indexed tables and weighs well over 150Mb.

我已经设法通过创建无内容FTS4表带上.db文件大小为最小。 数据库不能有任何小的。我也设法把pre-填充数据库中的应用程序,它工作正常。

I've managed to bring the .db file size to a minimum by creating a contentless fts4 tables. The database cannot be any smaller. I also managed to put the pre-populated database in the app and it works fine.

现在的问题是,我不能只是保持/资产最终.db文件,并将其复制到SD卡上的第一次运行,因为它太大了。我也不想将其下载在首次运行。

The problem is that I can't just keep the final .db file in /assets and copy it to sdcard on first run because it's too big. I also don't want to download it on first run.

散装插入荷兰国际集团的数据,即使在启动交易和SQLite优化,没有索引需要的永远所以它也不是一种选择。

Bulk INSERTing the data, even with transactions and sqlite optimized and no indexes at start takes forever so it's also not an option.

好事是用来建立数据库的原始数据,以CSV格式和COM pressed,是 30MB 和SQLite的命令行 .IMPORT 选项是非常快的(100,000行〜1秒),但...它不能从应用程序访问没有root权限。

The good thing is the raw data used to build the database, in CSV format and compressed, is 30Mb and sqlite's command line .import option is very fast (100,000 rows in ~1s) but... it can't be accessed from the app without root permissions.

我很想捆绑在/资产COM pressed CSV文件的应用程序,DECOM preSS它们,创建SD卡的数据库,然后导入CSV但的似乎的到我是不可能的。虽然有出现很多的字典应用程序是这样做正是这一点。 (下载的应用程序是一个几十兆,建立数据库第一次运行,并采取数百个百兆空间的SD卡)。

I would love to bundle the app with compressed CSV files in /assets, decompress them, create the database on sdcard and then import the CSV but that seems to me to be impossible. Although there are many dictionary apps that appear to be doing exactly this. (The downloaded app is a dozen megabytes, builds database on first run, and takes hundreds of megabytes of space on the sdcard).

我如何做到这一点?

我一直对这个过去的两个星期,只是跑出来的想法。我是新的Andr​​oid开发,因此任何帮助将非常AP preciated。

I've been working on this for past two weeks and simply ran out of ideas. I'm new to Android development so any help would be much appreciated.

推荐答案

计划A:安装后发布一个COM pressed SQLite数据库文件和DECOM preSS它;你应该能够省略指数,后来重建它们。 B计划:在CSV进口商的相关部分复制到你的应用程序,发运COM pressed CSV文件,并将其载入类的命令行工具将一个空数据库。 官方文档页面。