| 92 | }; |
| 93 | |
| 94 | const dropAllTables = () => { |
| 95 | try { |
| 96 | db.transaction(function (tx) { |
| 97 | tx.executeSql( |
| 98 | "SELECT name FROM sqlite_master WHERE type='table' and name !='__WebKitDatabaseInfoTable__'", |
| 99 | [], |
| 100 | function (tx, result) { |
| 101 | const len = result.rows.length; |
| 102 | const tableNames = []; |
| 103 | for (let i = 0; i < len; i++) { |
| 104 | const tableName = result.rows.item(i).name; |
| 105 | tableNames.push(`'${tableName}'`); |
| 106 | db.transaction(function (tx) { |
| 107 | tx.executeSql('DROP TABLE ' + tableName); |
| 108 | }); |
| 109 | } |
| 110 | pre.textContent = `Dropped table${tableNames.length > 1 ? 's' : ''}: ${tableNames.join(', ')}.`; |
| 111 | } |
| 112 | ); |
| 113 | }); |
| 114 | } catch (err) { |
| 115 | console.error(err.name, err.message); |
| 116 | } |
| 117 | }; |
| 118 | |
| 119 | webSQLCreateButton.addEventListener('click', () => createWebSQLDatabase()); |
| 120 | |