DBI (version 0.5-1)

dbSendStatement: Execute a data manipulation statement on a given database connection

Description

The function dbSendStatement only submits and synchronously executes the SQL data manipulation statement (e.g., UPDATE, DELETE, INSERT INTO, DROP TABLE, ...) to the database engine. To query the number of affected rows, call dbGetRowsAffected on the returned result object. You must also call dbClearResult after that. For interactive use, you should almost always prefer dbExecute.

Usage

dbSendStatement(conn, statement, ...)

Arguments

conn
A DBIConnection object, as produced by dbConnect.
statement
a character vector of length 1 containing SQL.
...
Other parameters passed on to methods.

Value

An object that inherits from DBIResult. Once you have finished using a result, make sure to disconnect it with dbClearResult.

Details

dbSendStatement comes with a default implementation that simply forwards to dbSendQuery, to support backends that only implement the latter.

See Also

For queries: dbSendQuery and dbGetQuery.

Other DBIConnection generics: DBIConnection-class, dbDataType, dbDisconnect, dbExecute, dbExistsTable, dbGetException, dbGetInfo, dbGetQuery, dbIsValid, dbListFields, dbListResults, dbListTables, dbReadTable, dbRemoveTable, dbSendQuery

Examples

Run this code
con <- dbConnect(RSQLite::SQLite(), ":memory:")

dbWriteTable(con, "cars", head(cars, 3))
rs <- dbSendStatement(con,
  "INSERT INTO cars (speed, dist) VALUES (1, 1), (2, 2), (3, 3);")
dbHasCompleted(rs)
dbGetRowsAffected(rs)
dbClearResult(rs)
dbReadTable(con, "cars")   # there are now 6 rows

dbDisconnect(con)

Run the code above in your browser using DataLab