Socket
Socket
Sign inDemoInstall

cordova-sqlite-storage

Package Overview
Dependencies
0
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.8.2 to 0.8.5

spec/www/spec/basic-misc-test.js

6

CHANGES.md
# Changes
## 0.8.5
- More explicit iosDatabaseLocation option
- iOS database location is now mandatory
- Split-up of some more spec test scripts
## 0.8.2

@@ -4,0 +10,0 @@

2

package.json
{
"name": "cordova-sqlite-storage",
"version": "0.8.2",
"version": "0.8.5",
"description": "Native interface to SQLite for PhoneGap/Cordova (core version)",

@@ -5,0 +5,0 @@ "cordova": {

@@ -11,8 +11,12 @@ # Cordova/PhoneGap sqlite storage adapter (core version)

|Android CI (limited suite)|iOS CI (limited suite)|
|Android Circle-CI (**full** suite)|iOS Travis-CI (*very* limited suite)|
|-----------------------|----------------------|
|[![Circle CI](https://circleci.com/gh/litehelpers/Cordova-sqlite-storage.svg?style=svg)](https://circleci.com/gh/litehelpers/Cordova-sqlite-storage)|[![Build Status](https://travis-ci.org/litehelpers/Cordova-sqlite-storage.svg?branch=master-rc)](https://travis-ci.org/litehelpers/Cordova-sqlite-storage)|
## IMPORTANT: iCloud backup of SQLite database is NOT allowed
## BREAKING CHANGE: Database location is now mandatory
The `location` or `iosDatabaseLocation` *must* be specified in the `openDatabase` and `deleteDatabase` calls, as documented below.
### IMPORTANT: iCloud backup of SQLite database is NOT allowed
As documented in the "**A User’s iCloud Storage Is Limited**" section of [iCloudFundamentals in Mac Developer Library iCloud Design Guide](https://developer.apple.com/library/mac/documentation/General/Conceptual/iCloudDesignGuide/Chapters/iCloudFundametals.html) (near the beginning):

@@ -37,12 +41,8 @@

### More information about iCloud backup
### How to disable iCloud backup
There are two ways iCloud backup is configured:
- For each app, iCloud backup is configured in `config.xml` and is *unfortunately* **enabled by default** as documented at: https://cordova.apache.org/docs/en/6.0.0/guide/platforms/ios/config.html
- In this plugin, the database is stored in the `Documents` subdirectory by default, which is backed up to iCloud. You can use the `location` option in `sqlitePlugin.openDatabase()` to store the database in a subdirectory that is *NOT* backed up to iCloud.
Use the `location` or `iosDatabaseLocation` option in `sqlitePlugin.openDatabase()` to store the database in a subdirectory that is *NOT* backed up to iCloud, as described in the section below.
Unless you want your app to use iCloud backup for some reason, it is recommended to turn it off as documented in: https://cordova.apache.org/docs/en/6.0.0/guide/platforms/ios/config.html
**NOTE:** Changing `BackupWebStorage` in `config.xml` has no effect on a database created by this plugin. `BackupWebStorage` applies only to local storage and/or Web SQL storage created in the WebView (*not* using this plugin). Ref: [phonegap/build#338 (comment)](https://github.com/phonegap/build/issues/338#issuecomment-113328140)
[@brodybits](https://github.com/brodybits) reported [Cordova bug CB-9830](https://issues.apache.org/jira/browse/CB-9830) to disable iCloud backup by default in `config.xml`.
## Support this project

@@ -54,4 +54,5 @@

- iOS database location is now mandatory, as documented below.
- Android version in this version branch is now using the built-in Android SQLite database classes. Integration with the lightweight [Android-sqlite-connector](https://github.com/liteglue/Android-sqlite-connector) is available in [litehelpers / cordova-sqlite-ext](https://github.com/litehelpers/cordova-sqlite-ext) and [litehelpers / Cordova-sqlite-legacy](https://github.com/litehelpers/Cordova-sqlite-legacy).
- Windows 8.1/Windows Phone 8.1 version is removed from this project, available in [litehelpers / cordova-sqlite-ext](https://github.com/litehelpers/cordova-sqlite-ext) and [litehelpers / Cordova-sqlite-legacy](https://github.com/litehelpers/Cordova-sqlite-legacy).
- Windows 8.1/Windows Phone 8.1 version is removed from this project, available in [litehelpers / Cordova-sqlite-legacy](https://github.com/litehelpers/Cordova-sqlite-legacy) (Windows 10 version is available in [litehelpers / cordova-sqlite-ext](https://github.com/litehelpers/cordova-sqlite-ext))
- WP(7/8) is not supported by this version branch, moved to [litehelpers / Cordova-sqlite-legacy](https://github.com/litehelpers/Cordova-sqlite-legacy).

@@ -69,9 +70,11 @@ - The following features are moved to [litehelpers / cordova-sqlite-ext](https://github.com/litehelpers/cordova-sqlite-ext) and removed from this project:

- More explicit `openDatabase` and `deleteDatabase` `iosDatabaseLocation` option
- Windows 10 version is available in [litehelpers / cordova-sqlite-ext](https://github.com/litehelpers/cordova-sqlite-ext)
- Added simple sql batch query function
- Added echo test function to verify installation of this plugin
- Published [litehelpers / Cordova-sqlite-legacy](https://github.com/litehelpers/Cordova-sqlite-legacy) for maintenance of WP(7/8) version, working with the other supported platforms Android/iOS/Windows 8.1(+)/Windows Phone 8.1(+)
- Published [litehelpers / Cordova-sqlite-legacy](https://github.com/litehelpers/Cordova-sqlite-legacy) for maintenance of WP(7/8) version along with Android/iOS/Windows 8.1(+)/Windows Phone 8.1(+)
- All iOS operations are now using background processing (reported to resolve intermittent problems with cordova-ios@4.0.1)
- Published [brodybits / Cordova-quick-start-checklist](https://github.com/brodybits/Cordova-quick-start-checklist) and [brodybits / Cordova-troubleshooting-guide](https://github.com/brodybits/Cordova-troubleshooting-guide)
- A version with support for web workers is available (with a different licensing scheme) at: [litehelpers / cordova-sqlite-workers-evfree](https://github.com/litehelpers/cordova-sqlite-workers-evfree)
- A version with pre-populated database support added for Windows "Universal" and REGEXP support added for Android is available at: [litehelpers / cordova-sqlite-ext](https://github.com/litehelpers/cordova-sqlite-ext)
- A version with pre-populated database support added for Windows (10) "Universal" and REGEXP support added for Android is available at: [litehelpers / cordova-sqlite-ext](https://github.com/litehelpers/cordova-sqlite-ext)
- PhoneGap Build is now supported through the npm package: http://phonegap.com/blog/2015/05/26/npm-plugins-available/

@@ -81,7 +84,6 @@ - [MetaMemoryT / websql-promise](https://github.com/MetaMemoryT/websql-promise) now provides a Promises-based interface to both Web SQL and this plugin

- [SQLCipher](https://www.zetetic.net/sqlcipher/) for Windows (8.1) in addition to Android & iOS is now supported by [litehelpers / Cordova-sqlcipher-adapter](https://github.com/litehelpers/Cordova-sqlcipher-adapter)
- New `openDatabase` and `deleteDatabase` `location` option to select database location (iOS *only*) and disable iCloud backup
## Highlights
- Drop-in replacement for HTML5/[Web SQL API](http://www.w3.org/TR/webdatabase/), the only change should be `window.openDatabase()` --> `sqlitePlugin.openDatabase()`
- Drop-in replacement for HTML5/[Web SQL API](http://www.w3.org/TR/webdatabase/), the only change should be `window.openDatabase()` --> `sqlitePlugin.openDatabase()` with parameters as documented below.
- Failure-safe nested transactions with batch processing optimizations

@@ -94,3 +96,3 @@ - As described in [this posting](http://brodyspark.blogspot.com/2012/12/cordovaphonegap-sqlite-plugins-offer.html):

- [Traiforks Mountain Bike Trail Map App](http://www.trailforks.com/apps/map/) with a couple of nice videos at: <http://www.pinkbike.com/news/trailforks-app-released.html>
- [Trailforks Mountain Bike Trail Map App](http://www.trailforks.com/apps/map/) with a couple of nice videos at: <http://www.pinkbike.com/news/trailforks-app-released.html>
- [Get It Done app](http://getitdoneapp.com/) by [marcucio.com](http://marcucio.com/)

@@ -111,3 +113,2 @@ - [KAAHE Health Encyclopedia](http://www.kaahe.org/en/index.php?option=com_content&view=article&id=817): Official health app of the Kingdom of Saudi Arabia.

- Possible crash on Android when using Unicode emoji characters due to [Android bug 81341](https://code.google.com/p/android/issues/detail?id=81341), which _should_ be fixed in Android 6.x
- In-memory database `db=window.sqlitePlugin.openDatabase({name: ":memory:"})` is currently not supported.
- Close database bugs described below.

@@ -123,2 +124,3 @@ - When a database is opened and deleted without closing, the iOS version is known to leak resources.

- The db version, display name, and size parameter values are not supported and will be ignored.
- _Absolute and relative subdirectory path(s) are not tested or supported._
- This plugin will not work before the callback for the 'deviceready' event has been fired, as described in **Usage**. (This is consistent with the other Cordova plugins.)

@@ -140,2 +142,3 @@ - This version will not work within a web worker (not properly supported by the Cordova framework).

- _Integration with PhoneGap developer app_
- Multi-page apps

@@ -181,5 +184,5 @@ - Use within [InAppBrowser](http://docs.phonegap.com/en/edge/cordova_inappbrowser_inappbrowser.md.html)

- [litehelpers / cordova-sqlite-ext](https://github.com/litehelpers/cordova-sqlite-ext) - version with REGEXP support Android/iOS and pre-populated database support *added* for Windows 8.1(+)/Windows Phone 8.1(+)
- [litehelpers / cordova-sqlite-ext](https://github.com/litehelpers/cordova-sqlite-ext) - version with REGEXP support for Android/iOS and pre-populated database support *added* for Windows 10
- [litehelpers / Cordova-sqlite-legacy](https://github.com/litehelpers/Cordova-sqlite-legacy) - maintenance of WP(7/8) version along with Android/iOS/Windows 8.1(+)/Windows Phone 8.1(+)
- [litehelpers / Cordova-sqlcipher-adapter](https://github.com/litehelpers/Cordova-sqlcipher-adapter) - supports [SQLCipher](https://www.zetetic.net/sqlcipher/) for Android, iOS, and Windows 8.1(+)/Windows Phone 8.1(+)
- [litehelpers / Cordova-sqlite-legacy](https://github.com/litehelpers/Cordova-sqlite-legacy) - maintenance of WP(7/8) version-working with the other supported platforms Android/iOS/Windows 8.1(+)/Windows Phone 8.1(+)
- [litehelpers / Cordova-sqlite-enterprise-free](https://github.com/litehelpers/Cordova-sqlite-enterprise-free) - internal memory improvements to support larger transactions (Android/iOS) and fix to support all Unicode characters (iOS) - with a different licensing scheme

@@ -225,3 +228,3 @@ - [litehelpers / cordova-sqlite-workers-evfree](https://github.com/litehelpers/cordova-sqlite-workers-evfree) - version with support for web workers, includes internal memory improvements to support larger transactions (Android/iOS) and fix to support all Unicode characters (iOS) - with a different licensing scheme

The idea is to emulate the HTML5/[Web SQL API](http://www.w3.org/TR/webdatabase/) as closely as possible. The only major change is to use `window.sqlitePlugin.openDatabase()` (or `sqlitePlugin.openDatabase()`) instead of `window.openDatabase()`. If you see any other major change please report it, it is probably a bug.
The idea is to emulate the HTML5/[Web SQL API](http://www.w3.org/TR/webdatabase/) as closely as possible. The only major change is to use `window.sqlitePlugin.openDatabase()` (or `sqlitePlugin.openDatabase()`) *with parameters as documented below* instead of `window.openDatabase()`. If you see any other major change please report it, it is probably a bug.

@@ -232,8 +235,18 @@ **NOTE:** If a sqlite statement in a transaction fails with an error, the error handler *must* return `false` in order to recover the transaction. This is correct according to the HTML5/[Web SQL API](http://www.w3.org/TR/webdatabase/) standard. This is different from the WebKit implementation of Web SQL in Android and iOS which recovers the transaction if a sql error hander returns a non-`true` value.

There are two options to open a database access object:
- **Recommended:** `var db = window.sqlitePlugin.openDatabase({name: "my.db", location: 1}, successcb, errorcb);`
- **Classical:** `var db = window.sqlitePlugin.openDatabase("myDatabase.db", "1.0", "Demo", -1);`
~~There are two options~~ to open a database access object:
- **Recommended:** `var db = window.sqlitePlugin.openDatabase({name: 'my.db', iosDatabaseLocation: 'default'}, successcb, errorcb);`
- No longer supported: ~~**Classical:** `var db = window.sqlitePlugin.openDatabase("myDatabase.db", "1.0", "Demo", -1);`~~
The `iosDatabaseLocation` option is used to select the database subdirectory location (iOS *only*) with the following choices:
- `default`: `Library/LocalDatabase` subdirectory - *NOT* visible to iTunes and *NOT* backed up by iCloud (will be the default in the future)
- `Library`: `Library` subdirectory - backed up by iCloud, *NOT* visible to iTunes
- `Documents`: `Documents` subdirectory - visible to iTunes and backed up by iCloud
**WARNING:** The new "default" iosDatabaseLocation value is *NOT* the same as the old default location and would break an upgrade for an app using the old default.
*ALTERNATIVE (deprecated):*
- `var db = window.sqlitePlugin.openDatabase({name: "my.db", location: 1}, successcb, errorcb);`
The `location` option is used to select the database subdirectory location (iOS *only*) with the following choices:
- `0` (default): `Documents` - visible to iTunes and backed up by iCloud
- `0` ~~(default)~~: `Documents` - visible to iTunes and backed up by iCloud
- `1`: `Library` - backed up by iCloud, *NOT* visible to iTunes

@@ -250,3 +263,3 @@ - `2`: `Library/LocalDatabase` - *NOT* visible to iTunes and *NOT* backed up by iCloud

function onDeviceReady() {
var db = window.sqlitePlugin.openDatabase({name: "my.db"});
var db = window.sqlitePlugin.openDatabase({name: 'my.db', iosDatabaseLocation: 'default'});
// ...

@@ -259,3 +272,3 @@ }

```js
window.sqlitePlugin.openDatabase({name: "my.db"}, function(db) {
window.sqlitePlugin.openDatabase({name: 'my.db', iosDatabaseLocation: 'default'}, function(db) {
db.transaction(function(tx) {

@@ -276,2 +289,12 @@ // ...

**TIP:**
To overwrite `window.openDatabase`:
```Javascript
window.openDatabase = function(dbname, ignored1, ignored2, ignored3) {
return window.sqlitePlugin.openDatabase({name: dbname, iosDatabaseLocation: 'default'});
};
```
### Workaround for Android db locking issue

@@ -398,2 +421,38 @@

**BUG:** If a row item object is retrieved twice, they should be safe from each other.
But this is not the case. This sample program demonstrates the bug:
```Javascript
var db = window.sqlitePlugin.openDatabase({name: "my.db"});
var res1 = null,
res2 = null;
db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)');
tx.executeSql('INSERT INTO test_table (data, data_num) VALUES (?,?)', ['test', 101], function(tx, res) {
tx.executeSql('SELECT * FROM test_table;', [], function(tx, res) {
res1 = res.rows.item(0);
res2 = res.rows.item(0);
res1.data = 'another';
// immediate check:
console.log('res1.data = ' + res1.data);
// output: res2.data = 'another'
console.log('res2.data = ' + res2.data);
});
}, function(e) {
console.log('Transaction error: ' + e.message);
}, function() {
// check stored info:
console.log('res1.data: ' + res1.data);
// output: res2.data = 'another';
console.log('res2.data: ' + res2.data);
});
```
## Background processing

@@ -547,6 +606,6 @@

```js
window.sqlitePlugin.deleteDatabase({name: "my.db", location: 1}, successcb, errorcb);
window.sqlitePlugin.deleteDatabase({name: 'my.db', iosDatabaseLocation: 'default'}, successcb, errorcb);
```
`location` as described above for `openDatabase` (iOS *only*)
with `iosDatabaseLocation` or `location` *required* as described above for `openDatabase` (iOS *only*)

@@ -553,0 +612,0 @@ # Schema versions

@@ -46,25 +46,75 @@ /* 'use strict'; */

// the androidLockWorkaround: 1 option in the case of implementation #2.
var scenarioList = [
var pluginScenarioList = [
isAndroid ? 'Plugin-implementation-default' : 'Plugin',
'HTML5',
'Plugin-implementation-2'
];
var scenarioCount = (!!window.hasWebKitBrowser) ? (isAndroid ? 3 : 2) : 1;
var pluginScenarioCount = isAndroid ? 2 : 1;
var mytests = function() {
describe('Plugin: db open-close-delete test(s)', function() {
describe('Plugin - BASIC sqlitePlugin.openDatabase test(s)', function() {
var scenarioList = [
isAndroid ? 'Plugin-implementation-default' : 'Plugin',
'Plugin-implementation-2'
];
var suiteName = 'plugin: ';
var scenarioCount = isAndroid ? 2 : 1;
it(suiteName + 'Open plugin database with Web SQL parameters (REJECTED with exception)', function(done) {
try {
var db = window.sqlitePlugin.openDatabase('open-with-web-sql-parameters-test.db', "1.0", "Demo", DEFAULT_SIZE);
for (var i=0; i<scenarioCount; ++i) {
// NOT EXPECTED:
// window.sqlitePlugin.openDatabase did not throw
expect(false).toBe(true);
describe(scenarioList[i] + ': basic sqlitePlugin.deleteDatabase test(s)', function() {
var scenarioName = scenarioList[i];
// check returned db object:
expect(db).toBeDefined();
expect(db.executeSql).toBeDefined();
expect(db.transaction).toBeDefined();
expect(db.close).toBeDefined();
//done();
// IMPORTANT FIX: avoid the risk of over 100 db handles open when running the full test suite
db.close(done, done);
} catch (e) {
// EXPECTED RESULT:
expect(true).toBe(true);
done();
}
}, MYTIMEOUT);
// NOTE: this was an issue due to the inconsistency ng cordova documentation and source code which
// triggered problems reported in litehelpers/Cordova-sqlite-storage#246 and
// litehelpers/Cordova-sqlcipher-adapter#5.
// The implementation now avoids this problem *by throwing an exception*.
// It could be nicer to just signal an error in the error callback, if present,
// through throwing an exception does prevent the user from using an invalid db object.
// Brody TBD: check how the Web SQL API would handle this condition?
it(suiteName + 'check that db name is really a string', function(done) {
var p1 = { name: 'my.db.name', location: 1 };
try {
window.sqlitePlugin.openDatabase({ name: p1 }, function(db) {
// not expected:
expect(false).toBe(true);
done();
}, function(error) {
// OK but NOT EXPECTED:
expect(true).toBe(true);
// XXX BRODY TODO:
//expect('Behavior changed, please update this test').toBe('--');
done();
});
} catch (e) {
// stopped by the implementation:
expect(true).toBe(true);
done();
}
}, MYTIMEOUT);
});
describe('Plugin: db open-close-delete test(s)', function() {
for (var i=0; i<pluginScenarioCount; ++i) {
describe(pluginScenarioList[i] + ': basic sqlitePlugin.deleteDatabase test(s)', function() {
var scenarioName = pluginScenarioList[i];
var suiteName = scenarioName + ': ';

@@ -75,5 +125,5 @@ var isOldAndroidImpl = (i === 1);

var openDatabase = function(first, second, third, fourth, fifth, sixth) {
if (!isOldAndroidImpl) {
return window.sqlitePlugin.openDatabase(first, second, third, fourth, fifth, sixth);
}
//if (!isOldAndroidImpl) {
// return window.sqlitePlugin.openDatabase(first, second, third, fourth, fifth, sixth);
//}

@@ -92,6 +142,11 @@ var dbname, okcb, errorcb;

dbopts = {
if (!isOldAndroidImpl) {
return window.sqlitePlugin.openDatabase({name: dbname, location: 0}, okcb, errorcb);
}
var dbopts = {
name: 'i2-'+dbname,
androidDatabaseImplementation: 2,
androidLockWorkaround: 1
androidLockWorkaround: 1,
location: 1
};

@@ -104,5 +159,5 @@

if (!isOldAndroidImpl) {
window.sqlitePlugin.deleteDatabase(first, second, third);
window.sqlitePlugin.deleteDatabase({name: first, location: 0}, second, third);
} else {
window.sqlitePlugin.deleteDatabase('i2-'+first, second, third);
window.sqlitePlugin.deleteDatabase({name: 'i2-'+first, location: 0}, second, third);
}

@@ -183,6 +238,6 @@ }

for (var i=0; i<scenarioCount; ++i) {
for (var i=0; i<pluginScenarioCount; ++i) {
describe(scenarioList[i] + ': basic plugin open-close test(s)', function() {
var scenarioName = scenarioList[i];
describe(pluginScenarioList[i] + ': basic plugin open-close test(s)', function() {
var scenarioName = pluginScenarioList[i];
var suiteName = scenarioName + ': ';

@@ -193,5 +248,5 @@ var isOldAndroidImpl = (i === 1);

var openDatabase = function(first, second, third, fourth, fifth, sixth) {
if (!isOldAndroidImpl) {
return window.sqlitePlugin.openDatabase(first, second, third, fourth, fifth, sixth);
}
//if (!isOldAndroidImpl) {
// return window.sqlitePlugin.openDatabase(first, second, third, fourth, fifth, sixth);
//}

@@ -210,6 +265,11 @@ var dbname, okcb, errorcb;

dbopts = {
if (!isOldAndroidImpl) {
return window.sqlitePlugin.openDatabase({name: dbname, location: 0}, okcb, errorcb);
}
var dbopts = {
name: 'i2-'+dbname,
androidDatabaseImplementation: 2,
androidLockWorkaround: 1
androidLockWorkaround: 1,
location: 1
};

@@ -398,6 +458,10 @@

// NOTE: MUST be defined in function scope, NOT outer scope:
var openDatabase = function(first, second, third, fourth, fifth, sixth) {
return window.sqlitePlugin.openDatabase(first, second, third, fourth, fifth, sixth);
var openDatabase = function(first, second, third) {
return window.sqlitePlugin.openDatabase(first, second, third);
}
var deleteDatabase = function(first, second, third) {
window.sqlitePlugin.deleteDatabase(first, second, third);
}
// Needed to support some large-scale applications:

@@ -447,7 +511,7 @@ test_it(suiteName + ' open same database twice in [same] specified location works', function () {

openDatabase(dbName, "1.0", "Demo", DEFAULT_SIZE, function (db) {
openDatabase({name: dbName, location: 0}, function (db) {
db.close(function () {
openDatabase(dbName, "1.0", "Demo", DEFAULT_SIZE, function (db) {
openDatabase({name: dbName, location: 0}, function (db) {
db.close(function () {
openDatabase(dbName, "1.0", "Demo", DEFAULT_SIZE, function (db) {
openDatabase({name: dbName, location: 0}, function (db) {
db.readTransaction(function (tx) {

@@ -492,5 +556,4 @@ tx.executeSql('SELECT 1', [], function (tx, results) {

// Needed to support some large-scale applications:
test_it(suiteName + ' delete then re-open allows subsequent queries to run', function () {
test_it(suiteName + ' delete then re-open (location: 2) allows subsequent queries to run', function () {
var dbName = "Database-delete-and-Reopen.db";
var dbLocation = 2;

@@ -500,6 +563,6 @@ // async test coming up

var db = openDatabase({name: dbName, location: dbLocation}, function () {
var db = openDatabase({name: dbName, iosDatabaseLocation: 'default'}, function () {
// success CB
window.sqlitePlugin.deleteDatabase({name: dbName, location: dbLocation}, function () {
db = openDatabase({name: dbName, location: dbLocation}, function () {
deleteDatabase({name: dbName, iosDatabaseLocation: 'default'}, function () {
db = openDatabase({name: dbName, iosDatabaseLocation: 'default'}, function () {
db.readTransaction(function (tx) {

@@ -534,3 +597,3 @@ tx.executeSql('SELECT 1', [], function (tx, results) {

// XXX TODO: repeat scenario but wait for open callback before close/delete/reopen
// XXX SEE BELOW: repeat scenario but wait for open callback before close/delete/reopen
// Needed to support some large-scale applications:

@@ -547,7 +610,7 @@ test_it(suiteName + ' immediate close, then delete then re-open allows subsequent queries to run', function () {

var db1 = openDatabase({name: dbName});
var db1 = openDatabase({name: dbName, iosDatabaseLocation: 'Documents'});
db1.close(function () {
window.sqlitePlugin.deleteDatabase(dbName, function () {
openDatabase({name: dbName}, function(db) {
deleteDatabase({name: dbName, iosDatabaseLocation: 'Documents'}, function () {
openDatabase({name: dbName, iosDatabaseLocation: 'Documents'}, function(db) {
db.readTransaction(function (tx) {

@@ -586,7 +649,7 @@ tx.executeSql('SELECT 1', [], function (tx, results) {

openDatabase({name: dbName}, function(db1) {
openDatabase({name: dbName, iosDatabaseLocation: 'Library'}, function(db1) {
db1.close(function () {
window.sqlitePlugin.deleteDatabase(dbName, function () {
openDatabase({name: dbName}, function(db) {
deleteDatabase({name: dbName, iosDatabaseLocation: 'Library'}, function () {
openDatabase({name: dbName, iosDatabaseLocation: 'Library'}, function(db) {
db.readTransaction(function (tx) {

@@ -630,3 +693,3 @@ tx.executeSql('SELECT 1', [], function (tx, results) {

openDatabase({name: dbName}, function(db) {
openDatabase({name: dbName, location: 0}, function(db) {
ok(!!db, 'valid db object 1/4');

@@ -636,3 +699,3 @@ db.close(function () {

openDatabase({name: dbName}, function(db) {
openDatabase({name: dbName, location: 0}, function(db) {
ok(!!db, 'valid db object 2/4');

@@ -642,3 +705,3 @@ db.close(function () {

openDatabase({name: dbName}, function(db) {
openDatabase({name: dbName, location: 0}, function(db) {
ok(!!db, 'valid db object 3/4');

@@ -648,3 +711,3 @@ db.close(function () {

openDatabase({name: dbName}, function(db) {
openDatabase({name: dbName, location: 0}, function(db) {
ok(!!db, 'valid db object 4/4');

@@ -698,3 +761,3 @@ db.close(function () {

var db = openDatabase({name: dbName});
var db = openDatabase({name: dbName, location: 0});
ok(!!db, 'valid db object 1/5');

@@ -704,3 +767,3 @@ db.close(function () {

db = openDatabase({name: dbName});
db = openDatabase({name: dbName, location: 0});
ok(!!db, 'valid db object 2/5');

@@ -710,3 +773,3 @@ db.close(function () {

db = openDatabase({name: dbName});
db = openDatabase({name: dbName, location: 0});
ok(!!db, 'valid db object 3/5');

@@ -716,3 +779,3 @@ db.close(function () {

db = openDatabase({name: dbName});
db = openDatabase({name: dbName, location: 0});
ok(!!db, 'valid db object 4/5');

@@ -722,3 +785,3 @@ db.close(function () {

db = openDatabase({name: dbName});
db = openDatabase({name: dbName, location: 0});
ok(!!db, 'valid db object 5/5');

@@ -754,2 +817,3 @@ db.close(function () {

var dbName = "repeatedly-open-and-delete-4x.db";
var dbargs = {name: dbName, iosDatabaseLocation: 'Documents'};

@@ -759,20 +823,20 @@ // async test coming up

openDatabase({name: dbName}, function(db) {
openDatabase(dbargs, function(db) {
ok(true, 'valid db object 1/4');
window.sqlitePlugin.deleteDatabase(dbName, function () {
deleteDatabase(dbargs, function () {
ok(true, 'success 1/4');
openDatabase({name: dbName}, function(db) {
openDatabase(dbargs, function(db) {
ok(true, 'valid db object 2/4');
window.sqlitePlugin.deleteDatabase(dbName, function () {
deleteDatabase(dbargs, function () {
ok(true, 'success 2/4');
openDatabase({name: dbName}, function(db) {
openDatabase(dbargs, function(db) {
ok(true, 'valid db object 3/4');
window.sqlitePlugin.deleteDatabase(dbName, function () {
deleteDatabase(dbargs, function () {
ok(true, 'success 3/4');
openDatabase({name: dbName}, function(db) {
openDatabase(dbargs, function(db) {
ok(true, 'valid db object 4/4');
window.sqlitePlugin.deleteDatabase(dbName, function () {
deleteDatabase(dbargs, function () {
ok(true, 'success 4/4');

@@ -825,25 +889,25 @@

var db = openDatabase({name: dbName});
var db = openDatabase({name: dbName, location: 0});
ok(!!db, 'valid db object 1/5');
window.sqlitePlugin.deleteDatabase(dbName, function () {
sqlitePlugin.deleteDatabase({name: dbName, location: 0}, function () {
ok(true, 'success 1/5');
db = openDatabase({name: dbName});
db = openDatabase({name: dbName, location: 0});
ok(!!db, 'valid db object 2/5');
window.sqlitePlugin.deleteDatabase(dbName, function () {
sqlitePlugin.deleteDatabase({name: dbName, location: 0}, function () {
ok(true, 'success 2/5');
db = openDatabase({name: dbName});
db = openDatabase({name: dbName, location: 0});
ok(!!db, 'valid db object 3/5');
window.sqlitePlugin.deleteDatabase(dbName, function () {
sqlitePlugin.deleteDatabase({name: dbName, location: 0}, function () {
ok(true, 'success 3/5');
db = openDatabase({name: dbName});
db = openDatabase({name: dbName, location: 0});
ok(!!db, 'valid db object 4/5');
window.sqlitePlugin.deleteDatabase(dbName, function () {
sqlitePlugin.deleteDatabase({name: dbName, location: 0}, function () {
ok(true, 'success 4/5');
db = openDatabase({name: dbName});
db = openDatabase({name: dbName, location: 0});
ok(!!db, 'valid db object 5/5');
window.sqlitePlugin.deleteDatabase(dbName, function () {
sqlitePlugin.deleteDatabase({name: dbName, location: 0}, function () {
ok(true, 'success 5/5');

@@ -850,0 +914,0 @@

@@ -20,3 +20,3 @@ /* 'use strict'; */

// the androidLockWorkaround: 1 option in the case of implementation #2.
var scenarioList = [
var pluginScenarioList = [
isAndroid ? 'Plugin-implementation-default' : 'Plugin',

@@ -26,3 +26,3 @@ 'Plugin-implementation-2'

var scenarioCount = isAndroid ? 2 : 1;
var pluginScenarioCount = isAndroid ? 2 : 1;

@@ -32,6 +32,6 @@ // simple tests:

for (var i=0; i<scenarioCount; ++i) {
for (var i=0; i<pluginScenarioCount; ++i) {
describe(scenarioList[i] + ': BATCH SQL test(s)', function() {
var scenarioName = scenarioList[i];
describe(pluginScenarioList[i] + ': BATCH SQL test(s)', function() {
var scenarioName = pluginScenarioList[i];
var suiteName = scenarioName + ': ';

@@ -47,10 +47,11 @@ var isImpl2 = (i === 1);

androidDatabaseImplementation: 2,
androidLockWorkaround: 1
androidLockWorkaround: 1,
location: 1
});
} else {
return window.sqlitePlugin.openDatabase(name, '1.0', 'Test', DEFAULT_SIZE);
return window.sqlitePlugin.openDatabase({name: name, location: 0});
}
}
describe(scenarioList[i] + ': Basic sql batch test(s)', function() {
describe(pluginScenarioList[i] + ': Basic sql batch test(s)', function() {

@@ -57,0 +58,0 @@ it(suiteName + 'Single-column batch sql test', function(done) {

@@ -86,2 +86,3 @@ # SQLite plugin in Markdown (litcoffee)

# _should_ already be checked by openDatabase:
if !(openargs and openargs['name'])

@@ -560,4 +561,10 @@ throw newSQLError "Cannot create a SQLitePlugin db instance without a db name"

# OLD:
dblocations = [ "docs", "libs", "nosync" ]
iosLocationMap =
'default' : 'nosync'
'Documents' : 'docs'
'Library' : 'libs'
SQLiteFactory =

@@ -570,27 +577,53 @@ ###

###
opendb: argsArray (args) ->
if args.length < 1 then return null
openDatabase: argsArray (args) ->
if args.length < 1 || !args[0]
throw newSQLError 'Sorry missing mandatory open arguments object in openDatabase call'
first = args[0]
openargs = null
okcb = null
errorcb = null
#first = args[0]
#openargs = null
#okcb = null
#errorcb = null
if first.constructor == String
openargs = {name: first}
#if first.constructor == String
# openargs = {name: first}
if args.length >= 5
okcb = args[4]
if args.length > 5 then errorcb = args[5]
# if args.length >= 5
# okcb = args[4]
# if args.length > 5 then errorcb = args[5]
else
openargs = first
#else
# openargs = first
if args.length >= 2
okcb = args[1]
if args.length > 2 then errorcb = args[2]
# if args.length >= 2
# okcb = args[1]
# if args.length > 2 then errorcb = args[2]
dblocation = if !!openargs.location then dblocations[openargs.location] else null
openargs.dblocation = dblocation || dblocations[0]
if args[0].constructor == String
throw newSQLError 'Sorry first openDatabase argument must be an object'
openargs = args[0]
# check here
if !openargs.name
throw newSQLError 'Database name value is missing in openDatabase call'
if !openargs.iosDatabaseLocation and !openargs.location and openargs.location isnt 0
throw newSQLError 'Database location or iosDatabaseLocation value is now mandatory in openDatabase call'
# XXX TODO (with test):
#if !!openargs.location and !!openargs.iosDatabaseLocation
# throw newSQLError 'Abiguous: both location or iosDatabaseLocation values are present in openDatabase call'
dblocation =
if !!openargs.iosDatabaseLocation
iosLocationMap[openargs.iosDatabaseLocation]
else
dblocations[openargs.location]
# XXX TODO (with test):
#if !dblocation
# throw newSQLError 'Valid iOS database location could not be determined in openDatabase call'
openargs.dblocation = dblocation
if !!openargs.createFromLocation and openargs.createFromLocation == 1

@@ -605,5 +638,11 @@ openargs.createFromResource = "1"

okcb = null
errorcb = null
if args.length >= 2
okcb = args[1]
if args.length > 2 then errorcb = args[2]
new SQLitePlugin openargs, okcb, errorcb
deleteDb: (first, success, error) ->
deleteDatabase: (first, success, error) ->
args = {}

@@ -613,4 +652,5 @@

#console.log "delete db name: #{first}"
args.path = first
args.dblocation = dblocations[0]
#args.path = first
#args.dblocation = dblocations[0]
throw newSQLError 'Sorry first deleteDatabase argument must be an object'

@@ -621,5 +661,24 @@ else

args.path = first.name
dblocation = if !!first.location then dblocations[first.location] else null
args.dblocation = dblocation || dblocations[0]
#dblocation = if !!first.location then dblocations[first.location] else null
#args.dblocation = dblocation || dblocations[0]
if !first.iosDatabaseLocation and !first.location and first.location isnt 0
throw newSQLError 'Database location or iosDatabaseLocation value is now mandatory in deleteDatabase call'
# XXX TODO (with test):
#if !!first.location and !!first.iosDatabaseLocation
# throw newSQLError 'Abiguous: both location or iosDatabaseLocation values are present in deleteDatabase call'
dblocation =
if !!first.iosDatabaseLocation
iosLocationMap[first.iosDatabaseLocation]
else
dblocations[first.location]
# XXX TODO (with test):
#if !dblocation
# throw newSQLError 'Valid iOS database location could not be determined in deleteDatabase call'
args.dblocation = dblocation
# XXX [BUG #210] TODO: when closing or deleting a db, abort any pending transactions (with error callback)

@@ -647,4 +706,4 @@ delete SQLitePlugin::openDBs[args.path]

openDatabase: SQLiteFactory.opendb
deleteDatabase: SQLiteFactory.deleteDb
openDatabase: SQLiteFactory.openDatabase
deleteDatabase: SQLiteFactory.deleteDatabase

@@ -651,0 +710,0 @@ ## vim directives

(function() {
var DB_STATE_INIT, DB_STATE_OPEN, READ_ONLY_REGEX, SQLiteFactory, SQLitePlugin, SQLitePluginTransaction, argsArray, dblocations, newSQLError, nextTick, root, txLocks;
var DB_STATE_INIT, DB_STATE_OPEN, READ_ONLY_REGEX, SQLiteFactory, SQLitePlugin, SQLitePluginTransaction, argsArray, dblocations, iosLocationMap, newSQLError, nextTick, root, txLocks;

@@ -535,2 +535,8 @@ root = this;

iosLocationMap = {
'default': 'nosync',
'Documents': 'docs',
'Library': 'libs'
};
SQLiteFactory = {

@@ -544,32 +550,19 @@

*/
opendb: argsArray(function(args) {
var dblocation, errorcb, first, okcb, openargs;
if (args.length < 1) {
return null;
openDatabase: argsArray(function(args) {
var dblocation, errorcb, okcb, openargs;
if (args.length < 1 || !args[0]) {
throw newSQLError('Sorry missing mandatory open arguments object in openDatabase call');
}
first = args[0];
openargs = null;
okcb = null;
errorcb = null;
if (first.constructor === String) {
openargs = {
name: first
};
if (args.length >= 5) {
okcb = args[4];
if (args.length > 5) {
errorcb = args[5];
}
}
} else {
openargs = first;
if (args.length >= 2) {
okcb = args[1];
if (args.length > 2) {
errorcb = args[2];
}
}
if (args[0].constructor === String) {
throw newSQLError('Sorry first openDatabase argument must be an object');
}
dblocation = !!openargs.location ? dblocations[openargs.location] : null;
openargs.dblocation = dblocation || dblocations[0];
openargs = args[0];
if (!openargs.name) {
throw newSQLError('Database name value is missing in openDatabase call');
}
if (!openargs.iosDatabaseLocation && !openargs.location && openargs.location !== 0) {
throw newSQLError('Database location or iosDatabaseLocation value is now mandatory in openDatabase call');
}
dblocation = !!openargs.iosDatabaseLocation ? iosLocationMap[openargs.iosDatabaseLocation] : dblocations[openargs.location];
openargs.dblocation = dblocation;
if (!!openargs.createFromLocation && openargs.createFromLocation === 1) {

@@ -584,10 +577,17 @@ openargs.createFromResource = "1";

}
okcb = null;
errorcb = null;
if (args.length >= 2) {
okcb = args[1];
if (args.length > 2) {
errorcb = args[2];
}
}
return new SQLitePlugin(openargs, okcb, errorcb);
}),
deleteDb: function(first, success, error) {
deleteDatabase: function(first, success, error) {
var args, dblocation;
args = {};
if (first.constructor === String) {
args.path = first;
args.dblocation = dblocations[0];
throw newSQLError('Sorry first deleteDatabase argument must be an object');
} else {

@@ -598,5 +598,8 @@ if (!(first && first['name'])) {

args.path = first.name;
dblocation = !!first.location ? dblocations[first.location] : null;
args.dblocation = dblocation || dblocations[0];
}
if (!first.iosDatabaseLocation && !first.location && first.location !== 0) {
throw newSQLError('Database location or iosDatabaseLocation value is now mandatory in deleteDatabase call');
}
dblocation = !!first.iosDatabaseLocation ? iosLocationMap[first.iosDatabaseLocation] : dblocations[first.location];
args.dblocation = dblocation;
delete SQLitePlugin.prototype.openDBs[args.path];

@@ -629,6 +632,6 @@ return cordova.exec(success, error, "SQLitePlugin", "delete", [args]);

},
openDatabase: SQLiteFactory.opendb,
deleteDatabase: SQLiteFactory.deleteDb
openDatabase: SQLiteFactory.openDatabase,
deleteDatabase: SQLiteFactory.deleteDatabase
};
}).call(this);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc