• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua how to use numRows

tiddpd

PHP Scripter
Joined
Apr 16, 2008
Messages
331
Reaction score
0
I've spent 2 hours now trying to use this sql function called numRows. I need this is that if theres 0 rows (or results) in the query it wont spam the server windows with errors.

Ive tried it in the following formats which doesn't work:

Code:
Result.numRows
Result:numRows
Result.numRows(free)
Result:numRows(free)
Result.numRows("field name")
Result:numRows("field name")

I also tried all those above ones using getRows too which never worked. Theres probably other combonations i've tried but just dont work. And its driving me crazy, anyone know how to use it?
 
Are you sure that this function even exists in TFS natively? I cant seem to find it anywhere in the list of available functions. all i could find was

Code:
//db table
db.executeQuery(query)
db.storeQuery(query)
db.escapeString(str)
db.escapeBlob(s, length)
db.stringComparisonOperator()

//result table
result.getDataInt(resId, s)
result.getDataLong(resId, s)
result.getDataString(resId, s)
result.getDataStream(resId, s, length)
result.next(resId)
result.free(resId)


EDIT:
Actually I looked up that a bit more and found it in the database.lua in libs.

Try using something like...

Code:
local dbstuff = db.executeQuery("OMG QUERY")
local dbfree = result.free(dbstuff)
local numrows = Result.getRows(dbfree)
 
Last edited:
when you look at lib/database.lua you see this:
Code:
Result.numRows = Result.getRows
function db.getResult(query)
	if(type(query) ~= 'string') then
		return nil
	end

	local ret = Result:new()
	ret:create(query)
	return ret
end
 
You can use res:getID() to see if query is set. Its -1 where no rows was returned.

for example:
Code:
local myRes = db.getResult("SELECT `something` FROM `somewhere`")
if(myRes:getID() == -1) then
	return -- no rows
end
-- do what you want
 

Similar threads

Back
Top