Created
April 22, 2011 18:28
-
-
Save macdonst/937307 to your computer and use it in GitHub Desktop.
Opendatabase issue on Android 3.0
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | |
"http://www.w3.org/TR/html4/strict.dtd"> | |
<html> | |
<head> | |
<title>Contact Example</title> | |
<script type="text/javascript" charset="utf-8" src="phonegap.0.9.4.js"></script> | |
<script type="text/javascript" charset="utf-8"> | |
// Wait for PhoneGap to load | |
// | |
function onLoad() { | |
document.addEventListener("deviceready", onDeviceReady, false); | |
} | |
// Populate the database | |
// | |
function populateDB(tx) { | |
tx.executeSql('DROP TABLE IF EXISTS DEMO'); | |
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)'); | |
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")'); | |
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")'); | |
} | |
// Query the database | |
// | |
function queryDB(tx) { | |
tx.executeSql('SELECT * FROM DEMO', [], querySuccess, errorCB); | |
} | |
// Query the success callback | |
// | |
function querySuccess(tx, results) { | |
// this will be empty since no rows were inserted. | |
console.log("Insert ID = " + results.insertId); | |
// this will be 0 since it is a select statement | |
console.log("Rows Affected = " + results.rowAffected); | |
// the number of rows returned by the select statement | |
console.log("Insert ID = " + results.rows.length); | |
} | |
// Transaction error callback | |
// | |
function errorCB(err) { | |
console.log("Error processing SQL: "+err.code); | |
} | |
// Transaction success callback | |
// | |
function successCB() { | |
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000); | |
db.transaction(queryDB, errorCB); | |
} | |
// PhoneGap is ready | |
// | |
function onDeviceReady() { | |
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000); | |
db.transaction(populateDB, errorCB, successCB); | |
} | |
</script> | |
</head> | |
<body onload="onLoad()"> | |
<h1>Example</h1> | |
<p>Database</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment