MySQL Query (MySQLOO)

So basically I’m wanting to join multiple queries into 1 query. After failing for a while I created a very simple test query and it also seems to fail.I created the test to simply try executing the query when it’s stored inside a variable, I’ve dumped the variable to see it’s contents and all seems fine in that regard:

For example, this works fine:
[LUA]
DB.Query(“UPDATE testable SET value=value+1 WHERE steamid =”…sql.SQLStr(v:SteamID())…";")
[/LUA]
But when trying to execute the query in this manner it doesn’t seem to update the values, however no errors are appearing either on the gmod server or the mysql server.
[LUA]
xquery = “UPDATE testable SET value=value+1 WHERE steamid =”…sql.SQLStr(v:SteamID())…";"
DB.Query(xquery)
[/LUA]

print of xquery:

http://goo.gl/skm1j

I’ve received no errors either on the garrysmod server or the mysql server so im a bit stumped. Any ideas?

Works fine for me:



lua_run xquery = "UPDATE a_test SET field1 = field1 + 1 WHERE field2 = 'testing'"
> xquery = "UPDATE a_test SET field1 = field1 + 1 WHERE field2 = 'testing'"...
lua_run testquery = SRH.DB.MySQL:query( xquery )
> testquery = SRH.DB.MySQL:query( xquery )...
lua_Run testquery.onSuccess = function() print("Query Successful") end
> testquery.onSuccess = function() print("Query Successful") end...
lua_run testquery.onError = function() print("Query Errored") end
> testquery.onError = function() print("Query Errored") end...
lua_run testquery:start()
> testquery:start()...
Query Successful


http://puu.sh/1C6ii

(it was 3 before)

This is incredibly strange if true, it’s like print( “hi” ) working but str = “hi” print( str ) not working.

Maybe it’s due to the “” used by sql.SQLStr?

[lua]xquery = “UPDATE testable SET value=value+1 WHERE steamid =’”…sql.SQLStr(v:SteamID())…"’;"[/lua]

Use ’ '.

I don’t think sql.SQLStr is safe to use with MySQL anyway, it doesn’t escape some extra stuff it should, try using db:escape( str ) instead

I had just tried to test it again incase I was being an idiot, however no such luck, a screenshot of my code + server readout and the table after the code was executed.

http://goo.gl/EDB3P

[LUA]local xquery;
for k,v in pairs(player.GetAll()) do
if IsValid(v) and v:IsPlayer() then
xquery = “UPDATE testable SET value=value+1 WHERE = “…sql.SQLStr(v:SteamID())…”;”;
end
end[/LUA]
@ Aide, I also tried that just after, no change.

Uhh, xquery is defined locally? It will be nil anywhere outside that file

But you’re not actually making a query in that file.

Fixed.
[LUA]
xquery = “UPDATE testtable SET value=value+1 WHERE steamid= '”…DB.MySQLDB:escape(v:SteamID())…"’;";
[/LUA]

It seems when using sql.SQLStr it messes it up, no idea why.

Thanks for the help. Also @ Luni I was I just failed my copy paste into this thread, sorry.

-edit

Actually [LUA] xquery = “UPDATE testtable SET value=value+1 WHERE steamid= “…sql.SQLStr(v:SteamID())…”;”;
[/LUA]

Is working fine now, but it seems to have issues when using multiple sql.SQLStr, I’ll stick with DB:escape, seems more friendly.

Thanks :slight_smile: