Skip to content

Commit 530b058

Browse files
Allow SQLiteOpenHelper to accept a SQLiteDatabaseHook
1 parent 2e8b53f commit 530b058

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/net/sqlcipher/database/SQLiteOpenHelper.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.File;
2020

2121
import android.content.Context;
22+
import net.sqlcipher.database.SQLiteDatabaseHook;
2223
import net.sqlcipher.database.SQLiteDatabase.CursorFactory;
2324
import android.util.Log;
2425

@@ -38,10 +39,11 @@ public abstract class SQLiteOpenHelper {
3839
private final String mName;
3940
private final CursorFactory mFactory;
4041
private final int mNewVersion;
42+
private final SQLiteDatabaseHook mHook;
4143

4244
private SQLiteDatabase mDatabase = null;
4345
private boolean mIsInitializing = false;
44-
46+
4547
/**
4648
* Create a helper object to create, open, and/or manage a database.
4749
* The database is not actually created or opened until one of
@@ -54,12 +56,30 @@ public abstract class SQLiteOpenHelper {
5456
* {@link #onUpgrade} will be used to upgrade the database
5557
*/
5658
public SQLiteOpenHelper(Context context, String name, CursorFactory factory, int version) {
59+
this(context, name, factory, version, null);
60+
}
61+
62+
/**
63+
* Create a helper object to create, open, and/or manage a database.
64+
* The database is not actually created or opened until one of
65+
* {@link #getWritableDatabase} or {@link #getReadableDatabase} is called.
66+
*
67+
* @param context to use to open or create the database
68+
* @param name of the database file, or null for an in-memory database
69+
* @param factory to use for creating cursor objects, or null for the default
70+
* @param version number of the database (starting at 1); if the database is older,
71+
* {@link #onUpgrade} will be used to upgrade the database
72+
* @param hook to run on pre/post key events
73+
*/
74+
public SQLiteOpenHelper(Context context, String name, CursorFactory factory,
75+
int version, SQLiteDatabaseHook hook) {
5776
if (version < 1) throw new IllegalArgumentException("Version must be >= 1, was " + version);
5877

5978
mContext = context;
6079
mName = name;
6180
mFactory = factory;
6281
mNewVersion = version;
82+
mHook = hook;
6383
}
6484

6585
/**
@@ -104,12 +124,7 @@ public synchronized SQLiteDatabase getWritableDatabase(String password) {
104124
if (!dbPathFile.exists())
105125
dbPathFile.getParentFile().mkdirs();
106126

107-
db = SQLiteDatabase.openOrCreateDatabase(path, password, mFactory);
108-
109-
// db = SQLiteDatabase.openDatabase(path,mFactory , SQLiteDatabase.OPEN_READWRITE);
110-
111-
//db = mContext.openOrCreateDatabase(mName, 0, mFactory);
112-
127+
db = SQLiteDatabase.openOrCreateDatabase(path, password, mFactory, mHook);
113128
}
114129

115130

0 commit comments

Comments
 (0)