Change SQLite Database Version Number

笑着哭i 提交于 2019-11-27 12:44:35

问题


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.

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, separating the upgrade command from the helper I used to retrieve data, but this is still a problem.

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 isn't writing the old version number over the new one?


回答1:


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

PRAGMA user_version = 4



回答2:


You can also set it via the setVersion SqlLiteDatabase method.

Source: http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#setVersion(int)




回答3:


Another way to change the version of your Sqlite Database. You can use DB Browser for SQLite:

  1. Open the database file with "DB Browser for SQLite".
  2. Change the "User Version" number to whatever number you want
  3. Click the "Save" button



来源:https://stackoverflow.com/questions/8030779/change-sqlite-database-version-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!