Adding Table to DB Through Lua

Hey guys! So I have the following:



local BannedProps = {}
function AddBannedProp(mdl) table.insert(BannedProps, mdl) end

AddBannedProp("models/hunter/blocks/cube025x025x025.mdl")
AddBannedProp("models/hunter/blocks/cube025x05x025.mdl")
AddBannedProp("models/hunter/blocks/cube025x075x025.mdl")
ect.


I see where sv.db has a table named “FPP_BLOCKEDMODELS1” where it has one field named “model”.

How would I go about adding the “BannedProps” table to the DB, and have the values of the keys in the table put into the “model” field.

I tried the following:



local BannedProps = {}
function AddBannedProp(mdl) table.insert(BannedProps, mdl) end

AddBannedProp("models/hunter/blocks/cube025x025x025.mdl")
AddBannedProp("models/hunter/blocks/cube025x05x025.mdl")
AddBannedProp("models/hunter/blocks/cube025x075x025.mdl")
ect.

function bannedDB()
	for k, v in pairs(BannedProps) do
		sql.Query("INSERT INTO FPP_BLOCKEDMODELS1 (model) VALUES model = '" .. v .. "'")
	end
end
hook.Add("OnGamemodeLoaded", "bannedDB", bannedDB)


However, it doesn’t add the props. What would I have to do in order to add them through Lua?

** I’m not looking to get bashed for posting things about this. I’m simply looking for the most convenient way to add blocked models. I don’t care how much you hate me, there’s no point in posting if you’re not going to help me. **

[lua]
local function AddBlockedModel(ply, cmd, args)
if not args[1] then FPP.Notify(ply, “Argument(s) invalid”, false) return end

local models = getIntendedBlockedModels(args[1], tonumber(args[2]) and Entity(args[2]) or nil)

for k, model in pairs(models) do
    if FPP.BlockedModels[model] then FPP.Notify(ply, string.format([["%s" is already in the black/whitelist]], model), false) continue end
    FPP.BlockedModels[model] = true
    MySQLite.query("REPLACE INTO FPP_BLOCKEDMODELS1 VALUES(" .. sql.SQLStr(model) .. ");")
    FPP.NotifyAll(((ply.Nick and ply:Nick()) or "Console") .. " added " .. model .. " to the blocked models black/whitelist", true)
end

end
[/lua]

Taken from:

Nope, this isn’t working. I have the following:



local function bannedDB(ply)
    for k, model in pairs(BannedProps) do
        FPP.BlockedModels[model] = true
        MySQLite.query("REPLACE INTO FPP_BLOCKEDMODELS1 VALUES(" .. sql.SQLStr(model) .. ");")
    end
end
hook.Add("OnGamemodeLoaded", "bannedDB", bannedDB)


[editline]24th April 2016[/editline]

I fixed it. Thanks for your help bro!