Skip to content

Commit 7d6ea22

Browse files
committed
Small Changes
1 parent 8e09803 commit 7d6ea22

File tree

4 files changed

+30
-24
lines changed

4 files changed

+30
-24
lines changed

hdr/sqlite_modern_cpp.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ namespace sqlite {
8585
return ++_inx;
8686
}
8787

88-
sqlite3_stmt* _prepare(U16STR_REF sql) {
88+
sqlite3_stmt* _prepare(u16str_ref sql) {
8989
return _prepare(utility::utf16_to_utf8(sql));
9090
}
9191

92-
sqlite3_stmt* _prepare(STR_REF sql) {
92+
sqlite3_stmt* _prepare(str_ref sql) {
9393
int hresult;
9494
sqlite3_stmt* tmp = nullptr;
9595
const char *remaining;
@@ -105,13 +105,13 @@ namespace sqlite {
105105

106106
public:
107107

108-
database_binder(std::shared_ptr<sqlite3> db, U16STR_REF sql):
108+
database_binder(std::shared_ptr<sqlite3> db, u16str_ref sql):
109109
_db(db),
110110
_stmt(_prepare(sql), sqlite3_finalize),
111111
_inx(0) {
112112
}
113113

114-
database_binder(std::shared_ptr<sqlite3> db, STR_REF sql):
114+
database_binder(std::shared_ptr<sqlite3> db, str_ref sql):
115115
_db(db),
116116
_stmt(_prepare(sql), sqlite3_finalize),
117117
_inx(0) {
@@ -372,19 +372,19 @@ namespace sqlite {
372372
*this << R"(PRAGMA encoding = "UTF-16";)";
373373
}
374374

375-
database(const std::u16string &db_name, const sqlite_config &config = {}): database(utility::utf16_to_utf8(db_name.data()), config) {
375+
database(const std::u16string &db_name, const sqlite_config &config = {}): database(utility::utf16_to_utf8(db_name), config) {
376376
if (config.encoding == Encoding::ANY)
377377
*this << R"(PRAGMA encoding = "UTF-16";)";
378378
}
379379

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

383-
database_binder operator<<(STR_REF sql) {
383+
database_binder operator<<(str_ref sql) {
384384
return database_binder(_db, sql);
385385
}
386386

387-
database_binder operator<<(U16STR_REF sql) {
387+
database_binder operator<<(u16str_ref sql) {
388388
return database_binder(_db, sql);
389389
}
390390

@@ -419,7 +419,7 @@ namespace sqlite {
419419

420420
auto funcPtr = new auto(std::make_pair(std::forward<StepFunction>(step), std::forward<FinalFunction>(final)));
421421
if(int result = sqlite3_create_function_v2(
422-
_db.get(), name.data(), traits::arity - 1, SQLITE_UTF8, funcPtr, nullptr,
422+
_db.get(), name.c_str(), traits::arity - 1, SQLITE_UTF8, funcPtr, nullptr,
423423
sql_function_binder::step<ContextType, traits::arity, typename std::remove_reference<decltype(*funcPtr)>::type>,
424424
sql_function_binder::final<ContextType, typename std::remove_reference<decltype(*funcPtr)>::type>,
425425
[](void* ptr){

hdr/sqlite_modern_cpp/errors.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ namespace sqlite {
99

1010
class sqlite_exception: public std::runtime_error {
1111
public:
12-
sqlite_exception(const char* msg, STR_REF sql, int code = -1): runtime_error(msg), code(code), sql(std::move(sql)) {}
13-
sqlite_exception(int code, STR_REF sql): runtime_error(sqlite3_errstr(code)), code(code), sql(std::move(sql)) {}
12+
sqlite_exception(const char* msg, str_ref sql, int code = -1): runtime_error(msg), code(code), sql(sql) {}
13+
sqlite_exception(int code, str_ref sql): runtime_error(sqlite3_errstr(code)), code(code), sql(sql) {}
1414
int get_code() const {return code & 0xFF;}
1515
int get_extended_code() const {return code;}
1616
std::string get_sql() const {return sql;}
@@ -40,7 +40,7 @@ namespace sqlite {
4040
class more_statements: public sqlite_exception { using sqlite_exception::sqlite_exception; }; // Prepared statements can only contain one statement
4141
class invalid_utf16: public sqlite_exception { using sqlite_exception::sqlite_exception; };
4242

43-
static void throw_sqlite_error(const int& error_code, const STR_REF &sql = "") {
43+
static void throw_sqlite_error(const int& error_code, str_ref sql = "") {
4444
switch(error_code & 0xFF) {
4545
#define SQLITE_MODERN_CPP_ERROR_CODE(NAME,name,derived) \
4646
case SQLITE_ ## NAME: switch(error_code) { \

hdr/sqlite_modern_cpp/type_wrapper.h

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,17 @@
3737
#endif
3838
#ifdef MODERN_SQLITE_STRINGVIEW_SUPPORT
3939
#include <string_view>
40-
typedef const std::string_view STR_REF;
41-
typedef const std::u16string_view U16STR_REF;
40+
namespace sqlite
41+
{
42+
typedef const std::string_view str_ref;
43+
typedef const std::u16string_view u16str_ref;
44+
}
4245
#else
43-
typedef const std::string& STR_REF;
44-
typedef const std::u16string& U16STR_REF;
46+
namespace sqlite
47+
{
48+
typedef const std::string& sqlite::str_ref;
49+
typedef const std::u16string& sqlite::u16str_ref;
50+
}
4551
#endif
4652
#include <sqlite3.h>
4753
#include "errors.h"
@@ -161,14 +167,14 @@ namespace sqlite {
161167
sqlite3_result_null(db);
162168
}
163169

164-
// STR_REF
170+
// str_ref
165171
template<>
166172
struct has_sqlite_type<std::string, SQLITE3_TEXT, void> : std::true_type {};
167-
inline int bind_col_in_db(sqlite3_stmt* stmt, int inx, STR_REF val) {
173+
inline int bind_col_in_db(sqlite3_stmt* stmt, int inx, str_ref val) {
168174
return sqlite3_bind_text(stmt, inx, val.data(), val.length(), SQLITE_TRANSIENT);
169175
}
170176

171-
// Convert char* to string_view to trigger op<<(..., const STR_REF )
177+
// Convert char* to string_view to trigger op<<(..., const str_ref )
172178
template<std::size_t N> inline int bind_col_in_db(sqlite3_stmt* stmt, int inx, const char(&STR)[N]) {
173179
return sqlite3_bind_text(stmt, inx, &STR[0], N-1, SQLITE_TRANSIENT);
174180
}
@@ -182,17 +188,17 @@ namespace sqlite {
182188
std::string(reinterpret_cast<char const *>(sqlite3_value_text(value)), sqlite3_value_bytes(value));
183189
}
184190

185-
inline void store_result_in_db(sqlite3_context* db, STR_REF val) {
191+
inline void store_result_in_db(sqlite3_context* db, str_ref val) {
186192
sqlite3_result_text(db, val.data(), val.length(), SQLITE_TRANSIENT);
187193
}
188-
// U16STR_REF
194+
// u16str_ref
189195
template<>
190196
struct has_sqlite_type<std::u16string, SQLITE3_TEXT, void> : std::true_type {};
191-
inline int bind_col_in_db(sqlite3_stmt* stmt, int inx, U16STR_REF val) {
197+
inline int bind_col_in_db(sqlite3_stmt* stmt, int inx, u16str_ref val) {
192198
return sqlite3_bind_text16(stmt, inx, val.data(), sizeof(char16_t) * val.length(), SQLITE_TRANSIENT);
193199
}
194200

195-
// Convert char* to string_view to trigger op<<(..., const STR_REF )
201+
// Convert char* to string_view to trigger op<<(..., const str_ref )
196202
template<std::size_t N> inline int bind_col_in_db(sqlite3_stmt* stmt, int inx, const char16_t(&STR)[N]) {
197203
return sqlite3_bind_text16(stmt, inx, &STR[0], N-1, SQLITE_TRANSIENT);
198204
}
@@ -206,7 +212,7 @@ namespace sqlite {
206212
std::u16string(reinterpret_cast<char16_t const *>(sqlite3_value_text16(value)), sqlite3_value_bytes16(value));
207213
}
208214

209-
inline void store_result_in_db(sqlite3_context* db, U16STR_REF val) {
215+
inline void store_result_in_db(sqlite3_context* db, u16str_ref val) {
210216
sqlite3_result_text16(db, val.data(), sizeof(char16_t) * val.length(), SQLITE_TRANSIENT);
211217
}
212218

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 U16STR_REF &input) {
11+
inline std::string utf16_to_utf8(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)