Add a reference to the connection from prepared statements #107
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ref: #105
To close a prepared statement you need to have access to the connection that created it.
But in managed languages like Ruby, the obvious thing to do is to close the prepared statement when the associated object is garbage collected.
But the order in which objects are garbaged collected is never guaranteed so when freeing a statement the connection might have been freed already and it's hard to detect.
We checked how libmysqlclient handles it, and each
MYSQL_STMT
has a reference to itsMYSQL
(connection), and the connection keeps a doubly linked list of the statements it created.When a statement is closed it's removed from the list, when the connection is closed, all the connection references are set to NULL.
We implemented exactly the same logic here.
Additionally, prepared statement can only be used with the connection they were created from. As such having all the
trilogy_stmt_*
function take a connection isn't great for usability. So this change opens the door to only taking atrilogy_stmt_t *
.