Jump to content

[Help] query


Fire Monkey

Recommended Posts

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 by Fire Monkey
Link to comment
  • Moderators

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 by Patrick
  • Like 1
Link to comment
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
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

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