3737#endif
3838#ifdef MODERN_SQLITE_STRINGVIEW_SUPPORT
3939#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;
4242#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;
4545#endif
4646#include < sqlite3.h>
4747#include " errors.h"
@@ -164,12 +164,14 @@ namespace sqlite {
164164 // STR_REF
165165 template <>
166166 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) {
168168 return sqlite3_bind_text (stmt, inx, val.data (), val.length (), SQLITE_TRANSIENT);
169169 }
170170
171171 // 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+ }
173175
174176 inline std::string get_col_from_db (sqlite3_stmt* stmt, int inx, result_type<std::string>) {
175177 return sqlite3_column_type (stmt, inx) == SQLITE_NULL ? std::string () :
@@ -180,18 +182,20 @@ namespace sqlite {
180182 std::string (reinterpret_cast <char const *>(sqlite3_value_text (value)), sqlite3_value_bytes (value));
181183 }
182184
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) {
184186 sqlite3_result_text (db, val.data (), val.length (), SQLITE_TRANSIENT);
185187 }
186188 // U16STR_REF
187189 template <>
188190 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) {
190192 return sqlite3_bind_text16 (stmt, inx, val.data (), sizeof (char16_t ) * val.length (), SQLITE_TRANSIENT);
191193 }
192194
193195 // 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+ }
195199
196200 inline std::u16string get_col_from_db (sqlite3_stmt* stmt, int inx, result_type<std::u16string>) {
197201 return sqlite3_column_type (stmt, inx) == SQLITE_NULL ? std::u16string () :
@@ -202,7 +206,7 @@ namespace sqlite {
202206 std::u16string (reinterpret_cast <char16_t const *>(sqlite3_value_text16 (value)), sqlite3_value_bytes16 (value));
203207 }
204208
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) {
206210 sqlite3_result_text16 (db, val.data (), sizeof (char16_t ) * val.length (), SQLITE_TRANSIENT);
207211 }
208212
0 commit comments