You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.markdown
+52-15Lines changed: 52 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,23 +9,42 @@ It is implemented as an extension to `SQLiteOpenHelper`, providing an efficient
9
9
10
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.
11
11
12
+
Setup
13
+
-----
14
+
15
+
#### Gradle
16
+
17
+
If you are using the Gradle build system, simply add the following dependency in your `build.gradle` file:
If you are using the old build system, download and place the latest library [JAR][1] inside your project's `libs` folder.
28
+
29
+
12
30
Usage
13
31
-----
14
32
15
33
Copy [android-sqlite-asset-helper.jar](https://github.com/jgilfelt/android-sqlite-asset-helper/blob/master/lib/android-sqlite-asset-helper.jar?raw=true) into your Android project's `libs` directory and add it to the build path.
16
34
17
35
Extend `SQLiteAssetHelper` as you would normally do `SQLiteOpenHelper`, providing the constructor with a database name and version number:
18
36
19
-
public class MyDatabase extends SQLiteAssetHelper {
20
-
21
-
private static final String DATABASE_NAME = "northwind";
The name of the database must match a zip compressed file placed in your project's `assets/databases` directory. This zip file must contain a single SQLite database file. For example:
31
50
@@ -41,7 +60,7 @@ The database is made available for use the first time either `getReadableDatabas
41
60
42
61
The class will throw a `SQLiteAssetHelperException` if you do not provide the appropriately named file.
43
62
44
-
The [samples:v1](https://github.com/jgilfelt/android-sqlite-asset-helper/tree/master/samples/v1) project demonstrates a simple database creation and usage example using the classic Northwind database.
63
+
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.
45
64
46
65
Database Upgrades
47
66
-----------------
@@ -56,11 +75,11 @@ Update the initial SQLite database in the project's `assets/databases` directory
For example, [assets/databases/northwind_upgrade_1-2.sql](https://github.com/jgilfelt/android-sqlite-asset-helper/blob/master/samples/v2/assets/databases/northwind_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.
78
+
For example, [assets/databases/northwind.db_upgrade_1-2.sql](https://github.com/jgilfelt/android-sqlite-asset-helper/blob/v2/samples/database-v2-upgrade/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.
60
79
61
80
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`.
62
81
63
-
The [samples:v2](https://github.com/jgilfelt/android-sqlite-asset-helper/tree/master/example-v2) project demonstrates a simple upgrade to the Northwind database which adds a FullName column to the Employee table.
82
+
The [samples:database-v2-upgrade](https://github.com/jgilfelt/android-sqlite-asset-helper/tree/v2/samples/database-v2-upgrade) project demonstrates a simple upgrade to the Northwind database which adds a FullName column to the Employee table.
0 commit comments