@@ -1025,7 +1025,9 @@ public static SQLiteDatabase openDatabase(String path, char[] password, CursorFa
10251025
10261026 try {
10271027 // 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+
10291031 if (SQLiteDebug .DEBUG_SQL_STATEMENTS ) {
10301032 sqliteDatabase .enableSqlTracing (path );
10311033 }
@@ -1037,11 +1039,16 @@ public static SQLiteDatabase openDatabase(String path, char[] password, CursorFa
10371039 // TODO: should we do this for other open failures?
10381040 Log .e (TAG , "Deleting and re-creating corrupt database " + path , e );
10391041 // EventLog.writeEvent(EVENT_DB_CORRUPT, path);
1042+
10401043 if (!path .equalsIgnoreCase (":memory" )) {
10411044 // delete is only for non-memory database files
10421045 new File (path ).delete ();
10431046 }
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 );
10451052 }
10461053
10471054 synchronized (sActiveDatabases ) {
@@ -2160,7 +2167,8 @@ protected void finalize() {
21602167 * @throws IllegalArgumentException if the database path is null
21612168 */
21622169 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 );
21642172 }
21652173
21662174 /**
@@ -2180,19 +2188,37 @@ public SQLiteDatabase(String path, char[] password, CursorFactory factory, int f
21802188 * @throws IllegalArgumentException if the database path is null
21812189 */
21822190 public SQLiteDatabase (String path , char [] password , CursorFactory factory , int flags , SQLiteDatabaseHook databaseHook ) {
2191+ this (path , factory , flags );
2192+ this .openDatabaseInternal (password , databaseHook );
2193+ }
21832194
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 ) {
21842205 if (path == null ) {
21852206 throw new IllegalArgumentException ("path should not be null" );
21862207 }
2208+
21872209 mFlags = flags ;
21882210 mPath = path ;
2211+
21892212 mSlowQueryThreshold = -1 ;//SystemProperties.getInt(LOG_SLOW_QUERIES_PROPERTY, -1);
21902213 mStackTrace = new DatabaseObjectNotClosedException ().fillInStackTrace ();
21912214 mFactory = factory ;
21922215 mPrograms = new WeakHashMap <SQLiteClosable ,Object >();
2216+ }
2217+
2218+ private void openDatabaseInternal (char [] password , SQLiteDatabaseHook databaseHook ) {
21932219 dbopen (mPath , mFlags );
21942220
2195- if (databaseHook != null ){
2221+ if (databaseHook != null ) {
21962222 databaseHook .preKey (this );
21972223 }
21982224
0 commit comments