This generic tests whether a database object is still valid (i.e. it hasn't been disconnected or cleared).
Methods in other packages
This documentation page describes the generics. Refer to the documentation pages linked below for the documentation for the methods that are implemented in various backend packages.
DatabaseConnector::dbIsValid("DatabaseConnectorDbiConnection")
DatabaseConnector::dbIsValid("DatabaseConnectorJdbcConnection")
RJDBC::dbIsValid("JDBCConnection")
RJDBC::dbIsValid("JDBCResult")
sparklyr::dbIsValid("DBISparkResult")
sparklyr::dbIsValid("spark_connection")
Arguments
- dbObj
An object inheriting from DBIObject, i.e. DBIDriver, DBIConnection, or a DBIResult
- ...
Other arguments to methods.
Value
dbIsValid()
returns a logical scalar,
TRUE
if the object specified by dbObj
is valid,
FALSE
otherwise.
A DBIConnection object is initially valid,
and becomes invalid after disconnecting with dbDisconnect()
.
For an invalid connection object (e.g., for some drivers if the object
is saved to a file and then restored), the method also returns FALSE
.
A DBIResult object is valid after a call to dbSendQuery()
,
and stays valid even after all rows have been fetched;
only clearing it with dbClearResult()
invalidates it.
A DBIResult object is also valid after a call to dbSendStatement()
,
and stays valid after querying the number of rows affected;
only clearing it with dbClearResult()
invalidates it.
If the connection to the database system is dropped (e.g., due to
connectivity problems, server failure, etc.), dbIsValid()
should return
FALSE
. This is not tested automatically.
See also
Other DBIDriver generics:
DBIDriver-class
,
dbCanConnect()
,
dbConnect()
,
dbDataType()
,
dbDriver()
,
dbGetInfo()
,
dbIsReadOnly()
,
dbListConnections()
Other DBIConnection generics:
DBIConnection-class
,
dbAppendTable()
,
dbAppendTableArrow()
,
dbCreateTable()
,
dbCreateTableArrow()
,
dbDataType()
,
dbDisconnect()
,
dbExecute()
,
dbExistsTable()
,
dbGetException()
,
dbGetInfo()
,
dbGetQuery()
,
dbGetQueryArrow()
,
dbIsReadOnly()
,
dbListFields()
,
dbListObjects()
,
dbListResults()
,
dbListTables()
,
dbQuoteIdentifier()
,
dbReadTable()
,
dbReadTableArrow()
,
dbRemoveTable()
,
dbSendQuery()
,
dbSendQueryArrow()
,
dbSendStatement()
,
dbUnquoteIdentifier()
,
dbWriteTable()
,
dbWriteTableArrow()
Other DBIResult generics:
DBIResult-class
,
dbBind()
,
dbClearResult()
,
dbColumnInfo()
,
dbFetch()
,
dbGetInfo()
,
dbGetRowCount()
,
dbGetRowsAffected()
,
dbGetStatement()
,
dbHasCompleted()
,
dbIsReadOnly()
,
dbQuoteLiteral()
,
dbQuoteString()
Other DBIResultArrow generics:
DBIResultArrow-class
,
dbBind()
,
dbClearResult()
,
dbFetchArrow()
,
dbFetchArrowChunk()
,
dbHasCompleted()
Examples
dbIsValid(RSQLite::SQLite())
#> [1] TRUE
con <- dbConnect(RSQLite::SQLite(), ":memory:")
dbIsValid(con)
#> [1] TRUE
rs <- dbSendQuery(con, "SELECT 1")
dbIsValid(rs)
#> [1] TRUE
dbClearResult(rs)
dbIsValid(rs)
#> [1] FALSE
dbDisconnect(con)
dbIsValid(con)
#> [1] FALSE