sqlite数据库快速查看器

本工具是一个windows平台轻量级的sqlite数据库查看器,应用启动十分迅速。本应用使用了autohotkey1.1 + bootstarp 4 + sqlite。

介绍

本工具是一个windows平台轻量级的sqlite数据库查看器,应用启动十分迅速,目前只支持查看单个表
应用场景:如,用sqlite存储了各个网站的账号密码。要查看时用其他数据库软件打开启动比较慢,步骤比较繁琐,用这个就比较方便了。

 

演示:

sqlite数据库快速查看器

 

将下载好的压缩包解压到E盘(这里的路径可自定),然后修改config.ini的配置

[system]
appName=QuickShowDB.exe
[soft]
sqlitePath=E:\QuickShowDB\TEST.DB
defaultTable=test

sqlitePath:数据库的路径,用于加载数据库,加载的数据库在任意路径都可以。支持中文路径 defaultTable:需要查看的表

配置好这两个参数后,直接运行QuickShowDB.exe即可

这里的TEST.DB只是用于演示

代码

QuickShowDB.ahk

; ======================================================================================================================
;author: paomian
;Version: V1.0.0
; ======================================================================================================================

; ======================================================================================================================
; 编译声明(勿删)
; ======================================================================================================================

;@Ahk2Exe-AddResource *10 index.html
;@Ahk2Exe-AddResource *10 %A_ScriptDir%\assets\bootstrap\bootstrap.min.css
;@Ahk2Exe-AddResource *10 %A_ScriptDir%\assets\bootstrap\jquery.min.js
;@Ahk2Exe-AddResource *10 %A_ScriptDir%\assets\bootstrap\bootstrap.min.js
;@Ahk2Exe-AddResource *10 %A_ScriptDir%\assets\bootstrap\play-fill.svg
;@Ahk2Exe-AddResource *10 %A_ScriptDir%\assets\imgs\20231205093500.ico
; ======================================================================================================================
; 依赖与变量声明
; ======================================================================================================================

#Include lib/Class_SQLiteDB.ahk
#Include lib/EasyIni.ahk
#Include lib/Neutron.ahk

;数据库配置 全局变量
global DB := new SQLiteDB

;加载配置文件
vIni := class_EasyIni("config.ini")
global appName := vIni.system.appName
DBFileName := vIni.soft.sqlitePath
;默认表 全局变量
global defaultTable := vIni.soft.defaultTable


;html页面配置
global neutron := new NeutronWindow()
neutron.Load("index.html")
neutron.Gui("+LabelNeutron")

; ======================================================================================================================
; 主要处理流程
; ======================================================================================================================

;打开数据库
If !DB.OpenDB(DBFileName) {
   MsgBox, 16, SQLite Error, % "Msg:`t" . DB.ErrorMsg . "`nCode:`t" . DB.ErrorCode
   ExitApp
}

;获取总条数
totalCount := getTableTotalNum()

;数据量过大时,使用加载条
if (totalCount >= 1000) {
   Progress, ON , , , loading ..., 
   neutron.Show("w800 h400")
}

;查询表数据
dataIterators := getDbDataIterators()

;数据量过大时,使用加载条
if (totalCount >= 1000) {
   Progress, 90
}

;渲染thead
buildThead(dataIterators)
;渲染tbody
buildTbody(dataIterators)

;释放查询的结果
dataIterators.Free()

neutron.Show("w800 h600")
;进度条关闭
Progress, OFF

return

; ======================================================================================================================
; 事件监听
; ======================================================================================================================

;关闭页面时,退出
NeutronClose:
ExitApp
return

; 按ESC键时, 退出脚本:
#If isThisWinActive()
Esc::ExitApp

;禁用 鼠标右键
#If isThisWinActive()
RButton::
return

; ======================================================================================================================
; 方法
; ======================================================================================================================

;构建数据库数据对象 取值dataList[i,j]
buildDbDataList(Iterators) {
   dataList := Object()

   ArrayCount = 0
   If (Iterators.HasRows) {
      If (Iterators.Next(Row) < 1) {
         MsgBox, 16, %A_ThisFunc%, % "Msg:`t" . Iterators.ErrorMsg . "`nCode:`t" . Iterators.ErrorCode
         Return
      }
      Loop {
         ;循环字段,给对象赋值
         Loop, % Iterators.ColumnCount {
            ;二维数组
            dataList[ArrayCount, A_Index] := Row[A_Index]
         }
         ArrayCount += 1
         RC := Iterators.Next(Row)
      } Until (RC < 1)
   }

Return dataList
}

;构建HEAD
;neutron执行对象,Iterators迭代器对象
buildThead(Iterators) {
   titleList := Object()
   ;查出标题
   Loop, % Iterators.ColumnCount {
      titleList[0, A_Index] := Iterators.ColumnNames[A_Index]
   }

   ;渲染thead
   for row, data in titleList
   {
      tr := neutron.doc.createElement("tr")
      for col, cell in data
      {
         th := neutron.doc.createElement("th")
         th.innerText := cell
         tr.appendChild(th)
      }
      neutron.qs("#db_table_body>thead").appendChild(tr)
   }
}

;构建BODY
;neutron执行对象,Iterators迭代器对象
buildTbody(Iterators) {
   db_table_body := buildDbDataList(Iterators)

   html := ""
   for row, data in db_table_body
   {
      html .= "<tr>"
      for col, cell in data
         html .= neutron.FormatHTML("<td>{}</td>", cell)
      html .= "</tr>"
   }
   neutron.qs("#db_table_body>tbody").innerHTML := html
}


;获取表总数
getTableTotalNum() {
   SQL := "SELECT COUNT(*) FROM " defaultTable ";"
   SB_SetText("SQLite_GetTable : " . SQL)
   If !DB.GetTable(SQL, Result) {
      MsgBox, 16, SQLite Error: GetTable, % "Msg:`t" . DB.ErrorMsg . "`nCode:`t" . DB.ErrorCode
   }

   If (Result.HasRows) {

      Result.Next(Row)
      Loop, % Result.ColumnCount {
         totalCount := Row[A_Index]
      }

   }
Return totalCount
}

;获取表数据迭代器
getDbDataIterators() {
   SQL := "SELECT * FROM " defaultTable ";"
   ;SB_SetText("Query : " . SQL)
   If !DB.Query(SQL, Iterators) {
      MsgBox, 16, SQLite Error: Query, % "Msg:`t" . Iterators.ErrorMsg . "`nCode:`t" . Iterators.ErrorCode
   }
Return Iterators
}

;重新加载Tbody
reloadTbody(neutron) {
 
   dbDataList := getDbDataIterators()

   buildTbody(dbDataList)

}

;判断是否当前窗口活动
isThisWinActive() {
   MouseGetPos, , , id
   WinGetTitle, title, ahk_id %id%
   if (appName = Title) {
      return 1
   } else {
      return 0
   }
   
}


;数据库执行SQL
execSqlWithDB(neutron, event, execSQL) {
   ;用户不输入时,直接返回
   if (execSQL = null) {
      return
   }
   If !DB.Exec(execSQL) {
      MsgBox, 16, SQLite Error, % "Msg:`t" . DB.ErrorMsg . "`nCode:`t" . DB.ErrorCode
   } else {
      SQL := "SELECT * FROM " defaultTable ";"
      SB_SetText("Query : " . SQL)
      If !DB.Query(SQL, RecordSet) {
         MsgBox, 16, SQLite Error: Query, % "Msg:`t" . RecordSet.ErrorMsg . "`nCode:`t" . RecordSet.ErrorCode
      }

      reloadTbody(neutron)
   } 

   
}

 

特别感谢

以下排名不分先后
河许人的EasyIni
G33kDude的Neutron
AHK-just-me的Class_SQLiteDB

下载使用

给TA捐赠
共{{data.count}}人
人已捐赠
应用

windows超级运行框-表达式计算(8)—连续数学运算

2023-12-1 10:04:31

应用

windows超级运行框-表达式计算(12)—功能汇总

2023-12-6 19:42:11

14 条回复 A文章作者 M管理员
  1. ahk小明

    试试看

  2. ahk小明

    使用试试

  3. ahk小明

    太棒了

  4. yxldh

    感谢分享 学习一下

  5. 恐刀酷

    消除零回复,看看

  6. dbgba
    dbgba给作者打赏了¥3
  7. dbgba

    Msg: 1
    Code: 14
    下载的报这个错误

    • 爪哇泡面

      估计是数据库文件的路径不对,需要修改一下config.ini的配置sqlitePath=E:QuickShowDBTEST.db,这个路径修改一下。

  8. 天幻

    thx

  9. 天幻
    天幻给作者打赏了¥1
  10. fmlimeng

    thx

  11. fmlimeng

    感谢分享 学习一下

个人中心
购物车
优惠劵
有新私信 私信列表
搜索