Skip to content

Commit

Permalink
cdbRemoveDB() now should look on the existing DBs
Browse files Browse the repository at this point in the history
        modified:   R4CouchDB/R/cdbIni.R
        modified:   R4CouchDB/R/cdbListDB.R
        modified:   R4CouchDB/R/cdbRemoveDB.R
  • Loading branch information
wactbprot committed Sep 21, 2009
1 parent e6fd29c commit 4e44d9d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 26 deletions.
1 change: 1 addition & 0 deletions R4CouchDB/R/cdbIni.R
Expand Up @@ -11,6 +11,7 @@ cdbIni <- function(){
port = "5984",
DBName="",
newDBName="",
removeDBName="",
id="",
rev="",
dataList=list(),
Expand Down
22 changes: 11 additions & 11 deletions R4CouchDB/R/cdbListDB.R
@@ -1,17 +1,17 @@
cdbListDB <- function(cdb){

if(cdb$serverName == ""){
cdb$error <- paste(cdb$error," no cdb$serverName given")
}
if(cdb$error == ""){
adrString <- paste("http://",
cdb$serverName,":",
cdb$port, "/_all_dbs",
sep="")
cdb$error <- paste(cdb$error," no cdb$serverName given")
}
if(cdb$error == ""){
adrString <- paste("http://",
cdb$serverName,":",
cdb$port, "/_all_dbs",
sep="")

res <- getURL(adrString)
cdb$res <- fromJSON(res)
return( cdb )
res <- getURL(adrString)
cdb$res <- fromJSON(res)
return( cdb )
}else{
print(cdb$error)
return( cdb )
Expand Down
50 changes: 35 additions & 15 deletions R4CouchDB/R/cdbRemoveDB.R
@@ -1,25 +1,45 @@
cdbRemoveDB <- function(cdb){

if(cdb$serverName == ""){
cdb$error <- paste(cdb$error," no cdb$serverName given")
}

if(cdb$removeDBName == ""){
cdb$error <- paste(cdb$error, "no cdb$removeDBName given")
}else{

DBNames <- cdbListDB(cdb)$res
DBexists <- which(DBNames == cdb$removeDBName)

if(length(DBexists) == 0){

cdb$error <- paste(cdb$error,
" there is no cdb$removeDBName to delete")

}
}

if( cdb$error == ""){

if(cdb$DBName == ""){
adrString <- paste("http://",
cdb$serverName,":",
cdb$port,"/",
cdb$removeDBName,
sep="")

cdb$error <- "no cdb$DBName to remove"
return(cdb)
}else{
res <- getURLContent(adrString,
.opts = list(customrequest = "DELETE")
)

adrString <- paste("http://",
cdb$serverName,":",
cdb$port,"/",
cdb$DBName,
sep="")
cdb$res <- fromJSON(res)

res <- getURLContent(adrString, .opts = list(customrequest = "DELETE"))
cdb$res <- fromJSON(res)
cdb$DBName <- ""
## the DB should be history
cdb$removeDBName <- ""
return( cdb )

}

}else{
return(cdb)
}
print(cdb$error)
return(cdb)
}
}

0 comments on commit 4e44d9d

Please sign in to comment.