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

Add a reference to the connection from prepared statements #107

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Jul 25, 2023

  1. Add a reference to the connection from prepared statements

    Ref: trilogy-libraries#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 its `MYSQL` (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 a `trilogy_stmt_t *`.
    
    Co-Authored-By: Adrianna Chang <[email protected]>
    byroot and adrianna-chang-shopify committed Jul 25, 2023
    Configuration menu
    Copy the full SHA
    f333f6b View commit details
    Browse the repository at this point in the history