3

I have a published app with several tables in its database. I want to add a new column to one of the tables and then populate it based on entries from another table. Basically, I'll need to:

1) Add the new column with ALTER TABLE

2) Query another table to find the correct values

3) Update every row in the new column with the values found in step 2

Obviously, I do this in onUpgrade(). But do I do it asynchronously (like with an AsyncTask)? I'm just worried about other changes to the database occurring while the asynchronous tasks in onUpgrade() are still running. My guess is the database would be locked during this operation, but I'm not sure.

Gavin Wright
  • 3,124
  • 3
  • 14
  • 35
  • 1
    onUpgrade() will be called when you first get the database reference through a getReadable/WritableDatabase() call. So you can't really make other calls while onUpgrade() runs because you'll not have the database reference yet. If onUpgrade() takes some time, all you'll end up is with an initial delay before you can actually access the database in your app. – user Apr 17 '19 at 10:10

0 Answers0