@@ -535,7 +535,8 @@ void DatabaseSync::Prepare(const FunctionCallbackInfo<Value>& args) {
535
535
sqlite3_stmt* s = nullptr ;
536
536
int r = sqlite3_prepare_v2 (db->connection_ , *sql, -1 , &s, 0 );
537
537
CHECK_ERROR_OR_THROW (env->isolate (), db, r, SQLITE_OK, void ());
538
- BaseObjectPtr<StatementSync> stmt = StatementSync::Create (env, db, s);
538
+ BaseObjectPtr<StatementSync> stmt =
539
+ StatementSync::Create (env, BaseObjectPtr<DatabaseSync>(db), s);
539
540
db->statements_ .insert (stmt.get ());
540
541
args.GetReturnValue ().Set (stmt->object ());
541
542
}
@@ -946,11 +947,10 @@ void DatabaseSync::LoadExtension(const FunctionCallbackInfo<Value>& args) {
946
947
947
948
StatementSync::StatementSync (Environment* env,
948
949
Local<Object> object,
949
- DatabaseSync* db,
950
+ BaseObjectPtr< DatabaseSync> db,
950
951
sqlite3_stmt* stmt)
951
- : BaseObject(env, object) {
952
+ : BaseObject(env, object), db_(std::move(db)) {
952
953
MakeWeak ();
953
- db_ = db;
954
954
statement_ = stmt;
955
955
// In the future, some of these options could be set at the database
956
956
// connection level and inherited by statements to reduce boilerplate.
@@ -977,7 +977,7 @@ inline bool StatementSync::IsFinalized() {
977
977
978
978
bool StatementSync::BindParams (const FunctionCallbackInfo<Value>& args) {
979
979
int r = sqlite3_clear_bindings (statement_);
980
- CHECK_ERROR_OR_THROW (env ()->isolate (), db_, r, SQLITE_OK, false );
980
+ CHECK_ERROR_OR_THROW (env ()->isolate (), db_. get () , r, SQLITE_OK, false );
981
981
982
982
int anon_idx = 1 ;
983
983
int anon_start = 0 ;
@@ -1107,7 +1107,7 @@ bool StatementSync::BindValue(const Local<Value>& value, const int index) {
1107
1107
return false ;
1108
1108
}
1109
1109
1110
- CHECK_ERROR_OR_THROW (env ()->isolate (), db_, r, SQLITE_OK, false );
1110
+ CHECK_ERROR_OR_THROW (env ()->isolate (), db_. get () , r, SQLITE_OK, false );
1111
1111
return true ;
1112
1112
}
1113
1113
@@ -1173,7 +1173,7 @@ void StatementSync::All(const FunctionCallbackInfo<Value>& args) {
1173
1173
env, stmt->IsFinalized (), " statement has been finalized" );
1174
1174
Isolate* isolate = env->isolate ();
1175
1175
int r = sqlite3_reset (stmt->statement_ );
1176
- CHECK_ERROR_OR_THROW (isolate, stmt->db_ , r, SQLITE_OK, void ());
1176
+ CHECK_ERROR_OR_THROW (isolate, stmt->db_ . get () , r, SQLITE_OK, void ());
1177
1177
1178
1178
if (!stmt->BindParams (args)) {
1179
1179
return ;
@@ -1202,7 +1202,7 @@ void StatementSync::All(const FunctionCallbackInfo<Value>& args) {
1202
1202
rows.emplace_back (row);
1203
1203
}
1204
1204
1205
- CHECK_ERROR_OR_THROW (isolate, stmt->db_ , r, SQLITE_DONE, void ());
1205
+ CHECK_ERROR_OR_THROW (isolate, stmt->db_ . get () , r, SQLITE_DONE, void ());
1206
1206
args.GetReturnValue ().Set (Array::New (isolate, rows.data (), rows.size ()));
1207
1207
}
1208
1208
@@ -1270,7 +1270,8 @@ void StatementSync::IterateNextCallback(
1270
1270
1271
1271
int r = sqlite3_step (stmt->statement_ );
1272
1272
if (r != SQLITE_ROW) {
1273
- CHECK_ERROR_OR_THROW (env->isolate (), stmt->db_ , r, SQLITE_DONE, void ());
1273
+ CHECK_ERROR_OR_THROW (
1274
+ env->isolate (), stmt->db_ .get (), r, SQLITE_DONE, void ());
1274
1275
1275
1276
// cleanup when no more rows to fetch
1276
1277
sqlite3_reset (stmt->statement_ );
@@ -1322,7 +1323,7 @@ void StatementSync::Iterate(const FunctionCallbackInfo<Value>& args) {
1322
1323
auto isolate = env->isolate ();
1323
1324
auto context = env->context ();
1324
1325
int r = sqlite3_reset (stmt->statement_ );
1325
- CHECK_ERROR_OR_THROW (env->isolate (), stmt->db_ , r, SQLITE_OK, void ());
1326
+ CHECK_ERROR_OR_THROW (env->isolate (), stmt->db_ . get () , r, SQLITE_OK, void ());
1326
1327
1327
1328
if (!stmt->BindParams (args)) {
1328
1329
return ;
@@ -1386,7 +1387,7 @@ void StatementSync::Get(const FunctionCallbackInfo<Value>& args) {
1386
1387
env, stmt->IsFinalized (), " statement has been finalized" );
1387
1388
Isolate* isolate = env->isolate ();
1388
1389
int r = sqlite3_reset (stmt->statement_ );
1389
- CHECK_ERROR_OR_THROW (isolate, stmt->db_ , r, SQLITE_OK, void ());
1390
+ CHECK_ERROR_OR_THROW (isolate, stmt->db_ . get () , r, SQLITE_OK, void ());
1390
1391
1391
1392
if (!stmt->BindParams (args)) {
1392
1393
return ;
@@ -1396,7 +1397,7 @@ void StatementSync::Get(const FunctionCallbackInfo<Value>& args) {
1396
1397
r = sqlite3_step (stmt->statement_ );
1397
1398
if (r == SQLITE_DONE) return ;
1398
1399
if (r != SQLITE_ROW) {
1399
- THROW_ERR_SQLITE_ERROR (isolate, stmt->db_ );
1400
+ THROW_ERR_SQLITE_ERROR (isolate, stmt->db_ . get () );
1400
1401
return ;
1401
1402
}
1402
1403
@@ -1432,7 +1433,7 @@ void StatementSync::Run(const FunctionCallbackInfo<Value>& args) {
1432
1433
THROW_AND_RETURN_ON_BAD_STATE (
1433
1434
env, stmt->IsFinalized (), " statement has been finalized" );
1434
1435
int r = sqlite3_reset (stmt->statement_ );
1435
- CHECK_ERROR_OR_THROW (env->isolate (), stmt->db_ , r, SQLITE_OK, void ());
1436
+ CHECK_ERROR_OR_THROW (env->isolate (), stmt->db_ . get () , r, SQLITE_OK, void ());
1436
1437
1437
1438
if (!stmt->BindParams (args)) {
1438
1439
return ;
@@ -1441,7 +1442,7 @@ void StatementSync::Run(const FunctionCallbackInfo<Value>& args) {
1441
1442
auto reset = OnScopeLeave ([&]() { sqlite3_reset (stmt->statement_ ); });
1442
1443
r = sqlite3_step (stmt->statement_ );
1443
1444
if (r != SQLITE_ROW && r != SQLITE_DONE) {
1444
- THROW_ERR_SQLITE_ERROR (env->isolate (), stmt->db_ );
1445
+ THROW_ERR_SQLITE_ERROR (env->isolate (), stmt->db_ . get () );
1445
1446
return ;
1446
1447
}
1447
1448
@@ -1597,9 +1598,8 @@ Local<FunctionTemplate> StatementSync::GetConstructorTemplate(
1597
1598
return tmpl;
1598
1599
}
1599
1600
1600
- BaseObjectPtr<StatementSync> StatementSync::Create (Environment* env,
1601
- DatabaseSync* db,
1602
- sqlite3_stmt* stmt) {
1601
+ BaseObjectPtr<StatementSync> StatementSync::Create (
1602
+ Environment* env, BaseObjectPtr<DatabaseSync> db, sqlite3_stmt* stmt) {
1603
1603
Local<Object> obj;
1604
1604
if (!GetConstructorTemplate (env)
1605
1605
->InstanceTemplate ()
@@ -1608,7 +1608,7 @@ BaseObjectPtr<StatementSync> StatementSync::Create(Environment* env,
1608
1608
return BaseObjectPtr<StatementSync>();
1609
1609
}
1610
1610
1611
- return MakeBaseObject<StatementSync>(env, obj, db , stmt);
1611
+ return MakeBaseObject<StatementSync>(env, obj, std::move (db) , stmt);
1612
1612
}
1613
1613
1614
1614
Session::Session (Environment* env,
@@ -1675,7 +1675,7 @@ void Session::Changeset(const FunctionCallbackInfo<Value>& args) {
1675
1675
void * pChangeset;
1676
1676
int r = sqliteChangesetFunc (session->session_ , &nChangeset, &pChangeset);
1677
1677
CHECK_ERROR_OR_THROW (
1678
- env->isolate (), session->database_ , r, SQLITE_OK, void ());
1678
+ env->isolate (), session->database_ . get () , r, SQLITE_OK, void ());
1679
1679
1680
1680
auto freeChangeset = OnScopeLeave ([&] { sqlite3_free (pChangeset); });
1681
1681
0 commit comments