Skip to content

Commit b08f6b6

Browse files
committed
Reuse UTF-8 prepare function, and add length to prepare call
1 parent b9ddb6b commit b08f6b6

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

hdr/sqlite_modern_cpp.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,14 @@ namespace sqlite {
8686
}
8787

8888
sqlite3_stmt* _prepare(const U16STR_REF& sql) {
89-
//return _prepare(utility::utf16_to_utf8(sql));
90-
int hresult;
91-
sqlite3_stmt* tmp = nullptr;
92-
const void *remaining;
93-
hresult = sqlite3_prepare16_v2(_db.get(), sql.data(), -1, &tmp, &remaining);
94-
if (hresult != SQLITE_OK) errors::throw_sqlite_error(hresult, utility::utf16_to_utf8(sql.data()));
95-
if (!std::all_of(static_cast<const char16_t*>(remaining), sql.data() + sql.size(), [](char16_t ch) {return std::isspace(ch); }))
96-
throw errors::more_statements("Multiple semicolon separated statements are unsupported", utility::utf16_to_utf8(sql.data()));
97-
return tmp;
89+
return _prepare(utility::utf16_to_utf8(sql));
9890
}
9991

10092
sqlite3_stmt* _prepare(const STR_REF& sql) {
10193
int hresult;
10294
sqlite3_stmt* tmp = nullptr;
10395
const char *remaining;
104-
hresult = sqlite3_prepare_v2(_db.get(), sql.data(), -1, &tmp, &remaining);
96+
hresult = sqlite3_prepare_v2(_db.get(), sql.data(), sql.length(), &tmp, &remaining);
10597
if(hresult != SQLITE_OK) errors::throw_sqlite_error(hresult, sql);
10698
if(!std::all_of(remaining, sql.data() + sql.size(), [](char ch) {return std::isspace(ch);}))
10799
throw errors::more_statements("Multiple semicolon separated statements are unsupported", sql);

hdr/sqlite_modern_cpp/utility/utf16_utf8.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace sqlite {
1010
namespace utility {
11-
inline std::string utf16_to_utf8(const std::u16string &input) {
11+
inline std::string utf16_to_utf8(const U16STR_REF &input) {
1212
struct : std::codecvt<char16_t, char, std::mbstate_t> {
1313
} codecvt;
1414
std::mbstate_t state{};

0 commit comments

Comments
 (0)