odbc icon indicating copy to clipboard operation
odbc copied to clipboard

Crash when querying non-existent table

Open jwhendy opened this issue 2 years ago • 4 comments

Issue Description and Expected Result

I think this is essentially #386, but the solution there was a higher odbc version (1.2.2 -> 1.2.3, but I'm on 1.3.3). I kept getting RStudio crashes when trying to query an MS SQL database, finally figuring out I'd remembered the name of the db incorrectly.

Database

It's an Azure hosted Microsoft SQL databse.

Reproducible Example

I can't share the real example, and took some time to try and find a public SQL db for testing purposes, but 10min of googling just pointed me to websites oriented toward query training, or databases one can unpack locally. I'm too busy for that right now. Hopefully someone can reproduce on their own db.

library(odbc)
library(DBI)

conn <- DBI::dbConnect(
  odbc::odbc(),
  Driver='{ODBC Driver 17 for SQL Server}',
  Server='server, 1433',
  Database='database',
  uid='uid',
  pwd='pwd',
  encrypt='yes')

dbGetQuery(conn, "SELECT * from DoesntExist")

That crashes RStudio as well as my R terminal.

> sessionInfo()
R version 4.2.0 (2022-04-22 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

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

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

other attached packages:
[1] odbc_1.3.3    ggplot2_3.3.6 dplyr_1.0.9   DBI_1.1.2    

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.8.3     rstudioapi_0.13  magrittr_2.0.3   hms_1.1.1        munsell_0.5.0    tidyselect_1.1.2
 [7] bit_4.0.4        colorspace_2.0-3 R6_2.5.1         rlang_1.0.2      fansi_1.0.3      blob_1.2.3      
[13] tools_4.2.0      grid_4.2.0       gtable_0.3.0     utf8_1.2.2       cli_3.3.0        withr_2.5.0     
[19] ellipsis_0.3.2   bit64_4.0.5      assertthat_0.2.1 tibble_3.1.7     lifecycle_1.0.1  crayon_1.5.1    
[25] purrr_0.3.4      vctrs_0.4.1      glue_1.6.2       compiler_4.2.0   pillar_1.7.0     scales_1.2.0    
[31] generics_0.1.2   pkgconfig_2.0.3 

Thanks for taking a look.

jwhendy avatar May 05 '22 23:05 jwhendy

I've been having this same issue with Postgres and SQL server connections. Anytime an invalid query is sent to the database it terminates the R session and closes the project. E.g. If I forget to unlist a character vector and try to pass it to a query or reference a non-existent table.

PJDuszynski avatar Jun 02 '22 14:06 PJDuszynski

#bump. Anyone able to take a look at this? It really stinks to have waited for a bunch of queries and preprocessing to run, then to have the session completely crash due to a typo and have to start over :(

jwhendy avatar Aug 11 '22 01:08 jwhendy

We had this exact same problem with odbc 1.3.3. Our organisation is currently locked into an older version of R (3.6.3) on Windows and it came down to if we installed the odbc package from the win binary which had been compiled at R 4.2 we had the problem, but if installed odbc 1.3.3 from source then no problem - i.e. get errors, not R crashes querying non-existent tables.

tomwilsonsco avatar Sep 23 '22 07:09 tomwilsonsco

I do have the same issue. By choosing a different R Version this issue does not occoure any more.

Working Version: R 4.0.1 odbc 1.3.3

Not Working Versions: R 4.1.1 or R 4.1.2 odbc 1.3.3

My system: sysname "Linux" release "5.3.18-150300.59.90-default" version "#1 SMP Tue Aug 9 08:49:53 UTC 2022 (127973b)" machine "x86_64" ODBC: unixODBC 2.3.9

R-Michael avatar Sep 27 '22 11:09 R-Michael

I had the same issue. After quite a lot of time debugging, I updated the dependencies of odbc: i.e. "rlang", "vctrs", "Rcpp" and "cli". And this has fixed the issue.

I'm going to guess that it was Rcpp not being up to date that was causing R to have a conniption

> sessionInfo()
R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.utf8  LC_CTYPE=English_Australia.utf8    LC_MONETARY=English_Australia.utf8
[4] LC_NUMERIC=C                       LC_TIME=English_Australia.utf8    

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

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.11      rstudioapi_0.14  magrittr_2.0.3   usethis_2.1.6    hms_1.1.3        odbc_1.3.5      
 [7] tidyselect_1.2.0 bit_4.0.5        R6_2.5.1         rlang_1.1.1      fansi_0.4.2      stringr_1.5.0   
[13] blob_1.2.4       dplyr_1.1.2      tools_4.2.2      srcutils_0.1.9   utf8_1.2.1       cli_3.6.1       
[19] DBI_1.1.3        bit64_4.0.5      tibble_3.2.1     lifecycle_1.0.3  brio_1.1.3       purrr_1.0.1     
[25] vctrs_0.6.3      fs_1.5.2         testthat_3.1.6   glue_1.6.2       stringi_1.7.12   compiler_4.2.2  
[31] pillar_1.9.0     generics_0.1.3   testdat_0.4.1    pkgconfig_2.0.3 

paddytobias avatar Jul 10 '23 23:07 paddytobias

I'm not able to reproduce on R 4.3.1 + odbc 1.4.1. As a more recent commenter found that updating package dependencies did the trick, I'm going to go ahead and close.

simonpcouch avatar Jan 17 '24 18:01 simonpcouch