boostorg / mysql

MySQL C++ client based on Boost.Asio
https://www.boost.org/doc/libs/master/libs/mysql
Boost Software License 1.0
252 stars 32 forks source link

Free statements/results #159

Closed Mecanik closed 1 year ago

Mecanik commented 1 year ago

Thanks for the awesome library! I do have a question and concern since I am trying to use it. Assuming that I want to keep the connection with MySQL opened to perform continuous work (multi-threaded), how do you free results?

At the moment all I can see is .close() and .close_statement(), but there is no implementation like .free() or .free_results().

Please advise.

anarthal commented 1 year ago

The results destructor does the work. You don't need to do anything on your side to free a results object.

The reason why prepared statements need a special close_statement function is because statements are really handles to server-side objects. close_statement sends a message to the server instructing to deallocate the server-side object. This is an operation that may block and fail, so running it from a destructor is nor adequate.

A similar reasoning applies to close - it will send a message to the server instructing to kill the connection.

TL;DR: results memory freeing happens automatically as part of its destructor.

Mecanik commented 1 year ago

That sounds great, so action needed from the user; just do your queries. Thanks!

anarthal commented 1 year ago

Yep, no action needed unless you're preparing statements dynamically, in which case close_statement is needed.

I'm gonna close this issue. Should you have more questions, please feel free to ask!