RMySQL icon indicating copy to clipboard operation
RMySQL copied to clipboard

Typing name of disconnected connection after running dbUnloadDriver() crashes R on Windows

Open JoshOBrien opened this issue 8 years ago • 8 comments

On my Windows machine, running the following crashes my R session.

library(RMySQL)
drv <- dbDriver("MySQL")
con <- dbConnect(drv, dbname="butterfly", username="root",
                 password="password", host="localhost",
                 port=3306)
dbDisconnect(con)
dbUnloadDriver(drv)
## Following which this next line crashes my R session
con

It would be nice if RMySQL took the additional steps needed to render con harmless (presumably (?) by adding tests to the appropriate methods for MySQLConnection objects to ensure that they gracefully handle situations in which the driver has been unloaded).

In case it matters: I am R version 3.2.3, RMySQL_0.10.8 DBI_0.3.1, and MySQL Server version 5.7.11-log MySQL Community Server.

JoshOBrien avatar Feb 19 '16 18:02 JoshOBrien

Do you see the problem with the development version of RMySQL?

krlmlr avatar Mar 29 '16 17:03 krlmlr

Just installed the development version, and with it in place, I haven't been able to figure out how to get a connection set up using dbConnect(). The use of dbDriver() (as in my example above) is deprecated, but I don't know what to replace it with.

?dbConnect made me think that this might work, but it doesn't:

con <- dbConnect("RMySQL", dbname="butterfly", username="root",
                  password="password", host="localhost",
                  port=3306)
## Error in (function (classes, fdef, mtable)  : 
##   unable to find an inherited method for function ‘dbConnect’ for signature ‘"character"’

This doesn't work either:

con <- dbConnect(RMySQL::MySQL(), dbname="butterfly", username="root",
                 password="password", host="localhost",
                 port=3306)
## Error in .Call("RMySQL_connection_create", PACKAGE = "RMySQL", host, user,  : 
##   "RMySQL_connection_create" not available for .Call() for package "RMySQL"

I then tried setting up parameters in a .my.cnf file, but nothing seems to work. I've got now clue whether the problem lies in my MySQL, or in my compilation of the development version of RMySQL, or my use of dbConnect, so don't really know how to proceed.

So, in short, I haven't been able to check the issue I reported, 'cause I can't even get a connection set up!

JoshOBrien avatar Mar 29 '16 21:03 JoshOBrien

Could you please retry

devtools::install_github("rstats-db/RMySQL")

and post the output if connection still doesn't work?

krlmlr avatar Mar 29 '16 21:03 krlmlr

Sure. Thanks for your help.

I just did that, and get the same output as before for the two approaches tried above:

con <- dbConnect("RMySQL", ..., 
## Error in (function (classes, fdef, mtable)  : 
##   unable to find an inherited method for function 'dbConnect' for signature '"character"'

con <- dbConnect(RMySQL::MySQL(), ...
## Error in .Call("RMySQL_connection_create", PACKAGE = "RMySQL", host, user,  : 
##   "RMySQL_connection_create" not available for .Call() for package "RMySQL"

In case it's useful, here's my sessionInfo()

R version 3.2.4 Revised (2016-03-16 r70336)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RMySQL_0.11-2

loaded via a namespace (and not attached):
 [1] compiler_3.2.4  httr_1.1.0      R6_2.1.2        DBI_0.3.1.9008 
 [5] tools_3.2.4     withr_1.0.1     curl_0.9.6      Rcpp_0.12.4.1  
 [9] memoise_1.0.0   git2r_0.14.0    digest_0.6.9    devtools_1.10.0

JoshOBrien avatar Mar 29 '16 21:03 JoshOBrien

Could you please post the output of

devtools::install_github("rstats-db/RMySQL")

?

krlmlr avatar Mar 29 '16 21:03 krlmlr

Oh, sure:

> devtools::install_github("rstats-db/RMySQL")
Downloading GitHub repo rstats-db/RMySQL@master
from URL https://api.github.com/repos/rstats-db/RMySQL/zipball/master
Installing RMySQL
Skipping 2 packages ahead of CRAN: DBI, Rcpp
"c:/R/R-current/bin/i386/R" --no-site-file --no-environ --no-save  \
  --no-restore CMD INSTALL  \
  "C:/tmp/Rtmpuu60EL/devtools1e343b53158/rstats-db-RMySQL-cf9be6d"  \
  --library="C:/R/Library" --install-tests 

* installing *source* package 'RMySQL' ...
** libs

*** arch - i386
rm -f RMySQL-init.o
"c:/R/R-CURR~1/bin/i386/Rscript.exe" "../tools/winlibs.R"
gcc -m32 -I"c:/R/R-CURR~1/include" -DNDEBUG -I../windows/libmariadbclient-2.1.0/include   -I"C:/R/Library/Rcpp/include" -I"C:/R/Library/BH/include" -I"d:/RCompile/r-compiling/local/local323/include"     -O3 -Wall  -std=gnu99 -mtune=core2 -c RMySQL-init.c -o RMySQL-init.o
g++ -m32 -shared -s -static-libgcc -o RMySQL.dll tmp.def RMySQL-init.o -L../windows/libmariadbclient-2.1.0/lib/i386 -lmariadbclient -lssl -lcrypto -lgdi32 -lz -lws2_32 -Ld:/RCompile/r-compiling/local/local323/lib/i386 -Ld:/RCompile/r-compiling/local/local323/lib -Lc:/R/R-CURR~1/bin/i386 -lR
installing to C:/R/Library/RMySQL/libs/i386

*** arch - x64
rm -f RMySQL-init.o
"c:/R/R-CURR~1/bin/x64/Rscript.exe" "../tools/winlibs.R"
gcc -m64 -I"c:/R/R-CURR~1/include" -DNDEBUG -I../windows/libmariadbclient-2.1.0/include   -I"C:/R/Library/Rcpp/include" -I"C:/R/Library/BH/include" -I"d:/RCompile/r-compiling/local/local323/include"     -O2 -Wall  -std=gnu99 -mtune=core2 -c RMySQL-init.c -o RMySQL-init.o
g++ -m64 -shared -s -static-libgcc -o RMySQL.dll tmp.def RMySQL-init.o -L../windows/libmariadbclient-2.1.0/lib/x64 -lmariadbclient -lssl -lcrypto -lgdi32 -lz -lws2_32 -Ld:/RCompile/r-compiling/local/local323/lib/x64 -Ld:/RCompile/r-compiling/local/local323/lib -Lc:/R/R-CURR~1/bin/x64 -lR
installing to C:/R/Library/RMySQL/libs/x64
** R
** tests
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
*** arch - x64
* DONE (RMySQL)

JoshOBrien avatar Mar 29 '16 21:03 JoshOBrien

Forgot that RMySQL master currently doesn't install on Windows. Working on it.

krlmlr avatar Mar 29 '16 22:03 krlmlr

Thanks. Would help if I could, and am happy to test whatever fixes you come up with, when you have the time.

JoshOBrien avatar Mar 30 '16 00:03 JoshOBrien