37
37
#endif
38
38
#ifdef MODERN_SQLITE_STRINGVIEW_SUPPORT
39
39
#include < string_view>
40
- typedef std::string_view STR_REF;
41
- typedef std::u16string_view U16STR_REF;
40
+ typedef const std::string_view STR_REF;
41
+ typedef const std::u16string_view U16STR_REF;
42
42
#else
43
- typedef std::string STR_REF;
44
- typedef std::u16string U16STR_REF;
43
+ typedef const std::string& STR_REF;
44
+ typedef const std::u16string& U16STR_REF;
45
45
#endif
46
46
#include < sqlite3.h>
47
47
#include " errors.h"
@@ -164,12 +164,14 @@ namespace sqlite {
164
164
// STR_REF
165
165
template <>
166
166
struct has_sqlite_type <std::string, SQLITE3_TEXT, void > : std::true_type {};
167
- inline int bind_col_in_db (sqlite3_stmt* stmt, int inx, const STR_REF& val) {
167
+ inline int bind_col_in_db (sqlite3_stmt* stmt, int inx, STR_REF val) {
168
168
return sqlite3_bind_text (stmt, inx, val.data (), val.length (), SQLITE_TRANSIENT);
169
169
}
170
170
171
171
// Convert char* to string_view to trigger op<<(..., const STR_REF )
172
- template <std::size_t N> inline int bind_col_in_db (sqlite3_stmt* stmt, int inx, const char (&STR)[N]) { return bind_col_in_db (stmt, inx, STR_REF (STR, N-1 )); }
172
+ template <std::size_t N> inline int bind_col_in_db (sqlite3_stmt* stmt, int inx, const char (&STR)[N]) {
173
+ return sqlite3_bind_text (stmt, inx, &STR[0 ], N-1 , SQLITE_TRANSIENT);
174
+ }
173
175
174
176
inline std::string get_col_from_db (sqlite3_stmt* stmt, int inx, result_type<std::string>) {
175
177
return sqlite3_column_type (stmt, inx) == SQLITE_NULL ? std::string () :
@@ -180,18 +182,20 @@ namespace sqlite {
180
182
std::string (reinterpret_cast <char const *>(sqlite3_value_text (value)), sqlite3_value_bytes (value));
181
183
}
182
184
183
- inline void store_result_in_db (sqlite3_context* db, const STR_REF& val) {
185
+ inline void store_result_in_db (sqlite3_context* db, STR_REF val) {
184
186
sqlite3_result_text (db, val.data (), val.length (), SQLITE_TRANSIENT);
185
187
}
186
188
// U16STR_REF
187
189
template <>
188
190
struct has_sqlite_type <std::u16string, SQLITE3_TEXT, void > : std::true_type {};
189
- inline int bind_col_in_db (sqlite3_stmt* stmt, int inx, const U16STR_REF& val) {
191
+ inline int bind_col_in_db (sqlite3_stmt* stmt, int inx, U16STR_REF val) {
190
192
return sqlite3_bind_text16 (stmt, inx, val.data (), sizeof (char16_t ) * val.length (), SQLITE_TRANSIENT);
191
193
}
192
194
193
195
// Convert char* to string_view to trigger op<<(..., const STR_REF )
194
- template <std::size_t N> inline int bind_col_in_db (sqlite3_stmt* stmt, int inx, const char16_t (&STR)[N]) { return bind_col_in_db (stmt, inx, U16STR_REF (STR, N-1 )); }
196
+ template <std::size_t N> inline int bind_col_in_db (sqlite3_stmt* stmt, int inx, const char16_t (&STR)[N]) {
197
+ return sqlite3_bind_text16 (stmt, inx, &STR[0 ], N-1 , SQLITE_TRANSIENT);
198
+ }
195
199
196
200
inline std::u16string get_col_from_db (sqlite3_stmt* stmt, int inx, result_type<std::u16string>) {
197
201
return sqlite3_column_type (stmt, inx) == SQLITE_NULL ? std::u16string () :
@@ -202,7 +206,7 @@ namespace sqlite {
202
206
std::u16string (reinterpret_cast <char16_t const *>(sqlite3_value_text16 (value)), sqlite3_value_bytes16 (value));
203
207
}
204
208
205
- inline void store_result_in_db (sqlite3_context* db, const U16STR_REF& val) {
209
+ inline void store_result_in_db (sqlite3_context* db, U16STR_REF val) {
206
210
sqlite3_result_text16 (db, val.data (), sizeof (char16_t ) * val.length (), SQLITE_TRANSIENT);
207
211
}
208
212
0 commit comments