> Let's say in version 1 of my app, I've got a X, with a column Y, that
> lists integers:
>
> Y
> 1
> 2
> 3
> 4
> 5....
>
> The database version is also 1. Users can add or remove from Y as they
> see fit (through the app).
>
> Now, in the next version of my program--2--suppose I changed my mind,
> and now I want Y to only contain roman numerals:
>
> Y
> I
> II
> III
> IV
> V...
>
> Again, users can add or remove rows from Y as they want.
>
> The problem, however, is that the version 1 information is still
> there. As a user inserts information, the database becomes a mix of
> old and new formats:
>
> Y
> 1
> 2
> 3
> 4
> 5
> VI
> VII
> VIII
>
> Am I totally screwed here? What I'm looking for, basically, is an
> upgrade script to run over the database, on the next install--but only
> if a prior install already exists. Users of version 2 won't need
> anything done, as their program is already set for the new version. Is
> it optimal to copy the database, change its version, and reinsert the
> rows, applying an algorithm on the column?

Use SQLiteOpenHelper. In onUpgrade(), you copy the existing table data to
a temp table, drop and recreate your existing table with the new type, and
then insert into the new table the old data from the temp table, with some
suitable bit of conversion logic.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
Android App Developer Books: http://commonsware.com/books.html


-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to