diff options
Diffstat (limited to 'tests/auto/declarative/sql/data')
17 files changed, 355 insertions, 0 deletions
diff --git a/tests/auto/declarative/sql/data/README b/tests/auto/declarative/sql/data/README new file mode 100644 index 0000000..7efca3a --- /dev/null +++ b/tests/auto/declarative/sql/data/README @@ -0,0 +1,3 @@ +These tests are executed in sequence - the database persist until the end of the +testing. This is done to better exercise the persistence of the database, since +that is how it is used. diff --git a/tests/auto/declarative/sql/data/changeversion.js b/tests/auto/declarative/sql/data/changeversion.js new file mode 100644 index 0000000..680d7a6 --- /dev/null +++ b/tests/auto/declarative/sql/data/changeversion.js @@ -0,0 +1,53 @@ +function test() { + var r="transaction_not_finished"; + + var db = openDatabaseSync("QmlTestDB-changeversion", "", "Test database from Qt autotests", 1000000, + function(db) { + db.changeVersion("","1.0") + db.transaction(function(tx){ + tx.executeSql('CREATE TABLE Greeting(salutation TEXT, salutee TEXT)'); + }) + }); + + db.transaction(function(tx){ + tx.executeSql('INSERT INTO Greeting VALUES ("Hello", "world")'); + tx.executeSql('INSERT INTO Greeting VALUES ("Goodbye", "cruel world")'); + }); + + + db = openDatabaseSync("QmlTestDB-changeversion", "", "Test database from Qt autotests", 1000000); + + if (db.version == "1.0") + db.changeVersion("1.0","2.0",function(tx) + { + tx.executeSql('CREATE TABLE Utterance(type TEXT, phrase TEXT)') + var rs = tx.executeSql('SELECT * FROM Greeting'); + for (var i=0; i<rs.rows.length; ++i) { + var type = "Greeting"; + var phrase = rs.rows.item(i).salutation + ", " + rs.rows.item(i).salutee; + if (rs.rows.item(i).salutation == "Goodbye" + || rs.rows.item(i).salutation == "Farewell" + || rs.rows.item(i).salutation == "Good-bye") type = "Valediction"; + var ins = tx.executeSql('INSERT INTO Utterance VALUES(?,?)',[type,phrase]); + } + tx.executeSql('DROP TABLE Greeting'); + }); + else + return "db.version should be 1.0, but is " + db.version; + + var db = openDatabaseSync("QmlTestDB-changeversion", "2.0", "Test database from Qt autotests", 1000000); + + db.transaction(function(tx){ + var rs = tx.executeSql('SELECT * FROM Utterance'); + r = "" + for (var i=0; i<rs.rows.length; ++i) { + r += "(" + rs.rows.item(i).type + ": " + rs.rows.item(i).phrase + ")"; + } + if (r == "(Greeting: Hello, world)(Valediction: Goodbye, cruel world)") + r = "passed" + else + r = "WRONG DATA: " + r; + }) + + return r; +} diff --git a/tests/auto/declarative/sql/data/creation-a.js b/tests/auto/declarative/sql/data/creation-a.js new file mode 100644 index 0000000..bd7d5c5 --- /dev/null +++ b/tests/auto/declarative/sql/data/creation-a.js @@ -0,0 +1,18 @@ +function test() { + var r="transaction_not_finished"; + + var db = openDatabaseSync("QmlTestDB-creation-a", "1.0", "Test database from Qt autotests", 1000000, + function(db) { + db.transaction(function(tx){ + tx.executeSql('CREATE TABLE Greeting(salutation TEXT, salutee TEXT)'); + r = "passed"; + }) + }); + + var db = openDatabaseSync("QmlTestDB-creation-a", "1.0", "Test database from Qt autotests", 1000000, + function(db) { + r = "FAILED: should have already been created"; + }); + + return r; +} diff --git a/tests/auto/declarative/sql/data/creation.js b/tests/auto/declarative/sql/data/creation.js new file mode 100644 index 0000000..317b4c1 --- /dev/null +++ b/tests/auto/declarative/sql/data/creation.js @@ -0,0 +1,14 @@ +function test() { + var r="transaction_not_finished"; + var db = openDatabaseSync("QmlTestDB-creation", "1.0", "Test database from Qt autotests", 1000000); + + db.transaction( + function(tx) { + tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)'); + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + r = "passed"; + } + ); + + return r; +} diff --git a/tests/auto/declarative/sql/data/error-a.js b/tests/auto/declarative/sql/data/error-a.js new file mode 100644 index 0000000..10a23f6 --- /dev/null +++ b/tests/auto/declarative/sql/data/error-a.js @@ -0,0 +1,20 @@ +function test() { + var db = openDatabaseSync("QmlTestDB-error-a", "1.0", "Test database from Qt autotests", 1000000); + var r="transaction_not_finished"; + + try { + db.transaction( + function(tx) { + var rs = tx.executeSql('SELECT * FROM NotExists'); + r = "SHOULD NOT SUCCEED"; + } + ); + } catch (err) { + if (err.message == "no such table: NotExists Unable to execute statement") + r = "passed"; + else + r = "WRONG ERROR="+err.message; + } + + return r; +} diff --git a/tests/auto/declarative/sql/data/error-b.js b/tests/auto/declarative/sql/data/error-b.js new file mode 100644 index 0000000..4dd0ecf --- /dev/null +++ b/tests/auto/declarative/sql/data/error-b.js @@ -0,0 +1,13 @@ +function test() { + var db = openDatabaseSync("QmlTestDB-error-b", "1.0", "Test database from Qt autotests", 1000000); + var r="transaction_not_finished"; + + db.transaction( + function(tx) { + tx.executeSql('INSERT INTO Greeting VALUES("junk","junk")'); + notexist[123] = "oops" + } + ); + + return r; +} diff --git a/tests/auto/declarative/sql/data/error-creation.js b/tests/auto/declarative/sql/data/error-creation.js new file mode 100644 index 0000000..92245fd --- /dev/null +++ b/tests/auto/declarative/sql/data/error-creation.js @@ -0,0 +1,12 @@ +function test() { + var r="transaction_not_finished"; + try { + var db = openDatabaseSync("QmlTestDB-creation", "2.0", "Test database from Qt autotests", 1000000); + } catch (err) { + if (err.message == "SQL: database version mismatch") + r = "passed"; + else + r = "WRONG ERROR="+err.message; + } + return r; +} diff --git a/tests/auto/declarative/sql/data/error-notransaction.js b/tests/auto/declarative/sql/data/error-notransaction.js new file mode 100644 index 0000000..b9cc647 --- /dev/null +++ b/tests/auto/declarative/sql/data/error-notransaction.js @@ -0,0 +1,15 @@ +function test() { + var db = openDatabaseSync("QmlTestDB-data/error-notransaction", "1.0", "Test database from Qt autotests", 1000000); + var r="transaction_not_finished"; + + try { + db.transaction(); + } catch (err) { + if (err.message == "transaction: missing callback") + r = "passed"; + else + r = "WRONG ERROR="+err.message; + } + + return r; +} diff --git a/tests/auto/declarative/sql/data/error-outsidetransaction.js b/tests/auto/declarative/sql/data/error-outsidetransaction.js new file mode 100644 index 0000000..a7af3bd --- /dev/null +++ b/tests/auto/declarative/sql/data/error-outsidetransaction.js @@ -0,0 +1,17 @@ +function test() { + var db = openDatabaseSync("QmlTestDB-data/error-notransaction", "1.0", "Test database from Qt autotests", 1000000); + var r="transaction_not_finished"; + var v; + + try { + db.transaction(function(tx) { v = tx }); + v.executeSql("SELECT 'bad'") + } catch (err) { + if (err.message == "executeSql called outside transaction()") + r = "passed"; + else + r = "WRONG ERROR="+err.message; + } + + return r; +} diff --git a/tests/auto/declarative/sql/data/iteration-forwardonly.js b/tests/auto/declarative/sql/data/iteration-forwardonly.js new file mode 100644 index 0000000..45947c0 --- /dev/null +++ b/tests/auto/declarative/sql/data/iteration-forwardonly.js @@ -0,0 +1,29 @@ +function test() { + var db = openDatabaseSync("QmlTestDB-iteration-forwardonly", "", "Test database from Qt autotests", 1000000); + var r="transaction_not_finished"; + + db.transaction( + function(tx) { + tx.executeSql('CREATE TABLE Greeting(salutation TEXT, salutee TEXT)'); + tx.executeSql('INSERT INTO Greeting VALUES ("Hello", "world")'); + tx.executeSql('INSERT INTO Greeting VALUES ("Goodbye", "cruel world")'); + } + ) + + db.transaction( + function(tx) { + var rs = tx.executeSql('SELECT * FROM Greeting'); + rs.forwardOnly = !rs.forwardOnly + var r1="" + for(var i = 0; i < rs.rows.length; i++) + r1 += rs.rows.item(i).salutation + ", " + rs.rows.item(i).salutee + ";" + if (r1 != "hello, world;hello, world;hello, world;hello, world;") + if (r1 != "Hello, world;Goodbye, cruel world;") + r = "SELECTED DATA WRONG: "+r1; + else + r = "passed"; + } + ); + + return r; +} diff --git a/tests/auto/declarative/sql/data/iteration.js b/tests/auto/declarative/sql/data/iteration.js new file mode 100644 index 0000000..c34cbbb --- /dev/null +++ b/tests/auto/declarative/sql/data/iteration.js @@ -0,0 +1,28 @@ +function test() { + var db = openDatabaseSync("QmlTestDB-iteration", "", "Test database from Qt autotests", 1000000); + var r="transaction_not_finished"; + + db.transaction( + function(tx) { + tx.executeSql('CREATE TABLE Greeting(salutation TEXT, salutee TEXT)'); + tx.executeSql('INSERT INTO Greeting VALUES ("Hello", "world")'); + tx.executeSql('INSERT INTO Greeting VALUES ("Goodbye", "cruel world")'); + } + ) + + db.transaction( + function(tx) { + var rs = tx.executeSql('SELECT * FROM Greeting'); + var r1="" + for(var i = 0; i < rs.rows.length; i++) + r1 += rs.rows.item(i).salutation + ", " + rs.rows.item(i).salutee + ";" + if (r1 != "hello, world;hello, world;hello, world;hello, world;") + if (r1 != "Hello, world;Goodbye, cruel world;") + r = "SELECTED DATA WRONG: "+r1; + else + r = "passed"; + } + ); + + return r; +} diff --git a/tests/auto/declarative/sql/data/readonly-error.js b/tests/auto/declarative/sql/data/readonly-error.js new file mode 100644 index 0000000..69ec67f --- /dev/null +++ b/tests/auto/declarative/sql/data/readonly-error.js @@ -0,0 +1,27 @@ +function test() { + var r="transaction_not_finished"; + var db = openDatabaseSync("QmlTestDB-readonly-error", "1.0", "Test database from Qt autotests", 1000000); + + db.transaction( + function(tx) { + tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)'); + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + } + ); + + try { + db.readTransaction( + function(tx) { + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + r = "FAILED"; + } + ); + } catch (err) { + if (err.message == "Read-only Transaction") + r = "passed"; + else + r = "WRONG ERROR="+err.message; + } + + return r; +} diff --git a/tests/auto/declarative/sql/data/readonly.js b/tests/auto/declarative/sql/data/readonly.js new file mode 100644 index 0000000..5ee862c --- /dev/null +++ b/tests/auto/declarative/sql/data/readonly.js @@ -0,0 +1,24 @@ +function test() { + var r="transaction_not_finished"; + var db = openDatabaseSync("QmlTestDB-readonly", "1.0", "Test database from Qt autotests", 1000000); + + db.transaction( + function(tx) { + tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)'); + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + r = "passed"; + } + ); + + db.readTransaction( + function(tx) { + var rs = tx.executeSql('SELECT * FROM Greeting'); + if (rs.rows.item(0).salutation == 'hello') + r = "passed"; + else + r = "FAILED"; + } + ); + + return r; +} diff --git a/tests/auto/declarative/sql/data/reopen1.js b/tests/auto/declarative/sql/data/reopen1.js new file mode 100644 index 0000000..c1a8157 --- /dev/null +++ b/tests/auto/declarative/sql/data/reopen1.js @@ -0,0 +1,14 @@ +function test() { + var r="transaction_not_finished"; + var db = openDatabaseSync("QmlTestDB-reopen", "1.0", "Test database from Qt autotests", 1000000); + + db.transaction( + function(tx) { + tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)'); + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + r = "passed"; + } + ); + + return r; +} diff --git a/tests/auto/declarative/sql/data/reopen2.js b/tests/auto/declarative/sql/data/reopen2.js new file mode 100644 index 0000000..4f7248f --- /dev/null +++ b/tests/auto/declarative/sql/data/reopen2.js @@ -0,0 +1,16 @@ +function test() { + var r="transaction_not_finished"; + var db = openDatabaseSync("QmlTestDB-reopen", "1.0", "Test database from Qt autotests", 1000000); + + db.transaction( + function(tx) { + var rs = tx.executeSql('SELECT * FROM Greeting'); + if (rs.rows.item(0).salutation == 'hello') + r = "passed"; + else + r = "FAILED"; + } + ); + + return r; +} diff --git a/tests/auto/declarative/sql/data/selection-bindnames.js b/tests/auto/declarative/sql/data/selection-bindnames.js new file mode 100644 index 0000000..9786821 --- /dev/null +++ b/tests/auto/declarative/sql/data/selection-bindnames.js @@ -0,0 +1,26 @@ +function test() { + var db = openDatabaseSync("QmlTestDB-bindnames", "", "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(?, ?)', [ 'goodbye', 'world' ]); + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'there' ]); + } + ); + + db.transaction( + function(tx) { + var rs = tx.executeSql('SELECT * FROM Greeting WHERE salutation=:p2 AND salutee=:p1', {':p1':'world', ':p2':'hello'}); + if ( rs.rows.length != 2 ) + r = "SELECT RETURNED WRONG VALUE "+rs.rows.length+rs.rows.item(0)+rs.rows.item(1) + else + r = "passed"; + } + ); + + return r; +} diff --git a/tests/auto/declarative/sql/data/selection.js b/tests/auto/declarative/sql/data/selection.js new file mode 100644 index 0000000..f116eff --- /dev/null +++ b/tests/auto/declarative/sql/data/selection.js @@ -0,0 +1,26 @@ +function test() { + var db = 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' ]); + } + ); + + 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"; + } + ); + + return r; +} |