-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid connection when doing initial DB build with custom db_connection #102
Comments
I think this will also be problematic when there are lots of missing games actually: if(length(missing) >= 50) {
DBI::dbDisconnect(connection)
message("The number of missing games is so large that rebuilding the database is more efficient.")
build_db(dbdir, dbname, tblname, db_connection)
if (is.null(db_connection)) {
connection <- DBI::dbConnect(RSQLite::SQLite(), db)
} else {
connection <- db_connection
}
missing <- get_missing_games(completed_games, connection, tblname)
} would probably need to become: if(length(missing) >= 50) {
if(is.null(db_connection)){DBI::dbDisconnect(connection)}
message("The number of missing games is so large that rebuilding the database is more efficient.")
if(is.null(db_connection)){build_db(dbdir, dbname, tblname, db_connection, FALSE)}
else{build_db(dbdir, dbname, tblname, db_connection)}
if (is.null(db_connection)) {
connection <- DBI::dbConnect(RSQLite::SQLite(), db)
} else {
connection <- db_connection
}
missing <- get_missing_games(completed_games, connection, tblname)
} |
Can you please provide a code example to reproduce the Error message? I am wondering if you are doing the connection correct as nobody else had those problems. |
Looked at it and think you are right. Should not disconnect if a custom connection is provided. Good catch, thanks! |
Just in case it does make a difference this is the code I use to connect. It's a local Postgres instance on my Mac. conn <- DBI::dbConnect(RPostgres::Postgres(), dbname = dbname)
nflfastR::update_db(db_connection = conn, tblname = 'pbp', dbname = dbname, force_rebuild = force_rebuild)
DBI::dbDisconnect(conn) |
The issue got closed automatically as I merged in a potential fix now. If you are still having problems @awgymer please feel free to reopen the issue. |
When using building the DB for the first time or using
force_rebuild
anError: Invalid connection
is raised (usingRPostgres
- suspect error message may differ between drivers) which I believe is caused bybuild_db
callingDBI::dbDisconnect(connection)
. This is not a problem when using the default RSQLite connection because the following code is run after the initial build/rebuild code which re-establishes an SQLite connection:I'm not overly familiar with
DBI::DBIConnection
objects but as far as I know there isn't a way to reconnect? Perhaps the best solution to this would be adisconnect
parameter tobuild_db
- so that it can still run independently from update_db where necessary - but when a custom connection is used inupdate_db
and you are calling it you don't disconnect?Something like the following:
The text was updated successfully, but these errors were encountered: