SQLiteCpp
SQLiteCpp copied to clipboard
Enable to declare an object on stack without initialization
Hello, Currently there is no way to declare a SQLite::Database object without initialization. I have a recommendation that the class SQLite::Database should have more functions allowing to delay initialization or to open/close any database at any time without destroying and recreating the Database object.
What's the use case for delaying initialization? I can't think of any off the top of my head, but I could certainly be missing a scenario that is uncommon for me.
The scenario is quite popular, I want to declare a SQLite::Database object (not a pointer) as a member of a class and the path to data file for sqlite can be specified only at Initialize() function of the class. With current version of SQLite::Database, the scenario is impossible.
Hi. I'm running into this too. I'm trying to create a static SQLite::Database object that I connect to when required and keep the connection open. I think the only way to do this is add an empty constructor and a new method to open a db. Would that be best do you think?
Thank you for this library. 👍
Edit: For the record, I ended up using a unique_ptr to the Database object. In this case I don't mind the allocation and it's neat and tidy at least.
A Pull Request was actually provided by @kirillin to improve this #225 Add default constructor and open() method.
This main thing is that his code is no passing all checks! I could fix this, but I lack the time right now
Cheers, Sébastien