-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_debugger.html
More file actions
62 lines (52 loc) · 2.1 KB
/
db_debugger.html
File metadata and controls
62 lines (52 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<html>
<head>
<title>DB Debugger 2</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.8.0/sql-wasm.js"></script>
<script src="databases.js"></script>
</head>
<body>
<pre id="out"></pre>
<script>
async function run() {
const out = document.getElementById('out');
let SQL;
try {
SQL = await initSqlJs({ locateFile: file => `https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.8.0/${file}` });
} catch (e) {
out.innerText = "Error initing SQL.js: " + e;
return;
}
const b64 = steelDBs['AISCSections'];
if (!b64) {
out.innerText = "DB not found in databases.js";
return;
}
const binString = atob(b64);
const size = binString.length;
const bytes = new Uint8Array(size);
for (let i = 0; i < size; i++) bytes[i] = binString.charCodeAt(i);
const db = new SQL.Database(bytes);
out.innerText += "--- Tables in DB ---\n";
let res = db.exec("SELECT name FROM sqlite_master WHERE type='table';");
if (res.length > 0) {
out.innerText += JSON.stringify(res[0].values.map(r => r[0]), null, 2) + "\n\n";
}
out.innerText += "--- 'Field Units' Columns ---\n";
res = db.exec("PRAGMA table_info('Field Units');");
if (res.length > 0) {
out.innerText += JSON.stringify(res[0].values.map(r => r[1]), null, 2) + "\n\n";
}
out.innerText += "--- 'Field Units' Data ---\n";
res = db.exec("SELECT * FROM 'Field Units';");
if (res.length > 0) {
out.innerText += JSON.stringify(res[0].columns, null, 2) + "\n";
out.innerText += JSON.stringify(res[0].values, null, 2) + "\n";
} else {
out.innerText += "No data in Field Units.";
}
}
run();
</script>
</body>
</html>