• MySQLOO -- Get variable from the data table?
    7 replies, posted
Hey guys, I'm trying to use MySQLOO, but the only way I can get any data from the query is to use PrintTable(). Is there a way I can get the exact data that is returned, such as get the string from that query. This is the only way I can get anything from the query, anything else just returns nil. [LUA] function q:onSuccess(data) PrintTable(data) end [/LUA] What I want to be able to do is: [LUA] function q:onSuccess(data) print(data[1]) end [/LUA] How is that possible? It just returns nil for me.
[lua]function q:onSuccess( data ) for k,v in pairs( data ) do print( v ); break; end; end; [/lua] The key to the table isn't a number, it's the name of the field.
Yeah, but data will be a table of rows. If it's printing nil, the query must've returned no result. Also why are you breaking unconditionally on the first object in the table?
[lua] local query1 = database:query("SELECT `username` FROM " .. Prefix .. "_user WHERE `username`='" .. user .. "'") query1.onSuccess = function( query ) local Arg = query:getData()[1] or nil if Arg then umsg.Start("cl_register", self) umsg.End() umsg.Start("cl_error", self) umsg.String("Registeration Error;This username is taken.") umsg.End() return end end [/lua]
Sweet, thanks, Blaspehmy, you helped me a ton!
Example already posted above but not explained, onSuccess returns the query (not the data), so you use query:getData() in order to retrieve the data.
Related. [QUOTE=Aide;38283582][QUOTE=Drakehawke;38281003]My version now passes all of query:getData as the [b]second argument [/b]to onSuccess too[/QUOTE] Your example is wrong then.[/quote]
Sorry, didn't notice you used a colon so I thought you were assigning data to the first argument.
Sorry, you need to Log In to post a reply to this thread.