-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTableReader.html
212 lines (179 loc) · 7.05 KB
/
TableReader.html
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!DOCTYPE html>
<html>
<head>
<title>Database table reader</title>
<style>
#container
{
display: grid;
grid-template-columns: 150px auto;
grid-template-areas:
"types databases"
"settings settings"
"controls query"
"buttons contents";
}
#types { grid-area: types }
#databases { grid-area: databases }
#settings { grid-area: settings }
#controls { grid-area: controls }
#query { grid-area: query }
#buttons { grid-area: buttons }
#contents { grid-area: contents }
#types { background-color: #CFFFAF; }
#databases { background-color: #DBEAFA; }
#settings { background-color: #EFDEFF; }
#controls { background-color: #FAFEBF; }
#query { background-color: #FFEBEC; }
#buttons { background-color: #FFFCAF; }
#contents { background-color: #DDFFED; }
header
{
padding: 25px 0 25px 0;
}
table, tr, td
{
border-width: 1px;
border-style: solid;
border-color: #CCC;
border-collapse: collapse;
white-space: nowrap;
font-family: monospace;
}
th
{
text-align: left;
background-color: #DDD;
border-color: #AAA
}
</style>
</head>
<body>
<template id="spinner">
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 38 38" stroke="#88E">
<g fill="none" fill-rule="evenodd">
<g transform="translate(1 1)" stroke-width="2">
<circle stroke-opacity=".5" cx="18" cy="18" r="18"/>
<path d="M36 18c0-9.94-8.06-18-18-18">
<animateTransform attributeName="transform" type="rotate" from="0 18 18" to="360 18 18" dur="1s" repeatCount="indefinite"/>
</path>
</g>
</g>
</svg>
</template>
<main id="container">
<header id="types">
Type:<br>
<input type="radio" name="optType" id="MDB" checked /> <label for="MDB">MDB</label><br>
<input type="radio" name="optType" id="SQL" /> <label for="SQL">SQL</label><br><br>
</header>
<header id="databases">
Databases:<br>
<button onclick="switchDb('SchemaTest.mdb')">SchemaTest.mdb</button>
<button onclick="switchDb('MfgHist.mdb')">MfgHist.mdb</button>
<button onclick="switchDb('FloorSys')">FloorSys</button><br>
<button onclick="switchDb('Packers.mdb')">Packers.mdb</button>
<button onclick="switchDb('Bridge.mdb')">Bridge.mdb</button>
<button onclick="switchDb('Ms3Edi.mdb')">Ms3Edi.mdb</button>
</header>
<header id="settings">
Server URI: <input type="text" id="txtServerURI" size="30" value="http://10.220.36.15:8889/" ></input><br>
MDB Database: <input type="text" id="txtDatabase" size="60" value="T:\Databases\Admin\SchemaTest.mdb" ></input><br><br>
SQL Server: <input type="text" id="txtSQLServer" size="15" value="SRV03" ></input>
SQL Instance: <input type="text" id="txtSQLInstance" size="15" value="FloorSysDB" ></input>
</header>
<header id="controls">
Top: <input type="number" id="numRows" value="100" min="1" max="10000000"></input><br>
<h5>(for tables below)</h5>
</header>
<header id="query">
Query:<br>
<textarea id="txtQuery" rows="5" cols="50"></textarea><br>
<button onclick="queryBtnClick()">Run...</button>
</header>
<nav id="buttons"></nav>
<section id="contents"></section>
</main>
<script defer>
let currentTable = '';
let orderBy = '';
let getPostBody = (type, db, qry) =>
({
method: 'POST',
headers: {'Content-Type': 'text/plain'},
body: type + '://' + db + '\r\n //// \r\n' + qry
});
let toTable = (table, th) =>
table ?
"<table>"
+ th.map(v => `<th> <a href="#" onclick="orderBy = '${v}'; tableBtnClick('${currentTable}');">${v}</a></th>`).join('')
+ table.map((tr) =>
'<tr>' + tr.map((td) =>
`<td>${td}</td>`).join('')
+ '</tr>').join('')
+ '</table>'
: 'Data not found.';
let getData = async (type, uri, db, qry) =>
JSON.parse(await fetch(uri, getPostBody(type, db, qry)).then(res => res.text()));
let queryBtnClick = async () =>
{
contents.innerHTML = spinner.innerHTML;
orderBy = '';
let data = await getData(MDB.checked ? 'MDB' : 'SQL',
txtServerURI.value,
MDB.checked ? txtDatabase.value : txtSQLServer.value + '/' + txtSQLInstance.value,
txtQuery.value);
console.log(data);
contents.innerHTML = data.ErrDesc || toTable(data.Values, data.Names);
};
let tableBtnClick = async (tableName) =>
{
txtQuery.value = `SELECT TOP ${numRows.value} * FROM ${tableName}`
+ (orderBy ? ` ORDER BY ${orderBy} ASC;` : ';');
currentTable = tableName;
queryBtnClick();
};
let switchDb = (db_txt) =>
{
let is_mdb = ['mdb','accdb'].includes(db_txt.split('.').slice(-1).toString().toLowerCase());
orderBy = '';
MDB.checked = is_mdb;
SQL.checked = !is_mdb;
if (is_mdb)
{
txtDatabase.value =
{
'SchemaTest.mdb' : "T:\\Databases\\Admin\\SchemaTest.mdb",
'MfgHist.mdb' : "\\\\tandlsbs\\databases\\floor\\MfgHist.mdb",
'Packers.mdb' : "\\\\tandlsbs\\databases\\packline\\Packers.mdb",
'Bridge.mdb' : "\\\\tandlsbs\\databases\\floor\\Bridge.mdb",
'Ms3Edi.mdb' : "\\\\tandlsbs\\databases\\admin\\Ms3Edi.mdb"
}[db_txt];
}
else
{
txtSQLServer.value = {'FloorSys': "SRV03"}[db_txt];
txtSQLInstance.value = {'FloorSys': "FloorSysDB"}[db_txt];
}
window.onload();
};
/*-------------------------------------------------------------------------------------------------------*/
window.onload = (async () =>
{
buttons.innerHTML = spinner.innerHTML;
orderBy = '';
let data = await getData(MDB.checked ? 'MDB' : 'SQL', // Populate initial buttons.
txtServerURI.value,
MDB.checked ? txtDatabase.value : txtSQLServer.value + '/' + txtSQLInstance.value,
MDB.checked ?
"SELECT Name FROM MSysObjects WHERE Type = 1 AND Name NOT LIKE '~%' AND Name NOT LIKE 'MSys%' ORDER BY Name ASC"
: "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES ORDER BY TABLE_NAME ASC");
console.log(data);
buttons.innerHTML = data.ErrDesc ||
data.Values.map(v => v[0])
.map(v => `<button onClick="tableBtnClick('${v}')"> ${v} </button>`)
.join('<br>\n');
});
</script>
</body>
</html>