vendredi 29 avril 2016

Achieving a robust connection to SQLite from

I am creating a connection to an SQLite database (using package RSQLite) in the following way:

fPath <- file.path(getwd(), "db_name.sqlite")
db <<- dbConnect(SQLite(), dbname = fPath)

This allows me to perform queries in multiple functions, in multiple ways, without having to reconnect, pass in the connection object 'db'

A typical query looks like

dbGetQuery(db, "SELECT * FROM table;")
dbWriteTable(df, "table", data, append = TRUE)

I am generating and storing a lot of data, and also modifying the R code I am using, table structures etc. as I go.

I decided to close my R session, and reload. When I reconnected to the database, using the method above, I found that the state of the database was old; old tables, missing data.

It seems that somehow the changes I made and data I stored went to a different database than the one I specified in fPath. I cannot locate a separate database on my machine.

Why/how would this happen? Does SQLite create a temporary database if the original connection is lost? How can I make a connection robust? Losing data / changes is obviously unpleasant.

Is there a way of confirming the file path to an open connection?

e.g.

dbGetInfo(db)$path
summary(db)

Aucun commentaire:

Enregistrer un commentaire