Skip to content

Commit a0f258a

Browse files
committed
update docs
1 parent f4a37c7 commit a0f258a

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

README.markdown

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This class provides developers with a simple way to ship their Android app with
77

88
It is implemented as an extension to `SQLiteOpenHelper`, providing an efficient way for `ContentProvider` implementations to defer opening and upgrading the database until first use.
99

10-
Rather than implementing `onCreate()` and `onUpgrade()` methods to execute a bunch of SQL statements, developers simply include appropriately named file assets in their project's `assets` directory. These will include the initial SQLite database file for creation and optionally any SQL upgrade scripts.
10+
Rather than implementing the `onCreate()` and `onUpgrade()` methods to execute a bunch of SQL statements, developers simply include appropriately named file assets in their project's `assets` directory. These will include the initial SQLite database file for creation and optionally any SQL upgrade scripts.
1111

1212
Setup
1313
-----
@@ -45,19 +45,19 @@ public class MyDatabase extends SQLiteAssetHelper {
4545
}
4646
```
4747

48-
SQLiteAssetHelper relies upon asset file and folder naming conventions. At minimum, you must provide the following in your `assets` directory, which will either be in your project root directory or under `src/main` in the gradle project structure:
48+
SQLiteAssetHelper relies upon asset file and folder naming conventions. Your `assets` folder will either be under your project root, or under `src/main` if you are using the default gradle project structure. At minimum, you must provide the following:
4949

50-
* A `databases` subdirectory inside `assets`
51-
* A SQLite database inside the `databases` subdirectory whose file name matches the database name you provide in code (including the file extension, if any)
50+
* A `databases` folder inside `assets`
51+
* A SQLite database inside the `databases` folder whose file name matches the database name you provide in code (including the file extension, if any)
5252

53-
For the example above, ther project would contain the following:
53+
For the example above, the project would contain the following:
5454

55-
`src/main/assets/databases/northwind.db`
55+
assets/databases/northwind.db
5656

57-
Earlier versions of this library required the database asset to be compressed within a ZIP archive. This is no longer required, but is still supported. Applications still targeting Gingerbread or lower should continue to provide a compressed archive to ensure large database files are not corrupted during the packaging process. The more Linux friendly GZIP format is also supported. The naming conventions using the above example are as follows:
57+
Earlier versions of this library required the database asset to be compressed within a ZIP archive. This is no longer a requirement, but is still supported. Applications still targeting Gingerbread (API 10) or lower should continue to provide a compressed archive to ensure large database files are not corrupted during the packaging process. The more Linux friendly GZIP format is also supported. The naming conventions using the above example are as follows:
5858

59-
* ZIP: `src/main/assets/databases/northwind.db.zip` (a single SQLite database file must be the only file within the archive)
60-
* GZIP: `src/main/assets/databases/northwind.db.gz`
59+
* ZIP: `assets/databases/northwind.db.zip` (a single SQLite database file must be the only file within the archive)
60+
* GZIP: `assets/databases/northwind.db.gz`
6161

6262
The database will be extracted from the assets and copied into place within your application's private data directory. If you prefer to store the database file somewhere else (such as external storage) you can use the alternate constructor to specify a storage path. You must ensure that this path is available and writable whenever your application needs to access the database.
6363

@@ -67,6 +67,8 @@ The database is made available for use the first time either `getReadableDatabas
6767

6868
The class will throw a `SQLiteAssetHelperException` if you do not provide the appropriately named file.
6969

70+
The SQLiteOpenHelper methods `onConfigure`, `onCreate` and `onDowngrade` are not supported by this implementation and have been declared `final`.
71+
7072
The [samples:database-v1](https://github.com/jgilfelt/android-sqlite-asset-helper/tree/v2/samples/database-v1) project demonstrates a simple database creation and usage example using the classic Northwind database.
7173

7274
Database Upgrades
@@ -76,13 +78,15 @@ At a certain point in your application's lifecycle you will need to alter it's d
7678

7779
To facilitate a database upgrade, increment the version number that you pass to your `SQLiteAssetHelper` constructor:
7880

79-
private static final int DATABASE_VERSION = 2;
81+
```java
82+
private static final int DATABASE_VERSION = 2;
83+
```
8084

8185
Update the initial SQLite database in the project's `assets/databases` directory with the changes and create a text file containing all required SQL commands to upgrade the database from its previous version to it's current version and place it in the same folder. The required naming convention for this upgrade file is as follows:
8286

8387
assets/databases/<database_name>_upgrade_<from_version>-<to_version>.sql
8488

85-
For example, [northwind.db_upgrade_1-2.sql](https://github.com/jgilfelt/android-sqlite-asset-helper/blob/v2/samples/database-v2-upgrade/src/main/assets/databases/northwind.db_upgrade_1-2.sql) upgrades the database named "northwind" from version 1 to 2. You can include multiple upgrade files to upgrade between any two given versions.
89+
For example, [northwind.db_upgrade_1-2.sql](https://github.com/jgilfelt/android-sqlite-asset-helper/blob/v2/samples/database-v2-upgrade/src/main/assets/databases/northwind.db_upgrade_1-2.sql) upgrades the database named "northwind.db" from version 1 to 2. You can include multiple upgrade files to upgrade between any two given versions.
8690

8791
If there are no files to form an upgrade path from a previously installed version to the current one, the class will throw a `SQLiteAssetHelperException`.
8892

@@ -92,9 +96,13 @@ The [samples:database-v2-upgrade](https://github.com/jgilfelt/android-sqlite-ass
9296

9397
You can use 3rd party tools to automatically generate the SQL required to modify a database from one schema version to another. One such application is [SQLite Compare Utility](http://www.codeproject.com/KB/database/SQLiteCompareUtility.aspx) for Windows.
9498

95-
### Forcing upgrades
99+
### Upgrades via overwrite
100+
101+
If you have a read-only database or do not care about user data loss, you can force users onto the latest version of the SQLite database each time the version number is incremented (overwriting the local database with the one in the assets) by calling the `setForcedUpgrade()` method in your `SQLiteAsstHelper` subclass constructor.
102+
103+
You can additionally pass an argument that is the version number below which the upgrade will be forced.
96104

97-
You can force users onto the latest version of the SQLite database (overwriting the local database with the one in the assets) by calling the `setForcedUpgradeVersion(int version)` method in your constructor. The argument passed is the version number below which the upgrade will be forced. Note that this will forcibly overwriting any existing local database and all data within it.
105+
Note that this will overwrite an existing local database and all data within it.
98106

99107
Credits
100108
-------

0 commit comments

Comments
 (0)