MrDante Posted March 21, 2020 Share Posted March 21, 2020 Hi guys, I have a problem with the database, don't update and don't display errors in theDebugScript, the problem is when the eventName "onResourceStop" will UPDATE the Database, but i don't UPDATE. I trying use dbFREE, dbQuery and dbExec, it still doesn't work NOTE: OOP use B = { Database = {}, InventoryData = {} } function onSystemConnect () B.Database.create = Connection("sqlite", "files/database/inventory.db"); if (eventName == "onResourceStart") then if (B.Database.create) then local query = B.Database.create:query("CREATE TABLE IF NOT EXISTS inventoryData ('ID' int NOT NULL, 'SLOT' tinyint NOT NULL, 'NAME' varchar(30), 'TYPE' varchar(10), 'IDType' tinyint, 'AMOUNT' tinyint);"); local poll = query:poll(-1); if (poll) then local selectTable = B.Database.create:query("SELECT * FROM inventoryData"); local pollTable = selectTable:poll(-1); if (pollTable) then if (#pollTable == 0) then for k, v in ipairs (Element.getAllByType("player")) do B.InventoryData[v] = {} for i = 1, 18 do local setTable = B.Database.create:query("INSERT INTO inventoryData ('ID', 'SLOT', 'NAME', 'TYPE', 'IDType', 'AMOUNT') VALUES (?, ?, ?, ?, ?, ?)", v:getData("TN:IDSYSTEM"), i, 'empyt', 'empyt', 0, 0); local resultTable = setTable:poll(-1); if (resultTable) then table.insert(B.InventoryData[v], {["ID"] = v:getData("TN:IDSYSTEM"), ["NAME"] = "empyt", ["TYPE"] = "empyt", ["IDType"] = 0, ["AMOUNT"] = 0}); end end end return; end for k, v in ipairs(Element.getAllByType("player")) do B.InventoryData[v] = {} for i = 1, #pollTable do if (v:getData("TN:IDSYSTEM") == pollTable[i]["ID"]) then table.insert(B.InventoryData[v], {["ID"] = v:getData("TN:IDSYSTEM"), ["NAME"] = pollTable[i]["NAME"], ["TYPE"] = pollTable[i]["TYPE"], ["IDType"] = pollTable[i]["IDType"], ["AMOUNT"] = pollTable[i]["AMOUNT"]}); print(pollTable[1]["NAME"]) end end end end end end elseif (eventName == "onResourceStop") then if (B.Database.create) then for k, v in ipairs (Element.getAllByType("player")) do local data = B.InventoryData[v]; if (data) then for i = 1, #data do B.Database.create:exec("UPDATE inventoryData SET 'NAME' = ?, 'TYPE' = ?, 'IDType' = ?, 'AMOUNT' = ? WHERE 'ID' = ? AND 'SLOT' = ?", data[i]["NAME"], data[i]["TYPE"], data[i]["IDType"], data[i]["AMOUNT"], data[i]["ID"], i); end end end end end end addEventHandler("onResourceStart", resourceRoot, onSystemConnect) addEventHandler("onResourceStop", resourceRoot, onSystemConnect) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now