attempt to get length of local 'query' (a userdata value)

Hey!

So here I am, I’m trying to fix an old gamemode, from 2009 and I’ve got some issues to convert the mysql.

(It used gdatabase and now it’s on mysqloo)

So here’s the error:


attempt to get length of local 'query' (a nil value)

And the script:

[lua]local query = DB:query(“SELECT id, steamid, name, model, age FROM characters WHERE steamid = '”…steamid…"’;", DB)

ply:ChatPrint("SAVES READY")
if(#query > 4)then
ply:ChatPrint("YOU HAVE MORE THAN 4 SAVES! Any more than 4 have been discarded!")
end
	umsg.Start( "save", ply );
		umsg.String( "RECREATETABLE" );
		umsg.String( "RECREATETABLE" );
	umsg.End( );
for k,v in pairs(query) do
	if(k >= 5)then
		break
	end
	ply:ChatPrint("SAVE SENT")
	print("SAVE: " .. v[3])
	print("MODEL: " .. v[4])
	umsg.Start( "save", ply );
		umsg.String( v[3] );
		umsg.String( v[4] );
	umsg.End( );
end

end
[/lua]

Thanks for your help!

Why’s DB the second argument in query? I don’t see a reason in that being there.

MySQLOO’s queries are asynchronous, DB:query will return an object you can use asynchronously, it will not return the data from the query.

The error’s caused because you’re trying to get the length of a query, rather than the query’s results.

So, any idea on how to do it? And the DB second argument’s being there is because well, it works that way but isn’t really necessary.

I told you what you need to know, you should be able to figure it out from there.

Here’s a quick fix, I don’t recommend using it, though.
[lua]
local query = DB:query(“SELECT id, steamid, name, model, age FROM characters WHERE steamid = '”…steamid…"’;")

query:wait();
query = query:getData();
[/lua]