tmysql4 - A multi-connection version of tmysql3 (Now with mysqloo wrapper!)
384 replies, posted
I guess it turns out that this doesn't support multiple statements at once? That should be noted somewhere, just spent a decent bit of time with help from a few others trying to figure out what was wrong with this query...
[lua]local makeTableOne = "CREATE TABLE IF NOT EXISTS `sstore_users` (`steamid32` TEXT, `money` INTEGER);"
local makeTableTwo = "CREATE TABLE IF NOT EXISTS `sstore_masks` (`steamid32` TEXT, `item_ids` TEXT);"
sstore.Database.DB:Query(makeTableOne..makeTableTwo, somefunc())[/lua]
but nothing was actually wrong with it.
[QUOTE=YourStalker;50127263]I guess it turns out that this doesn't support multiple statements at once?[/QUOTE]
Use CLIENT_MULTI_STATEMENTS as the 7th argument in tmysql.initialize. Only found this out by looking through this thread, well that and looking at the source code, but there should really be a list somewhere.
[QUOTE=bigdogmat;50128053]but there should really be a list somewhere.[/QUOTE]
It's literally in the OP
:v:
I recently switched from mysqloo to tmysql4; the win version from the OP's github. (thanks for that btw, I was leaking up to 1000MB an hour on TTT servers that were idling).
I first switch to it on my new lobby server, using the wrapper provided. The lobby server at the time connected to 3 different databases, and converted with no issues or side effects.
After a few weeks, 2 days ago, I switched my TTT test server over. I didn't test every feature I had out but quick tests resulted in full functionality. I informed my server dev of the changes and he reported no problems during his testing.
Today I implemented it on my main TTT servers. These servers connect to several databases, including the one my forums use.
I put one server up and things are going good with no problems, about 15 people in the server. I then put another one up and a little while after people join it gets all fritzy and crashes and doesnt want to reboot. condebug shows that db:onConnectionFailed(err) is being called on one or more of the db connections sometimes. It also shows '...failed to connect. Can't connect to MySQL server on 'xxxxxxxxx' (10060)
Most of the time however, it only allows one server at once. If I have 2 turned on, the one that is off and crashing/restarting will come back online when the first server is map changing, thus leading me to the hypothesis that;
I think tmysql4 and/or the wrapper I used, or a combination of one or both of those things along with one or more of the countless db connections in the code cause one server not function while another is active.
Has anyone had a similar issue? Ideas in how to investigate it further?
[QUOTE=BlackAwps;50132049]It's literally in the OP
:v:[/QUOTE]
It literally never mentions it's purpose or that you'd need it for multiple statements in one query. Also, in the example you do use CLIENT_MULTI_STATEMENTS but you don't really show it sending multiple statements.
[QUOTE=Phishcook;50133513]I recently switched from mysqloo to tmysql4; the win version from the OP's github. (thanks for that btw, I was leaking up to 1000MB an hour on TTT servers that were idling).
I first switch to it on my new lobby server, using the wrapper provided. The lobby server at the time connected to 3 different databases, and converted with no issues or side effects.
After a few weeks, 2 days ago, I switched my TTT test server over. I didn't test every feature I had out but quick tests resulted in full functionality. I informed my server dev of the changes and he reported no problems during his testing.
Today I implemented it on my main TTT servers. These servers connect to several databases, including the one my forums use.
I put one server up and things are going good with no problems, about 15 people in the server. I then put another one up and a little while after people join it gets all fritzy and crashes and doesnt want to reboot. condebug shows that db:onConnectionFailed(err) is being called on one or more of the db connections sometimes. It also shows '...failed to connect. Can't connect to MySQL server on 'xxxxxxxxx' (10060)
Most of the time however, it only allows one server at once. If I have 2 turned on, the one that is off and crashing/restarting will come back online when the first server is map changing, thus leading me to the hypothesis that;
I think tmysql4 and/or the wrapper I used, or a combination of one or both of those things along with one or more of the countless db connections in the code cause one server not function while another is active.
Has anyone had a similar issue? Ideas in how to investigate it further?[/QUOTE]
Where is your database hosted? Is it on some form of shared hosting or on a dedicated machine?
[QUOTE=Teddi Orange;50136226]Where is your database hosted? Is it on some form of shared hosting or on a dedicated machine?[/QUOTE]
I use a dedicated VPS from NFO servers, the managed format. It has a local database (on the webserver that is in the package).
Maybe I've just gone insane, but were null items from a database always a single space when selected?
Edit: Nope, according to the Source it's supposed to return nil. I'll do some more digging and see if I can find what's causing this.
Would anyone happen to have a version before this one?, preferably from 2014?
Thanks
[QUOTE=Borris_Squad;50450242]Would anyone happen to have a version before this one?, preferably from 2014?
Thanks[/QUOTE]
Is there any reason why you need an older version? Anything around the ~2014 time is unlikely to work due to GM13 being released and further updates.
[QUOTE=Teddi Orange;50450440]Is there any reason why you need an older version? Anything around the ~2014 time is unlikely to work due to GM13 being released and further updates.[/QUOTE]
Yes, there is. - But if it would complicate things more then i don't know. Basically the gm uses the DATABASE:Escape string, and well, its either have it working with that string or change a load of code.
[QUOTE=Borris_Squad;50450500]Yes, there is. - But if it would complicate things more then i don't know. Basically the gm uses the DATABASE:Escape string, and well, its either have it working with that string or change a load of code.[/QUOTE]
What? The method name is still Escape, unless I'm misunderstanding what you're saying.
[QUOTE=bigdogmat;50450517]What? The method name is still Escape, unless I'm misunderstanding what you're saying.[/QUOTE]
I think it used to be tmysql.escape and not Database.Escape. I could be wrong. Either way, that is a very simple 1 liner to fix...
At worst you can do tmysql.escape = db.escape at worst
Hrmm okay. I'll look into this; I have very basic SQL knowledge
[QUOTE=andreblue;50450924]At worst you can do tmysql.escape = db.escape at worst[/QUOTE]
That did not work. The gamemode was working fine in 2015 - It just does not like the newer tmysql 4. A few functions have changed etc.
I'm having an issue when using the module where in if I do a query inside the callback of another, it doesn't run. I've also tried calling a hook inside the callback, but the queries inside the hooked function do not run either.
[QUOTE=Dannelor;50465346]I'm having an issue when using the module where in if I do a query inside the callback of another, it doesn't run. I've also tried calling a hook inside the callback, but the queries inside the hooked function do not run either.[/QUOTE]
Got the code? Not having such issues here so far!
[QUOTE=Teddi Orange;50470637]Got the code? Not having such issues here so far![/QUOTE]
[CODE]
local Database = tmysql.initialize(GM.Config.SQLDatabaseAddress,
GM.Config.SQLDatabaseUsername,
GM.Config.SQLDatabasePassword,
GM.Config.SQLDatabaseName,
GM.Config.SQLDatabasePort,
nil,CLIENT_MULTI_STATEMENTS)
Database:Query("SELECT version()",function(results)
print("This is called")
hook.Call("TestQueryHook")
end)
hook.Add("TestQueryHook","TestQueryHook",function()
print("This hook is called.")
Database:Query("SELECT version()",function()
print("The second query is called.")
end)
end)
[/CODE]
In console I get the first two prints, but the second query one is never run. (I did SELECT version() just so it would always return something)
[QUOTE=Dannelor;50470877][CODE]
local Database = tmysql.initialize(GM.Config.SQLDatabaseAddress,
GM.Config.SQLDatabaseUsername,
GM.Config.SQLDatabasePassword,
GM.Config.SQLDatabaseName,
GM.Config.SQLDatabasePort,
nil,CLIENT_MULTI_STATEMENTS)
Database:Query("SELECT version()",function(results)
print("This is called")
hook.Call("TestQueryHook")
end)
hook.Add("TestQueryHook","TestQueryHook",function()
print("This hook is called.")
Database:Query("SELECT version()",function()
print("The second query is called.")
end)
end)
[/CODE]
In console I get the first two prints, but the second query one is never run. (I did SELECT version() just so it would always return something)[/QUOTE]
Works fine for me here. Below is some sample code which essentially does the same thing, just in a wrapper of mine.
[code]
local function TestQueryCallbackTwo(tblResults)
print("Second callback has fired!")
end
hook.Add("TestCallbackTwo", "TestCallbackTwo", TestQueryCallbackTwo)
local function TestQueryCallbackOne(tblResults)
print("Received first callback. Now attempting to fire second.")
BB.Query("db", "SELECT version()", function() hook.Run("TestCallbackTwo") end)
end
local function TestQueryFire()
print("Firing main function")
BB.Query("db", "SELECT version()", TestQueryCallbackOne)
end
concommand.Add("testquery", TestQueryFire)
[/code]
Output:
[code]
Firing main function
Received first callback. Now attempting to fire second.
Second callback has fired!
[/code]
Does it work before players have joined onto the server though? I'm wanting to setup some tables as soon as the server starts, and they require the previous to have run before they can start. On startup the first query will always run, but the rest are delayed until a player joins.
[QUOTE=Dannelor;50479217]Does it work before players have joined onto the server though? I'm wanting to setup some tables as soon as the server starts, and they require the previous to have run before they can start. On startup the first query will always run, but the rest are delayed until a player joins.[/QUOTE]
Because this runs a function on tick to check if any of its queries have finished you either need to have a player on, or have `sv_hibernate_think` set to 1. At least I think, I'm pretty sure it'll run tick as well
[QUOTE=Dannelor;50479217]Does it work before players have joined onto the server though? I'm wanting to setup some tables as soon as the server starts, and they require the previous to have run before they can start. On startup the first query will always run, but the rest are delayed until a player joins.[/QUOTE]
Spawn a bot, and once you are done with your creation, kick it.
[QUOTE=NightExcessive;50098011]A limited version could be implemented without support from the binary module, but it would not be as efficient as using the API.[/QUOTE]
Following up on this, if you look look at the link below I did a side by side of how you can do prepared statements now, where you have to prepare the statement every time you call the query, which really kind of defeats the purpose. And also provides none of the security benefits of prepared statements
[url]https://facepunch.com/showthread.php?t=1442438&p=49035547&viewfull=1#post49035547[/url]
I went to the Github to get the latest Windows DLL, but there only seems to be one for Linux. I would compile the code myself, but I don't know how. Can anybody help?
[QUOTE=letrollerman;50591217]I went to the Github to get the latest Windows DLL, but there only seems to be one for Linux. I would compile the code myself, but I don't know how. Can anybody help?[/QUOTE]
just go to the most recent windows one. The linux one i believe was due to a issue with a linux resource
[code]Jul 4 15:57:07 ns5000269 kernel: [1632403.435253] srcds_linux[27515]: segfault at 5c ip 00000000e6b1112a sp 00000000ff89cf4c error 4 in gmsv_tmysql4_linux.dll[e6aef000+39b000]
Jul 4 15:57:21 ns5000269 kernel: [1632417.269210] srcds_linux[28736]: segfault at 77 ip 00000000e691412a sp 00000000ff8f47ec error 4 in gmsv_tmysql4_linux.dll[e68f2000+39b000]
Jul 4 15:57:34 ns5000269 kernel: [1632430.561841] srcds_linux[29888]: segfault at 5c ip 00000000e691412a sp 00000000fff4282c error 4 in gmsv_tmysql4_linux.dll[e68f2000+39b000]
Jul 4 15:57:48 ns5000269 kernel: [1632444.102441] srcds_linux[31044]: segfault at 77 ip 00000000e6a1412a sp 00000000ffdf45cc error 4 in gmsv_tmysql4_linux.dll[e69f2000+39b000]
Jul 4 15:58:00 ns5000269 kernel: [1632456.322372] srcds_linux[32068]: segfault at 5c ip 00000000e691412a sp 00000000ff8c6a1c error 4 in gmsv_tmysql4_linux.dll[e68f2000+39b000][/code]
MySQL server died in the middle of the night and the server was bootlooping on this, should be on the latest version, I switched to a linux box about 2 weeks ago
My server is fine with your module but as soon as I try to use your wrapper my server segmentation faults?
[QUOTE=Cheese_3;50859227]My server is fine with your module but as soon as I try to use your wrapper my server segmentation faults?[/QUOTE]
Maybe... Your wrapper is to blame.
big bump time, I know (Piss of mate)
Anyway, gettin this error whenever there is a mapchange or a restart of a kind. I think it may be a problem that occasionally crashes my server.
[CODE][ERROR] Error in my_thread_global_end(): 2 threads didn't exist.[/CODE]
Traced it back to here (I use Linux): [url]https://github.com/bkacjios/gm_tmysql4/blob/835ca867fd7c14d133c2bd3beace832e3d8d3051/include/linux/my_pthread.h#L206[/url]
Sorry, you need to Log In to post a reply to this thread.