diff --git a/hdr/sqlite_modern_cpp.h b/hdr/sqlite_modern_cpp.h index 5605f369..7fe77fe4 100644 --- a/hdr/sqlite_modern_cpp.h +++ b/hdr/sqlite_modern_cpp.h @@ -415,26 +415,7 @@ namespace sqlite { std::shared_ptr _db; public: - database(std::u16string const & db_name): _db(nullptr) { - sqlite3* tmp = nullptr; - auto ret = sqlite3_open16(db_name.data(), &tmp); - _db = std::shared_ptr(tmp, [=](sqlite3* ptr) { sqlite3_close_v2(ptr); }); // this will close the connection eventually when no longer needed. - if(ret != SQLITE_OK) exceptions::throw_sqlite_error(ret); - //_db.reset(tmp, sqlite3_close); // alternative close. (faster?) - } - - database(std::string const & db_name): _db(nullptr) { - sqlite3* tmp = nullptr; - auto ret = sqlite3_open(db_name.data(), &tmp); - _db = std::shared_ptr(tmp, [=](sqlite3* ptr) { sqlite3_close_v2(ptr); }); // this will close the connection eventually when no longer needed. - if(ret != SQLITE_OK) exceptions::throw_sqlite_error(ret); - //_db.reset(tmp, sqlite3_close); // alternative close. (faster?) - } - - database(std::shared_ptr db): - _db(db) {} - - database(const std::string &db_name, const sqlite_config &config): _db(nullptr) { + database(const std::string &db_name, const sqlite_config &config = {}): _db(nullptr) { sqlite3* tmp = nullptr; auto ret = sqlite3_open_v2(db_name.data(), &tmp, config.flags, config.gVfs); _db = std::shared_ptr(tmp, [=](sqlite3* ptr) { sqlite3_close_v2(ptr); }); // this will close the connection eventually when no longer needed. @@ -443,7 +424,7 @@ namespace sqlite { *this << R"(PRAGMA encoding = "UTF-16";)"; } - database(const std::u16string &db_name, const sqlite_config &config): _db(nullptr) { + database(const std::u16string &db_name, const sqlite_config &config = {}): _db(nullptr) { auto db_name_utf8 = std::wstring_convert, char16_t>().to_bytes(db_name); sqlite3* tmp = nullptr; auto ret = sqlite3_open_v2(db_name_utf8.data(), &tmp, config.flags, config.gVfs); @@ -453,6 +434,9 @@ namespace sqlite { *this << R"(PRAGMA encoding = "UTF-16";)"; } + database(std::shared_ptr db): + _db(db) {} + database_binder operator<<(const std::string& sql) { return database_binder(_db, sql); }