In my app, I have a sqlite database for collectibles. The DB is pre-populated, but the user adds data to indicate he owns that particular item. The collectibles are structured in categories, each having its own table.
So in the first version of the app, I have the 2011 baseball players, identified by a number and a name. I have all the 2009 to 2011 cards in a database (with a table for each year) which is situated in the assets folder and imported via InputStream. So far everything works great, and the user can add a flag saying he owns a card.
My problem is now I want to add the 2012 cards, so I added those as an additional table in my assets database for version 2 of the app. What I can't get to work is adding the new (pre-populated) table to the existing database on upgrade, without losing the flags the user set.
Obviously I don't want to lose the data users have already entered, so no DROP table.
I tried to get the new table onUpgrade by attaching the updated database and copying the missing table. Unfortunately, it seems I can't ATTACH a table during a transaction, as showed by the error I get:
Failure 1 (cannot ATTACH database within transaction) on 0x2a1900 when executing 'ATTACH DATABASE '/data/data/my.app/databases/updateddb' as myNewDb'
Am I missing something, is there a workaround? Or am I going about this the wrong way?