R RODBC sqlSave crashing/disconnecting when too many columns supplied to existing table

落花浮王杯 提交于 2019-12-24 02:58:07

问题


I've found a situation where R hangs due to sqlSave not handling cases where the are more columns being inserted than are present in the table.

Does anyone have any insight on how I can resolve this behaviour? I had the idea of retrieving the number of columns already in the table but this would be a siginificant performance drain and add significant complexity to the code.



The error (reproduction will require a dsn/database connection locally)

 channel <- odbcConnect("mydb")
  odbcClearError(channel)
sqlSave(channel, dat=data.frame(a=1:3,b=letters[1:3]),
               tablename="R_update_test",
              # rownames=FALSE,
               append=TRUE)
  odbcClose(channel)

Or

channel <- odbcConnect("mydb")
  odbcClearError(channel)
sqlSave(channel, dat=data.frame(a=1:3,b=letters[1:3],c=letters[1:3])]),
               tablename="R_update_test",
               rownames=FALSE,
               append=TRUE)
  odbcClose(channel)

sessionInfo included below, and target db is mysql 5.6

> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C         LC_TIME=C            LC_COLLATE=C         LC_MONETARY=C        LC_MESSAGES=C       
 [7] LC_PAPER=C           LC_NAME=C            LC_ADDRESS=C         LC_TELEPHONE=C       LC_MEASUREMENT=C     LC_IDENTIFICATION=C 

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

other attached packages:
 [1] data.table_1.8.10 Hmisc_3.13-0      Formula_1.1-1     survival_2.37-4   caret_5.17-7      reshape2_1.2.2    plyr_1.8         
 [8] lattice_0.20-24   foreach_1.4.1     cluster_1.14.4    RODBC_1.3-9       Nemo_1.0          testthat_0.7.1    devtools_1.4     

loaded via a namespace (and not attached):
 [1] MASS_7.3-29        RColorBrewer_1.0-5 RCurl_1.95-4.1     codetools_0.2-8    colorspace_1.2-4   dichromat_2.0-0    digest_0.6.3      
 [8] evaluate_0.5.1     ggplot2_0.9.3.1    gtable_0.1.2       httr_0.2           iterators_1.0.6    labeling_0.2       memoise_0.1       
[15] munsell_0.4.2      parallel_3.0.2     proto_0.3-10       scales_0.2.3       stringr_0.6.2      tools_3.0.2        whisker_0.3-2   

来源:https://stackoverflow.com/questions/20215213/r-rodbc-sqlsave-crashing-disconnecting-when-too-many-columns-supplied-to-existin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!