aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlsqldatabase/data/selection.js
blob: 18d4dce80fb4821dd1d7f81f353da416ab611fe5 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
.import QtQuick.LocalStorage 2.0 as Sql

function test() {
    var db = Sql.openDatabaseSync("QmlTestDB-selection", "", "Test database from Qt autotests", 1000000);
    var r="transaction_not_finished";

    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('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]);
            tx.executeSql('CREATE TABLE IF NOT EXISTS TypeTest(num INTEGER, txt1 TEXT, txt2 TEXT)');
            tx.executeSql("INSERT INTO TypeTest VALUES(1, null, 'hello')");
        }
    );

    db.transaction(
        function(tx) {
            tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]);
            tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]);
            var rs = tx.executeSql('SELECT * FROM Greeting');
            if ( rs.rows.length != 4 )
                r = "SELECT RETURNED WRONG VALUE "+rs.rows.length+rs.rows[0]+rs.rows[1]
            else
                r = "passed";
        }
    );
    if (r == "passed") {
        db.transaction(function (tx) {
            r = "";
            var firstRow = tx.executeSql("SELECT * FROM TypeTest").rows.item(0);
            if (typeof(firstRow.num) != "number")
                r += " num:" + firstRow.num+ "type:" + typeof(firstRow.num);
            if (typeof(firstRow.txt1) != "object" || firstRow.txt1 != null)
                r += " txt1:" + firstRow.txt1 + " type:" + typeof(firstRow.txt1);
            if (typeof(firstRow.txt2) != "string" || firstRow.txt2 != "hello")
                r += " txt2:" + firstRow.txt2 + " type:" + typeof(firstRow.txt2);
            if (r == "")
               r = "passed";
            else
               r = "SELECT RETURNED VALUES WITH WRONG TYPES " + r;
        });
    }

    return r;
}