1<!DOCTYPE HTML> 2<html> 3<title>Pseudo-random transactions</title> 4<script src="../head.js"></script> 5<script src="../common.js"></script> 6<script> 7var SELECT_STATEMENT_IN_READ_TRANSACTION = 0; 8var SELECT_STATEMENT_IN_TRANSACTION = 1; 9var INSERT_STATEMENT = 2; 10var UPDATE_STATEMENT = 3; 11var DELETE_STATEMENT = 4; 12var STATEMENTS = 13 [2, 0, 4, 2, 2, 2, 2, 2, 1, 4, 1, 1, 0, 2, 0, 0, 2, 1, 2, 0, 14 4, 4, 2, 3, 3, 4, 3, 1, 3, 3, 2, 4, 3, 3, 2, 3, 1, 1, 4, 2, 15 4, 1, 4, 2, 3, 0, 4, 2, 4, 0, 4, 3, 3, 2, 0, 2, 1, 4, 4, 4, 16 4, 2, 3, 2, 0, 3, 3, 0, 4, 4, 4, 2, 3, 1, 4, 2, 4, 2, 3, 0, 17 2, 4, 0, 4, 2, 2, 4, 0, 3, 2, 3, 2, 3, 2, 0, 0, 4, 0, 2, 0]; 18 19var transactionsCompleted = 0; 20var startTime = 0; 21 22function statementSuccessCallback(tx, data) {} 23function statementErrorCallback(tx, error) {} 24 25function transactionSuccessCallback() { 26 if (++transactionsCompleted == TRANSACTIONS) 27 testComplete(Date.now() - startTime); 28} 29 30function transactionErrorCallback(error) { 31 testComplete(TEST_FAILED); 32} 33 34function customRunTransactions(db) { 35 var selectIDCounter = 0; 36 var insertIDCounter = 0; 37 var updateIDCounter = 0; 38 var deleteIDCounter = 0; 39 var randomString = getRandomString(); 40 var randomStringForUpdates = getRandomString(); 41 startTime = Date.now(); 42 for (var i = 0; i < TRANSACTIONS; i++) { 43 switch (STATEMENTS[i % STATEMENTS.length]) { 44 case SELECT_STATEMENT_IN_READ_TRANSACTION: 45 db.readTransaction( 46 function(tx) { 47 tx.executeSql('SELECT * FROM Test WHERE ID = ?', 48 [selectIDCounter++], 49 statementSuccessCallback, statementErrorCallback); 50 }, transactionErrorCallback, transactionSuccessCallback); 51 break; 52 case SELECT_STATEMENT_IN_TRANSACTION: 53 db.transaction( 54 function(tx) { 55 tx.executeSql('SELECT * FROM Test WHERE ID = ?', 56 [selectIDCounter++], 57 statementSuccessCallback, statementErrorCallback); 58 }, transactionErrorCallback, transactionSuccessCallback); 59 break; 60 case INSERT_STATEMENT: 61 db.transaction( 62 function(tx) { 63 tx.executeSql('INSERT INTO Test VALUES (?, ?)', 64 [insertIDCounter++, randomString], 65 statementSuccessCallback, statementErrorCallback); 66 }, transactionErrorCallback, transactionSuccessCallback); 67 break; 68 case UPDATE_STATEMENT: 69 db.transaction( 70 function(tx) { 71 tx.executeSql('UPDATE Test SET Foo = ? WHERE ID = ?', 72 [randomStringForUpdates, updateIDCounter++], 73 statementSuccessCallback, statementErrorCallback); 74 }, transactionErrorCallback, transactionSuccessCallback); 75 break; 76 case DELETE_STATEMENT: 77 db.transaction( 78 function(tx) { 79 tx.executeSql('DELETE FROM Test WHERE ID = ?', 80 [deleteIDCounter++], 81 statementSuccessCallback, statementErrorCallback); 82 }, transactionErrorCallback, transactionSuccessCallback); 83 break; 84 default: 85 testComplete(TEST_FAILED); 86 return; 87 } 88 } 89} 90</script> 91 92<body> 93<script> 94 runPerformanceTest({ 95 dbName: "PseudoRandomTransactions", 96 readOnly: false, 97 insertRowsAtSetup: true, 98 transactionCallback: null, 99 customRunTransactions: customRunTransactions 100 }); 101</script> 102</body> 103</html> 104