SQL Issues

Hi there, here’s my problem: I have a database, which prior to me reinstalling Garry’s Mod (which obviously brought a new sv.db), did work. Now I am using the exact same but it refuses to work. To my utter frustration, I have located the problem and know what seems to be causing it, but I can not do anything about it. I have a snippet of code which essentially checks if a player exists in the database and if not, calls another function which adds it to the table. Once the new player has been added, the original check is run again and the stats are loaded.

There are two separate errors I get from this, first off it seems that if I run a check to see if a player is in the table --> there isn’t, so it adds him/her to the table --> check again for this player --> the check doesn’t work and the cycle repeats. This causes a stack overflow of loading and adding this player in the db. The next error happens when I remove the possibility of there being a cycle it doesn’t add any stats to the player. I’m assuming there’s a change within how the new db works. Also this is working with DarkRP (Yes, yes, darkrp boo stupid)

Ok, enough babbling, here’s the code:

GDB = {}
function GDB.Initialize()
	if sql.TableExists('bob') == false then
		sql.Query( "CREATE TABLE bob ( uid TEXT, kills INT, deaths INT)" )
		return true
hook.Add("Initialize", "GDB Init", GDB.Initialize)

function GDB.LoadEntry( person )
	if not person:IsValid() then return end

	local Result = sql.Query( "SELECT * FROM bob WHERE uid = '"..person:UniqueID().."'" )
	if  then
		Result = Result[1]
		person.Kills = Result.kills or 0
		person.Deaths = Result.deaths or 0
		GDB.SendEntry( person )
		GDB.AddEntry( person )
hook.Add("PlayerInitialSpawn", "GDB LoadEntry", GDB.LoadEntry)

function GDB.UpdateEntry( person )
	if not person then return end
	sql.Query("UPDATE bob SET kills = '"..person.Kills.."', deaths = '"..person.Deaths.."' WHERE uid = '"..person:UniqueID().."'")

function GDB.SendEntry( person )
	net.Start( 'NET_Entry' )
		net.WriteEntity( person )
		net.WriteInt( person.Kills, 32 )
		net.WriteInt( person.Deaths, 32 )
	net.Send( person )

function GDB.AddEntry( person )
	sql.Query( "INSERT INTO bob (uid, kills, deaths) VALUES ('"..person:UniqueID().."', 0, 0)" )
	GDB.LoadEntry( person )

Can’t get the error message right now, sorry will update in due time!

Thanks in advance

As I told you Goose over steam.

Change line where you are adding new entry so it looks like this:

local q = sql.Query( "INSERT [ rest of code here ]" )

And then execute:

print( sql.LastError( q ) )