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
{{ message }}
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
Adds WebSQL functionality as Apache Cordova Plugin implemented on top of Csharp-Sqlite library. Support of Windows 8.0, Windows 8.1, Windows Phone 8.0 and Windows Phone 8.1.
Sample usage
Plugin follows WebDatabase specification, no special changes are required. The following sample code creates todo table (if not exist) and adds new record. Complete example is available here.
vardbSize=5*1024*1024;// 5MBvardb=openDatabase("Todo","","Todo manager",dbSize,function(){console.log('db successfully opened or created');});db.transaction(function(tx){tx.executeSql("CREATE TABLE IF NOT EXISTS todo(ID INTEGER PRIMARY KEY ASC, todo TEXT, added_on TEXT)",[],onSuccess,onError);tx.executeSql("INSERT INTO todo(todo, added_on) VALUES (?,?)",['my todo item',newDate().toUTCString()],onSuccess,onError);});functiononSuccess(transaction,resultSet){console.log('Query completed: '+JSON.stringify(resultSet));}functiononError(transaction,error){console.log('Query failed: '+error.message);}
Make sure an up-to-date version of Node.js is installed, then type the following command to install the Cordova CLI:
npm install -g cordova
Create a project and add the platforms you want to support:
cordova create sampleApp
cd sampleApp
cordova platform add windows <- support of Windows 8.0, Windows 8.1 and Windows Phone 8.1
cordova platform add wp8 <- support of Windows Phone 8.0
The display name, and size parameter values are not supported and will be ignored.
Due to SQLite limitations db version parameter to openDatabase and changeVersion methods should be an integer value or integer's string representation.
openDatabase on WP8 bypass version check by default. The reason of this is async nature of cordova calls to native APIs. To force version check and enable full versioning functionality set up the following variable:
window.__webSqlUseSyncConstructor=true;
To use nested transactions you will need to pass parent transaction like this:
vardb=openDatabase('test1.db','1.0','testLongTransaction',2*1024);db.transaction(function(tx1){tx1.executeSql('DROP TABLE IF EXISTS foo');tx1.executeSql('CREATE TABLE IF NOT EXISTS foo (id unique, text)');
...
db.transaction(function(tx2){tx2.executeSql('INSERT INTO foo (id, text) VALUES (1, "foobar")');},null,null,null,null,false,tx1);
...
},null,null);
tx1 passed as the last argument in the nested db.transaction refers to the parent transaction.
Other arguments (null, null, null, null, false, tx1) are:
the db.transaction error callback,
the db.transaction success callback,
preflight operation callback,
postflight operation callback,
readOnly flag,
parent transaction - respectively.
To enable logging use:
window.__webSqlDebugModeOn=true;
Copyrights
Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.