SQLiteCpp icon indicating copy to clipboard operation
SQLiteCpp copied to clipboard

Enable to declare an object on stack without initialization

Open ghost opened this issue 5 years ago • 4 comments

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.

ghost avatar Jun 11 '20 01:06 ghost

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.

ptrks avatar Jun 15 '20 19:06 ptrks

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.

ghost avatar Jun 17 '20 23:06 ghost

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.

frithrah avatar Aug 09 '20 17:08 frithrah

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

SRombauts avatar Aug 11 '20 14:08 SRombauts