• gmsv_mysqloo - Updated OO MySQL Module (multiple statements/stored procs!)
    139 replies, posted
Ah, thank you very much. I never use aliases so that thought never occurred to me to use them here. By the way, is there anything that can be done about the crash caused when trying to escape a nil value?
-Snip- I fixed the issue.
With regards to query:Wait(), Does it need to be called every function that I create with it or is it not needed at all. The current server I am running is having some issues and trying to optimize code to see what may be causing some lag.
[QUOTE=Futt Bucker;45121040]With regards to query:Wait(), Does it need to be called every function that I create with it or is it not needed at all. The current server I am running is having some issues and trying to optimize code to see what may be causing some lag.[/QUOTE] You shouldn't need query:wait() at all; queries that you execute will run asynchronously and will give you a result in a callback function when they are done.
[QUOTE=_nonSENSE;45122415]You shouldn't need query:wait() at all; queries that you execute will run asynchronously and will give you a result in a callback function when they are done.[/QUOTE] Thanks for the info :) Also, MoronYard is amazing!
I still experience "Out of sync" errors, and I _think_ I have found the cause. After googling around the issue, I found a reference implementation, that handles multiple statements like this: [code] /* more results? -1 = no, >0 = error, 0 = yes (keep looping) */ if ((status = mysql_next_result(mysql)) > 0) printf("Could not execute statement\n"); [/code] Note the comment. Then I checked the source of the module: [code] while (mysql_next_result(sql) == 0) { pResult = mysql_store_result(sql); mysql_free_result(pResult); } [/code] So it seems that the module stops processing results as soon as one of the statements failed, causing an out of sync. That '==' should be '>' [editline]10th July 2014[/editline] In the meantime if you are dieing to use multiple statements for transactions, you could use my workaround: Just do a "SELECT 1;" as the first statement, and try not to make errors in the rest, otherwise out-of-sync will hit you.
This is what I get when I use MySQL with my DarkRP Server... Couldn't include file 'libraries\database.lua' (File not found) (@gamemodes/dark rp/gamemode/init.lua (line 31)) [code][ERROR] gamemodes/darkrp/gamemode/modules/fadmin/fadmin/motd/sv_init.lua:13: att empt to index global 'MySQLite' (a nil value) 1. unknown - gamemodes/darkrp/gamemode/modules/fadmin/fadmin/motd/sv_init.lua: 13 2. include - [C]:-1 3. AddCSLuaFolder - gamemodes/darkrp/gamemode/modules/fadmin/sv_fadmin.lua:3 2 4. unknown - gamemodes/darkrp/gamemode/modules/fadmin/sv_fadmin.lua:41 5. include - [C]:-1 6. unknown - gamemodes/darkrp/gamemode/init.lua:56 [ERROR] gamemodes/darkrp/gamemode/init.lua:65: attempt to index global 'MySQLite ' (a nil value) 1. unknown - gamemodes/darkrp/gamemode/init.lua:65 Couldn't Load Init Script: 'darkrp/gamemode/init.lua'[/code] [b]When Player is connecting/connected...[/b] [code][ERROR] gamemodes/darkrp/gamemode/modules/fadmin/fadmin/access/sv_init.lua:83: a ttempt to index global 'MySQLite' (a nil value) 1. SetUserGroup - gamemodes/darkrp/gamemode/modules/fadmin/fadmin/access/sv_in it.lua:83 2. fn - lua/includes/extensions/player_auth.lua:90 3. unknown - addons/ulib/lua/ulib/shared/hook.lua:183 4. oldUID - [C]:-1 5. UniqueID - gamemodes/darkrp/gamemode/modules/workarounds/sh_workarounds .lua:137 6. query - addons/ulib/lua/ulib/shared/sh_ucl.lua:48 7. echoToAdmins - addons/ulx/lua/ulx/log.lua:164 8. fn - addons/ulx/lua/ulx/log.lua:196 9. unknown - addons/ulib/lua/ulib/shared/hook.lua:183 [ERROR] Unauthed player 1. query - [C]:-1 2. echoToAdmins - addons/ulx/lua/ulx/log.lua:164 3. fn - addons/ulx/lua/ulx/log.lua:196 4. unknown - addons/ulib/lua/ulib/shared/hook.lua:183 [ERROR] addons/ulx/lua/ulx/modules/uteam.lua:23: attempt to index a nil value 1. fn - addons/ulx/lua/ulx/modules/uteam.lua:23 2. unknown - addons/ulib/lua/ulib/shared/hook.lua:183 [Hazard|2|STEAM_0:1:20608063] Lua Error: [ERROR] Unauthed player 1. query - [C]:-1 2. refresh - addons/ulx/lua/ulx/xgui/commands.lua:299 3. unknown - addons/ulx/lua/ulx/xgui/commands.lua:388 4. include - [C]:-1 5. fn - addons/ulx/lua/ulx/modules/cl/xgui_client.lua:114 6. Call - addons/ulib/lua/ulib/shared/hook.lua:183 7. fn - addons/ulib/lua/ulib/cl_init.lua:54 8. func - addons/ulib/lua/ulib/client/cl_util.lua:22 9. unknown - lua/includes/modules/net.lua:32 [Hazard|2|STEAM_0:1:20608063] Lua Error: [ERROR] Unauthed player 1. query - [C]:-1 2. processModules - addons/ulx/lua/ulx/modules/cl/xgui_client.lua:205 3. fn - addons/ulx/lua/ulx/modules/cl/xgui_client.lua:162 4. Call - addons/ulib/lua/ulib/shared/hook.lua:183 5. fn - addons/ulib/lua/ulib/cl_init.lua:54 6. func - addons/ulib/lua/ulib/client/cl_util.lua:22 7. unknown - lua/includes/modules/net.lua:32 [Hazard|2|STEAM_0:1:20608063] Lua Error: [ERROR] lua/autorun/workshop.lua:5: attempt to call field 'AddWorkshop' (a nil v alue) 1. unknown - lua/autorun/workshop.lua:5 [Hazard|2|STEAM_0:1:20608063] Lua Error: [ERROR] gamemodes/darkrp/gamemode/modules/base/sh_createitems.lua:591: attempt t o index global 'disjoint' (a nil value) 1. AddAgenda - gamemodes/darkrp/gamemode/modules/base/sh_createitems.lua:591 2. unknown - gamemodes/darkrp/gamemode/config/jobrelated.lua:230 3. include - [C]:-1 4. unknown - gamemodes/darkrp/gamemode/cl_init.lua:36 [ERROR] Unauthed player 1. query - [C]:-1 2. sendDataTable - addons/ulx/lua/ulx/modules/xgui_server.lua:153 3. unknown - addons/ulx/lua/ulx/modules/xgui_server.lua:74 4. unknown - addons/ulx/lua/ulx/modules/xgui_server.lua:53 5. unknown - lua/includes/modules/concommand.lua:69 MDLCache: TDMCars\bmwm3e92.mdl needs to be recompiled [ERROR] gamemodes/darkrp/gamemode/modules/doorsystem/sv_doors.lua:59: attempt to perform arithmetic on field 'OwnedNumz' (a nil value) 1. keysOwn - gamemodes/darkrp/gamemode/modules/doorsystem/sv_doors.lua:59 2. SpawnVehicle - addons/npcardealer/lua/npcshop/server.lua:142 3. unknown - addons/npcardealer/lua/npcshop/server.lua:196 4. unknown - lua/includes/modules/concommand.lua:69[/code] [b]The Only tables I have in my MySQL database is "commands". I had an autodonation script that requiered MySQL. It works BUT the actual DarkRP Gamemode does not work with MySQL, unauthing players and nothing works like Jobs, Salary and Money, Models going full reatarded etc... I have the latest versions of MySQLOO and libMySQL, the AutoDonation script is connecting with the MySQL database so I used the EXACT same information for the DarkRP MySQL connection information, but does not work. I've been googilin' and everythin'. No luck and now im so sick of it.[/b]
So for some reason, db:connect() doesn't open a connection, but also doesn't run db:OnConnectionFailed [code] require("mysqloo") local queue = {} local db = mysqloo.connect("69.162.113.xxx", "gtest_gtest", "*********", "gtest_leaderboard_test", 3306) function db:OnConnected() print("SQL successfully connected!") for k,v in pairs(queue) do runQuery(v, true) end queue = {} end function db:OnConnectionFailed(err) print("[FATAL] SQL connection failure!") print("SQL Error: " .. err) end db:connect() db:wait() print(db:status()) -- Prints 2, not connected [/code]
why do you do db:wait()???
[QUOTE=frietje2008;45369479]why do you do db:wait()???[/QUOTE] I thought maybe db:status() was being called before the connection could be made, so I told it to wait until the connection finished. But apparently it had no effect. I have the same problem with and without db:wait()
For the record, I do this in init.lua. Will this be a problem? Since it's called before any players are on the server?
the mysqloo connection works with the think hook so...
Well it was unclear whether connections depend on the think hook. I thought it was just queries.
Try starting the connection in the Initialize hook
Noob question inbound, where is the place I should set up my connection info (This:) [CODE]require( "mysqloo" ) local db = mysqloo.connect( "123.456.789.0", "drake", "abc123", "database_name", 3306 ) function db:onConnected() print( "Database has connected!" ) local q = self:query( "SELECT 5+5;" ) function q:onSuccess( data ) print( "Query successful!" ) PrintTable( data ) end function q:onError( err, sql ) print( "Query errored!" ) print( "Query:", sql ) print( "Error:", err ) end q:start() end function db:onConnectionFailed( err ) print( "Connection to database failed!" ) print( "Error:", err ) end db:connect()[/CODE] Is the correct place, lua/autorun by any chance?
[QUOTE=TheDoggy;45418639]Noob question inbound, where is the place I should set up my connection info (This:) [CODE]require( "mysqloo" ) local db = mysqloo.connect( "123.456.789.0", "drake", "abc123", "database_name", 3306 ) function db:onConnected() print( "Database has connected!" ) local q = self:query( "SELECT 5+5;" ) function q:onSuccess( data ) print( "Query successful!" ) PrintTable( data ) end function q:onError( err, sql ) print( "Query errored!" ) print( "Query:", sql ) print( "Error:", err ) end q:start() end function db:onConnectionFailed( err ) print( "Connection to database failed!" ) print( "Error:", err ) end db:connect()[/CODE] Is the correct place, lua/autorun by any chance?[/QUOTE] If you want people [del]connecting to your database[/del] fucking up your database sure. (IF it was AddCSLuaFile()'d) [B]lua/autorun/server[/B]
[QUOTE=Phoenixf129;45418781]If you want people [del]connecting to your database[/del] fucking up your database sure. (IF it was AddCSLuaFile()'d) [B]lua/autorun/server[/B][/QUOTE] Thanks mate, I told you it would be a n00b question! But yeah thanks, you also made me realise why it was giving a certain error before too :P
hi guys, i wanna install this module for my server and then synchronize members from server to website but on my server ftp, i don't have srcns_run ... so someone could tell me where i must put the lib file please ? at the root of my ftp i have :. Addons Background Bin Cfg Data Download .... Thanks for help.
You may have to contact your host if you don't have access to the root folder.
It was that i believe >< but i wanted a confirmation. so let's go for some hours or days of more waiting ^^' Thanks for answer and i hope i'll succeed to use it after install :)
I'm connecting with mysqloo.CLIENT_MULTI_RESULTS and mysqloo.CLIENT_MULTI_STATEMENTS, but it looks like local q = db:query( "SELECT 1; SELECT 2;" )function q:onSuccess( results ) PrintTable( results )endfunction q:onError( err ) MsgN( "err: " .. err )endq:start() Only outputs [code]1: 1 = 1[/code] How can I get multi results to work?
-problem resolved
[QUOTE=Hollistupid;45492196][CODE]Couldn't include file 'includes\modules\mysqloo.lua' (File not found) (<nowhere>) [/CODE] Still seeming to get this... libmysql.dll and libmysqlclient.so.18 - are both in the root folder /garrysmod gmsv_mysqloo_win32.dll - is in garrysmod/lua/bind I'm using automated donation system and it works just fine but it keeps giving me that annoying error that spams my clientside errors file[/QUOTE] It sounds like it's trying to run [B]require( "mysqloo" )[/B] on your client instead of just the server. If you can find the exact spot that the script is requiring mysqloo and report back if the file is shared and doesn't have something like [B]if ( SERVER ) then[/B] to ensure it's only running on the server, that might help out.
[QUOTE=Mista Tea;45492974]It sounds like it's trying to run [B]require( "mysqloo" )[/B] on your client instead of just the server. If you can find the exact spot that the script is requiring mysqloo and report back if the file is shared and doesn't have something like [B]if ( SERVER ) then[/B] to ensure it's only running on the server, that might help out.[/QUOTE] Thanks for the response, it seems the top line is causing this? [CODE]local succ, err = pcall(require, "mysqloo" ) if succ then addlog( "Successfully loaded MySQLOO module!" )[/CODE]
no it's your file placement... you said : [QUOTE]libmysql.dll and libmysqlclient.so.18 - are both in the root folder /garrysmod gmsv_mysqloo_win32.dll - is in garrysmod/lua/bind[/QUOTE] but it's : libmysqlclient.so.18 -> GarrysMod/ and gmsv_mysqloo_win32.dll -> /GarrysMod/garrysmod/lua/bin but i have a question for mine : i seen the libmysql is named libmysqlclient so the functions are they clientside functions ? because my script is full serverside but don't work so wanna know if it could be cause some mysqloo function are clientside. or maybe all.
[QUOTE=zemec9;45495381]no it's your file placement... you said : but it's : libmysqlclient.so.18 -> GarrysMod/ and gmsv_mysqloo_win32.dll -> /GarrysMod/garrysmod/lua/bin but i have a question for mine : i seen the libmysql is named libmysqlclient so the functions are they clientside functions ? because my script is full serverside but don't work so wanna know if it could be cause some mysqloo function are clientside. or maybe all.[/QUOTE] I take it you saw /lua/bind as the actually folder as my mistake I'll correct myself I meant to put /garrysmod/lua/bin but put bind on accident, I have them both in the right spot. The modules work with the addon I'm using but it still produces the error.
no, maybe i didn't understand cause of my english compehension but i didn't said that cause of the bind repertory ( id didn't seen this error) but cause you said "libmysqlclient.so.18 - are both in the root folder /garrysmod" but the root folder isn't /garrysmod but his parent folder normally. [editline]25th July 2014[/editline] so my problem : [URL="http://pastebin.com/gmru6Qm2"]http://pastebin.com/gmru6Qm2[/URL] so the script is serverside but i don't see anything in the console else "test" prints i puted
[QUOTE=Agent766;45477302]I'm connecting with mysqloo.CLIENT_MULTI_RESULTS and mysqloo.CLIENT_MULTI_STATEMENTS, but it looks like How can I get multi results to work?[/QUOTE] Unfortunately you can not. It is because the bug I posted a week ago and that the module currently throws away multiple result sets. (Not to mention that it seems the author is unwilling to fix it..)
[QUOTE=MDave;45509223]Unfortunately you can not. It is because the bug I posted a week ago and that the module currently throws away multiple result sets. (Not to mention that it seems the author is unwilling to fix it..)[/QUOTE] Oh, I thought this version fixed that.
I fixed it. Gimme a bit to make a pull request. [editline]29th July 2014[/editline] [url]https://github.com/KingofBeast/gmsv_mysqloo/pull/2[/url]
Sorry, you need to Log In to post a reply to this thread.