有時從由唯一父物件建立的函式返回連線、陳述式或串流會很有用。這些輔助函式將唯一父物件的生命週期連結到其子物件,以便在子物件之後可預測且立即地釋放父物件。這些函式將使所有對先前 R 物件的參考失效。
引數
- 連線
使用
adbc_connection_init()
建立的連線- 資料庫
使用
adbc_database_init()
建立的資料庫- 陳述式
使用
adbc_statement_init()
建立的陳述式
範例
# Use local_adbc to ensure prompt cleanup on error;
# use join functions to return a single object that manages
# the lifecycle of all three.
stmt <- local({
db <- local_adbc(adbc_database_init(adbc_driver_log()))
con <- local_adbc(adbc_connection_init(db))
adbc_connection_join(con, db)
stmt <- local_adbc(adbc_statement_init(con))
adbc_statement_join(stmt, con)
adbc_xptr_move(stmt)
})
#> LogDatabaseNew()
#> LogDatabaseInit()
#> LogConnectionNew()
#> LogConnectionInit()
#> LogStatementNew()
# Everything is released immediately when the last object is released
adbc_statement_release(stmt)
#> LogStatementRelease()
#> LogConnectionRelease()
#> LogDatabaseRelease()