Skip to content

Commit

Permalink
Add echo test (Android & iOS)
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher J. Brody committed Feb 7, 2016
1 parent ab81860 commit 1246edf
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 0.x.x-xx

- Echo test function
- Remove extra runInBackground: step from iOS version
- Android-sqlite-connector (NDK) support removed from this version branch
- Windows version removed from this version branch
Expand Down
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ I raised [Cordova bug CB-9830](https://issues.apache.org/jira/browse/CB-9830) to

## Announcements

- Added echo test function to verify installation of this plugin
- All iOS operations are now using background processing (reported to resolve intermittent problems with [email protected])
- 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)
Expand Down Expand Up @@ -203,6 +204,18 @@ naelA/nativescript-sqlite) (Android and/or iOS)

# Usage

## Echo test

To verify that both the Javascript and native part of this plugin are installed in your application:

```js
window.sqlitePlugin.echoTest(successCallback, errorCallback);
```

**IMPORTANT:** Please wait for the 'deviceready' event, (see below for an example).

## General

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.

**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.
Expand Down Expand Up @@ -655,7 +668,13 @@ Sample change to `config.xml` for Cordova/PhoneGap 2.x:
<plugin name="Compass" value="CDVLocation" />
```

## Quick installation test
## Installation test

### Easy installation test

Use `window.sqlitePlugin.echoTest` as described above (please wait for the `deviceready` event).

### Quick installation test

Assuming your app has a recent template as used by the Cordova create script, add the following code to the `onDeviceReady` function, after `app.receivedEvent('deviceready');`:

Expand Down
12 changes: 12 additions & 0 deletions SQLitePlugin.coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,18 @@
sqliteFeatures:
isSQLitePlugin: true

echoTest: (okcb, errorcb) ->
ok = (s) ->
if s is 'test-string'
okcb()
else
errorcb "Mismatch: got: '#{s}' expected 'test-string'"

error = (e) ->
errorcb e

cordova.exec okcb, errorcb, "SQLitePlugin", "echoStringValue", [{value:'test-string'}]

openDatabase: SQLiteFactory.opendb
deleteDatabase: SQLiteFactory.deleteDb

Expand Down
1 change: 1 addition & 0 deletions spec/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

<!-- spec file(s): -->
<script src="spec/browser-check-startup.js"></script>
<script src="spec/self-test.js"></script>
<script src="spec/simple-test.js"></script>
<script src="spec/legacy.js"></script>

Expand Down
32 changes: 32 additions & 0 deletions spec/www/spec/self-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* 'use strict'; */

var MYTIMEOUT = 12000;

// simple tests:
var mytests = function() {

describe('SELF test(s)', function() {

describe('ECHO test(s)', function() {
it('Simple echo test',
function(done) {
window.sqlitePlugin.echoTest(function() {
// ok:
expect(true).toBe(true);
done();
}, function(err) {
// went wrong:
expect(false).toBe(true);
done();
});
}, MYTIMEOUT);
});

});

};

if (window.hasBrowser) mytests();
else exports.defineAutoTests = mytests;

/* vim: set expandtab : */
8 changes: 8 additions & 0 deletions src/android/io/sqlc/SQLitePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,16 @@ private boolean executeAndPossiblyThrow(Action action, JSONArray args, CallbackC

boolean status = true;
JSONObject o;
String echo_value;
String dbname;

switch (action) {
case echoStringValue:
o = args.getJSONObject(0);
echo_value = o.getString("value");
cbc.success(echo_value);
break;

case open:
o = args.getJSONObject(0);
dbname = o.getString("name");
Expand Down Expand Up @@ -429,6 +436,7 @@ private final class DBQuery {
}

private static enum Action {
echoStringValue,
open,
close,
delete,
Expand Down
18 changes: 18 additions & 0 deletions www/SQLitePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,24 @@
sqliteFeatures: {
isSQLitePlugin: true
},
echoTest: function(okcb, errorcb) {
var error, ok;
ok = function(s) {
if (s === 'test-string') {
return okcb();
} else {
return errorcb("Mismatch: got: '" + s + "' expected 'test-string'");
}
};
error = function(e) {
return errorcb(e);
};
return cordova.exec(okcb, errorcb, "SQLitePlugin", "echoStringValue", [
{
value: 'test-string'
}
]);
},
openDatabase: SQLiteFactory.opendb,
deleteDatabase: SQLiteFactory.deleteDb
};
Expand Down

0 comments on commit 1246edf

Please sign in to comment.