Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
296 views
in Technique[技术] by (71.8m points)

android - Change SQLite Database Version Number

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

PRAGMA user_version = 4

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...