| 1 | .import QtQuick.LocalStorage 2.0 as Sql |
| 2 | |
| 3 | function test() { |
| 4 | var db = Sql.LocalStorage.openDatabaseSync("QmlTestDB-selection", "", "Test database from Qt autotests", 1000000); |
| 5 | var r="transaction_not_finished"; |
| 6 | |
| 7 | db.transaction( |
| 8 | function(tx) { |
| 9 | tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)'); |
| 10 | tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); |
| 11 | tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); |
| 12 | tx.executeSql('CREATE TABLE IF NOT EXISTS TypeTest(num INTEGER, txt1 TEXT, txt2 TEXT)'); |
| 13 | tx.executeSql("INSERT INTO TypeTest VALUES(1, null, 'hello')"); |
| 14 | } |
| 15 | ); |
| 16 | |
| 17 | db.transaction( |
| 18 | function(tx) { |
| 19 | tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); |
| 20 | tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); |
| 21 | var rs = tx.executeSql('SELECT * FROM Greeting'); |
| 22 | if ( rs.rows.length != 4 ) |
| 23 | r = "SELECT RETURNED WRONG VALUE "+rs.rows.length+rs.rows[0]+rs.rows[1] |
| 24 | else |
| 25 | r = "passed"; |
| 26 | } |
| 27 | ); |
| 28 | if (r == "passed") { |
| 29 | db.transaction(function (tx) { |
| 30 | r = ""; |
| 31 | var firstRow = tx.executeSql("SELECT * FROM TypeTest").rows.item(0); |
| 32 | if (typeof(firstRow.num) != "number") |
| 33 | r += " num:" + firstRow.num+ "type:" + typeof(firstRow.num); |
| 34 | if (typeof(firstRow.txt1) != "object" || firstRow.txt1 != null) |
| 35 | r += " txt1:" + firstRow.txt1 + " type:" + typeof(firstRow.txt1); |
| 36 | if (typeof(firstRow.txt2) != "string" || firstRow.txt2 != "hello") |
| 37 | r += " txt2:" + firstRow.txt2 + " type:" + typeof(firstRow.txt2); |
| 38 | if (r == "") |
| 39 | r = "passed"; |
| 40 | else |
| 41 | r = "SELECT RETURNED VALUES WITH WRONG TYPES " + r; |
| 42 | }); |
| 43 | } |
| 44 | |
| 45 | return r; |
| 46 | } |