The problem is if the unique_ptr containing the statement object gets dropped *after* the unique_ptr containing the sql connection object you get a double delete. C is more than capable of stripping out the underlying data from under the smart pointers nose.
Holding onto your local data is only part of the challenge. I spend so much time crafting smart pointers in a way that they also hold onto their parent references up the hierarchy to stop them dropping in order to make things safe.
Chuck some callbacks in the mix and some already awkward deletion strategies and you have lots of fun. This issue is purely because our middleware doesn't provide proper C++ bindings of course ;)