Jump to content

checking if some specific data already exists in SQLDatabase


Recommended Posts

hi i wrote this code

function addPlayerInTeam(player,cmd,targetElement,team,rank) 
  if exports.admin:isPlayerAdmin(player) then 
     if not team then outputChatBox("[/setplayerteam] team is missing at argument 2!",player,255,0,0) return end 
     if not rank then outputChatBox("[/setplayerteam] rank is missing at argument 3!",player,255,0,0) return end 
     local targetElement = getPlayerFromName(targetElement) 
     if targetElement then 
        local isPlayerInClan = dbExec(database,"SELECT * FROM "..team.." WHERE memberSerial=?",getPlayerSerial(targetElement)) 
        if not isPlayerInClan then 
           local result = dbExec(database,"INSERT INTO "..team:lower().." ( memberName, memberSerial, memberRank ) VALUES (?,?,?)",getPlayerName(targetElement):gsub("#%x%x%x%x%x%x",""),getPlayerSerial(targetElement),rank) 
           outputChatBox("Transferring player to sql database into "..team.." team...",player,0,0,255) 
           outputChatBox("Result: "..tostring(result)) 
        else 
           outputChatBox("WARNING! Player is already in that clan!",player,255,0,0) 
        end 
     else 
        outputChatBox("[/setplayerteam] player not found.",player,255,0,0) 
     end 
   end 
end 
addCommandHandler("setplayerteam",addPlayerInTeam) 

i am pretty new at sql and i didnt know any other way to check if something exists rather than SELECT * FROM something WHERE memberSerial=?,serial

please help if you know sql

Link to comment

i changed lines to this

  
        local isPlayerInClan = dbQuery(database,"SELECT * FROM "..team.." WHERE memberSerial=?",getPlayerSerial(targetElement)) 
        local theResult = dbPoll(isPlayerInClan,-1) 
               if not theResult then  
                  --dbExec(...) 
               else 
               --output warning player found 
              --... 
  

still it always says player already in database

i am not sure how do i debug this, result returns a table, i thought it returns a boolean.. idk what to do now

Link to comment

thanks but umm i have other problem..

in my code theres variable team which is transferred over command

i have inserted myself into team a and it returned true

if i want to put myself again into a it doesnt allow it - nice

however if i want to put myself in team b as well, it wont allow me

:|

Link to comment

i am in a progress of making team/clan manager which will later consist of a gui where i or someone else would put people in other teams or in my own team

i have created a command like in above code just for testing with SQL since im pretty new at it, still learning

with above code+ some editions from you(which you posted) i got a script which will successfully put me in my sql table team of choice

however when i put myself once in any team, i cant put myself in any other team since it outputs to chatbox

"player is already in a clan"

and i dont know how to solve this as im new to sql..

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...