-
-
Save shamsealam/4add6b2401c8eddb5ea1 to your computer and use it in GitHub Desktop.
Java script Code to perform insert operation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var errCallback = function (error, res) { | |
console.log("**************************Database error"); | |
console.dir(res); | |
counter = 0; | |
} | |
var db; | |
var counter; | |
var initDB = function () { | |
db = openDatabase("MyTestDatabase", "1.0", "Transaction Test", 32678); | |
db.transaction(function (transaction) { | |
transaction.executeSql("CREATE TABLE IF NOT EXISTS TEST_TABLE (" + | |
"id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT," + | |
"JSONDATA TEXT NOT NULL, JSONCODE TEXT NOT NULL);"); | |
}); | |
counter = 0; | |
} | |
//SAVE function -> test transaction | |
var save = function (data, code, success, tx) { | |
if (tx) { | |
var successCallback = success.bind(this, tx); | |
tx.executeSql(("INSERT INTO TEST_TABLE (JSONCODE, JSONCODE) VALUES (?, ?);"), [data, code], function (transaction, results) { successCallback(results); }, errCallback); | |
} else { | |
db.transaction(function (transaction) { | |
var successCallback = success.bind(this, transaction); | |
transaction.executeSql(("INSERT INTO TEST_TABLE (JSONCODE, JSONCODE) VALUES (?, ?);"), [data, code], function (transaction, results) { successCallback(results); }, errCallback); | |
}); | |
} | |
}; | |
var form = $("form"); | |
function saveSuccess(tx) { | |
counter++; | |
console.log(counter + "'s data has been saved!"); | |
save($('#data').val(), $('#code').val(), saveSuccess, tx); | |
}; | |
form.submit(function (event) { | |
event.preventDefault(); | |
save($('#data').val(), $('#code').val(), saveSuccess); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment