Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB Locking issues #1

Open
jarofgreen opened this issue May 29, 2013 · 0 comments
Open

DB Locking issues #1

jarofgreen opened this issue May 29, 2013 · 0 comments

Comments

@jarofgreen
Copy link
Member

Have seen this error:

at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
11at android.database.sqlite.SQLiteDatabase.(SQLiteDatabase.java:2005)
12at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:905)
13at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:197)
14at uk.co.jarofgreen.cityoutdoors.Storage.getFeatures(Storage.java:148)
15at uk.co.jarofgreen.cityoutdoors.UI.BrowseMapActivity$MarkerTask.doInBackground(BrowseMapActivity.java:240)
16at uk.co.jarofgreen.cityoutdoors.UI.BrowseMapActivity$MarkerTask.doInBackground(BrowseMapActivity.java:1)

Reading up, there are several steps to look into:

try {} finally {} on all db helper calls to make sure close is called in case of exception.

Singleton Helper, only one?

Is a Synchronized Lock something to look into?

http://stackoverflow.com/questions/7657223/sqlite-exception-database-is-locked-issue

public class DbExp extends SQLiteOpenHelper{
    public static String Lock = "dblock";
    private static final String DATABASE_NAME = "db.db";
    private static final String TABLE_NAME = "table_name";

    public void delete(Context mContext){
        synchronized(Lock) {
            SQLiteDatabase db  = getWritableDatabase();
            db.delete(TABLE_NAME, null, null);
            db.close();
        }
    }

    public void insert(){
        synchronized(Lock) {
            SQLiteDatabase db  = getWritableDatabase();
            db.insert(TABLE_NAME, ..., ...);
            db.close();
        }
    }

}```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant