[Rodbcext-commits] r9 - in pkg/rodbcExt: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Mar 3 04:51:51 CET 2009


Author: jaunario
Date: 2009-03-03 04:51:51 +0100 (Tue, 03 Mar 2009)
New Revision: 9

Modified:
   pkg/rodbcExt/R/closeExt.R
   pkg/rodbcExt/R/connectExt.R
   pkg/rodbcExt/man/closeExt.Rd
   pkg/rodbcExt/man/connectExt.Rd
Log:
Added drvConnect for connecting without creating DSN. disconnect checks if object is RODBC class instead of atomic or list.

Modified: pkg/rodbcExt/R/closeExt.R
===================================================================
--- pkg/rodbcExt/R/closeExt.R	2009-02-26 03:27:08 UTC (rev 8)
+++ pkg/rodbcExt/R/closeExt.R	2009-03-03 03:51:51 UTC (rev 9)
@@ -3,13 +3,13 @@
 # Version 0.1.1  
 # License GPL3
 
-cleanDisconnect <- function(channel, rmv=T, env=.GlobalEnv){
+disconnect <- function(channel, clean=T, env=.GlobalEnv){
     odbcClose(channel)
-    if (rmv){
+    if (clean){
         objs <- ls(envir=env)
         for (obj in objs){            
             cobj <- get(obj, envir=env)
-            if(is.atomic(cobj)|is.list(cobj) ){
+            if(class(cobj)=="RODBC"){
                 if (cobj==channel){
                     rm(list=obj, envir=env)
                 }

Modified: pkg/rodbcExt/R/connectExt.R
===================================================================
--- pkg/rodbcExt/R/connectExt.R	2009-02-26 03:27:08 UTC (rev 8)
+++ pkg/rodbcExt/R/connectExt.R	2009-03-03 03:51:51 UTC (rev 9)
@@ -3,13 +3,13 @@
 # Version 0.1.1  
 # License GPL3
 
-dsnConnect <- function(dsn, retries=3){
+dsnConnect <- function(dsn, retries=3, ...){
     cnt <- 0
     repeat {
 		cnt<-cnt+1
-		db <- odbcConnect(dsn)
-		if (db!=-1){
-		    return(db)
+		con <- odbcConnect(dsn, ...)
+		if (con!=-1){
+		    return(con)
 			break
 		}
 		else if (cnt > retries) {
@@ -17,7 +17,27 @@
 			return(NULL)
 			stop();
 		}
-		rm(db)
+		rm(con)
 		cat("Retrying to connect. (retries=",retries,") \n", sep="")
 	}    
 }
+
+drvConnect <- function(drvname, server, db, usr, pwd, opt=27, retries=3, ...){
+    cstring <- paste("DRIVER={",drvname,"};SERVER=",server,";DATABASE=",db,";USER=",usr,";PASSWORD=",pwd,";OPTION=",opt,";", sep="")
+    cnt <- 0
+    repeat {
+		cnt<-cnt+1
+		con <- odbcDriverConnect(cstring, ...)
+		if (con!=-1){
+		    return(con)
+			break
+		}
+		else if (cnt > retries) {
+			cat("Unable to connect to database on ",server,". \n", sep="")
+			return(NULL)
+			stop();
+		}
+		rm(con)
+		cat("Retrying to connect. (retries=",retries,") \n", sep="")
+	}
+}

Modified: pkg/rodbcExt/man/closeExt.Rd
===================================================================
--- pkg/rodbcExt/man/closeExt.Rd	2009-02-26 03:27:08 UTC (rev 8)
+++ pkg/rodbcExt/man/closeExt.Rd	2009-03-03 03:51:51 UTC (rev 9)
@@ -1,17 +1,18 @@
 \name{closeExt}
-\alias{cleanDisconnect}
+\alias{disconnect}
 %- Also NEED an '\alias' for EACH other topic documented here.
 \title{ Closing Connections in rodbcExt }
 \description{
   Closes a databases connection and then removes the object from memory. 
 }
 \usage{
-cleanDisconnect(channel, rmv=T)
+disconnect(channel, clean=T, env=.GlobalEnv)
 }
 %- maybe also 'usage' for other objects documented here.
 \arguments{
   \item{channel}{ ~~Describe \code{yields} here~~ }
-  \item{rmv}{ ~~Describe \code{fact} here~~ }
+  \item{clean}{ ~~Describe \code{fact} here~~ }
+  \item{env}{ ~~Describe \code{fact} here~~ }
 }
 \details{
   ~~ If necessary, more details than the description above ~~

Modified: pkg/rodbcExt/man/connectExt.Rd
===================================================================
--- pkg/rodbcExt/man/connectExt.Rd	2009-02-26 03:27:08 UTC (rev 8)
+++ pkg/rodbcExt/man/connectExt.Rd	2009-03-03 03:51:51 UTC (rev 9)
@@ -1,17 +1,27 @@
 \name{connectExt}
 \alias{dsnConnect}
+\alias{drvConnect}
 %- Also NEED an '\alias' for EACH other topic documented here.
 \title{ Connecting to Databases in rodbcExt }
 \description{
   Functions for connecting to databases with automatic retry capability
 }
 \usage{
-dsnConnect(dsn, retries=3)
+dsnConnect(dsn, retries=3, ...)
+drvConnect(drvname, server, db, usr, pwd, opt=27, retries=3, ...)
 }
 %- maybe also 'usage' for other objects documented here.
 \arguments{
   \item{dsn}{ ~~Describe \code{yields} here~~ }
+  \item{drvname}{ ~~Describe \code{fact} here~~ }
+  \item{server}{ ~~Describe \code{fact} here~~ }
+  \item{db}{ ~~Describe \code{fact} here~~ }
+  \item{usr}{ ~~Describe \code{fact} here~~ }
+  \item{pwd}{ ~~Describe \code{fact} here~~ }
+  \item{opt}{ ~~Describe \code{fact} here~~ }
   \item{retries}{ ~~Describe \code{fact} here~~ }
+  \item{...}{ ~~Describe \code{fact} here~~ }
+  
 }
 \details{
   ~~ If necessary, more details than the description above ~~



More information about the Rodbcext-commits mailing list