xTravax Posted May 26, 2015 Share Posted May 26, 2015 Hi I've got this code: executeSQLQuery( 'CREATE TABLE IF NOT EXISTS SerialData ( serialPlayer TEXT, key STRING, value TEXT )' ) aType = {["number"] = true,["string"] = true} function setSerialData(serial,key,value) outputDebugString("setSerialData '"..key.."', '"..tostring(value).."'") if type(key) == "string" and aType[type(value)] then if getSerialData( serial, key ) then executeSQLQuery( 'UPDATE SerialData SET serialPlayer = ?, key = ?, value = ?', serial, key, value ) return true else executeSQLQuery( 'INSERT INTO SerialData( serialPlayer, key, value ) VALUES( ?, ?, ? )', serial, key, value ) return true end end end function getSerialData(serial,key) outputDebugString("getSerialData") if type(key) == "string" then result = executeSQLQuery( 'SELECT value FROM SerialData WHERE key = ? AND serialPlayer = ?', key, serial ) end if result and type(result) == "table" and #result > 0 then if result[1]["value"] then return result[1]["value"] else return false end end return false end function removeSerialData(serial,key) if type(key) == "string" then if getSerialData(serial,key) then executeSQLQuery( 'DELETE FROM SerialData WHERE key = ? AND serialPlayer = ?', key, serial ) return true end end end it works flawlessly, though there's one problem When i use those functions to store data on my serial, it works but if i log out and make completely new account and login to it, that data will get lost(returning false) for unknown reason Does anyone know why does this occur?it only occurs onPlayerLogin and this code above is not even executed when data gets corrupted Link to comment
Walid Posted May 26, 2015 Share Posted May 26, 2015 i recommand you to use db functions. dbConnect dbExec dbQuery dbPoll dbFree Anyways executeSQLQuery( 'CREATE TABLE IF NOT EXISTS SerialData ( serialPlayer TEXT, key STRING, value TEXT )' ) function setSerialData(serial,key,value) if getSerialData( serial, key ) then executeSQLQuery( 'UPDATE SerialData SET serialPlayer = ?, key = ?, value = ?', serial, tostring(key), tostring(value)) else executeSQLQuery( 'INSERT INTO SerialData( serialPlayer, key, value ) VALUES( ?, ?, ? )', serial, tostring(key), tostring(value)) end end function getSerialData(serial,key) local result = executeSQLQuery( 'SELECT value FROM SerialData WHERE key = ? AND serialPlayer = ?', tostring(key), serial ) if type(result) == "table" and #result == 0 or not result then return false else return tostring (result[1]["value"]) end end function removeSerialData(serial,key) if getSerialData(serial,key) then executeSQLQuery( 'DELETE FROM SerialData WHERE key = ? AND serialPlayer = ?', tostring(key), serial ) return true end end function Load(_,cur) local serial = getAccountSerial (cur) if serial then -- Your Code here end end addEventHandler("onPlayerLogin",root,Load) Link to comment
xTravax Posted May 26, 2015 Author Share Posted May 26, 2015 no still, data gets lost onPlayerLogin Link to comment
Walid Posted May 26, 2015 Share Posted May 26, 2015 no still, data gets lost onPlayerLogin Try to use db functions 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