Di seguito è riportato un riepilogo di ciò che è attualmente supportato in RSQLite per i parametri associati. Hai ragione che al momento non è disponibile il supporto per SELECT, ma non c'è una buona ragione per questo e vorrei aggiungere il supporto per questo.
Se ti senti come l'hacking, è possibile ottenere una cassa di sola lettura di tutti le DBI relativi pacchetti qui:
use --user=readonly --password=readonly
https://hedgehog.fhcrc.org/compbio/r-dbi/trunk
https://hedgehog.fhcrc.org/compbio/r-dbi/trunk/DBI
https://hedgehog.fhcrc.org/compbio/r-dbi/trunk/SQLite/RSQLite
Mi piace ricevere patch, specialmente se includono test e documentazione. Diff Unified, per favore.Io in realtà faccio tutto il mio sviluppo utilizzando git e così migliore dei casi è quello di creare un clone git di dire RSQLite e poi mi inviare diff come git format-patch -n git-svn..
In ogni caso, ecco alcuni esempi:
library("RSQLite")
make_data <- function(n)
{
alpha <- c(letters, as.character(0:9))
make_key <- function(n)
{
paste(sample(alpha, n, replace = TRUE), collapse = "")
}
keys <- sapply(sample(1:5, replace=TRUE), function(x) make_key(x))
counts <- sample(seq_len(1e4), n, replace = TRUE)
data.frame(key = keys, count = counts, stringsAsFactors = FALSE)
}
key_counts <- make_data(100)
db <- dbConnect(SQLite(), dbname = ":memory:")
sql <- "
create table keys (key text, count integer)
"
dbGetQuery(db, sql)
bulk_insert <- function(sql, key_counts)
{
dbBeginTransaction(db)
dbGetPreparedQuery(db, sql, bind.data = key_counts)
dbCommit(db)
dbGetQuery(db, "select count(*) from keys")[[1]]
}
## for all styles, you can have up to 999 parameters
## anonymous
sql <- "insert into keys values (?, ?)"
bulk_insert(sql, key_counts)
## named w/ :, $, @
## names are matched against column names of bind.data
sql <- "insert into keys values (:key, :count)"
bulk_insert(sql, key_counts[ , 2:1])
sql <- "insert into keys values ($key, $count)"
bulk_insert(sql, key_counts)
sql <- "insert into keys values (@key, @count)"
bulk_insert(sql, key_counts)
## indexed (NOT CURRENTLY SUPPORTED)
## sql <- "insert into keys values (?1, ?2)"
## bulk_insert(sql)
puoi fornire qualche esempio di codice che funzionerebbe come vorresti che funzionasse? quale comportamento ti aspetteresti che le variabili vincolate abbiano? –
Intendi qualcosa del genere? http://stackoverflow.com/questions/2182337/how-to-use-a-variable-name-in-a-mysql-statement –
Sento odore di un nuovo DBI con caratteristiche migliori in arrivo. Saremo tutti felici beta-tester, Ken .... –