rodbc

Installation of RODBC on OS X Yosemite

百般思念 提交于 2019-11-27 21:29:34
When installing the R package RODBC in RStudio on OS X Yosemite, I get the following error: configure: error: "ODBC headers sql.h and sqlext.h not found" This is a common error and indicates that ODBC drivers haven't been installed (iODBC headers aren't included in OS 10.9 hence the separate install required). So, I install unixODBC and confirm that the header files are present in the PATH. Sys.getenv("PATH") gives me the correct path including where the two files are found. However, when I try install.packages("RODBC",type = "source") again, the same error persists. Have tested this with

How to insert a dataframe into a SQL Server table?

冷暖自知 提交于 2019-11-27 19:48:18
I'm trying to upload a dataframe to a SQL Server table, I tried breaking it down to a simple SQL query string.. library(RODBC) con <- odbcDriverConnect("driver=SQL Server; server=database") df <- data.frame(a=1:10, b=10:1, c=11:20) values <- paste("(",df$a,",", df$b,",",df$c,")", sep="", collapse=",") cmd <- paste("insert into MyTable values ", values) result <- sqlQuery(con, cmd, as.is=TRUE) ..which seems to work but does not scale very well. Is there an easier way? [edited] Perhaps pasting the names(df) would solve the scaling problem: values <- paste( " df[ , c(", paste( names(df),collapse=

RODBC queries returning zero rows

依然范特西╮ 提交于 2019-11-27 19:46:53
Issue: RODBC (falsely) returning zero rows Situation: I'm using RODBC to connect to a DSN I created using a commercial DB's ODBC driver (OSI Soft's PI Historian Time Series DB, if you're curious). > library(RODBC) > piconn <- odbcConnect("PIRV", uid = "pidemo") > sqlStr <- "SELECT tag, time, status, value FROM piinterp WHERE tag = 'PW1.PLANT1.PRODUCTION_RATE' and time > DATE('-4h') and timestep = '+2m'" Now if I query, I get zero rows. > sqlQuery(piconn, sqlStr) [1] TAG TIME STATUS VALUE <0 rows> (or 0-length row.names) With BelieveNRows = FALSE these all still show zero results, even though

Connect R and Vertica using RODBC

邮差的信 提交于 2019-11-27 19:21:12
问题 This is my first time connecting to Vertica. I have already connected to a MySQL database sucessfully by using RODBC library. I have the database setup in vertica and I installed the windows 64-bit ODBC driver from https://my.vertica.com/download-community-edition/ When I tried to connect to vertica using R, I get the below error: channel = odbcDriverConnect(connection = "Server=myserver.edu;Database=mydb;User=mydb;Password=password") Warning messages: 1: In odbcDriverConnect(connection =

Failure to connect to odbc database in R

佐手、 提交于 2019-11-27 15:29:06
I've been trying to connect my company's DMS to R using the odbcConnect command, but get the following message: myConn <-odbcConnect("NZSQL", uid="cejacobson", pwd="password") Warning messages: 1: In odbcDriverConnect("DSN=NZSQL;UID=cejacobson;PWD=password") : [RODBC] ERROR: state IM002, code 0, message [unixODBC][Driver Manager]Data source name not found, and no default driver specified 2: In odbcDriverConnect("DSN=NZSQL;UID=cejacobson;PWD=password") : ODBC connection failed The thing is, I'm positive the Data source name is NZSQL and my uid and password are correct as well. Any insight as to

RODBC loses time values of datetime when result set is large

烂漫一生 提交于 2019-11-27 13:56:55
问题 So this is VERY strange. RODBC seems to drop the time portion of DateTime SQL columns if the result set is large enough. (The queries are running against an SQL Server 2012 machine, and, yes, when I run them on the SQL Server side they produce identical and proper results, regardless of how many rows are returned.) For example, the following works perfectly: myconn <- odbcConnect(dsnName, uid, pwd) results <- sqlQuery(myconn, "SELECT TOP 100 MyID, MyDateTimeColumn from MyTable ORDER BY

RODBC Temporary Table Issue when connecting to MS SQL Server

耗尽温柔 提交于 2019-11-27 13:38:04
I am running R on unix and I am using the RODBC package to connect to MS SQL server. I can execute a query that returns results fine with the package, but if I use a temporary table somewhere in my SQL query, an empty string is returned to me. After looking over the web, I think the problem might be that the RODBC package was written assuming an end-user was writing in standard SQL (as opposed to MS SQL). I have provided the below code as an example. Interestingly enough, the temporary table problem does not exist if I use the RJDBC package. However, the RJDBC package is painfully slow with

SQL Server RODBC Connection

孤街醉人 提交于 2019-11-26 23:55:54
Does anyone have a connection string example for using RODBC and connecting to MS SQL Server 2005 or 2008. Thank you. Henrico library(RODBC) dbhandle <- odbcDriverConnect('driver={SQL Server};server=mysqlhost;database=mydbname;trusted_connection=true') res <- sqlQuery(dbhandle, 'select * from information_schema.tables') 42- Taken from a posting to r-help : library(RODBC) channel <- odbcDriverConnect("driver=SQL Server;server=01wh155073") initdata<- sqlQuery(channel,paste("select * from test_DB .. test_vikrant")) dim(initdata) odbcClose(channel) Try to use RSQLS package: https://github.com

Dynamic “string” in R

牧云@^-^@ 提交于 2019-11-26 23:18:15
Simple question, but cannot find the answer. Instead of: Df <- sqlQuery(ch, "SELECT * FROM tblTest WHERE Id=25") I want a more dynamic piece of code. Something like: Id <- 25 Df <- sqlQuery(ch, c("SELECT * FROM tblTest WHERE Id=", Id)) But this is not correct. Joshua Ulrich We can use paste: Df <- sqlQuery(ch, paste("SELECT * FROM tblTest WHERE Id =", Id)) c concatenates into a vector, paste is for string concatenation. Or we can use sprintf: sprintf("SELECT * FROM tblTest WHERE Id = %s", Id) If you have multiple or reused arguments and a query that contains % you can use something like the

Installation of RODBC on OS X Yosemite

天大地大妈咪最大 提交于 2019-11-26 23:05:10
问题 When installing the R package RODBC in RStudio on OS X Yosemite, I get the following error: configure: error: "ODBC headers sql.h and sqlext.h not found" This is a common error and indicates that ODBC drivers haven't been installed (iODBC headers aren't included in OS 10.9 hence the separate install required). So, I install unixODBC and confirm that the header files are present in the PATH. Sys.getenv("PATH") gives me the correct path including where the two files are found. However, when I