summaryrefslogtreecommitdiffstats
path: root/examples/declarative/sql/hello.qml
blob: db568a9f4d3dc36094cb6f278f7e4879c6cd4f7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import Qt 4.6

Text {
    Script {
        function allGreetings()
        {
            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"
                        }
                    },
                    function(tx, error) {
                        print("ERROR:", error.message)
                    }
                );
            })

            return r
        }
    }
    text: allGreetings()
}