Skip to content

Commit

Permalink
Remove old constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
zauguin committed Feb 18, 2017
1 parent 73cf176 commit 040af82
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions hdr/sqlite_modern_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,26 +415,7 @@ namespace sqlite {
std::shared_ptr<sqlite3> _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<sqlite3>(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<sqlite3>(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<sqlite3> 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<sqlite3>(tmp, [=](sqlite3* ptr) { sqlite3_close_v2(ptr); }); // this will close the connection eventually when no longer needed.
Expand All @@ -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<std::codecvt_utf8_utf16<char16_t>, char16_t>().to_bytes(db_name);
sqlite3* tmp = nullptr;
auto ret = sqlite3_open_v2(db_name_utf8.data(), &tmp, config.flags, config.gVfs);
Expand All @@ -453,6 +434,9 @@ namespace sqlite {
*this << R"(PRAGMA encoding = "UTF-16";)";
}

database(std::shared_ptr<sqlite3> db):
_db(db) {}

database_binder operator<<(const std::string& sql) {
return database_binder(_db, sql);
}
Expand Down

0 comments on commit 040af82

Please sign in to comment.