• sqlite error
    6 replies, posted
I tried to create a little something for an event I'm doing, I haven't done much in gmod lately and never used sqlite so i'm pretty rusty. But I am receiving this error near "LIMIT": syntax error seems weird because I am not using limit in any of my queries [QUOTE]if SERVER then util.AddNetworkString( "ticket_recieve" ) if not sql.TableExists( "ticket" ) then sql.Query( "CREATE TABLE IF NOT EXISTS ticket ( steamid string NOT NULL PRIMARY KEY, name string NOT NULL, lastticket string NOT NULL, ticketcount INTEGER NOT NULL);" ) end function Ticket_ServerTicker() local Timestamp = os.time() local TimeString = os.date( "%m/%d/%Y" , Timestamp ) for _,ply in pairs(player.GetAll()) do if !(ply:IsValid()) then return end timeConnected = math.Round(ply:TimeConnected() / 60) if timeConnected <= 30 then return end local lastticket = sql.QueryValue( "select lastticket from ticket where steamid = '" .. ply:SteamID() .. "'") if !(lastticket) then --print("Insert new steamid") sql.Query ("INSERT into ticket VALUES ( '" .. ply:SteamID() .. "', '" .. sql.SQLStr(ply:Name(), true) .. "', '" .. TimeString .. "', 1)") net.Start("ticket_recieve") net.Send( ply ) else if lastticket != TimeString then local ticketcount = sql.QueryValue( "select ticketcount from ticket where steamid = '" .. ply:SteamID() .. "'") ticketcount = ticketcount + 1 --print("update ticketcount and date") sql.Query ("UPDATE ticket SET ticketcount = '" .. ticketcount .. "', lastticket = '" .. TimeString .. "' where steamid = '" .. ply:SteamID() .. "'") net.Start("ticket_recieve") net.Send( ply ) end end --print(sql.LastError()) end end hook.Add('Tick', 'ticket_tick', Ticket_ServerTicker) end if CLIENT then net.Receive( "ticket_recieve", function( len, ply ) chat.AddText( Color(255, 0, 0), "You have received your event ticket for the day!") end ) end[/QUOTE]
[QUOTE=ZachPL;52257815]I tried to create a little something for an event I'm doing, I haven't done much in gmod lately and never used sqlite so i'm pretty rusty. But I am receiving this error near "LIMIT": syntax error seems weird because I am not using limit in any of my queries[/QUOTE] Do you think you could send the whole error? Also I recommend putting the code in [CODE] tags :)
[QUOTE=Bings;52257832]Do you think you could send the whole error? Also I recommend putting the code in [CODE] tags :)[/QUOTE] Sorry thought I did, and that is the only part of the error that comes back from sql.LastError() the code runs fine itself. I forgot to mention that it inserted like 7 people before it started giving that error [CODE]if SERVER then util.AddNetworkString( "ticket_recieve" ) if not sql.TableExists( "ticket" ) then sql.Query( "CREATE TABLE IF NOT EXISTS ticket ( steamid string NOT NULL PRIMARY KEY, name string NOT NULL, lastticket string NOT NULL, ticketcount INTEGER NOT NULL);" ) end function Ticket_ServerTicker() local Timestamp = os.time() local TimeString = os.date( "%m/%d/%Y" , Timestamp ) for _,ply in pairs(player.GetAll()) do if !(ply:IsValid()) then return end timeConnected = math.Round(ply:TimeConnected() / 60) if timeConnected <= 30 then return end local lastticket = sql.QueryValue( "select lastticket from ticket where steamid = '" .. ply:SteamID() .. "'") if !(lastticket) then --print("Insert new steamid") sql.Query ("INSERT into ticket VALUES ( '" .. ply:SteamID() .. "', '" .. sql.SQLStr(ply:Name(), true) .. "', '" .. TimeString .. "', 1)") net.Start("ticket_recieve") net.Send( ply ) else if lastticket != TimeString then --print("select ticketcount in update") local ticketcount = sql.QueryValue( "select ticketcount from ticket where steamid = '" .. ply:SteamID() .. "'") ticketcount = ticketcount + 1 --print("update ticketcount and date") sql.Query ("UPDATE ticket SET ticketcount = '" .. ticketcount .. "', lastticket = '" .. TimeString .. "' where steamid = '" .. ply:SteamID() .. "'") net.Start("ticket_recieve") net.Send( ply ) end end --print(sql.LastError()) end end hook.Add('Tick', 'ticket_tick', Ticket_ServerTicker) end if CLIENT then net.Receive( "ticket_recieve", function( len, ply ) chat.AddText( Color(255, 0, 0), "You have received your event ticket for the day!") chat.AddText( Color(255, 0, 0), "For more info visit the forums,") chat.AddText( Color(255, 0, 0), "http://www.joinsg.net/forums/topic/75546-summertime-vanilla-madness-may-21st-31st/") chat.AddText( Color(255, 0, 0), "You could win prizes!") end ) end[/CODE]
I made a few changes - Made any lowercase SELECT, FROM, etc uppercase as that was annoying me, its essentially just better coding practices - Added LIMIT 1 so it knows to stop searching after it's found one, little bit of efficiency - Made timeConnected a local - Changed the check on lastticket to include for if its nil because sometimes it throws nil back and i'm not sure if what you had would handle iit well (never thought of checking that way lol), - Made the 2 SQL statements on line 26 - 29 1 query May fix you're problem, maybe not - but at least its neater! [CODE] if SERVER then util.AddNetworkString( "ticket_recieve" ) if not sql.TableExists( "ticket" ) then sql.Query( "CREATE TABLE IF NOT EXISTS ticket ( steamid STRING NOT NULL PRIMARY KEY, name STRING NOT NULL, lastticket STRING NOT NULL, ticketcount INTEGER NOT NULL);" ) end function Ticket_ServerTicker() local Timestamp = os.time() local TimeString = os.date( "%m/%d/%Y" , Timestamp ) for _, ply in pairs(player.GetAll()) do if !(ply:IsValid()) then return end --------------------------- local timeConnected = math.Round(ply:TimeConnected() / 60) -- MADE LOCAL if timeConnected <= 30 then return end -------------------------- local lastticket = sql.QueryValue( "SELECT lastticket FROM ticket WHERE steamid = '" .. ply:SteamID() .. "' LIMIT 1 ") -- FIXED UPPERCASE -------------------------- if lastticket == false or nil then -- sometimes it does either for me so fuck it sql.Query ("INSERT INTO ticket VALUES ( '" .. ply:SteamID() .. "', '" .. sql.SQLStr(ply:Name(), true) .. "', '" .. TimeString .. "', 1)") -- MADE 1 STATEMENTS & UPPERCASE net.Start("ticket_recieve") net.Send( ply ) else if lastticket != TimeString then sql.Query ("UPDATE ticket SET ticketcount = ticketcount + 1, lastticket = '" .. TimeString .. "' WHERE steamid = '" .. ply:SteamID() .. "'") -- MADE 1 STATEMENTS & UPPERCASE net.Start("ticket_recieve") net.Send( ply ) end end end end hook.Add('Tick', 'ticket_tick', Ticket_ServerTicker) end if CLIENT then net.Receive( "ticket_recieve", function( len, ply ) chat.AddText( Color(255, 0, 0), "You have received your event ticket for the day!") chat.AddText( Color(255, 0, 0), "For more info visit the forums,") chat.AddText( Color(255, 0, 0), "http://www.joinsg.net/forums/topic/75546-summertime-vanilla-madness-may-21st-31st/") chat.AddText( Color(255, 0, 0), "You could win prizes!") end ) end [/CODE] [B]Edit:[/B] you also spelt receive wrong but no biggie and I didn't change it :p
Still not working unfortunately, it has added 12 people, but my guess is it should be at least double that I know at least myself and someone else were not added. Here is the DB and the error it spams to console [img]http://i.imgur.com/7hMr8u9.png[/img] I'll keep trying different variations to see if I can figure anything else out.
[QUOTE=ZachPL;52257979]Still not working unfortunately, it has added 12 people, but my guess is it should be at least double that I know at least myself and someone else were not added. Here is the DB and the error it spams to console [img]http://i.imgur.com/7hMr8u9.png[/img] I'll keep trying different variations to see if I can figure anything else out.[/QUOTE] The error could be originating from somewhere else in you're/someone's code but its the last error recorded meaning it will keep saying that till a new one comes along. Stick a print below "for _, ply in pairs(player.GetAll()) do" with [CODE]print(ply:Nick())[/CODE] If its stops abruptly before then end of players, we will have a better idea on what's going on!
Oh I see, I bet that error is from the damagelogs manager and completed unrelated. I noticed it goes through a few people when the map changes, then it keeps repeating the same person over and over, I guess I need a way to skip someone so they aren't repeated. Edit: not really sure how to fix, just spamming the same person over and over
Sorry, you need to Log In to post a reply to this thread.