diff options
| author | Fyodor Kupolov <fkupolov@google.com> | 2017-08-08 16:46:24 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-08-08 16:46:24 +0000 |
| commit | 3102245b62081783015330e8dfabbd9fa97609c1 (patch) | |
| tree | cc8247e7e864e184e3a4ee7d196991b4af57dd14 /core/java/android | |
| parent | eebd8779046334baae3caf59c6db8f5b51f0a31d (diff) | |
| parent | 76436c04a42892d49be7a9df6893b4f2880d490e (diff) | |
Merge "API Review update for SQLiteDatabase" into oc-mr1-dev
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/database/sqlite/SQLiteDatabase.java | 19 | ||||
| -rw-r--r-- | core/java/android/database/sqlite/SQLiteOpenHelper.java | 8 |
2 files changed, 18 insertions, 9 deletions
diff --git a/core/java/android/database/sqlite/SQLiteDatabase.java b/core/java/android/database/sqlite/SQLiteDatabase.java index 5b6efd4dcffe..de02ee51ac3a 100644 --- a/core/java/android/database/sqlite/SQLiteDatabase.java +++ b/core/java/android/database/sqlite/SQLiteDatabase.java @@ -703,12 +703,19 @@ public final class SQLiteDatabase extends SQLiteClosable { /** * Open the database according to the specified {@link OpenParams parameters} * - * @param path to database file to open and/or create + * @param path path to database file to open and/or create. + * <p><strong>Important:</strong> The file should be constructed either from an absolute path or + * by using {@link android.content.Context#getDatabasePath(String)}. * @param openParams configuration parameters that are used for opening {@link SQLiteDatabase} * @return the newly opened database * @throws SQLiteException if the database cannot be opened */ - public static SQLiteDatabase openDatabase(@NonNull String path, + public static SQLiteDatabase openDatabase(@NonNull File path, + @NonNull OpenParams openParams) { + return openDatabase(path.getPath(), openParams); + } + + private static SQLiteDatabase openDatabase(@NonNull String path, @NonNull OpenParams openParams) { Preconditions.checkArgument(openParams != null, "OpenParams cannot be null"); SQLiteDatabase db = new SQLiteDatabase(path, openParams.mOpenFlags, @@ -873,7 +880,8 @@ public final class SQLiteDatabase extends SQLiteClosable { * * @param factory an optional factory class that is called to instantiate a * cursor when query is called - * @return a SQLiteDatabase object, or null if the database can't be created + * @return a SQLiteDatabase instance + * @throws SQLiteException if the database cannot be created */ @NonNull public static SQLiteDatabase create(@Nullable CursorFactory factory) { @@ -889,7 +897,8 @@ public final class SQLiteDatabase extends SQLiteClosable { * <p>Sets the locale of the database to the the system's current locale. * Call {@link #setLocale} if you would like something else.</p> * @param openParams configuration parameters that are used for opening SQLiteDatabase - * @return a SQLiteDatabase object, or null if the database can't be created + * @return a SQLiteDatabase instance + * @throws SQLException if the database cannot be created */ @NonNull public static SQLiteDatabase createInMemory(@NonNull OpenParams openParams) { @@ -2322,7 +2331,7 @@ public final class SQLiteDatabase extends SQLiteClosable { } /** - * Returns flags to control database access mode + * Returns flags to control database access mode. Default value is 0. * * @see Builder#setOpenFlags(int) */ diff --git a/core/java/android/database/sqlite/SQLiteOpenHelper.java b/core/java/android/database/sqlite/SQLiteOpenHelper.java index dfaf714963eb..cc9e0f4ded84 100644 --- a/core/java/android/database/sqlite/SQLiteOpenHelper.java +++ b/core/java/android/database/sqlite/SQLiteOpenHelper.java @@ -289,12 +289,12 @@ public abstract class SQLiteOpenHelper { } else if (mName == null) { db = SQLiteDatabase.createInMemory(mOpenParamsBuilder.build()); } else { - final String path = mContext.getDatabasePath(mName).getPath(); + final File filePath = mContext.getDatabasePath(mName); SQLiteDatabase.OpenParams params = mOpenParamsBuilder.build(); try { - db = SQLiteDatabase.openDatabase(path, params); + db = SQLiteDatabase.openDatabase(filePath, params); // Keep pre-O-MR1 behavior by resetting file permissions to 660 - setFilePermissionsForDb(path); + setFilePermissionsForDb(filePath.getPath()); } catch (SQLException ex) { if (writable) { throw ex; @@ -302,7 +302,7 @@ public abstract class SQLiteOpenHelper { Log.e(TAG, "Couldn't open " + mName + " for writing (will try read-only):", ex); params = params.toBuilder().addOpenFlags(SQLiteDatabase.OPEN_READONLY).build(); - db = SQLiteDatabase.openDatabase(path, params); + db = SQLiteDatabase.openDatabase(filePath, params); } } |
