// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);
// Populate the database
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS BIRDS');
tx.executeSql('CREATE TABLE IF NOT EXISTS BIRDS (id unique, bodyType TEXT NOT NULL, category TEXT NOT NULL, name TEXT NULL, photo TEXT NULL, resource TEXT NULL, caption TEXT NULL)');
tx.executeSql('INSERT INTO BIRDS (id, bodyType, category, name, photo, resource, caption) VALUES (1, "Short Course", "SC8.2e", "SC8.2e Ready-To-Run", "
http://www.teamassociated.com/pictures/cars_and_trucks/SC8.2e/SC8.2e_RTR_2560x2048_sm.jpg", "
http://www.teamassociated.com/cars_and_trucks/SC8.2e/RTR/","Modeled after the short-course race trucks that compete in the Lucas Oil Off Road Racing Series, the SC8.2e RTR takes the next evolutionary step in Team Associated\'s 1:8 scale short-course line by adding the new performance suspension developed on our R.O.A.R. National Championship-winning RC8.2 buggy.")');
tx.executeSql('INSERT INTO BIRDS (id, bodyType, category, name, photo, resource, caption) VALUES (2, "Short Course", "SC10GT", "SC10GT Ready-To-Run", "
http://www.teamassociated.com/pictures/cars_and_trucks/SC10GT/SC10GT_RTR_2560x2048_sm.jpg", "
http://www.teamassociated.com/cars_and_trucks/SC10GT/RTR/","For many people in the RC world, nothing beats a 2-stroke nitro-breathing engine. From the sound, to the smoke, to the brutal power, nitro delivers an experience in a RC truck like nothing else can. Now you can experience that awesome nitro power in the short-course class with the SC10GT!")');
tx.executeSql('INSERT INTO BIRDS (id, bodyType, category, name, photo, resource, caption) VALUES (3, "Short Course", "SC10 4×4", "SC10 4x4 RTR Combo", "
http://www.teamassociated.com/pictures/cars_and_trucks/SC10_4x4/SC10_4x4_Kit_2560x2048_sm.jpg", "
http://www.teamassociated.com/cars_and_trucks/SC10_4x4/RTR_Combo/","The SC10 4x4 Ready-To-Runs are RC replicas of the 800+ horsepower short course trucks driven in the Lucas Oil Off Road Racing Series.")');
tx.executeSql('INSERT INTO BIRDS (id, bodyType, category, name, photo, resource, caption) VALUES (4, "Short Course", "SC10", "SC10 RS RTR Combo", "
http://www.teamassociated.com/pictures/cars_and_trucks/SC10/SC10_RTR_Procomp_2560x2048_sm.jpg", "
http://www.teamassociated.com/cars_and_trucks/SC10/RS_Combo/","The SC10RS (Race-Spec) RTR Combo is a ready-to-run replica of the trucks driven in the Lucas Oil Off Road Racing Series.")');
tx.executeSql('INSERT INTO BIRDS (id, bodyType, category, name, photo, resource, caption) VALUES (5, "Buggy", "RC8.2e", "RC8.2e Factory Team", "
http://www.teamassociated.com/pictures/cars_and_trucks/RC8.2e/RC8.2e_2560x2048_sm.jpg", "
http://www.teamassociated.com/cars_and_trucks/RC8.2e/Factory_Team/","Team Associated has taken all of the refinements from the RC8.2 and have applied them to our electric-power platform. The RC8.2e has already been proven as a winner after TQ\’ing and winning the 2011 Sidewinder Nitro Explosion in the capable hands of Ryan Cavalieri.")');
}
// Query the database.
function queryDB(tx) {
tx.executeSql("SELECT * FROM BIRDS", [], querySuccess, errorCB);
}
// Query the success callback
function querySuccess(tx, results) {
var len = results.rows.length;
console.log("BIRDS table: " + len + " rows found.");
for (var i=0; i<len; i++){
document.getElementById("output").innerHTML +=
"<div class='even'><p class='title'>" + results.rows.item(i).name + "</p>" +
"<img src='' width='100px' height='100px'" + results.rows.item(i).photo + ">" +
"<p class='caption'>" + results.rows.item(i).caption + "</p>" +
"<p class='more'><a href=''" + results.rows.item(i).resource + ">More</a></p>";
}
}
// 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", "Birds", 2000000);
db.transaction(queryDB, errorCB);
}
// Cordova is ready
function onDeviceReady() {
var db = window.openDatabase("Database", "1.0", "Birds", 200000);
db.transaction(populateDB, errorCB, successCB);
}
... and create this html page to add another row to it, it doesn't add any data:
<!DOCTYPE html>
<html>
<head>
<title>Prepopulated DB (PG Storage Example)</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
<script type="text/javascript" charset="utf-8" src="storage2.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
var db = window.openDatabase("Database", "1.0", "Birds", 200000);
db.transaction(populateDB, errorCB, successCB);
function populateDB(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS BIRDS (id unique, bodyType TEXT NOT NULL, category TEXT NOT NULL, name TEXT NULL, photo TEXT NULL, resource TEXT NULL, caption TEXT NULL)');
tx.executeSql('INSERT INTO BIRDS (id, bodyType, category, name, photo, resource, caption) VALUES (1, "Short Course", "new", "new", "
http://www.teamassociated.com/pictures/cars_and_trucks/SC8.2e/SC8.2e_RTR_2560x2048_sm.jpg", "
http://www.teamassociated.com/cars_and_trucks/SC8.2e/RTR/","NEW.")');
}
</script>
</head>
<body onload="onDeviceReady()">
<button value="bookmark" onclick="populateDB(tx)">Add Bookmark</button>
</body>
</html>
I want to adapt the Storage DB to create bookmarks from any page (each row showing unique ID, page title, and page filename). Why won't the above code work?