From 5a972233826ac4b8855d725f53a6a63da38ec71d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Kr=C3=BCger?= Date: Thu, 9 Feb 2017 12:52:48 +0100 Subject: [PATCH 1/3] Fix UTF-8 encoding of filenames and SQL statements Fixes #82 --- hdr/sqlite_modern_cpp.h | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/hdr/sqlite_modern_cpp.h b/hdr/sqlite_modern_cpp.h index 68498914..df729faf 100644 --- a/hdr/sqlite_modern_cpp.h +++ b/hdr/sqlite_modern_cpp.h @@ -133,7 +133,6 @@ namespace sqlite { database_binder(database_binder&& other) : _db(std::move(other._db)), - _sql(std::move(other._sql)), _stmt(std::move(other._stmt)), _inx(other._inx), execution_started(other.execution_started) { } @@ -160,7 +159,6 @@ namespace sqlite { private: std::shared_ptr _db; - std::u16string _sql; std::unique_ptr _stmt; int _inx; @@ -209,6 +207,14 @@ namespace sqlite { return tmp; } + sqlite3_stmt* _prepare(const std::string& sql) { + int hresult; + sqlite3_stmt* tmp = nullptr; + hresult = sqlite3_prepare_v2(_db.get(), sql.data(), -1, &tmp, nullptr); + if((hresult) != SQLITE_OK) exceptions::throw_sqlite_error(hresult); + return tmp; + } + template struct is_sqlite_value : public std::integral_constant< bool, @@ -266,13 +272,15 @@ namespace sqlite { database_binder(std::shared_ptr db, std::u16string const & sql): _db(db), - _sql(sql), _stmt(_prepare(sql), sqlite3_finalize), _inx(1) { } database_binder(std::shared_ptr db, std::string const & sql): - database_binder(db, std::u16string(sql.begin(), sql.end())) {} + _db(db), + _stmt(_prepare(sql), sqlite3_finalize), + _inx(1) { + } ~database_binder() noexcept(false) { /* Will be executed if no >>op is found, but not if an exception @@ -318,13 +326,16 @@ namespace sqlite { 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): - database(std::u16string(db_name.begin(), db_name.end())) {} + 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) {} From a9c458ea1228b22600f076cee21ff18d5547eb5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Kr=C3=BCger?= Date: Thu, 9 Feb 2017 13:19:39 +0100 Subject: [PATCH 2/3] Add incompatibility warning to README --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 0840a8be..1bc0571f 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ sqlite modern cpp wrapper This library is a lightweight modern wrapper around sqlite C api . +**Heads up!** +The current master contains a _breaking change_ compared to the 2.4 release for database names with non-ASCII characters. For details, see [issue 82](https://github.com/aminroosta/sqlite_modern_cpp/issues/82). + ```c++ #include #include From 42dc3850aef85bb1af4aa7babed4658c72cd2c42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Kr=C3=BCger?= Date: Thu, 9 Feb 2017 13:19:39 +0100 Subject: [PATCH 3/3] Add Breaking Changes section to README --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1bc0571f..82f1b4c0 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,6 @@ sqlite modern cpp wrapper This library is a lightweight modern wrapper around sqlite C api . -**Heads up!** -The current master contains a _breaking change_ compared to the 2.4 release for database names with non-ASCII characters. For details, see [issue 82](https://github.com/aminroosta/sqlite_modern_cpp/issues/82). - ```c++ #include #include @@ -324,6 +321,12 @@ The usual way works for installing: Note, there's nothing to make, so you there's no need to run configure and you can simply point your compiler at the hdr/ directory. +Breaking Changes +---- + +- Databases with non-ASCII characters in their names created with versions up to 2.4 are not found by the current master. +You have to manually rename them to their actual (UTF-8 encoded) name. + Package managers ---- Pull requests are welcome :wink: