addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1light-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Vancouver PhoneGap Meetup Message Board › sql example not working and I do not know why HELP please

sql example not working and I do not know why HELP please

A former member
Post #: 3
<meta http-equiv="Content-type" content="text/html; charset=utf-8">

<title>GlucoTracker</title>­


<script type="text/javascript" charset="utf-8" src="phonegap.js"></scri­pt>

<script type="text/javascript" charset="utf-8">
// global variables
var db;
var shortName = 'WebSqlDB';
var version = '1.0';
var displayName = 'WebSqlDB';
var maxSize = 65535;

function onBodyLoad()
{
document.addEventListener("devicere­ady",onDeviceReady,false);
}



/* When this function is called, PhoneGap has been initialized and is ready to roll */
function onDeviceReady()
{
// do your thing!
if (!window.openDatabase) {
alert('Databases are not supported in this browser.');
return;
}

db = openDatabase(shortName, version, displayName, maxSize);

db.transaction(createUserTableIfNotExist­);



}

function createUserTableIfNotExist(transaction) {
transaction.executeSql( 'CREATE TABLE IF NOT EXISTS User (UserId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, FirstName TEXT NOT NULL, LastName TEXT NOT NULL)');
console.log("here I am 1aaaa");
ListDBValues();
}






function AddValueToDB() {
console.log("here I am 1");
if (!window.openDatabase) {
console.log("here I am 2");
alert('Databases are not supported in this browser.');
return;
}
db.transaction(function(transaction) {
transaction.executeSql(
'INSERT INTO User(FirstName, LastName) VALUES (?,?)',
[$('#txFirstName').val(), $('#txLastName').val()],
function() {alert('Record added');},
errorHandler);
});
console.log("here I am 3");
ListDBValues();
console.log("here I am 3_1");
return false;
}


function ListDBValues() {
console.log("here I am 4");
if (!window.openDatabase) {
console.log("here I am 5");
alert('Databases are not supported in this browser.');
return;
}
console.log("here I am 5555");
$('#lbUsers').html('');
console.log("here I am 6");
db.transaction(function(transaction) {
transaction.executeSql('SELECT * FROM User;', [], function(transaction, result) {
if (result != null && result.rows != null) {
for (var i = 0; i < result.rows.length; i++) {
console.log("here I am 7");
var row = result.rows.item(i);
$('#lbUsers').append('<br>' + row.UserId + '. ' + row.FirstName + ' ' + row.LastName);
}
}
}, errorHandler)
});

console.log("here I am 8");
}


function errorHandler(transaction, error) {
alert('Error: ' + error.message + ' code: ' + error.code);
}

</script>
</head>
<body onload="onBodyLoad()">
<h1>WebSQL</h1>
<input id="txFirstName" type="text" placeholder="FirstName">
<input id="txLastName" type="text" placeholder="Last Name">
<input type="button" value="Add record" onClick="AddValueToDB()">
<input type="button" value="Refresh" onClick="ListDBValues()"> <br> <br>
<span style="font-weight:bold;">C­urrently stored values:</span>
<span id="lbUsers"></span>
</body>
</html>
Michael B.
mwbrooks
Vancouver, BC
Post #: 2
Hi Dean,

Please ask this question on the PhoneGap Google Groups: http://groups.google....­

Typically, it is also useful to state what Platform (iOS / Android / BlackBerry / Palm / Symbian / WP7) and what OS you are using.

Michael
A former member
Post #: 4
Hi Michael

I did and have not received an reply. so I thought I would try here

platforms are iOS and Android

If you paste this into a phonegap project as your html page, it should just work, but does not. I am new to phonegap and am puzzled as to why.

I am a Java and objective C programmer and thought wow one tool for both iphone and android, awesome, then I ran into this issue.

If you could assist pointing out why this is not working that would great

Dean-O
Michael B.
mwbrooks
Vancouver, BC
Post #: 3
Hey Dean,

Our Google Groups are extremely active and rarely does a question go unanswered. You should update the question (reply to it) with your platforms and a little more detail (if possible).

We try to keep all of the PhoneGap knowledge / help on the Wiki and Google Groups, so that others can easily search for similar problems / answers.

Michael
Powered by mvnForum

Our Sponsors

  • Adobe

    Helping to sponsor venue + refreshments.

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy