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