Class: GDSQLitePluginTransaction

GDSQLitePluginTransaction()

GDSQLitePluginTransaction is an object that contains methods that allow the user to execute SQL statements against the secure Database.

Constructor

new GDSQLitePluginTransaction()

Properties:
Name Type Description
db string database object which the transaction is executing against.
Source:

Methods

executeSql(sql, values, successk, error)

Execute an SQL statements against the Secure Database.
Parameters:
Name Type Description
sql string SQL statement to execute.
values array Array of arguments for the SQL statement parameters.
successk function Success callback.
error function Error 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");
});