Class: GDSQLitePlugin

GDSQLitePlugin()

GDSQLitePlugin is a Secure Database object. Use this Object to manipulate the data.

Constructor

new GDSQLitePlugin()

Properties:
Name Type Description
name string The name of the database.
version string The version of the database.
displayName string The display name of the database.
size integer The size of the database in bytes.
Source:

Methods

_deleteDB(onSuccess, onError)

This method delete database
Parameters:
Name Type Description
onSuccess function Database deleted successfully.
onError function Error callback.
Source:
Example
var db = window.openDatabase("testDB.db", "1.0", "CordovaDemo", 200000, function(){
    console.log("DB is opened")
}, null);

db._deleteDB(function(){
    console.log("DB is deleted")
}, null);

close(onSuccess, onError)

This method close database connection
Parameters:
Name Type Description
onSuccess function Called when database closed
onError function Called error callback if error occurred.
Source:
Example
var db = window.openDatabase("testDB.db", "1.0", "CordovaDemo", 200000, function(){
    console.log("DB is opened")
}, null);

db.close(function(){
    console.log("DB is closed")
}, null);

openDatabase(creationCallback, errorCallback)

This method will return a Secure Database object. Use the Database Object to manipulate the data.
Parameters:
Name Type Description
creationCallback function Success callback.
errorCallback function Error callback.
Properties:
Name Type Description
dbPath string The file path of the database.
version string The version of the database.
displayName string The display name of the database.
size integer The size of the database in bytes.
Source:
Example
var db = window.openDatabase("testDB.db", "1.0", "CordovaDemo", 200000, function(){
    console.log("DB is opened")
}, null);

transaction(fn, error, success)

Calls the GDSQLitePluginTransaction object instance
Parameters:
Name Type Description
fn function function that has the transaction as a parameter
error function Error callback.
success function Success callback.
Source:
Example
var db = window.openDatabase("testDB.db", "1.0", "CordovaDemo", 200000, function(){
    console.log("DB is opened")
}, null);

var selectSQLsuccessCB = function(tx,result) {
    console.log("Success");
},
insertSuccess = function(tx,result) {
    if (result.rowsAffected) {
        console.log(result.rowsAffected); // rows affected
    }
},
updateSuccess = function(tx, result) {
    console.log("Success");
},
querySuccess = function(tx,result) {
    var len = result.rows.length,
        one = 1, two = 2, three = 3, four = 4;

    console.log(len); // 4

    console.log(result.rows.item(0).id.toString());
    console.log(result.rows.item(0).data);
    console.log(result.rows.item(1).id.toString());
    console.log(result.rows.item(1).data);
    console.log(result.rows.item(2).id.toString());
    console.log(result.rows.item(2).data);
    console.log(result.rows.item(3).id.toString());
    console.log(result.rows.item(3).data);
},
errorCB = function(tx, err) {
    console.log("Error");
},
errorTCB = function(tx, err) {
    console.log("Error");
};

db.transaction(function(tx){
    tx.executeSql('DROP TABLE IF EXISTS DEMO',[],selectSQLsuccessCB,errorCB);
    tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id integer primary key, data)',[],selectSQLsuccessCB,errorCB);
    tx.executeSql('INSERT OR ROLLBACK INTO DEMO (id, data) VALUES (?,?)',[1, "First row"],insertSuccess,errorCB);
    tx.executeSql('INSERT OR ROLLBACK INTO DEMO (id, data) VALUES (?,?)',[2, "Second row"],insertSuccess,errorCB);
    tx.executeSql('INSERT OR REPLACE INTO DEMO (id, data) VALUES (?,?)',[3, "Third row"],insertSuccess,errorCB);
    tx.executeSql('INSERT OR ROLLBACK INTO DEMO (id, data) VALUES (?,?)',[4, "Fourth row"],insertSuccess,errorCB);
    tx.executeSql('UPDATE DEMO SET DATA = ?',["row updated"], updateSuccess, errorCB);
    tx.executeSql('SELECT * FROM DEMO',[], querySuccess, errorCB);
}, errorTCB, function(){
    console.log("Transaction completed");
});