Jump to content

MySQL help


.:HyPeX:.

Recommended Posts

Well idk why i'm getting syntax error, since in theory this mysql syntax is fine..

  
error near 'IF EXISTS (SELECT * FROM statTable WHERE user = ?)' 
  

  
addCommandHandler('db',function(player,cmd) 
outputChatBox('db') 
    local source = player 
    local acc = getElementData(source,'username') 
    if not acc then  
    outputChatBox('no acc') 
    return end 
        dbQuery( 
        function(qh,rows,columns) 
            local result = dbPoll(qh,0) 
            outputChatBox('affected: ') 
        end, 
        Database, 
        [[ 
        IF EXISTS (SELECT * FROM statTable WHERE user = ?) 
            BEGIN 
             
            END 
        ELSE 
            BEGIN 
                INSERT INTO statTable ( 
                    (user, 
                    name, 
                    serial, 
                    cash, 
                    exp, 
                    playtime, 
                    joins, 
                    hunters, 
                    kills, 
                    deaths, 
                    mapsplayed, 
                    mapswon 
                    ) 
                    VALUES ( 
                    ?,?,?,0,0,0,1,0,0,0,0,0 
                    ) 
                ) 
            END 
       ]],acc,acc,getPlayerName(source):gsub('#%x%x%x%x%x%x',''),getPlayerSerial(source) )     
end) 

Link to comment

INSERT INTO serverdata.userdata (member_name) SELECT member_name FROM smf.smf_members WHERE member_name=`??` AND NOT EXISTS(SELECT member_name FROM serverdata.userdata WHERE member_name=`??`); 

This is how my one works. It clones name from another database & table if it exists and inserts row only if it doesn't exist (check last part).

Link to comment

INSERT INTO serverdata.userdata (member_name) SELECT member_name FROM smf.smf_members WHERE member_name=`??` AND NOT EXISTS(SELECT member_name FROM serverdata.userdata WHERE member_name=`??`); 

This is how my one works. It clones name from another database & table if it exists and inserts row only if it doesn't exist (check last part).

Thanks for the reply! thought in the end i ended doing a simple query and checking for results and doing an dbExec if no results :)

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...