• column name is not unique SQLite
    2 replies, posted
i have been working on a loadout menu for a deathmath gamemode. init.lua [CODE] AddCSLuaFile("menu.lua") AddCSLuaFile("sql.lua") include("sql.lua") function GM:ShowHelp(pl) pl:createSQL() umsg.Start("menu" ,pl) umsg.End() end[/CODE] sql.lua [CODE]local ply = FindMetaTable("Player") function CreateTable() sql.Query("CREATE TABLE player_data ( UniqueID string, prime string , sec string , melee string , grenades string)") end function ply:createSQL() if !sql.TableExists("player_data") then CreateTable() end t = sql.Query("SELECT UniqueID FROM player_data") if t != nil or t != false then for i,k in pairs(t) do if k.UniqueID == self:UniqueID() then print("nope") return false end end end sql.Query("INSERT INTO player_data ( UniqueID ,prime ,sec ,melee ,grenades) VALUES ('" .. self:UniqueID() .. "','ak47','deagle','knife','smoke_grenade')" ) end function ply:GetLoadout(key) if !sql.TableExists("player_data") then CreateTable() end if key == "prime" then Table = sql.Query("SELECT prime FROM player_data WHERE UniqueID = "..self:UniqueID()) print(sql.LastError()) print(Table) return Table elseif key == "sec" then elseif key == "melee" then elseif key == "grenades" then end end[/CODE] menu.lua [CODE]primarywep = LocalPlayer():GetLoadout("prime") //menu goes here[/CODE] when i open the menu i get column name is not unique as the [CODE]print(sql.LastError())[/CODE] end nil as the [CODE]print(Table)[/CODE] please help
bump
First off, stop using umsg, use the [URL="https://wiki.garrysmod.com/page/Net_Library_Usage"]Net Library[/URL] instead. And why are you running createSQL() on the player? Hope you know this means you're attempting to create player_data every time you call it on a player. You should use the Initialize hook instead.
Sorry, you need to Log In to post a reply to this thread.