.:HyPeX:. Posted December 31, 2015 Share Posted December 31, 2015 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
Gallardo9944 Posted January 1, 2016 Share Posted January 1, 2016 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
.:HyPeX:. Posted January 1, 2016 Author Share Posted January 1, 2016 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now