| 1 | .import QtQuick.LocalStorage 2.0 as Sql |
| 2 | |
| 3 | function test() { |
| 4 | var r="transaction_not_finished"; |
| 5 | |
| 6 | var db = Sql.LocalStorage.openDatabaseSync("QmlTestDB-changeversion", "", "Test database from Qt autotests", 1000000, |
| 7 | function(db) { |
| 8 | db.changeVersion("","1.0") |
| 9 | db.transaction(function(tx){ |
| 10 | tx.executeSql('CREATE TABLE Greeting(salutation TEXT, salutee TEXT)'); |
| 11 | }) |
| 12 | }); |
| 13 | |
| 14 | db.transaction(function(tx){ |
| 15 | tx.executeSql('INSERT INTO Greeting VALUES ("Hello", "world")'); |
| 16 | tx.executeSql('INSERT INTO Greeting VALUES ("Goodbye", "cruel world")'); |
| 17 | }); |
| 18 | |
| 19 | |
| 20 | db = Sql.LocalStorage.openDatabaseSync("QmlTestDB-changeversion", "", "Test database from Qt autotests", 1000000); |
| 21 | |
| 22 | if (db.version == "1.0") |
| 23 | db.changeVersion("1.0","2.0",function(tx) |
| 24 | { |
| 25 | tx.executeSql('CREATE TABLE Utterance(type TEXT, phrase TEXT)') |
| 26 | var rs = tx.executeSql('SELECT * FROM Greeting'); |
| 27 | for (var i=0; i<rs.rows.length; ++i) { |
| 28 | var type = "Greeting"; |
| 29 | var phrase = rs.rows.item(i).salutation + ", " + rs.rows.item(i).salutee; |
| 30 | if (rs.rows.item(i).salutation == "Goodbye" |
| 31 | || rs.rows.item(i).salutation == "Farewell" |
| 32 | || rs.rows.item(i).salutation == "Good-bye") type = "Valediction"; |
| 33 | var ins = tx.executeSql('INSERT INTO Utterance VALUES(?,?)',[type,phrase]); |
| 34 | } |
| 35 | tx.executeSql('DROP TABLE Greeting'); |
| 36 | }); |
| 37 | else |
| 38 | return "db.version should be 1.0, but is " + db.version; |
| 39 | |
| 40 | var db = Sql.LocalStorage.openDatabaseSync("QmlTestDB-changeversion", "2.0", "Test database from Qt autotests", 1000000); |
| 41 | |
| 42 | db.transaction(function(tx){ |
| 43 | var rs = tx.executeSql('SELECT * FROM Utterance'); |
| 44 | r = "" |
| 45 | for (var i=0; i<rs.rows.length; ++i) { |
| 46 | r += "(" + rs.rows.item(i).type + ": " + rs.rows.item(i).phrase + ")"; |
| 47 | } |
| 48 | if (r == "(Greeting: Hello, world)(Valediction: Goodbye, cruel world)") |
| 49 | r = "passed" |
| 50 | else |
| 51 | r = "WRONG DATA: " + r; |
| 52 | }) |
| 53 | |
| 54 | return r; |
| 55 | } |