SQLite 命令行客户端 + HTA 实现简易UI
- SQLite 客户端.hta
- 目录结构
- 参考资料
仅用于探索可行性,就只实现了 SELECT
。
SQLite 客户端.hta
<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><HTA:APPLICATIONAPPLICATIONNAME="Demo"ID="JerryHTA"VERSION="1.0"ICON=""BORDER="dialog"SCROLL="no"SINGLEINSTANCE="yes"CONTEXTMENU="yes"NAVIGABLE="yes"/><meta http-equiv="x-ua-compatible" content="ie=edge"/><title>SQLite 客户端 - HTA 版</title><style>body { font-family: Arial, sans-serif; }#cmdResult { white-space: pre-wrap; }/* 表格样式 */table {width: 100%;border-collapse: collapse;margin-top: 20px;}table th,table td {border: 1px solid #ddd;padding: 8px;text-align: left;}/* 表头样式 */tabl thead th {background-color: #007BFF;color: white;font-weight: bold;text-transform: uppercase;}/* 鼠标悬停效果 */table tbody tr:hover {background-color: #f5f5f5;}/* 交替行颜色 */table tbody tr:nth-child(even) {background-color: #f2f2f2;}</style><script language="JScript">function runCmd() {var cmd = document.getElementById('cmdInput').value;try {var shell = new ActiveXObject("WScript.Shell");var sqlCmd = 'sqlite3.exe MY_DB.db ".mode html" ".headers on" ".width auto" "'+ cmd + '"';var encodingCmd = 'cmd /C CHCP 65001 > nul & ' + sqlCmd;var exec = shell.Exec(encodingCmd);while (exec.Status == 0){}var Stream = new ActiveXObject("ADODB.Stream");Stream.Open();Stream.Type = 2; // Text typeStream.Charset = "UTF-8";// 直接从文件读取数据,确保编码正确Stream.LoadFromFile('sqltemp');// 读取所有数据var result = Stream.ReadText(-1);Stream.Close();// 清除之前的输出并显示新结果document.getElementById('cmdResult').innerHTML = '<table>' + result + '</table>';} catch (e) {document.getElementById('cmdResult').innerText = "Error: " + e.message;}}</script>
</head>
<body><h1>SQLite 客户端</h1><textarea id="cmdInput" rows="5" cols="60">SELECT * FROM 订单表;</textarea><br/><button onclick="runCmd()">执行</button><hr/><h2>执行结果</h2><pre id="cmdResult"></pre>
</body>
</html>
目录结构
参考资料
笑虾:SQLite 命令行客户端 + Windows 批处理应用
VBScript Scripting Techniques > HTAs
HTA & WSC Examples
599cd:HTA Tips