如何升级SQLite数据库文件 [英] How to upgrade sqlite database file

查看:141
本文介绍了如何升级SQLite数据库文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Im做一个应用程序,它使用的资产文件夹中的SQLite数据库文件,有一个在我的应用程序有一个按钮,检查更新屏幕。

Im doing an app which uses sqlite db file in assets folder, There is a screen in my app having a button 'check for update'.

客户端给了我一个网址链接更新数据库文件(该文件给出了一个源码文件)。

Client has given me an URL link to update db file(which gives a sqlite file).

当用户点击按钮,我需要升级旧的数据库文件与URL新的数据库文件。

When user clicks on the button i need to upgrade the old db file with new db file from URL.

请建议我怎么能做到这一点,或者给我一个参考跟着

Please suggest me how i can do this, or give me a reference to follow

感谢您

推荐答案

资产文件夹是只读的,所以你将无法更改或替换该副本。

The assets folder is read-only, so you won't be able to change or replace that copy.

基本上,你需要复制你的数据库文件出资产的文件夹到一个可写的应用程序目录(可能是从getFilesDir()或getExternalFilesDir())。你会打开,当你实际运行这个副本,你会用新的数据库,从网页的时候你的用户点击更新按钮取代它。因为SQLite数据库仅仅是一个文件,有一个与删除旧的和一个新的替换它没有问题。 (关闭旧的删除,当然,对于清洁之前。)

Basically, you need to copy your DB file out of the assets folder into a writable application directory (probably from getFilesDir() or getExternalFilesDir()). You'll open this copy when you are actually operating, and you'll replace it with the new DB from the web when your user hits the UPDATE button. Because a SQLite database is just a file, there's no problem with deleting the old one and replacing it with a new one. (Close the old one before deleting, of course, for cleanliness.)

这篇关于如何升级SQLite数据库文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆