From f56f8418ece38e74cdf2830dcd7f9660631295b1 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 20 Oct 2009 10:33:54 +1000 Subject: asynchronous --- examples/declarative/sql/hello.qml | 46 ++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/examples/declarative/sql/hello.qml b/examples/declarative/sql/hello.qml index db568a9..20ea611 100644 --- a/examples/declarative/sql/hello.qml +++ b/examples/declarative/sql/hello.qml @@ -2,28 +2,36 @@ import Qt 4.6 Text { Script { - function allGreetings() - { + function findGreetings() { var db = openDatabase("QmlExampleDB", "", "The Example QML SQL!", 1000000); - var r = "" - db.transaction(function(tx) { - tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)', []); - tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); - tx.executeSql('SELECT * FROM Greeting', [], - function(tx, rs) { - for(var i = 0; i < rs.rows.length; i++) { - r += rs.rows.item(i).salutation + ", " + rs.rows.item(i).salutee + "\n" + db.transaction( + function(tx) { + tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)', []); + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + 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(tx, error) { - print("ERROR:", error.message) - } - ); - }) - - return r + ); + }, + function() { + print("ERROR in transaction"); + }, + function() { + print("Transaction successful"); + } + ) } } - text: allGreetings() + text: "?" + Component.onCompleted: findGreetings() } + -- cgit v0.12