1. Post #1
    Gold Member
    Ludicium's Avatar
    March 2012
    174 Posts
    I apologize in advance for the terrible coding.

    So when i go to retrieve data from table donator_data i can't get anything out. I don't know where else to turn to but the bunch of geniuses you are.
    I have a bunch of commands in here that i was using to debug so just disregard those. sql.LastError() returns no such column: nil on all the queries in data retrieval.
    Please Help my stupidity.

    Data Entry:

    function saveText( ply, donatortext  )
    	steamID = ply:GetNWString("SteamID")
    	print(donatortext)
    	sql.Query("UPDATE donator_info SET donatortext = "..donatortext.." WHERE unique_id = '"..steamID.."'")
    	ply:ChatPrint("Text Changed!")
    end
    
    function saveColor( ply, textcolor )
    	steamID = ply:GetNWString("SteamID")
    	PrintTable(textcolor)
    	red = textcolor[r]
    	green = textcolor[g]
    	blue = textcolor[b]
    	alpha = textcolor[a]
    	sql.Query("UPDATE donator_info SET red = "..tostring(red)..", green = "..tostring(green)..", blue = "..tostring(blue)..", alpha = "..tostring(alpha).." WHERE unique_id = '"..steamID.."'")
    	ply:ChatPrint("Color Changed!")
    end
    


    New Player:

    function new_player( SteamID, ply )
     
    		steamID = SteamID
    		sql.Query( "INSERT INTO donator_info (`unique_id`, `donatortext`, `red`, `green`, `blue`, `alpha`)VALUES ('"..steamID.."', '(VIP)', '233', '0', '255', '255')" )
    		result = sql.Query( "SELECT unique_id, donatortext, red, green, blue, alpha FROM donator_info WHERE unique_id = '"..steamID.."'" )
    		if (result) then
     
    		else
    			Msg("Something went wrong with creating a donator info !\n")
    		end
    end
    


    Table Creation:

    function tables_exist()
     
    	if (sql.TableExists("donator_info")) then
    		Msg("Table already exists !")
    	else
    		if (!sql.TableExists("donator_info")) then
    			query = "CREATE TABLE donator_info ( unique_id varchar(255), red varchar(255), green varchar(255), blue varchar(255), alpha varchar(255) )"
    			result = sql.Query(query)
    			if (sql.TableExists("donator_info")) then
    				Msg("Succes ! table 1 created \n")
    			else
    				Msg("Somthing went wrong with the donator_info query ! \n")
    				Msg( sql.LastError( result ) .. "\n" )
    			end	
    		end
    	end
    end
    

    Retrieval:

    	elseif pl:GetUserGroup() == "vip" then
    	        unique_id = pl:SteamID()
    		donatortext = sql.Query("SELECT donatortext FROM donator_info WHERE unique_id = '"..unique_id.."'")
    		print(sql.LastError())
    		red = sql.Query("SELECT red FROM donator_info WHERE unique_id = '"..unique_id.."'")
    		print(sql.LastError())
    		green = sql.Query("SELECT green FROM donator_info WHERE unique_id = '"..unique_id.."'")
    		print(sql.LastError())
    		blue = sql.Query("SELECT blue FROM donator_info WHERE unique_id = '"..unique_id.."'")
    		print(sql.LastError())
    		alpha = sql.Query("SELECT alpha FROM donator_info WHERE unique_id = '"..unique_id.."'")
    		print(sql.LastError())
    		print(donatortext)
    		print(red)
    		print(green)
    		print(blue)
    		print(alpha)
    		table.insert( tab, Color( red, green, blue, alpha ) )
    			table.insert( tab, donatortext )
    

  2. Post #2
    Gold Member
    Hyper Iguana's Avatar
    March 2011
    700 Posts
     query = "CREATE TABLE donator_info ( unique_id varchar(255), red varchar(255), green varchar(255), blue varchar(255), alpha varchar(255) )"

    In table creation, donatortext is never specified.

  3. Post #3
    Map in a box's Avatar
    July 2009
    7,419 Posts
    R,G,B,A is a varchar with a max size of 255.

  4. Post #4
    Gold Member
    Ludicium's Avatar
    March 2012
    174 Posts
    No worries I'm even more stupid then u would imagine...