rodbc

RODBC command 'sqlQuery' has problems with table variables in t-SQL

我的梦境 提交于 2019-12-01 06:28:41
I am using the RODBC package which I am applying on a Microsoft SQL Server 2012. Now I have discovered a phenomenon that puzzles me. If I run the following query with the RODBC command sqlQuery, then, in R, I will get back an empty data frame with the columns Country, CID, PriceID and WindID. DECLARE @tbl_IDs TABLE ( Country nvarchar(30), CID nvarchar(5), PriceID int, WindID int ) SELECT * FROM @tbl_Ids So far, everything is fine. However, if I try to write a record to the table variable and execute DECLARE @tbl_IDs TABLE ( Country nvarchar(30), CID nvarchar(5), PriceID int, WindID int )

Show all open RODBC connections

半城伤御伤魂 提交于 2019-12-01 01:20:25
Does anyone know how to do this? showConnections won't list any open connections from odbcConnect. You can narrow down your search in the following way, which will return all variables of your environment currently of the class RODBC. envVariables<-ls() bools<-sapply(envVariables, function(string){ class(get(string))=="RODBC" }) rodbcObj<-envVariables[bools] Closed connections are still of the class RODBC though, so there is still a little work to be done here. We can define a function, using trycatch, that will try to get the connection info of the associated RODBC object. If it is an open

Connect R and Teradata using JDBC

空扰寡人 提交于 2019-11-30 23:03:11
I´m trying to connect R and Teradata using RJDBC. I´ve found this link that has an example using mysql, but i´m nos sure how to do the same with teradata. library(RJDBC) drv <- JDBC("com.mysql.jdbc.Driver", "/etc/jdbc/mysql-connector-java-3.1.14-bin.jar", identifier.quote="`") conn <- dbConnect(drv, "jdbc:mysql://localhost/test", "user", "pwd") I´ve downloaded this driver: http://downloads.teradata.com/download/connectivity/jdbc-driver But i´m not sure where i should reference the directory. I know there is a teradataR package out there , but i don´t know if it really works with the R 3.0.0.

RODBC: chars and numerics converted aggressively (with/without as.is)

柔情痞子 提交于 2019-11-30 20:58:21
Related to https://stackoverflow.com/a/33284035/3358272 , I'm finding inconsistent behavior with pulling data from SQL Server (2014). library(RODBC) sqlQuery(.conn, "CREATE TABLE r2test ( [mychar] [NVARCHAR](16), [mynum] [FLOAT])") # character(0) sqlQuery(.conn, "INSERT INTO r2test (mychar,mynum) VALUES ('1',3.141593),('2',6.283185)") character(0) str(sqlQuery(.conn, "SELECT * FROM r2test", stringsAsFactors = FALSE)) # 'data.frame': 2 obs. of 2 variables: # $ mychar: int 1 2 # $ mynum : num 3.14 6.28 In that example we see the undesired behavior: the characters of mychar are being internally

Connect R and Teradata using JDBC

痴心易碎 提交于 2019-11-30 18:29:46
问题 I´m trying to connect R and Teradata using RJDBC. I´ve found this link that has an example using mysql, but i´m nos sure how to do the same with teradata. library(RJDBC) drv <- JDBC("com.mysql.jdbc.Driver", "/etc/jdbc/mysql-connector-java-3.1.14-bin.jar", identifier.quote="`") conn <- dbConnect(drv, "jdbc:mysql://localhost/test", "user", "pwd") I´ve downloaded this driver: http://downloads.teradata.com/download/connectivity/jdbc-driver But i´m not sure where i should reference the directory.

How to pass data.frame for UPDATE with R DBI

非 Y 不嫁゛ 提交于 2019-11-30 07:19:10
With RODBC , there were functions like sqlUpdate(channel, dat, ...) that allowed you pass dat = data.frame(...) instead of having to construct your own SQL string. However, with R's DBI , all I see are functions like dbSendQuery(conn, statement, ...) which only take a string statement and gives no opportunity to specify a data.frame directly. So how to UPDATE using a data.frame with DBI? Really late, my answer, but maybe still helpful... There is no single function (I know) in the DBI/odbc package but you can replicate the update behavior using a prepared update statement (which should work

RODBC sqlSave table creation problems

六月ゝ 毕业季﹏ 提交于 2019-11-30 06:59:36
问题 I'm having trouble creating a table using RODBC's sqlSave (or, more accurately, writing data to the created table). This is different than the existing sqlSave question/answers, as the problems they were experiencing were different, I can create tables whereas they could not and I've already unsuccesfully incorporated their solutions, such as closing and reopening the connection before running sqlSave, also The error message is different, with the only exception being a post that was

Can I gracefully include formatted SQL strings in an R script?

限于喜欢 提交于 2019-11-30 06:33:07
问题 I'm working in an R script that uses a long SQL string, and I would like to keep the query relatively free of other markup so as to allow copying and pasting between editors and applications. I'd also like the ability to split the query across lines for better readability. In the RODBC documentation, the paste function is used to build the query out of separate chunks, but I'd prefer something less kludgy and with fewer quotes and commas. Thanks for your help. 回答1: you can override the %+%

RODBC: chars and numerics converted aggressively (with/without as.is)

泄露秘密 提交于 2019-11-30 05:28:29
问题 Related to https://stackoverflow.com/a/33284035/3358272, I'm finding inconsistent behavior with pulling data from SQL Server (2014). library(RODBC) sqlQuery(.conn, "CREATE TABLE r2test ( [mychar] [NVARCHAR](16), [mynum] [FLOAT])") # character(0) sqlQuery(.conn, "INSERT INTO r2test (mychar,mynum) VALUES ('1',3.141593),('2',6.283185)") character(0) str(sqlQuery(.conn, "SELECT * FROM r2test", stringsAsFactors = FALSE)) # 'data.frame': 2 obs. of 2 variables: # $ mychar: int 1 2 # $ mynum : num 3

Export data frame to SQL server using RODBC package

风格不统一 提交于 2019-11-29 23:09:13
问题 I am using RODBC package in R to import / export data frames from SQL Server database. While there is no problem in importing. I dont know how to export the contents of a data frame into an existing SQL table. I am trying to use sqlQuery() function available in the package, but I am not sure how to insert multiple records in the table. A sample on how to insert the rows will be helpful I have ensured that columns of my table and data frame are same. 回答1: Use sqlSave with append property. See