@@ -133,7 +133,6 @@ namespace sqlite {
133
133
134
134
database_binder (database_binder&& other) :
135
135
_db (std::move(other._db)),
136
- _sql (std::move(other._sql)),
137
136
_stmt (std::move(other._stmt)),
138
137
_inx (other._inx), execution_started(other.execution_started) { }
139
138
@@ -160,7 +159,6 @@ namespace sqlite {
160
159
161
160
private:
162
161
std::shared_ptr<sqlite3> _db;
163
- std::u16string _sql;
164
162
std::unique_ptr<sqlite3_stmt, decltype (&sqlite3_finalize)> _stmt;
165
163
166
164
int _inx;
@@ -209,6 +207,14 @@ namespace sqlite {
209
207
return tmp;
210
208
}
211
209
210
+ sqlite3_stmt* _prepare (const std::string& sql) {
211
+ int hresult;
212
+ sqlite3_stmt* tmp = nullptr ;
213
+ hresult = sqlite3_prepare_v2 (_db.get (), sql.data (), -1 , &tmp, nullptr );
214
+ if ((hresult) != SQLITE_OK) exceptions::throw_sqlite_error (hresult);
215
+ return tmp;
216
+ }
217
+
212
218
template <typename Type>
213
219
struct is_sqlite_value : public std ::integral_constant<
214
220
bool ,
@@ -266,13 +272,15 @@ namespace sqlite {
266
272
267
273
database_binder (std::shared_ptr<sqlite3> db, std::u16string const & sql):
268
274
_db (db),
269
- _sql (sql),
270
275
_stmt (_prepare(sql), sqlite3_finalize),
271
276
_inx (1 ) {
272
277
}
273
278
274
279
database_binder (std::shared_ptr<sqlite3> db, std::string const & sql):
275
- database_binder (db, std::u16string(sql.begin(), sql.end())) {}
280
+ _db (db),
281
+ _stmt (_prepare(sql), sqlite3_finalize),
282
+ _inx (1 ) {
283
+ }
276
284
277
285
~database_binder () noexcept (false ) {
278
286
/* Will be executed if no >>op is found, but not if an exception
@@ -318,13 +326,16 @@ namespace sqlite {
318
326
auto ret = sqlite3_open16 (db_name.data (), &tmp);
319
327
_db = std::shared_ptr<sqlite3>(tmp, [=](sqlite3* ptr) { sqlite3_close_v2 (ptr); }); // this will close the connection eventually when no longer needed.
320
328
if (ret != SQLITE_OK) exceptions::throw_sqlite_error (ret);
321
-
322
-
323
329
// _db.reset(tmp, sqlite3_close); // alternative close. (faster?)
324
330
}
325
331
326
- database (std::string const & db_name):
327
- database (std::u16string(db_name.begin(), db_name.end())) {}
332
+ database (std::string const & db_name): _db(nullptr ) {
333
+ sqlite3* tmp = nullptr ;
334
+ auto ret = sqlite3_open (db_name.data (), &tmp);
335
+ _db = std::shared_ptr<sqlite3>(tmp, [=](sqlite3* ptr) { sqlite3_close_v2 (ptr); }); // this will close the connection eventually when no longer needed.
336
+ if (ret != SQLITE_OK) exceptions::throw_sqlite_error (ret);
337
+ // _db.reset(tmp, sqlite3_close); // alternative close. (faster?)
338
+ }
328
339
329
340
database (std::shared_ptr<sqlite3> db):
330
341
_db (db) {}
0 commit comments