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:
DB.Query(“UPDATE testable SET value=value+1 WHERE steamid =”…sql.SQLStr(v:SteamID())…";")
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.
xquery = “UPDATE testable SET value=value+1 WHERE steamid =”…sql.SQLStr(v:SteamID())…";"

print of xquery:

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

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

[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())…”;”;
@ 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.

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

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.


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

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: