@@ -1025,7 +1025,9 @@ public static SQLiteDatabase openDatabase(String path, char[] password, CursorFa
1025
1025
1026
1026
try {
1027
1027
// Open the database.
1028
- sqliteDatabase = new SQLiteDatabase (path , password , factory , flags , hook );
1028
+ sqliteDatabase = new SQLiteDatabase (path , factory , flags );
1029
+ sqliteDatabase .openDatabaseInternal (password , hook );
1030
+
1029
1031
if (SQLiteDebug .DEBUG_SQL_STATEMENTS ) {
1030
1032
sqliteDatabase .enableSqlTracing (path );
1031
1033
}
@@ -1037,11 +1039,16 @@ public static SQLiteDatabase openDatabase(String path, char[] password, CursorFa
1037
1039
// TODO: should we do this for other open failures?
1038
1040
Log .e (TAG , "Deleting and re-creating corrupt database " + path , e );
1039
1041
// EventLog.writeEvent(EVENT_DB_CORRUPT, path);
1042
+
1040
1043
if (!path .equalsIgnoreCase (":memory" )) {
1041
1044
// delete is only for non-memory database files
1042
1045
new File (path ).delete ();
1043
1046
}
1044
- sqliteDatabase = new SQLiteDatabase (path , password , factory , flags , hook );
1047
+
1048
+ sqliteDatabase = new SQLiteDatabase (path , factory , flags );
1049
+
1050
+ // NOTE: this may throw an exception, which is sent directly to the caller:
1051
+ sqliteDatabase .openDatabaseInternal (password , hook );
1045
1052
}
1046
1053
1047
1054
synchronized (sActiveDatabases ) {
@@ -2160,7 +2167,8 @@ protected void finalize() {
2160
2167
* @throws IllegalArgumentException if the database path is null
2161
2168
*/
2162
2169
public SQLiteDatabase (String path , char [] password , CursorFactory factory , int flags ) {
2163
- this (path , password , factory , flags , null );
2170
+ this (path , factory , flags );
2171
+ this .openDatabaseInternal (password , null );
2164
2172
}
2165
2173
2166
2174
/**
@@ -2180,19 +2188,37 @@ public SQLiteDatabase(String path, char[] password, CursorFactory factory, int f
2180
2188
* @throws IllegalArgumentException if the database path is null
2181
2189
*/
2182
2190
public SQLiteDatabase (String path , char [] password , CursorFactory factory , int flags , SQLiteDatabaseHook databaseHook ) {
2191
+ this (path , factory , flags );
2192
+ this .openDatabaseInternal (password , databaseHook );
2193
+ }
2183
2194
2195
+ /**
2196
+ * Private constructor (without database password) which DOES NOT attempt to open the database.
2197
+ *
2198
+ * @param path The full path to the database
2199
+ * @param factory The factory to use when creating cursors, may be NULL.
2200
+ * @param flags to control database access mode and other options
2201
+ *
2202
+ * @throws IllegalArgumentException if the database path is null
2203
+ */
2204
+ private SQLiteDatabase (String path , CursorFactory factory , int flags ) {
2184
2205
if (path == null ) {
2185
2206
throw new IllegalArgumentException ("path should not be null" );
2186
2207
}
2208
+
2187
2209
mFlags = flags ;
2188
2210
mPath = path ;
2211
+
2189
2212
mSlowQueryThreshold = -1 ;//SystemProperties.getInt(LOG_SLOW_QUERIES_PROPERTY, -1);
2190
2213
mStackTrace = new DatabaseObjectNotClosedException ().fillInStackTrace ();
2191
2214
mFactory = factory ;
2192
2215
mPrograms = new WeakHashMap <SQLiteClosable ,Object >();
2216
+ }
2217
+
2218
+ private void openDatabaseInternal (char [] password , SQLiteDatabaseHook databaseHook ) {
2193
2219
dbopen (mPath , mFlags );
2194
2220
2195
- if (databaseHook != null ){
2221
+ if (databaseHook != null ) {
2196
2222
databaseHook .preKey (this );
2197
2223
}
2198
2224
0 commit comments