0

Hi I need advice on how to create the sqlite db for my app. You see, I have an app that connects to a server db in php/mysql platform. I need my android app to have an sqlite db that is a minimal version of the server db particularly only data that are relevant to the type of user using the app.

Some things I've considered:

  1. Attach a pre-populated sqlite db to the APK. This one would certainly make the APK package big.
  2. Create the sqlite db upon first time use of the app, connect to the server and extract necessary data to populate the sqlite db. I'm not sure how to do this as I usually use json to exctract data from server. This might also take so much time as each record will be inserted to the sqlite tables.
  3. I was thinking of requesting the server to create a pre-populated sqlite db based on the latest set of data it has. Then the app would then download this generated sqlite db and transfer it to my android app.

Any thoughts on this would be much appreciated. If you have other suggestions, please let me know.

4

1 回答 1

1

如果我是你,我会选择选项 3:让服务器准备 SQLite db 并使用 zip 或 gzip 或类似的东西对其进行压缩。根据您的数据,SQLite 数据库应该从原始大小压缩 2x-5x。

然后您的 apk 将连接到服务器,下载压缩的 SQLite db,将其解压缩到应用程序主目录(或 SD 卡,如果您有权限并希望这样做)。

从此时起,您只需从您的应用程序连接到此数据库。如果要下载更新,最好不要重新下载整个数据库,而是实施增量更新。如果服务器足够智能,它可以提供另一个较小的 SQLite 数据库,只提供增量更新(也压缩)。或者,它可以提供文本 SQL 脚本(同样是压缩的),通过执​​行它可以获得必要的更新(以及可能的模式更改)。

于 2013-02-08T05:31:15.997 回答