Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

untested encoding stuff

	geändert:   R4CouchDB/R/cdbIni.R
	geändert:   README.md
  • Loading branch information...
commit 24b0f11cb88d9ad417b9025cee0bda57fa510bbf 1 parent 8b6bea9
@wactbprot authored
Showing with 46 additions and 33 deletions.
  1. +41 −29 R4CouchDB/R/cdbIni.R
  2. +5 −4 README.md
View
70 R4CouchDB/R/cdbIni.R
@@ -32,31 +32,33 @@ cdbIni <- function(serverName="localhost",port="5984",dbname=""){
rj <- library(RJSONIO,
logical.return = TRUE,
quietly =TRUE)
-
+
if(rc && rj){
-
+
cdb <- list(
- serverName = serverName,
- port = port,
- prot = "http",
- uname="",
- pwd="",
- curl=getCurlHandle(),
- DBName=dbname,
- newDBName="",
- removeDBName="",
- id="",
- dataList=list(),
- fileName="",
- design="",
- view="",
- list="",
- queryParam="",
- date=toString(Sys.Date()),
- error="",
- res=""
- )
-
+ serverName = serverName,
+ port = port,
+ prot = "http",
+ uname = "",
+ pwd = "",
+ curl = getCurlHandle(),
+ DBName = dbname,
+ newDBName = "",
+ removeDBName = "",
+ id = "",
+ dataList = list(),
+ fileName = "",
+ design = "",
+ view = "",
+ list = "",
+ queryParam = "",
+ date = toString(Sys.Date()),
+ localEnc = unlist(strsplit(Sys.getlocale("LC_CTYPE"),"\\."))[2],
+ serverEnc = "UTF-8",
+ encSub = "?",
+ error = "",
+ res = "")
+
cdb$opts <- function(cdb){
if(cdb$uname == ""){
opts <- curlOptions(header = FALSE)
@@ -81,28 +83,38 @@ cdbIni <- function(serverName="localhost",port="5984",dbname=""){
}
cdb$toJSON <- function(lst){
+ jsn <- toJSON(lst, collapse = "")
+ ## couchdb has a right to get proper
+ ## json. bad requests often came from
+ ## stuff like \xa0\xbc\xed. Here we say
+ ## gtfo and replace it with cdb$encSub
+ jsn <- iconv(jsn,
+ cdb$localEnc,
+ cdb$serverEnc,
+ sub=cdb$encSub)
## one can {"a":"\r"} have in the
## database but one can not send it back
## in this way. A \r is here replaced by \\r
## resulting in \r in the database
- jsn <- toJSON(lst, collapse = "")
+
jsn <- gsub("\\r","\\\\r",jsn)
-
return(jsn)
}
cdb$checkRes <- function(cdb,res){
if(!(cdb$error == "")){
- stop( cdb$error )
+ stop( paste("local error:", cdb$error))
}
res <- cdb$fromJSON(res)
- if(!(length(res$error) > 0)){
+ if(length(res$error) > 0){
+ stop(paste("local error:", cdb$error,
+ "server error:", res$error,
+ "server reason:", res$reason))
+ }else{
cdb$res <- res
return( cdb )
- }else{
- stop(paste(cdb$error, res$error,res$reason))
}
}
View
9 README.md
@@ -51,16 +51,17 @@ provide a CouchDB. There are some examples below the demo folder.
* or make a twitter_db and fill up some search results from the request
http://search.twitter.com/search.json?q=couchdb
- foo$newDBName <- "twitter_db"
+ foo$newDBName <- "japan_db"
foo <- cdbMakeDB(foo)
- u <- "http://search.twitter.com/search.json?q=couchdb"
+ u <- "http://search.twitter.com/search.json?q=japan&rpp=100&page=10"
res <- fromJSON(getURLContent(u))
lapply(res$results,
function(i){
foo$dataList <- i
- cdbAddDoc(foo)})
- foo$res
+ cdbAddDoc(foo)$error
+ })
+
* get angry and write a ticket or mail
## Problems
Please sign in to comment.
Something went wrong with that request. Please try again.