3 function checkCompletion()
5 // The test should end after two transactions
6 if (++complete == 2 && window.testRunner)
7 testRunner.notifyDone();
10 // Opens the database used in this test case
11 function openTestDatabase()
13 return openDatabaseWithSuffix("MultipleTransactionsOnDifferentHandlesTest",
15 "Test to make sure that queueing multiple transactions on different DB handles does not result in a deadlock.",
19 function statementSuccessCallback(dbName, statementType)
21 log(dbName + " " + statementType + " statement succeeded");
24 function statementErrorCallback(dbName, statementType, error)
26 log(dbName + " " + statementType + " statement failed: " + error.message);
29 // Runs a transaction on the given database
30 function runTransaction(db, dbName, val)
32 db.transaction(function(tx) {
33 // Execute a read-only statement
34 tx.executeSql("SELECT COUNT(*) FROM Test;", [],
35 function(result) { statementSuccessCallback(dbName, "read"); },
36 function(tx, error) { statementErrorCallback(dbName, "read", error); });
38 // Execute a write statement to make sure SQLite tries to acquire an exclusive lock on the DB file
39 tx.executeSql("INSERT INTO Test VALUES (?);", [val],
40 function(result) { statementSuccessCallback(dbName, "write"); },
41 function(tx, error) { statementErrorCallback(dbName, "write", error); });
43 // Transaction failure callback
44 log(dbName + " transaction failed: " + error.message);
47 // Transaction success callback
48 log(dbName + " transaction succeeded");
53 // We need to guarantee that the Test table exists before we run our test.
54 // Therefore, the test code is in the successCallback of the transaction that creates the table.
57 var db = openTestDatabase();
58 db.transaction(function(tx) {
59 // Create the Test table if it does not exist
60 tx.executeSql("CREATE TABLE IF NOT EXISTS Test (Foo int);", [],
61 function(result) {}, function(tx, error) {});
63 log("Creating the Test table failed: " + error.message);
65 // The Test table was created successfully
66 var db1 = openTestDatabase();
67 var db2 = openTestDatabase();
69 log("failure: db1 == db2");
71 runTransaction(db1, "db1", 1);
72 runTransaction(db2, "db2", 2);