Changeset: ecb75bb3f5fe for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ecb75bb3f5fe
Modified Files:
        clients/R/MonetDB.R/NEWS
        clients/R/MonetDB.R/R/dbi.R
Branch: embedded
Log Message:

R client monetdb.read.csv transactions


diffs (54 lines):

diff --git a/clients/R/MonetDB.R/NEWS b/clients/R/MonetDB.R/NEWS
--- a/clients/R/MonetDB.R/NEWS
+++ b/clients/R/MonetDB.R/NEWS
@@ -18,6 +18,7 @@ 1.0.0
 - dplyr src_monetdb now has a con parameter to pass an existing DBI connection
 - Fixed a bug when running in a non-UTF8 locale (Thanks, Marcis)
 - Fixed a bug when dbWriteTable would not adhere to transactional semantics 
(Thanks, Anthony)
+- Added transactions to monetdb.read.csv so no empty tables are left over 
(Thanks, Anthony)
 
 0.9.7
 - Fixed crash on Windows (Sorry, everyone)
diff --git a/clients/R/MonetDB.R/R/dbi.R b/clients/R/MonetDB.R/R/dbi.R
--- a/clients/R/MonetDB.R/R/dbi.R
+++ b/clients/R/MonetDB.R/R/dbi.R
@@ -470,7 +470,10 @@ setMethod("dbWriteTable", "MonetDBConnec
       }
     }
   }
-  if (transaction) dbCommit(conn)
+  if (transaction) {
+    dbCommit(conn)
+    on.exit(NULL)
+  }
   return(invisible(TRUE))
 })
 
@@ -803,7 +806,9 @@ monet.read.csv <- monetdb.read.csv <- fu
     types <- sapply(headers, function(df) sapply(df, dbDataType, dbObj=conn))
     if(!all(types==types[, 1])) stop("Files have different variable types")
   } 
-  if (create){
+  dbBegin(conn)
+  on.exit(tryCatch(dbRollback(conn), error=function(e){}))
+  if (create) {
   tablename <- quoteIfNeeded(conn, tablename)
     if(lower.case.names) names(headers[[1]]) <- tolower(names(headers[[1]]))
     if(!is.null(col.names)) {
@@ -817,7 +822,7 @@ monet.read.csv <- monetdb.read.csv <- fu
       }
       names(headers[[1]]) <- quoteIfNeeded(conn, col.names)
     }
-    dbWriteTable(conn, tablename, headers[[1]][FALSE, ])
+    dbWriteTable(conn, tablename, headers[[1]][FALSE, ], transaction=F)
   }
   
   delimspec <- paste0("USING DELIMITERS '", delim, "','", newline, "','", 
quote, "'")
@@ -829,5 +834,7 @@ monet.read.csv <- monetdb.read.csv <- fu
       na.strings[1], "'", sep=""), if(locked) "LOCKED"))
   }
   dbGetQuery(conn, paste("SELECT COUNT(*) FROM", tablename))[[1]]
+  dbCommit(conn)
+  on.exit(NULL)
 }
 
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to