Jump to content

[AJUDA SQLITE] Como Obter Informações


Recommended Posts

Bom Minha duvida é a seguinte estou tentando obter os dados salvo da data-base, que eu fiz para treinar mas a questão e que no final só consigo retornar table não o valor dentro dela
 

local db = dbConnect("sqlite","db/savesystem.db")

function loaddb()
    dbExec(db,"CREATE TABLE IF NOT EXISTS SaveSystem(Account TEXT, Serial TEXT, Money REAL, POS TEXT, Skin TEXT )")
    print("DATA BASE CRIADA")
end
addEventHandler("onResourceStart",getRootElement(getThisResource()),loaddb)


addEventHandler("onPlayerQuit",root,function()
local result = dbPoll(dbQuery(db,"SELECT * FROM SaveSystem WHERE Account = ?",getAccountName(getPlayerAccount(source))),-1)
    if #result < 1 then 
        local posx, posy,posz = getElementPosition(source)
        local skin = getElementModel(source)
        local serial = getPlayerSerial(source) 
        local money = getPlayerMoney(source)
        local acc = getAccountName(getPlayerAccount(source))
        local pos = {posx,posy,posz}
        dbExec(db,"INSERT INTO SaveSystem(Account,Serial,Money,POS,Skin) VALUES(?,?,?,?,?)",acc,serial,money,toJSON(pos),skin)
        print("DATA BASE INSERIU")
    else
        local posx, posy,posz = getElementPosition(source)
        local skin = getElementModel(source)
        local serial = getPlayerSerial(source) 
        local money = getPlayerMoney(source)
        local acc = getAccountName(getPlayerAccount(source))
        local pos = {posx,posy,posz}
        dbExec(db,"UPDATE SaveSystem SET Account=?,Serial=?,Money=?,POS=?,Skin=?",acc,serial,money,toJSON(pos),skin)
        print("DATA ATUALIZOU")
    end
end)

addEventHandler("onPlayerLogin",root,function()
local result = dbPoll(dbQuery(db,"SELECT * FROM SaveSystem WHERE Account = ?",getAccountName(getPlayerAccount(source))),-1)
    if #result > 0 then
        
            setPlayerMoney(source,result[3]["SaveSystem"] )
      		--setPlayerMoney(source,dbPoll(dbQuery(db,"SELECT * FROM SaveSystem WHERE Money = ?",-1))) tentei dessa forma mas retorna table tb
    else
        return print("N tem info")
    end
end)


 

Link to comment
function data()
local result = dbPoll(dbQuery(db,"SELECT * FROM SaveSystem "), -1)
    if not result or #result > 0 then
        for i,v in ipairs(result) do
            outputChatBox ( ""..v["Account"].."", getRootElement(), 255, 255, 255, true )
        end
    end
end
addCommandHandler("valor", data)

 

Link to comment
41 minutes ago, kingsmi said:
function data()
local result = dbPoll(dbQuery(db,"SELECT * FROM SaveSystem "), -1)
    if not result or #result > 0 then
        for i,v in ipairs(result) do
            outputChatBox ( ""..v["Account"].."", getRootElement(), 255, 255, 255, true )
        end
    end
end
addCommandHandler("valor", data)

 

function setMoney()
	local select = dbQuery(db, "SELECT * FROM SaveSystem WHERE Account=?", getAccountName(getPlayerAccount(source)))
	local sql = dbPoll(select, -1)
	if #sql > 0 then 
		setPlayerMoney(source, sql[1].Money)
	end
end
addEventHandler ('onPlayerLogin', root, setMoney)

 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...