本文介绍了更改SQLite数据库版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我建的SQLite浏览器的数据库,并能正常工作。我发起了一个应用程序有prebuilt数据库,现在我想更多的表格和数据添加到数据库中。

I have a database that I built in SQLite browser, and it works fine. I launched an app with a prebuilt database and now I want to add more tables and data to that database.

我可以在应用程序启动SQLiteOpenHelper的onUpgrade方法。但问题是,它这样做,我每次使用助手。

I can get the app to launch the onUpgrade method of the SQLiteOpenHelper. But the problem is, it's doing that EVERY time I use the helper.

我把它定位于中,只有在应用程序启动,从我用来检索数据的助手,分离该升级命令,但这仍是一个问题。

I have it localized to, only on app launch, seperating the upgrade command from the helper I used to retrieve data, but this is still a problem.

我已经想通了,虽然,因为我已经使用了相同的数据库我的电脑(我正在编辑的那一个)以来第1版所以,当它写入新的数据库到SD卡上它显示的版本1被即使我应该是最多4个版本现在。

I have figured it out though, as I have been using the same database on my computer (the one that I'm editing) since version 1. So, whenever it writes the newer database onto the SD card it's showing version 1 even though I should be up to version 4 by now.

所以,我的问题是,我怎么能手动编辑原始数据库的数据库版本,这样,当它更新它不是在原来的版本号,在新的吗?

So, my question is, how can I manually edit the database version of the original database so that when it updates it isnt writing the old version number over the new one?

推荐答案

要手动更新的版本4执行下面的SQL语句:

To manually update the version to 4 you execute the following SQL statement:

PRAGMA user_version = 4

这篇关于更改SQLite数据库版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 02:59