Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use same PreparedStatement with different data multiple times in one Transaction #31

Closed
meepen opened this issue Sep 27, 2019 · 6 comments

Comments

@meepen
Copy link
Contributor

meepen commented Sep 27, 2019

It uses the last dataset given to the PrepareStatement

@meepen
Copy link
Contributor Author

meepen commented Sep 27, 2019

meepen@59a64e8

I fixed it here, not sure if right approach. Feel free to use.

@FredyH
Copy link
Owner

FredyH commented Sep 27, 2019

I am 95% sure this would leak memory, the reason I have a lua table to store the queries is exactly because tables us proper GC, while storing a reference does not.

Try running loads of transactions with callbacks that all reference all of the queries and the transaction itself (so that the closures keep references to them), and check mysqloo.objectCount() to see if anything leaks.

@meepen
Copy link
Contributor Author

meepen commented Sep 28, 2019

yeah it definitely does leak

@meepen
Copy link
Contributor Author

meepen commented Sep 28, 2019

actually both main and mine leak at same rate lol

@FredyH
Copy link
Owner

FredyH commented Sep 28, 2019

I did this test on my current version and it went back down from 50k objects to ~11 or something

local finished = 0;
local time = SysTime()
local query1 = db:prepare("SELECT ?")
local query2 = db:prepare("SELECT ?, 1")
local totalAmount = 50000
for i = 1, totalAmount do
    local transaction = db:createTransaction()
    query1:setNumber(1, math.random(1, 1000))
    query2:setNumber(1, math.random(1, 1000))
    transaction:addQuery(query1)
    transaction:addQuery(query2)
    function transaction:onSuccess()
        finished = finished + 1
        if (finished == totalAmount) then
            print("Done:", SysTime() - time, query1, query2, transaction)
            collectgarbage("collect")
        end
    end
    transaction:start()
end

@FredyH
Copy link
Owner

FredyH commented May 25, 2020

Fixed in master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants