I am trying to process a large number of queries with parameters in R using ROracle. I know which parameters appear in each query, but I don't know in which order they appear. I am therefore looking for a way to submit the parameters by name in each query. Sample code:
library(ROracle)
# establish connection to DB
drv <- dbDriver("Oracle")
con <- dbConnect(drv, "User", "password", dbname = "DB")
# create table
createTab <- "create table RORACLE_TEST(num1 number, num2 number)"
dbGetQuery(con, createTab)
# insert String
insStr <- "insert into RORACLE_TEST values(:row1, :row2)"
dbGetQuery(con, insStr, data.frame(row2 = 0, row1 = 1))
# check output
dbGetQuery(con, "SELECT * FROM RORACLE_TEST")
# Output is:
# NUM1 NUM2
#1 0 1
# Desired output should be:
# NUM1 NUM2
#1 1 0
Any workaround for this will be appreciated except solutions of the kind
dbGetQuery(con,gsub(":row2", "0", gsub(":row1", "1", insStr)))
since this will not sanitize against sql injection (parameters will come from user input).