# NOT RUN {
conn = odbcConnect('MyDataSource')
# prepare, execute and fetch results separately
sqlPrepare(conn, "SELECT * FROM myTable WHERE column = ?")
sqlExecute(conn, NULL, 'myValue')
sqlGetResults(conn)
# prepare and execute at one time, fetch results separately
sqlExecute(conn, "SELECT * FROM myTable WHERE column = ?", 'myValue')
sqlGetResults(conn)
# prepare, execute and fetch at one time
sqlExecute(conn, "SELECT * FROM myTable WHERE column = ?", 'myValue', TRUE)
# prepare, execute and fetch at one time using multiple wildcards for data passthrough
sqlExecute(
conn,
query="SELECT * FROM table WHERE column1 = ? AND column2 = ?",
data=data.frame('column1value', 'column2value'),
fetch=TRUE
)
# prepare, execute and fetch at one time, pass additional parameters to sqlFetch()
sqlExecute(
conn,
"SELECT * FROM myTable WHERE column = ?",
'myValue',
fetch = TRUE,
stringsAsFactors = FALSE
)
# prepare, execute and fetch at one time using a query timeout value
sqlExecute(conn, "SELECT * FROM myTable WHERE column = ?", 'myValue', TRUE, query_timeout=45)
# execute a simple statement without parameters using a query timeout value
sqlExecute(con, "SELECT * FROM myTable", fetch = TRUE, query_timeout = 60)
# }
Run the code above in your browser using DataLab