Returns the total number of rows actually fetched with calls to dbFetch()
for this result set.
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::dbGetRowCount("DatabaseConnectorDbiResult")
DatabaseConnector::dbGetRowCount("DatabaseConnectorJdbcResult")
sparklyr::dbGetRowCount("DBISparkResult")
Arguments
- res
An object inheriting from DBIResult.
- ...
Other arguments passed on to methods.
Value
dbGetRowCount()
returns a scalar number (integer or numeric),
the number of rows fetched so far.
After calling DBI::dbSendQuery()
,
the row count is initially zero.
After a call to DBI::dbFetch()
without limit,
the row count matches the total number of rows returned.
Fetching a limited number of rows
increases the number of rows by the number of rows returned,
even if fetching past the end of the result set.
For queries with an empty result set,
zero is returned
even after fetching.
For data manipulation statements issued with
DBI::dbSendStatement()
,
zero is returned before
and after calling dbFetch()
.
Failure modes
Attempting to get the row count for a result set cleared with
DBI::dbClearResult()
gives an error.
See also
Other DBIResult generics:
DBIResult-class
,
dbBind()
,
dbClearResult()
,
dbColumnInfo()
,
dbFetch()
,
dbGetInfo()
,
dbGetRowsAffected()
,
dbGetStatement()
,
dbHasCompleted()
,
dbIsReadOnly()
,
dbIsValid()
,
dbQuoteLiteral()
,
dbQuoteString()
Examples
con <- dbConnect(RSQLite::SQLite(), ":memory:")
dbWriteTable(con, "mtcars", mtcars)
rs <- dbSendQuery(con, "SELECT * FROM mtcars")
dbGetRowCount(rs)
#> [1] 0
ret1 <- dbFetch(rs, 10)
dbGetRowCount(rs)
#> [1] 10
ret2 <- dbFetch(rs)
dbGetRowCount(rs)
#> [1] 32
nrow(ret1) + nrow(ret2)
#> [1] 32
dbClearResult(rs)
dbDisconnect(con)