Closed yreibel closed 3 years ago
Hey,
It turns out that the query:status() method was always missing from MySQLOO 9 and no one has apparently noticed/reported it until now. The code for it is there so I will likely add that function back in the next release. You can use the function Query:isRunning() to see if it is running immediately after you started it and then stops at some point after.
As for the other problems you mentioned, can you please post the code you are using? One problem that I could think of is that you add the callbacks to the query after you started it, which would cause them to not be called.
Thanks for your reply !
I cannot post the code right now, but I can tell you that I start the query at the very end ! I created a prepareQuery function in which I declare the query and after, within the same part of the code, I declare 2 other functions : Query:onSuccess() Query:onError()
And i end up starting the query at the end of my custom prepareQuery function. Just to say that 2 years ago there was no problem at all with the query itself !
When the db gets connected, it goes through db:onConnected without any issues, that's why I'm a bit confused regarding the reason why the query is not working as it should be. I will paste the code as soon as I can, do you need more explanations ? It just seems like the query is avoided without even triggering the callback functions.
So I tried the method query:isRunning() and it prints true ! I showed you which print function is working well below :
`function prepareQuery( query, operators, callback, error ) local i = 0 local query = db:query( query:gsub( "#", function() i = i + 1 return escapeCharacters( operators[i] ) end ) ) local data
function query:onSuccess( data )
local row = data
print("callback okay") -- NOT PRINTED
if callback then
callback( row, query:lastInsert() )
end
end
function query:onError(q, err)
print(err) -- NOT PRINTED
if db:status() == mysqloo.DATABASE_NOT_CONNECTED then
print("connection lost")
mysqloo.connect(mysqlooHost,mysqlooUsername,mysqlooPassword,mysqlooName,mysqlooPort)
return
end
end
query:start()
print( "running ", query:isRunning() ) -- PRINT TRUE
end
function StoreDB() print("before query") -- PRINTED prepareQuery( "SELECT * FROM character", nil, function( data ) print("query okay") - NOT PRINTED end)
end
StoreDB() `
Whether i'm connected to the server or not, no queries are performed, it never prints the "query okay" line. I've tried with insert functions as well when being connected ! Thanks.
I just ran your code using "SELECT 1" as query and it worked:
before query
running true
callback okay
query okay
I am going to assume that your database is not connecting properly. Try running query:wait() after starting it and see if you get an exception or your server freezes.
Other than that it might also be interesting to know what MySQL version you are using.
I have tried with both remotemysql and my local server, and the same happens :
before query
running true
When using query:wait(), nothing makes me think of a crash or a freeze, it just loads the server normally. I'm currently using mysql 8.0.18 on my local mysql server !
I've just tried to change my query SELECT * FROM character" to "SELECT 1" as you did, and it prints the same as you, so everything works well in that case. I'm totally confused !
I think i've just found the solution ! The word character is recognized as the type and so by writing it that way "SELECT * FROM character
" with those `` around, it printed inside my prepare query function. It seems that it was just a blacklisted word...
Thanks for your time !
Hi !
I've started using mysqloo again after 2 years, and I noticed that queries don't work anymore, even though I use the same code as before.
Let me give you a short explanation :
I'm currently using the latest stable version released : the x64 version does not work but the x86 version seems to work well until I try to perform a query. Meaning the database gets connected but it's utterly impossible to get a callback after running a query. I did use query:start() but when I try to check the query status, it prints that as an error : "attempt to call method 'status' (a nil value)"
I've seen that : "The callbacks are only called if there's a player on the server (as they rely on the think hook). So that is also something to keep in mind." But even though I try to run an insert query while being on the server, it just does not do anything more ! Is there anything related to mysql hibernation ?
PS : I have installed any existing vcredist, and i have never had any issues with that in the past
Please help me !