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

R connector: now handling ctrl-c during query execution


diffs (110 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
@@ -13,6 +13,7 @@ 1.0.0
 - Fix for dbConnect() that should be more robust to invalid connections
 - Cleaned up quoting behavior in dbListTables(), dbRemoveTable() etc.
 - Initial support for running MonetDB in embedded mode (MonetDBLite)
+- Now re-establishing connection if interrupt (CMD-C or ESC) occurs
 
 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
@@ -123,28 +123,27 @@ setMethod("dbConnect", "MonetDBDriver", 
   }
   
   # make new socket with user-specified timeout
-  socket <- .mapiConnect(host, port, timeout) 
-  .mapiAuthenticate(socket, dbname, user, password, language=language)
+
   connenv <- new.env(parent=emptyenv())
   connenv$lock <- 0
   connenv$deferred <- list()
   connenv$exception <- list()
+  connenv$params <- list(host=host, port=port, timeout=timeout, dbname=dbname, 
user=user, password=password, language=language)
+  connenv$socket <- .mapiConnect(host, port, timeout) 
+  .mapiAuthenticate(connenv$socket, dbname, user, password, language=language)
   
-  conn <- new("MonetDBConnection", socket=socket, connenv=connenv)
+  conn <- new("MonetDBConnection", connenv=connenv)
   if (getOption("monetdb.sequential", F)) {
     message("MonetDB: Switching to single-threaded query execution.")
     dbSendQuery(conn, "set optimizer='sequential_pipe'")
   }
-
-  # if (getOption("monetdb.profile", T)) .profiler_enable(conn)
   conn
 }, 
 valueClass="MonetDBConnection")
 
 
 ### MonetDBConnection
-setClass("MonetDBConnection", representation("DBIConnection", socket="ANY", 
-                                             connenv="environment"))
+setClass("MonetDBConnection", representation("DBIConnection", 
connenv="environment"))
 
 setClass("MonetDBEmbeddedConnection", representation("MonetDBConnection", 
connenv="environment"))
 
@@ -162,7 +161,7 @@ setMethod("dbIsValid", "MonetDBConnectio
 })
 
 setMethod("dbDisconnect", "MonetDBConnection", def=function(conn, ...) {
-  .mapiDisconnect(conn@socket)
+  .mapiDisconnect(conn@connenv$socket)
   invisible(TRUE)
 })
 
@@ -247,8 +246,25 @@ setMethod("dbSendQuery", signature(conn=
   # if (getOption("monetdb.profile", T))  .profiler_arm()
 
   # the actual request
-  mresp <- .mapiRequest(conn, paste0("s", statement, "\n;"), async=async)
-  resp <- .mapiParseResponse(mresp)
+  resp <- NA
+  tryCatch({
+    mresp <- .mapiRequest(conn, paste0("s", statement, "\n;"), async=async)
+    resp <- .mapiParseResponse(mresp)
+  }, interrupt = function(ex) {
+    message("Interrupted query execution. Attempting to fix connection....")
+    
+    conn@connenv$params[[1]] <- NULL
+    conn@connenv$params$drv <- MonetDB.R()
+    
+    newconn <- do.call("dbConnect", conn@connenv$params)
+    dbDisconnect(conn)
+    conn@connenv$socket <- newconn@connenv$socket
+    conn@connenv$lock <- 0
+    conn@connenv$deferred <- list()
+    conn@connenv$exception <- list()
+
+    stop("No query result for now.")
+  })
 
   env <- new.env(parent=emptyenv())
 
diff --git a/clients/R/MonetDB.R/R/mapi.R b/clients/R/MonetDB.R/R/mapi.R
--- a/clients/R/MonetDB.R/R/mapi.R
+++ b/clients/R/MonetDB.R/R/mapi.R
@@ -61,16 +61,16 @@ REPLY_SIZE    <- 100 # Apparently, -1 me
   
   # send payload and read response             
  
-  .mapiWrite(conObj@socket, msg)
-  resp <- .mapiRead(conObj@socket)
+  .mapiWrite(conObj@connenv$socket, msg)
+  resp <- .mapiRead(conObj@connenv$socket)
   
   # get deferred statements from deferred list and execute
   while (length(conObj@connenv$deferred) > 0) {
     # take element, execute, check response for prompt
     dmesg <- conObj@connenv$deferred[[1]]
     conObj@connenv$deferred[[1]] <- NULL
-    .mapiWrite(conObj@socket, dmesg)
-    dresp <- .mapiParseResponse(.mapiRead(conObj@socket))
+    .mapiWrite(conObj@connenv$socket, dmesg)
+    dresp <- .mapiParseResponse(.mapiRead(conObj@connenv$socket))
     if (dresp$type == MSG_MESSAGE) {
       conObj@connenv$lock <- 0
       warning(paste("II: Failed to execute deferred statement '", dmesg, "'. 
Server said: '", 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to