mirror of
https://github.com/moparisthebest/PhoneGap-SQLitePlugin-Android
synced 2024-11-26 18:32:17 -05:00
116 lines
3.8 KiB
HTML
116 lines
3.8 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<meta name="viewport" content="width=320; user-scalable=no" />
|
|
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
|
|
|
<title>SQLitePlugin test</title>
|
|
|
|
<link rel="stylesheet" href="qunit-1.5.0.css" />
|
|
|
|
<script type="text/javascript" charset="utf-8" src="cordova-2.2.0.js"></script>
|
|
<script type="text/javascript" charset="utf-8" src="SQLitePlugin.js"></script>
|
|
<script type="text/javascript" charset="utf-8" src="qunit-1.5.0.js"></script>
|
|
|
|
<script>
|
|
|
|
document.addEventListener("deviceready", doTest, false);
|
|
|
|
function doTest() {
|
|
|
|
test( "db transaction test", function() {
|
|
|
|
var db = window.sqlitePlugin.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
|
|
|
|
ok(!!db, "db object");
|
|
|
|
stop(9);
|
|
|
|
db.transaction(function(tx) {
|
|
|
|
start(1);
|
|
ok(!!tx, "tx object");
|
|
|
|
tx.executeSql('DROP TABLE IF EXISTS test_table');
|
|
tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)');
|
|
|
|
tx.executeSql("INSERT INTO test_table (data, data_num) VALUES (?,?)", ["test", 100], function(tx, res) {
|
|
start(1);
|
|
ok(!!tx, "tx object");
|
|
ok(!!res, "res object");
|
|
|
|
console.log("insertId: " + res.insertId + " -- probably 1");
|
|
console.log("rowsAffected: " + res.rowsAffected + " -- should be 1");
|
|
|
|
ok(!!res.insertId, "Valid res.insertId"); /* issue #18 (Android) */
|
|
equal(res.rowsAffected, 1, "res rows affected"); /* #18 and/or #22 (Android) */
|
|
|
|
db.transaction(function(tx) {
|
|
start(1);
|
|
ok(!!tx, "second tx object");
|
|
|
|
tx.executeSql("SELECT count(id) as cnt from test_table;", [], function(tx, res) {
|
|
start(1);
|
|
|
|
console.log("res.rows.length: " + res.rows.length + " -- should be 1");
|
|
console.log("res.rows.item(0).cnt: " + res.rows.item(0).cnt + " -- should be 1");
|
|
|
|
equal(res.rows.length, 1, "res rows length");
|
|
equal(res.rows.item(0).cnt, 1, "select count");
|
|
});
|
|
|
|
tx.executeSql("SELECT data_num from test_table;", [], function(tx, res) {
|
|
start(1);
|
|
|
|
equal(res.rows.length, 1, "SELECT res rows length");
|
|
equal(res.rows.item(0).data_num, 100, "SELECT data_num");
|
|
});
|
|
|
|
tx.executeSql("UPDATE test_table SET data_num = ? WHERE data_num = 100", [101], function(tx, res) {
|
|
start(1);
|
|
|
|
console.log("UPDATE rowsAffected: " + res.rowsAffected + " -- should be 1");
|
|
|
|
equal(res.rowsAffected, 1, "UPDATE res rows affected"); /* issue #22 (Android) */
|
|
});
|
|
|
|
tx.executeSql("SELECT data_num from test_table;", [], function(tx, res) {
|
|
start(1);
|
|
|
|
equal(res.rows.length, 1, "SELECT res rows length");
|
|
equal(res.rows.item(0).data_num, 101, "SELECT data_num");
|
|
});
|
|
|
|
tx.executeSql("DELETE FROM test_table WHERE data LIKE 'tes%'", [], function(tx, res) {
|
|
start(1);
|
|
|
|
console.log("DELETE rowsAffected: " + res.rowsAffected + " -- should be 1");
|
|
|
|
equal(res.rowsAffected, 1, "DELETE res rows affected"); /* issue #22 (Android) */
|
|
});
|
|
|
|
tx.executeSql("SELECT data_num from test_table;", [], function(tx, res) {
|
|
start(1);
|
|
|
|
equal(res.rows.length, 0, "SELECT res rows length");
|
|
});
|
|
|
|
});
|
|
|
|
}, function(e) {
|
|
console.log("ERROR: " + e.message);
|
|
});
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</head>
|
|
<body>
|
|
<div id="qunit"></div>
|
|
</body>
|
|
</html>
|