Changeset: a1b1f2cc4ab3 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a1b1f2cc4ab3 Added Files: clients/nodejs/monetdb/README clients/nodejs/monetdb/mapiclient.js clients/nodejs/monetdb/package.json sql/test/BugTracker-2014/Tests/queueError.Bug-3604.sql sql/test/BugTracker-2014/Tests/queueError.Bug-3604.stable.err sql/test/BugTracker-2014/Tests/queueError.Bug-3604.stable.out Removed Files: clients/R/MonetDB.R/src/Makevars.win clients/R/MonetDB.R/src/mapi.c Modified Files: clients/R/MonetDB.R/NEWS clients/R/MonetDB.R/R/dbi.R clients/R/MonetDB.R/R/mapi.R clients/R/Tests/dbi.R clients/R/Tests/dbi.stable.out clients/R/Tests/dplyr.R clients/R/Tests/survey.R clients/Tests/MAL-signatures_all.stable.out clients/Tests/MAL-signatures_fits_geom.stable.out clients/Tests/MAL-signatures_geom.stable.out clients/Tests/MAL-signatures_none.stable.out clients/Tests/exports.stable.out gdk/gdk_firstn.c monetdb5/extras/rdf/rdf.h monetdb5/mal/mal_interpreter.c monetdb5/mal/mal_linker.c monetdb5/mal/mal_linker.h monetdb5/mal/mal_private.h monetdb5/modules/atoms/mtime.c monetdb5/modules/atoms/mtime.h monetdb5/modules/kernel/bat5.mal monetdb5/modules/kernel/batstr.c monetdb5/modules/kernel/counters.c monetdb5/modules/kernel/counters.mal monetdb5/modules/mal/Tests/inspect05.stable.out monetdb5/modules/mal/Tests/pqueue.stable.out monetdb5/modules/mal/Tests/pqueue2.stable.out monetdb5/modules/mal/batExtensions.c monetdb5/modules/mal/batExtensions.h monetdb5/modules/mal/batcalc.c monetdb5/modules/mal/factories.c monetdb5/modules/mal/factories.h monetdb5/modules/mal/inspect.h monetdb5/modules/mal/language.c monetdb5/modules/mal/language.h monetdb5/modules/mal/mal_mapi.c monetdb5/modules/mal/mal_mapi.h monetdb5/modules/mal/mat.c monetdb5/modules/mal/mat.h monetdb5/modules/mal/mdb.c monetdb5/modules/mal/mdb.h monetdb5/modules/mal/pcre.c monetdb5/modules/mal/pcre.mal monetdb5/modules/mal/profiler.c monetdb5/modules/mal/profiler.h monetdb5/modules/mal/transaction.c monetdb5/optimizer/opt_mergetable.c monetdb5/tests/gdkTests/Tests/All monetdb5/tests/gdkTests/Tests/firstn.stable.out sql/backends/monet5/bam/bam_db_interface.h sql/backends/monet5/rest/rest_jsonstore_handle_get.h sql/backends/monet5/sql.h sql/backends/monet5/sql.mal sql/backends/monet5/sql_cast.c sql/backends/monet5/sql_gencode.h sql/backends/monet5/sql_result.c sql/backends/monet5/sql_scenario.c sql/backends/monet5/sql_scenario.h sql/backends/monet5/sql_statistics.c sql/backends/monet5/vaults/fits.c sql/test/BugTracker-2014/Tests/All sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out sql/test/testdb-upgrade/Tests/upgrade.stable.out testing/malcheck.py Branch: Oct2014 Log Message:
merge diffs (truncated from 3893 to 300 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 @@ -1,3 +1,7 @@ +0.9.6 +- Fixed non-ASCII character handling (thanks, Roman!) +- Fully removed C-based socket code + 0.9.5 - Removed package date (Thanks, Dimitar) - Added sys. schema name to internal queries, so SET SCHEMA xx would not break things (Thanks again, Dimitar) 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 @@ -1,12 +1,6 @@ +# C library that contains our MAPI string splitting state machine C_LIBRARY <- "MonetDB.R" -.onLoad <- function(lib, pkg) { - if (getOption("monetdb.clib", FALSE)) { - library.dynam( C_LIBRARY, pkg, lib ) - .Call("mapiInit", PACKAGE=C_LIBRARY) - } -} - # Make S4 aware of S3 classes setOldClass(c("sockconn", "connection", "monetdb_mapi_conn")) @@ -234,6 +228,8 @@ setMethod("dbSendQuery", signature(conn= } conn@connenv$exception <- list() env <- NULL + # Auto-convert? + # statement <- enc2utf8(statement) if (getOption("monetdb.debug.query", F)) message("QQ: '", statement, "'") resp <- .mapiParseResponse(.mapiRequest(conn, paste0("s", statement, ";"), async=async)) @@ -539,8 +535,10 @@ setMethod("dbFetch", signature(res="Mone col <- ct[[j]] if (col == .CT_NUM) df[[j]] <- as.numeric(parts[[j]]) - if (col == .CT_CHRR) + if (col == .CT_CHRR) { df[[j]] <- parts[[j]] + Encoding(df[[j]]) <- "UTF-8" + } if (col == .CT_BOOL) df[[j]] <- parts[[j]]=="true" if (col == .CT_CHR) { 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 @@ -1,6 +1,5 @@ # MAPI implementation for R -PROTOCOL_v8 <- 8 PROTOCOL_v9 <- 9 MAX_PACKET_SIZE <- 8192 @@ -86,20 +85,11 @@ REPLY_SIZE <- 100 # Apparently, -1 me .mapiConnect <- function(host, port, timeout) { - if (getOption("monetdb.clib", FALSE)) { - return(.Call("mapiConnect", host, port, timeout, PACKAGE=C_LIBRARY)) - } else { - return(socketConnection(host = host, port = port, blocking = TRUE, open="r+b", timeout = timeout)) - } + socketConnection(host = host, port = port, blocking = TRUE, open="r+b", timeout = timeout) } .mapiDisconnect <- function(socket) { - if (getOption("monetdb.clib", FALSE)) { - .Call("mapiDisconnect", socket, PACKAGE=C_LIBRARY) - } else { - # close, don't care about the errors... - tryCatch(close(socket), error=function(e){}, warning=function(w){}) - } + tryCatch(close(socket), error=function(e){}, warning=function(w){}) } .mapiCleanup <- function(conObj) { @@ -110,69 +100,48 @@ REPLY_SIZE <- 100 # Apparently, -1 me } .mapiRead <- function(con) { - if (getOption("monetdb.clib", FALSE)) { - if (!identical(class(con)[[1]], "externalptr")) - stop("I can only be called with a MonetDB connection object as parameter.") - respstr <- .Call("mapiRead", con, PACKAGE=C_LIBRARY) - if (getOption("monetdb.debug.mapi", F)) { - dstr <- respstr - if (nchar(dstr) > 300) { - dstr <- paste0(substring(dstr, 1, 200), "...", substring(dstr, nchar(dstr)-100, nchar(dstr))) - } - message("RX: '", dstr, "'") + if (!identical(class(con)[[1]], "sockconn")) + stop("I can only be called with a MonetDB connection object as parameter.") + resp <- list() + repeat { + unpacked <- readBin(con, "integer", n=1, size=2, signed=FALSE, endian="little") + + if (length(unpacked) == 0) { + stop("Empty response from MonetDB server, probably a timeout. You can increase the time to wait for responses with the 'timeout' parameter to 'dbConnect()'.") } - return(respstr) - } else { - # R implementation - if (!identical(class(con)[[1]], "sockconn")) - stop("I can only be called with a MonetDB connection object as parameter.") - resp <- list() - repeat { - unpacked <- readBin(con,"integer",n=1,size=2,signed=FALSE,endian="little") - - if (length(unpacked) == 0) { - stop("Empty response from MonetDB server, probably a timeout. You can increase the time to wait for responses with the 'timeout' parameter to 'dbConnect()'.") - } - - length <- bitwShiftR(unpacked,1) - final <- bitwAnd(unpacked,1) - - if (length == 0) break - resp <- c(resp,readChar(con, length, useBytes = TRUE)) - if (final == 1) break - } - if (getOption("monetdb.debug.mapi", F)) cat(paste("RX: '",substring(paste0(resp,collapse=""),1,200),"'\n",sep="")) - return(paste0("",resp,collapse="")) + + length <- bitwShiftR(unpacked, 1) + final <- bitwAnd(unpacked, 1) + + if (length == 0) break + # no raw handling here (see .mapiWrite), since server tells us the length in bytes already + resp <- c(resp, readChar(con, length, useBytes = TRUE)) + if (final == 1) break } + if (getOption("monetdb.debug.mapi", F)) cat(paste("RX: '", substring(paste0(resp, collapse=""), 1, 200), "'\n", sep="")) + return(paste0("", resp, collapse="")) } .mapiWrite <- function(con, msg) { - if (getOption("monetdb.clib", FALSE)) { - # C implementation - if (!identical(class(con)[[1]], "externalptr")) - stop("I can only be called with a MonetDB connection object as parameter.") - - if (getOption("monetdb.debug.mapi", F)) message("TX: '", msg, "'") - .Call("mapiWrite", con, msg, PACKAGE=C_LIBRARY) - - } else { - # R implementation - if (!identical(class(con)[[1]], "sockconn")) - stop("I can only be called with a MonetDB connection object as parameter.") - final <- FALSE - pos <- 0 - if (getOption("monetdb.debug.mapi", F)) message("TX: '",msg,"'\n",sep="") - while (!final) { - req <- substring(msg,pos+1,min(MAX_PACKET_SIZE, nchar(msg))+pos) - bytes <- nchar(req) - pos <- pos + bytes - final <- max(nchar(msg) - pos,0) == 0 - header <- as.integer(bitwOr(bitwShiftL(bytes,1),as.numeric(final))) - writeBin(header, con, 2,endian="little") - writeChar(req,con,bytes,useBytes=TRUE,eos=NULL) - } - flush(con) + # R implementation + if (!identical(class(con)[[1]], "sockconn")) + stop("I can only be called with a MonetDB connection object as parameter.") + final <- FALSE + pos <- 0 + if (getOption("monetdb.debug.mapi", F)) message("TX: '", msg, "'\n", sep="") + # convert to raw byte array, otherwise multibyte characters are 'difficult' + msgr <- charToRaw(msg) + msglen <- length(msgr) + while (!final) { + bytes <- min(MAX_PACKET_SIZE, msglen - pos) + reqr <- msgr[(pos + 1) : (pos + bytes)] + pos <- pos + bytes + final <- max(msglen - pos, 0) == 0 + header <- as.integer(bitwOr(bitwShiftL(bytes, 1), as.numeric(final))) + writeBin(header, con, 2, endian="little") + writeBin(reqr, con, endian="little") } + flush(con) return(NULL) } @@ -262,14 +231,12 @@ REPLY_SIZE <- 100 # Apparently, -1 me # no need to check the returned values, as there is none. If we get no error, all is well. return(env) } - } } .mapiParseHeader <- function(line, stupidInverseColsRows=FALSE) { - tableinfo <- strsplit(line, " ", fixed=TRUE, useBytes=TRUE) - tableinfo <- tableinfo[[1]] - + tableinfo <- strsplit(line, " ", fixed=TRUE, useBytes=TRUE)[[1]] + id <- as.numeric(tableinfo[2]) if (!stupidInverseColsRows) { rows <- as.numeric(tableinfo[3]) @@ -368,8 +335,7 @@ REPLY_SIZE <- 100 # Apparently, -1 me .monetdbd.command <- function(passphrase, host="localhost", port=50000L, timeout=86400L) { socket <- .mapiConnect(host, port, timeout) .mapiAuthenticate(socket, "merovingian", "monetdb", passphrase, language="control") - .mapiWrite(socket, "#all status\n") - ret <- .mapiRead(socket) + ret <- .mapiRequest(socket, "#all status\n") .mapiDisconnect(socket) return (ret) } diff --git a/clients/R/MonetDB.R/src/Makevars.win b/clients/R/MonetDB.R/src/Makevars.win deleted file mode 100644 --- a/clients/R/MonetDB.R/src/Makevars.win +++ /dev/null @@ -1,1 +0,0 @@ -PKG_LIBS= -lws2_32 \ No newline at end of file diff --git a/clients/R/MonetDB.R/src/mapi.c b/clients/R/MonetDB.R/src/mapi.c deleted file mode 100644 --- a/clients/R/MonetDB.R/src/mapi.c +++ /dev/null @@ -1,348 +0,0 @@ -/* - * The contents of this file are subject to the MonetDB Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.monetdb.org/Legal/MonetDBLicense - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * The Original Code is the MonetDB Database System. - * - * The Initial Developer of the Original Code is CWI. - * Portions created by CWI are Copyright (C) 1997-July 2008 CWI. - * Copyright August 2008-2014 MonetDB B.V. - * All Rights Reserved. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <sys/types.h> -#ifdef __WIN32__ -#include <winsock2.h> -#include <ws2tcpip.h> -#undef ERROR -#else -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> -#endif -#include <assert.h> -#include <fcntl.h> -#include <errno.h> - -#ifndef SOCKET_ERROR -#define INVALID_SOCKET -1 -#define SOCKET_ERROR -1 -#endif - -// R headers -#include <R.h> -#include <Rdefines.h> - -#define BLOCKSIZE 8190 -#define BUFSIZE BLOCKSIZE+1 -#define SOCKET int -#define TRUE 1 -#define FALSE 0 -#define ALLOCSIZE 1048576 // 1 MB -#define DEBUG FALSE - -// reference tricks taken from http://homepage.stat.uiowa.edu/~luke/R/simpleref.html#NWarqU3-KrSQa-1 -static SEXP MAPI_type_tag; - -#define CHECK_MAPI_SOCK(s) do { \ - if (TYPEOF(s) != EXTPTRSXP || \ - R_ExternalPtrTag(s) != MAPI_type_tag || \ - EXTPTR_PTR(s) == NULL) \ - error("Socket was either not successfully connected or is already closed. Either way, it cannot be used."); \ -} while (0) - -SEXP mapiInit(void) { - MAPI_type_tag = install("MAPI_TYPE_TAG"); -#ifdef __WIN32__ - // I will not even TRY to understand why this is required - WSADATA wsaData; - int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); - if (iResult != 0) { - error("WSAStartup failed: %d", iResult); - } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list