Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

The Storage feature enables your mobile application to access the following storage mechanisms:

 1. SQLite Storage

This feature enables your mobile application to access SQLite databases. It enables you to store data in a structured database that can be queried using a standard SQL syntax.

Supported Platforms

This feature is supported in the following platforms:

  • iOS
  • Android

Installation

Execute the following command in your Cordova project directory:

cordova plugin add cordova-sqlite-storage

Usage

// This function opens the SQLite database and executes a SQL query.
this.fm.registerHandler("cbxclick", "SQLITE", 
                        function (fm, event, fieldName, value) 
						{
            				var params = 
							{
                				name: 'demo.db',
								location: 'default'
            				};
            				canvas.dbReference = canvas.env.storage.sqlite.openDatabase(params);
            				canvas.env.storage.sqlite.executeSql
							( 	canvas.dbReference, 
								'CREATE TABLE CANVAS (USER TEXT)', 
								[], 
								successCB, 
								errorCB
							);
});

// This function is called when SQL query successfully executed.
function successCB(success) 
{
    showAlert("success");
}

// This function is called when SQL query is not successfully executed.
function errorCB(error) 
{
    showAlert("error");
}


 2. Web SQL Storage

This feature enables your mobile application to access Web SQL storage. It enables you to store data in a structured database that can be queried using a standard SQL syntax.

Usage

// This function opens the WebSQL database and executes a SQL query.
this.fm.registerHandler("cbxclick", "WEBSQL", 
                        function (fm, event, fieldName, value) 
						{
            				var params = 
							{
                				name: 'canvas.db',
								version: '1.0',
								textDescription: 'demo',
								size: '2 * 1024 * 1024'
            				};
            				canvas.dbReferenceWeb = canvas.env.storage.websql.openDatabase(params);
            				canvas.env.storage.sqlite.executeSql
							(
								canvas.dbReferenceWeb, 
								'CREATE TABLE CANVAS (USER TEXT)', 
								[], 
								successCB, 
								errorCB
							);
});

// This function is called when SQL query successfully executed.
function successCB(success) 
{
    showAlert("success");
}

// This function is called when SQL query is not successfully executed.
function errorCB(error) 
{
    showAlert("error");
}


 3. Session Storage

This feature enables your mobile application to access session storage.

Usage

//This function stores data in session storage as key-value pair combination.
this.fm.registerHandler("cbxclick", "SESSIONSTORAGE", 
                        function (fm, event, fieldName, value) 
						{
            				var params = 
							{
                				key: 'name',
								value: 'Canvas'
            				};
            				canvas.env.storage.session.setItem(params);
            				var val = canvas.env.storage.session.getItem('name');
            				showAlert(val);
});


 4. Local Storage

This feature enables your mobile application to access local storage. It provides a simple and synchronous key-value pair storage.

Usage

//This function stores data in local storage as key-value pair combination.
this.fm.registerHandler("cbxclick", "LOCALSTORAGE", 
                        function (fm, event, fieldName, value) 
						{
            				var params = 
							{
                				key: 'name',
								value: 'Canvas'
            				};
            				canvas.env.storage.local.setItem(params);
            				var lval = canvas.env.storage.local.getItem('name');
            				showAlert(lval);
});



  • No labels