Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid onUpgrade() fails because database is locked, what should I do differently?
    primarykey
    data
    text
    <p>I have a project with a set of classes that are responsible for their respective database tables.</p> <p>Each table managing class contains CRUD methods that follow the pattern of get connection, run crud operation, close connection:</p> <pre><code>public class PersonManager { SQLiteDatabase db; DbAdapter dbAdapter; //This is a subclass of SQLiteOpenHelper public void addPerson(Person person) { ContentValues contentValues = new ContentValues(); contentValues.put("email", person.email); contentValues.put("first_name", person.firstName); db = dbAdapter.getWritableDatabase(); db.insert("person", null, contentValues); db.close(); } ...other crud/utility methods omitted... } </code></pre> <p>Now that I am upgrading my database via onUpgrade(), I run into database locked issues.</p> <p>The exact error message follows:</p> <pre><code>CREATE TABLE android_metadata failed Failed to setLocale() when constructing, closing the database android.database.sqlite.SQLiteException: database is locked </code></pre> <p>It appears that onUpgrade is either meant to:</p> <pre><code>1 run db.execSQL() calls or 2 use helper classes that use onUpgrade()'s SQLiteDatabase rather than their own </code></pre> <p>It would be much easier to use my table managing classes to migrate data in onUpgrade() than db.execSQL() statements, or rewrite all my CRUD methods to take onUpgrade()'s SQLiteDatabase.</p> <p>Am I setting up my database access correctly? If the above code follows the correct pattern, what should I do to fix this issue?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload