r/adbcdrivermanager: Get result schema for parametrized query before binding/executing
- Dominant language
- C#
- Stars
- 627
- Forks
- 217
- Avg merge
- 17h
- Merged PRs (30d)
- 57
Description
DBI requires me to return a zero-row `data.frame` when binding zero-length parameters in a parametrized query. For something like
```r
library(DBI)
con <- dbConnect(adbi::adbi("adbcsqlite"), uri = ":memory:")
dbWriteTable(con, "swiss", datasets::swiss)
res <- dbSendQuery(con, "SELECT * from swiss WHERE Agriculture < ?")
dbBind(res, list(integer()))
dbFetch(res)
```
I'd need to return something like
```r
swiss[0, ]
#> [1] Fertility Agriculture Examination Education
#> [5] Catholic Infant.Mortality
#> <0 rows> (or 0-length row.names)
```
but instead I currently have an error `Error parsing schema->format: Expected a null-terminated string but found NULL`.
One way for me to do this is by catching the zero-length parameter binding and constructing the zero-length `data.frame` from the result schema. To do this, I'd need to access the result schema without binding/executing.
We have the exported function `adbc_statement_execute_schema()` available. Does that possibly do what I need it to? Unfortunately, I get
```r
library(adbcdrivermanager)
db <- adbc_database_init(adbcsqlite::adbcsqlite(), uri = ":memory:")
con <- adbc_connection_init(db)
write_adbc(datasets::swiss, con, "swiss", temporary = TRUE)
stmt <- adbc_statement_init(con)
adbc_statement_set_sql_query(stmt, "SELECT * from swiss WHERE Agriculture < ?")
adbc_statement_prepare(stmt)
adbc_statement_execute_schema(stmt)
#> Error in adbc_statement_execute_schema(stmt) : NOT_IMPLEMENTED
```
Contributor guide
Assessment
This issue has not been assessed yet.