8000 Lazily create database when not present during request for getReadabl… · Sjith/android-database-sqlcipher@95096e4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 95096e4

Browse files
Lazily create database when not present during request for getReadableDatabase.
1 parent 1441907 commit 95096e4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/net/sqlcipher/database/SQLiteOpenHelper.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,18 @@ public synchronized SQLiteDatabase getReadableDatabase(String password) {
173173
try {
174174
mIsInitializing = true;
175175
String path = mContext.getDatabasePath(mName).getPath();
176+
File databasePath = new File(path);
177+
File databasesDirectory = new File(mContext.getDatabasePath(mName).getParent());
178+
179+
if(!databasesDirectory.exists()){
180+
databasesDirectory.mkdirs();
181+
}
182+
if(!databasePath.exists()){
183+
mIsInitializing = false;
184+
db = getWritableDatabase(password);
185+
mIsInitializing = true;
186+
db.close();
187+
}
176188
db = SQLiteDatabase.openDatabase(path, password, mFactory, SQLiteDatabase.OPEN_READONLY);
177189
if (db.getVersion() != mNewVersion) {
178190
throw new SQLiteException("Can't upgrade read-only database from version " +

0 commit comments

Comments
 (0)
0