Skip to content

Commit

Permalink
Fixed: Delete table contents failing due to query not being executed
Browse files Browse the repository at this point in the history
Updated: Use the control statements when validating table creation
Updated: Use the control statements when inserting data in DSV format
Removed: Logging the whole data level on access navigation key
  • Loading branch information
dvdvideo1234 committed Jan 11, 2025
1 parent 016185d commit 05956e9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 47 deletions.
12 changes: 6 additions & 6 deletions lua/autorun/trackassembly_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ local asmlib = trackasmlib; if(not asmlib) then -- Module present
------------ CONFIGURE ASMLIB ------------

asmlib.InitBase("track","assembly")
asmlib.SetOpVar("TOOL_VERSION","9.772")
asmlib.SetOpVar("TOOL_VERSION","9.773")

------------ CONFIGURE GLOBAL INIT OPVARS ------------

Expand All @@ -105,7 +105,7 @@ local gsGenerPrf = asmlib.GetOpVar("DBEXP_PREFGEN")
local gsLimitName = asmlib.GetOpVar("CVAR_LIMITNAME")
local gsDirDSV = asmlib.GetOpVar("DIRPATH_BAS")..asmlib.GetOpVar("DIRPATH_DSV")
local gsNoAnchor = asmlib.GetOpVar("MISS_NOID")..gsSymRev..asmlib.GetOpVar("MISS_NOMD")
local gsGrossDSV = gsDirDSV..gsGenerPrf..gsToolPrefU
local gsGenerDSV = gsDirDSV..gsGenerPrf..gsToolPrefU

------------ VARIABLE FLAGS ------------

Expand Down Expand Up @@ -2076,7 +2076,7 @@ asmlib.NewTable("PHYSPROPERTIES",{

--[[ Categories are only needed client side ]]--
if(CLIENT) then
if(fileExists(gsGrossDSV.."CATEGORY.txt", "DATA")) then
if(fileExists(gsGenerDSV.."CATEGORY.txt", "DATA")) then
asmlib.LogInstance("DB CATEGORY from GENERIC",gtInitLogs)
asmlib.ImportCategory(3, gsGenerPrf)
else asmlib.LogInstance("DB CATEGORY from LUA",gtInitLogs) end
Expand All @@ -2095,7 +2095,7 @@ end
* First argument of Categorize() is used to provide default track type for TABLE:Record()
* Second argument of Categorize() is used to generate track categories for the processed addon
]]--
if(fileExists(gsGrossDSV.."PIECES.txt", "DATA")) then
if(fileExists(gsGenerDSV.."PIECES.txt", "DATA")) then
asmlib.LogInstance("DB PIECES from GENERIC",gtInitLogs)
asmlib.ImportDSV("PIECES", true, gsGenerPrf)
else
Expand Down Expand Up @@ -4944,7 +4944,7 @@ else
if(gsMoDB == "SQL") then sqlCommit() end
end

if(fileExists(gsGrossDSV.."PHYSPROPERTIES.txt", "DATA")) then
if(fileExists(gsGenerDSV.."PHYSPROPERTIES.txt", "DATA")) then
asmlib.LogInstance("DB PHYSPROPERTIES from GENERIC",gtInitLogs)
asmlib.ImportDSV("PHYSPROPERTIES", true, gsGenerPrf)
else --- Valve's physical properties: https://developer.valvesoftware.com/wiki/Material_surface_properties
Expand Down Expand Up @@ -5053,7 +5053,7 @@ else --- Valve's physical properties: https://developer.valvesoftware.com/wiki/M
if(gsMoDB == "SQL") then sqlCommit() end
end

if(fileExists(gsGrossDSV.."ADDITIONS.txt", "DATA")) then
if(fileExists(gsGenerDSV.."ADDITIONS.txt", "DATA")) then
asmlib.LogInstance("DB ADDITIONS from GENERIC",gtInitLogs)
asmlib.ImportDSV("ADDITIONS", true, gsGenerPrf)
else
Expand Down
81 changes: 42 additions & 39 deletions lua/trackassembly/trackasmlib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2656,7 +2656,7 @@ function GetBuilderID(vID)
return makTab -- Return the dedicated table builder object
end

function NewTable(sTable,defTab,bDelete,bReload)
function NewTable(sTable,defTab,bReload,bDelete)
if(not isstring(sTable)) then
LogInstance("Table nick mismatch "..GetReport(sTable)); return false end
if(IsBlank(sTable)) then
Expand Down Expand Up @@ -2816,7 +2816,6 @@ function NewTable(sTable,defTab,bDelete,bReload)
LogInstance("Stats "..GetReport(iCnt, smTM, tmLif, tmDie, tmCol), tabDef.Nick)
if(smTM == "CQT") then
LogInstance("Navigation key "..GetReport(iCnt, unpack(tKey)), tabDef.Nick)
LogTable(oSpot, "Navigation", tabDef.Nick)
for key, rec in pairs(oSpot) do -- Check other items that qualify
if(rec.Used) then -- Used time is updated on this level
local vDif = (nNow - rec.Used) -- Calculate time difference
Expand Down Expand Up @@ -3208,61 +3207,63 @@ function NewTable(sTable,defTab,bDelete,bReload)
end
-- When database mode is SQL create a table in sqlite
if(sMoDB == "SQL") then local vO
vO = self:Create():Get(); if(not IsHere(vO)) then
LogInstance("Build create failed"); return self:Remove(false) end
vO = self:Index():Get(); if(not IsHere(vO)) then
LogInstance("Build index failed"); return self:Remove(false) end
vO = self:Drop():Get(); if(not IsHere(vO)) then
LogInstance("Build drop failed"); return self:Remove(false) end
vO = self:Delete():Get(); if(not IsHere(vO)) then
LogInstance("Build delete failed"); return self:Remove(false) end
vO = self:Begin():Get(); if(not IsHere(vO)) then
LogInstance("Build begin failed"); return self:Remove(false) end
vO = self:Commit():Get(); if(not IsHere(vO)) then
LogInstance("Build commit failed"); return self:Remove(false) end
vO = self:TimerSetup(); if(not IsHere(vO)) then
LogInstance("Build timer failed"); return self:Remove(false) end
local tQ = self:GetCommand(); if(not IsHere(tQ)) then
LogInstance("Build command failed"); return self:Remove(false) end
-- When enabled forces a table drop
if(bReload) then
if(sqlTableExists(defTab.Name)) then -- Remove table when SQL error is present
local qRez = sqlQuery(tQ.DROP); if(not qRez and isbool(qRez)) then
LogInstance("Table drop fail "..GetReport(sqlLastError(), tQ.DROP), tabDef.Nick)
if(bReload) then -- Remove table when SQL error is present
if(sqlTableExists(defTab.Name)) then
local qRez = sqlQuery(vO); if(not qRez and isbool(qRez)) then
LogInstance("Table drop fail "..GetReport(sqlLastError(), vO), tabDef.Nick)
return self:Remove(false) -- Remove table when SQL error is present
else LogInstance("Table drop success",tabDef.Nick) end
else LogInstance("Table drop skipped",tabDef.Nick) end
end
-- Use current query to drop the table
vO = self:Create():Get(); if(not IsHere(vO)) then
LogInstance("Build create failed"); return self:Remove(false) end
-- Create the table using the given name and properties
if(sqlTableExists(defTab.Name)) then
LogInstance("Table create skipped",tabDef.Nick)
else -- Remove table when SQL error is present
local qRez = sqlQuery(tQ.CREATE); if(not qRez and isbool(qRez)) then
LogInstance("Table create fail "..GetReport(sqlLastError(), tQ.CREATE), tabDef.Nick)
local qRez = sqlQuery(vO); if(not qRez and isbool(qRez)) then
LogInstance("Table create fail "..GetReport(sqlLastError(), vO), tabDef.Nick)
return self:Remove(false) -- Remove table when SQL error is present
end -- Check when SQL query has passed and the table is not yet created
if(sqlTableExists(defTab.Name)) then
for iQ = 1, tQ.INDEX.Size do local qInx = tQ.INDEX[iQ]
local qRez = sqlQuery(qInx); if(not qRez and isbool(qRez)) then
LogInstance("Table create index fail "..GetReport(sqlLastError(), iQ, qInx), tabDef.Nick)
return self:Remove(false) -- Clear table when index is not created
end -- Check when the index query has passed
LogInstance("Table create index: "..qInx,tabDef.Nick)
end
else
LogInstance("Table create check fail "..GetReport(sqlLastError(), tQ.CREATE), tabDef.Nick)
return self:Remove(false) -- Clear table when it is not created by the first pass
end
end
vO = self:Index():Get(); if(not IsHere(vO)) then
LogInstance("Build index failed"); return self:Remove(false) end
-- Check when SQL query has passed and the table is not yet created
if(sqlTableExists(defTab.Name)) then
for iQ = 1, vO.Size do local qInx = vO[iQ]
local qRez = sqlQuery(qInx); if(not qRez and isbool(qRez)) then
LogInstance("Table create index fail "..GetReport(sqlLastError(), iQ, qInx), tabDef.Nick)
return self:Remove(false) -- Clear table when index is not created
end -- Check when the index query has passed
LogInstance("Table create index: "..qInx,tabDef.Nick)
end
else
LogInstance("Table create check fail "..GetReport(sqlLastError(), vQ), tabDef.Nick)
return self:Remove(false) -- Clear table when it is not created by the first pass
end
vO = self:Delete():Get(); if(not IsHere(vO)) then
LogInstance("Build delete failed"); return self:Remove(false) end
-- When the table is present delete all records
if(bDelete) then
if(sqlTableExists(defTab.Name)) then local qRez = sqlQuery(tQ.DELETE)
if(not qRez and isbool(qRez)) then -- Remove table when SQL error is present
LogInstance("Table delete fail "..GetReport(sqlLastError(), tQ.DELETE), tabDef.Nick)
if(sqlTableExists(defTab.Name)) then -- Remove table when SQL error is present
local qRez = sqlQuery(vO); if(not qRez and isbool(qRez)) then
LogInstance("Table delete fail "..GetReport(sqlLastError(), vO), tabDef.Nick)
return self:Remove(false) -- Remove table when SQL error is present
else LogInstance("Table delete success",tabDef.Nick) end
else LogInstance("Table delete skipped",tabDef.Nick) end
end
vO = self:Begin():Get(); if(not IsHere(vO)) then
LogInstance("Build begin failed"); return self:Remove(false) end
vO = self:Commit():Get(); if(not IsHere(vO)) then
LogInstance("Build commit failed"); return self:Remove(false) end
vO = self:TimerSetup(); if(not IsHere(vO)) then
LogInstance("Build timer failed"); return self:Remove(false) end
local tQ = self:GetCommand(); if(not IsHere(tQ)) then
LogInstance("Build command failed"); return self:Remove(false) end
elseif(sMoDB == "LUA") then local tCache = libCache[tabDef.Nick]
if(IsHere(tCache)) then -- Empty the table when its cache is located
tableEmpty(tCache); LogInstance("Table create empty",tabDef.Nick)
Expand Down Expand Up @@ -3834,7 +3835,8 @@ function ImportDSV(sTable, bComm, sPref, sDelim, bExp)
F = fileOpen(fName, "rb", "DATA"); if(not F) then
LogInstance(sHew.." Open fail: "..fName,sTable); return false end
end
if(sMoDB == "SQL") then sqlQuery(cmdTab.BEGIN); LogInstance(sHew.." Begin",sTable) end
if(bComm and sMoDB == "SQL") then
sqlQuery(makTab:Begin():Get()); LogInstance(sHew.." Begin",sTable) end
while(not isEOF) do sLine, isEOF = GetStringFile(F)
if((not IsBlank(sLine)) and (not IsDisable(sLine))) then
local tData = sDelim:Explode(sLine); if((#tData-1) > defTab.Size) then
Expand All @@ -3845,7 +3847,8 @@ function ImportDSV(sTable, bComm, sPref, sDelim, bExp)
if(bComm) then makTab:Record(tData) end
end
end; F:Close()
if(sMoDB == "SQL") then sqlQuery(cmdTab.COMMIT); LogInstance(sHew.." Commit",sTable) end
if(bComm and sMoDB == "SQL") then
sqlQuery(makTab:Commit():Get()); LogInstance(sHew.." Commit",sTable) end
LogInstance(sHew.." Success",sTable); return true
end

Expand Down
4 changes: 2 additions & 2 deletions lua/weapons/gmod_tool/stools/trackassembly.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2577,7 +2577,7 @@ if(CLIENT) then
local iMaxDec = asmlib.GetAsmConvar("maxmenupr","INT")
CPanel:ClearControls(); CPanel:DockPadding(5, 0, 5, 10)
CPanel:SetName(languageGetPhrase("tool."..gsToolNameL..".utilities_user"))
CPanel:ControlHelp(languageGetPhrase("tool."..gsToolNameL..".client_var"))
CPanel:Help(languageGetPhrase("tool."..gsToolNameL..".client_var"))
asmlib.SetNumSlider(CPanel, "sizeucs" , iMaxDec)
asmlib.SetNumSlider(CPanel, "incsnplin", 0)
asmlib.SetNumSlider(CPanel, "incsnpang", 0)
Expand All @@ -2602,7 +2602,7 @@ if(CLIENT) then
local iMaxDec = asmlib.GetAsmConvar("maxmenupr","INT")
CPanel:ClearControls(); CPanel:DockPadding(5, 0, 5, 10)
CPanel:SetName(languageGetPhrase("tool."..gsToolNameL..".utilities_admin"))
CPanel:ControlHelp(languageGetPhrase("tool."..gsToolNameL..".nonrep_var"))
CPanel:Help(languageGetPhrase("tool."..gsToolNameL..".nonrep_var"))
asmlib.SetCheckBox(CPanel, "logfile")
asmlib.SetNumSlider(CPanel, "logsmax", 0)
asmlib.SetCheckBox(CPanel, "devmode")
Expand Down

0 comments on commit 05956e9

Please sign in to comment.