Skip to content

Commit f0d1268

Browse files
committed
CL SQLite Data
1 parent 6fe41c6 commit f0d1268

File tree

3 files changed

+93
-75
lines changed

3 files changed

+93
-75
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ For now, the all modules are currently locked away behind only a usergroup == su
2828
| Timers | :white_check_mark: | :white_check_mark: |
2929
| Profiling | :x: | :x: |
3030
| SQLite Schema | :white_check_mark: | :x: |
31-
| SQLite Data | :x: | :x: |
31+
| SQLite Data | :white_check_mark: | :x: |
3232
| SQLite Execute | :x: | :x: |
3333
| Remote SQL Schema | :x: | :x: |
3434
| Remote SQL Data | :x: | :x: |

lua/blobsprofiler/client/cl_blobsprofiler.lua

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,80 +1022,6 @@ local function buildDTree(luaState, parentPanel, rvarType)
10221022
end
10231023
end
10241024

1025-
--[[
1026-
1027-
local function buildSQLDataTab(luaState, parentPanel)
1028-
local realmDataTable = blobsProfiler.GetDataTableForRealm(luaState, "SQL")
1029-
1030-
local tableSelectorList = vgui.Create( "DComboBox", parentPanel )
1031-
1032-
local tableDataListView = vgui.Create("DListView", parentPanel)
1033-
tableDataListView:Dock(FILL)
1034-
1035-
tableSelectorList:Dock(TOP)
1036-
tableSelectorList:SetSortItems(false)
1037-
1038-
tableSelectorList.OnSelect = function(s, index, value)
1039-
for k, line in ipairs( tableDataListView:GetLines() ) do
1040-
tableDataListView:RemoveLine(k)
1041-
end
1042-
1043-
for k,v in ipairs(tableDataListView.Columns) do
1044-
if v and IsValid(v) then v:Remove() end
1045-
end
1046-
1047-
tableDataListView.Columns = {}
1048-
1049-
local colList = realmDataTable.SchemaTables[value]
1050-
if colList then
1051-
local colAmnt = table.Count(colList)
1052-
for i=0, colAmnt-1 do
1053-
local colData = realmDataTable.SchemaTables[value][tostring(i)] -- TODO: make this actual number ffs
1054-
tableDataListView:AddColumn(colData.Name)
1055-
end
1056-
end
1057-
tableDataListView:SetDirty( true )
1058-
1059-
tableDataListView:FixColumnsLayout()
1060-
1061-
local getSQLData = sql.Query("SELECT * FROM ".. sql.SQLStr(value) .. " LIMIT 25")
1062-
if getSQLData == false then
1063-
-- error
1064-
elseif getSQLData == nil then
1065-
-- no data
1066-
else
1067-
1068-
local tblOrder = {}
1069-
local colList = realmDataTable.SchemaTables[value]
1070-
if colList then
1071-
local colAmnt = table.Count(colList)
1072-
for i=0, colAmnt-1 do
1073-
local colData = realmDataTable.SchemaTables[value][tostring(i)] -- TODO: make this actual number ffs
1074-
table.insert(tblOrder, colData.Name)
1075-
end
1076-
end
1077-
1078-
for _, record in ipairs(getSQLData) do
1079-
local dataBuild = {}
1080-
for __, key in ipairs(tblOrder) do
1081-
table.insert(dataBuild, record[key])
1082-
end
1083-
tableDataListView:AddLine(unpack(dataBuild))
1084-
end
1085-
1086-
end
1087-
end
1088-
1089-
for k,v in pairs(realmDataTable.SchemaTables or {}) do
1090-
tableSelectorList:AddChoice(k)
1091-
1092-
if not tableSelectorList:GetSelected() then
1093-
tableSelectorList:ChooseOption(k, 1)
1094-
end
1095-
end
1096-
end
1097-
]]
1098-
10991025
if blobsProfiler.Menu.MenuFrame && IsValid(blobsProfiler.Menu.MenuFrame) then
11001026
blobsProfiler.Menu.MenuFrame:Remove() -- kill on lua refresh
11011027
end

lua/blobsprofiler/shared/modules/bp_sqlite.lua

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,101 @@ blobsProfiler.RegisterSubModule("SQLite", "Schema", {
6060
RefreshButton = "Refresh"
6161
})
6262

63+
local function requestSQLiteData(luaState, tableName, pageNum)
64+
pageNum = pageNum or 1
65+
local schemaDataTable = blobsProfiler[luaState].SQLite.Schema
66+
67+
local tableSelectorList = blobsProfiler[luaState].SQLite.Data.tableSelectorList
68+
local tableDataListView = blobsProfiler[luaState].SQLite.Data.tableDataListView
69+
70+
if luaState == "Client" then
71+
for k, line in ipairs( tableDataListView:GetLines() ) do
72+
tableDataListView:RemoveLine(k)
73+
end
74+
75+
for k,v in ipairs(tableDataListView.Columns) do
76+
if v and IsValid(v) then v:Remove() end
77+
end
78+
79+
tableDataListView.Columns = {}
80+
81+
local colList = schemaDataTable.Tables[tableName]
82+
if colList then
83+
local colAmnt = table.Count(colList)
84+
for i=0, colAmnt-1 do
85+
local colData = schemaDataTable.Tables[tableName][tostring(i)] -- TODO: make this actual number ffs
86+
tableDataListView:AddColumn(colData.Name)
87+
end
88+
end
89+
tableDataListView:SetDirty( true )
90+
91+
tableDataListView:FixColumnsLayout()
92+
93+
local getSQLData = sql.Query("SELECT * FROM ".. sql.SQLStr(tableName) .. " LIMIT 25")
94+
if getSQLData == false then
95+
-- error
96+
elseif getSQLData == nil then
97+
-- no data
98+
else
99+
100+
local tblOrder = {}
101+
local colList = schemaDataTable.Tables[tableName]
102+
if colList then
103+
local colAmnt = table.Count(colList)
104+
for i=0, colAmnt-1 do
105+
local colData = schemaDataTable.Tables[tableName][tostring(i)] -- TODO: make this actual number ffs
106+
table.insert(tblOrder, colData.Name)
107+
end
108+
end
109+
110+
for _, record in ipairs(getSQLData) do
111+
local dataBuild = {}
112+
for __, key in ipairs(tblOrder) do
113+
table.insert(dataBuild, record[key])
114+
end
115+
tableDataListView:AddLine(unpack(dataBuild))
116+
end
117+
118+
end
119+
else
120+
-- TODO
121+
end
122+
end
123+
63124
blobsProfiler.RegisterSubModule("SQLite", "Data", {
64125
Icon = "icon16/page_white_database.png",
65126
OrderPriority = 2,
127+
CustomPanel = function(luaState, parentPanel)
128+
blobsProfiler[luaState].SQLite = blobsProfiler[luaState].SQLite or {}
129+
blobsProfiler[luaState].SQLite.Data = blobsProfiler[luaState].SQLite.Data or {}
130+
131+
blobsProfiler[luaState].SQLite.Schema = blobsProfiler[luaState].SQLite.Schema or {}
132+
133+
local schemaDataTable = blobsProfiler[luaState].SQLite.Schema
134+
135+
blobsProfiler[luaState].SQLite.Data.tableSelectorList = vgui.Create("DComboBox", parentPanel)
136+
blobsProfiler[luaState].SQLite.Data.tableDataListView = vgui.Create("DListView", parentPanel)
137+
138+
local tableSelectorList = blobsProfiler[luaState].SQLite.Data.tableSelectorList
139+
local tableDataListView = blobsProfiler[luaState].SQLite.Data.tableDataListView
140+
141+
tableDataListView:Dock(FILL)
142+
143+
tableSelectorList:Dock(TOP)
144+
tableSelectorList:SetSortItems(false)
145+
146+
tableSelectorList.OnSelect = function(s, index, value)
147+
requestSQLiteData(luaState, value)
148+
end
149+
150+
for k,v in pairs(schemaDataTable.Tables or {}) do
151+
tableSelectorList:AddChoice(k)
152+
153+
if not tableSelectorList:GetSelected() then
154+
tableSelectorList:ChooseOption(k, 1)
155+
end
156+
end
157+
end
66158
})
67159

68160
blobsProfiler.RegisterSubModule("SQLite", "Execute", {

0 commit comments

Comments
 (0)