Skip to content

Commit

Permalink
Improve documentation for pre-populated database (#10/#172) and Andro…
Browse files Browse the repository at this point in the history
…id bug workaround (#193).
  • Loading branch information
Chris Brody committed Mar 18, 2015
1 parent b316586 commit 2b17229
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,35 @@ An [issue was reported](https://github.com/brodysoft/Cordova-SQLitePlugin/issues

It is suspected that this issue is caused by [this Android sqlite commit](https://github.com/android/platform_external_sqlite/commit/d4f30d0d1544f8967ee5763c4a1680cb0553039f), which references and includes the sqlite commit at: http://www.sqlite.org/src/info/6c4c2b7dba

The workaround is enabled by opening the database like:
There is an optional workaround that simply closes and reopens the database file at the end of every transaction that is committed. The workaround is enabled by opening the database like:

```js
var db = window.sqlitePlugin.openDatabase({name: "my.db", androidLockWorkaround: 1});
var db = window.sqlitePlugin.openDatabase({name: "my.db", androidLockWorkaround: 1});
```

**NOTE:** This workaround is *only* applied when using `db.transaction()` or `db.readTransaction()`, *not* applied when running `executeSql()` on the database object.

### Pre-populated database

For Android & iOS (*only*): put the database file in the `www` directory and open the database like:

```js
var db = window.sqlitePlugin.openDatabase({name: "my.db", createFromLocation: 1});
var db = window.sqlitePlugin.openDatabase({name: "my.db", createFromLocation: 1});
```

or to disable iCloud backup:

```js
db = sqlitePlugin.openDatabase({name: "my.db", location: 2, createFromLocation: 1});
```

**IMPORTANT NOTES:**

- Put the pre-populated database file in the `www` subdirectory. This should work well with using the Cordova CLI to support both Android & iOS versions.
- The pre-populated database file name must match **exactly** the file name given in `openDatabase`. The automatic extension has been completely eliminated.
- The pre-populated database file is ignored if the database file with the same name already exists in your database file location.

**TIP:** If you don't see the data from the pre-populated database file, completely remove your app and try it again!

## Background processing

Expand Down

0 comments on commit 2b17229

Please sign in to comment.