From 178d8c9cb87c5578e5175b5a405d470919644c4d Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 18 Nov 2009 13:02:52 +1000 Subject: Update examples for new SQL API. --- demos/declarative/samegame/content/samegame.js | 32 +++++++--------------- examples/declarative/sql/hello.qml | 29 ++++++-------------- .../samegame/samegame4/content/samegame.js | 32 +++++++--------------- 3 files changed, 29 insertions(+), 64 deletions(-) diff --git a/demos/declarative/samegame/content/samegame.js b/demos/declarative/samegame/content/samegame.js index 4d5a6be..3598c26 100755 --- a/demos/declarative/samegame/content/samegame.js +++ b/demos/declarative/samegame/content/samegame.js @@ -210,34 +210,22 @@ function saveHighScore(name) { if(scoresURL!="") sendHighScore(name); //OfflineStorage - var db = openDatabase("SameGameScores", "1.0", "Local SameGame High Scores",100); + var db = openDatabaseSync("SameGameScores", "1.0", "Local SameGame High Scores",100); var dataStr = "INSERT INTO Scores VALUES(?, ?, ?, ?)"; var data = [name, gameCanvas.score, maxX+"x"+maxY ,Math.floor(timer/1000)]; db.transaction( function(tx) { - tx.executeSql('CREATE TABLE IF NOT EXISTS Scores(name TEXT, score NUMBER, gridSize TEXT, time NUMBER)',[]); + tx.executeSql('CREATE TABLE IF NOT EXISTS Scores(name TEXT, score NUMBER, gridSize TEXT, time NUMBER)'); tx.executeSql(dataStr, data); - tx.executeSql('SELECT * FROM Scores WHERE gridSize = "12x17" ORDER BY score desc LIMIT 10',[], - function(tx, rs) { - var r = "\nHIGH SCORES for a standard sized grid\n\n" - for(var i = 0; i < rs.rows.length; i++){ - r += (i+1)+". " + rs.rows.item(i).name +' got ' - + rs.rows.item(i).score + ' points in ' - + rs.rows.item(i).time + ' seconds.\n'; - } - dialog.show(r); - }, - function(tx, error) { - print("ERROR:", error.message); - } - ); - }, - function() { - print("ERROR in transaction"); - }, - function() { - //print("Transaction successful"); + var rs = tx.executeSql('SELECT * FROM Scores WHERE gridSize = "12x17" ORDER BY score desc LIMIT 10'); + var r = "\nHIGH SCORES for a standard sized grid\n\n" + for(var i = 0; i < rs.rows.length; i++){ + r += (i+1)+". " + rs.rows.item(i).name +' got ' + + rs.rows.item(i).score + ' points in ' + + rs.rows.item(i).time + ' seconds.\n'; + } + dialog.show(r); } ); } diff --git a/examples/declarative/sql/hello.qml b/examples/declarative/sql/hello.qml index dc3ca35..96e0675 100644 --- a/examples/declarative/sql/hello.qml +++ b/examples/declarative/sql/hello.qml @@ -3,35 +3,24 @@ import Qt 4.6 Text { Script { function findGreetings() { - var db = openDatabase("QmlExampleDB", "1.0", "The Example QML SQL!", 1000000); + var db = openDatabaseSync("QmlExampleDB", "1.0", "The Example QML SQL!", 1000000); db.transaction( function(tx) { // Create the database if it doesn't already exist - tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)', []); + tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)'); // Add (another) greeting row tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); // Show all added greetings - tx.executeSql('SELECT * FROM Greeting', [], - function(tx, rs) { - var r = "" - for(var i = 0; i < rs.rows.length; i++) { - r += rs.rows.item(i).salutation + ", " + rs.rows.item(i).salutee + "\n" - } - text = r - }, - function(tx, error) { - print("ERROR:", error.message) - } - ); - }, - function() { - print("ERROR in transaction"); - }, - function() { - print("Transaction successful"); + var rs = tx.executeSql('SELECT * FROM Greeting'); + + var r = "" + for(var i = 0; i < rs.rows.length; i++) { + r += rs.rows.item(i).salutation + ", " + rs.rows.item(i).salutee + "\n" + } + text = r } ) } diff --git a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js index d5778fe..b833385 100755 --- a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js +++ b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js @@ -211,34 +211,22 @@ function saveHighScore(name) { if(scoresURL!="") sendHighScore(name); //OfflineStorage - var db = openDatabase("SameGameScores", "1.0", "Local SameGame High Scores",100); + var db = openDatabaseSync("SameGameScores", "1.0", "Local SameGame High Scores",100); var dataStr = "INSERT INTO Scores VALUES(?, ?, ?, ?)"; var data = [name, gameCanvas.score, maxX+"x"+maxY ,Math.floor(timer/1000)]; db.transaction( function(tx) { - tx.executeSql('CREATE TABLE IF NOT EXISTS Scores(name TEXT, score NUMBER, gridSize TEXT, time NUMBER)',[]); + tx.executeSql('CREATE TABLE IF NOT EXISTS Scores(name TEXT, score NUMBER, gridSize TEXT, time NUMBER)'); tx.executeSql(dataStr, data); - tx.executeSql('SELECT * FROM Scores WHERE gridSize = "12x17" ORDER BY score desc LIMIT 10',[], - function(tx, rs) { - var r = "\nHIGH SCORES for a standard sized grid\n\n" - for(var i = 0; i < rs.rows.length; i++){ - r += (i+1)+". " + rs.rows.item(i).name +' got ' - + rs.rows.item(i).score + ' points in ' - + rs.rows.item(i).time + ' seconds.\n'; - } - dialog.show(r); - }, - function(tx, error) { - print("ERROR:", error.message); - } - ); - }, - function() { - print("ERROR in transaction"); - }, - function() { - //print("Transaction successful"); + var rs = tx.executeSql('SELECT * FROM Scores WHERE gridSize = "12x17" ORDER BY score desc LIMIT 10'); + var r = "\nHIGH SCORES for a standard sized grid\n\n" + for(var i = 0; i < rs.rows.length; i++){ + r += (i+1)+". " + rs.rows.item(i).name +' got ' + + rs.rows.item(i).score + ' points in ' + + rs.rows.item(i).time + ' seconds.\n'; + } + dialog.show(r); } ); } -- cgit v0.12