Fire Monkey Posted October 13, 2020 Share Posted October 13, 2020 (edited) addCommandHandler("info", function (player, cmd, name) if name then dbQuery(function (qh) local res = dbPoll(qh, 0) if res[1] ~= nil then outputChatBox("Password: "..res[1]["password"], player) return end outputChatBox("Not found!", player, 0, 255, 0) return end, db, "SELECT * FROM `accounts` WHERE `name` = ? LIMIT 1", value) end end ) Is this query of optimized? Does not damage the server & bandwidth? Need dbFree for this query? Edited October 13, 2020 by Fire Monkey Link to comment
Moderators Patrick Posted October 13, 2020 Moderators Share Posted October 13, 2020 (edited) Hi! Looks okay, but you should limit the usage of command, because players can spam it. And the value variable is not defined in 12th line, I think you wanted to use name. Quote Need dbFree for this query? No, because dbPoll do it for you. As well dbQuery's callback function would be better like that: And return is unnecessary because you can't return value from callback. (but of course, you can use it to leave from function, if you want) local res = dbPoll(qh, 0) if res and #res == 1 then outputChatBox("Password: "..res[1]["password"], player) else outputChatBox("Not found!", player, 0, 255, 0) end Edited October 13, 2020 by Patrick 1 Link to comment
Fire Monkey Posted October 13, 2020 Author Share Posted October 13, 2020 1 minute ago, Patrick said: Hi! Looks okay, but you should limit the usage of command, because players can spam it. And the value variable is not defined in 12th line, I think you wanted to use name. No, because dbPoll do it for you. As well dbQuery's callback function would be better like that: local res = dbPoll(qh, 0) if res and #res == 1 then outputChatBox("Password: "..res[1]["password"], player) else outputChatBox("Not found!", player, 0, 255, 0) end Should it be used from dbFree when there are no dbPoll? How many times should I limit the command? Link to comment
Moderators Patrick Posted October 13, 2020 Moderators Share Posted October 13, 2020 2 minutes ago, Fire Monkey said: Should it be used from dbFree when there are no dbPoll? Yes, dbFree only needs to be used if a result has not been obtained with dbPoll. 4 minutes ago, Fire Monkey said: How many times should I limit the command? Let it be used once in every 30s or more. (but 10s minimum I think) Link to comment
Fire Monkey Posted October 13, 2020 Author Share Posted October 13, 2020 (edited) Thanks you! Edited October 13, 2020 by Fire Monkey 1 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