Skip to content

Commit

Permalink
Address import step in Windows 10 failing - MonetDB#34
Browse files Browse the repository at this point in the history
  • Loading branch information
zeyus authored Mar 23, 2021
1 parent 1fbcfb8 commit 5ec80d4
Showing 1 changed file with 58 additions and 54 deletions.
112 changes: 58 additions & 54 deletions R/embedded.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,60 +43,64 @@ monetdb_embedded_startup <- function(dir=":memory:", quiet=TRUE, sequential=TRUE
}

monetdb_embedded_query <- function(conn, query, execute=TRUE, resultconvert=TRUE, int64=FALSE) {
if (!inherits(conn, classname)) {
stop("Invalid connection")
}
query <- as.character(query)
if (length(query) != 1) {
stop("Need a single query as parameter.")
}
if (!monetdb_embedded_env$is_started) {
stop("Call monetdb_embedded_startup() first")
}
if (monetdb_embedded_env$started_dir != ":memory:" && !dir.exists(file.path(monetdb_embedded_env$started_dir, "bat"))) {
stop("Someone killed all the BATs! Call Brigitte Bardot!")
}
execute <- as.logical(execute)
if (length(execute) != 1) {
stop("Need a single execute flag as parameter.")
}
resultconvert <- as.logical(resultconvert)
if (length(resultconvert) != 1) {
stop("Need a single resultconvert flag as parameter.")
}
int64 <- as.logical(int64)
if (length(resultconvert) != 1) {
stop("Need a single int64 flag as parameter.")
}
if (int64 && !requireNamespace("bit64", quietly = TRUE)) {
stop("Need bit64 package for integer64 support")
}

# make sure the query is terminated
query <- paste(query, "\n;", sep="")
res <- .Call(monetdb_query_R, conn, query, execute, resultconvert, interactive() && getOption("monetdb.progress", FALSE), int64)
resp <- list()
if (is.character(res)) { # error
resp$type <- "!" # MSG_MESSAGE
resp$message <- gsub("\n", " ", res, fixed=TRUE)
}
if (is.numeric(res)) { # no result set, but successful
resp$type <- 2 # Q_UPDATE
resp$rows <- res
}
if (is.list(res)) {
resp$type <- 1 # Q_TABLE
if ("__prepare" %in% names(attributes(res))) {
resp$type <- Q_PREPARE
resp$prepare = attr(res, "__prepare")
attr(res, "__prepare") <- NULL
}
attr(res, "row.names") <- c(NA_integer_, as.integer(-1 * attr(res, "__rows")))
class(res) <- "data.frame"
names(res) <- gsub("\\", "", names(res), fixed=T)
resp$tuples <- res
}
resp
print('My function')
if (!inherits(conn, MonetDBLite:::classname)) {
stop("Invalid connection")
}
query <- as.character(query)
if (length(query) != 1) {
stop("Need a single query as parameter.")
}
if (!MonetDBLite:::monetdb_embedded_env$is_started) {
stop("Call monetdb_embedded_startup() first")
}
if (MonetDBLite:::monetdb_embedded_env$started_dir != ":memory:" &&
!dir.exists(file.path(MonetDBLite:::monetdb_embedded_env$started_dir, "bat"))) {
stop("Someone killed all the BATs! Call Brigitte Bardot!")
}
execute <- as.logical(execute)
if (length(execute) != 1) {
stop("Need a single execute flag as parameter.")
}
resultconvert <- as.logical(resultconvert)
if (length(resultconvert) != 1) {
stop("Need a single resultconvert flag as parameter.")
}
int64 <- as.logical(int64)
if (length(resultconvert) != 1) {
stop("Need a single int64 flag as parameter.")
}
if (int64 && !requireNamespace("bit64", quietly = TRUE)) {
stop("Need bit64 package for integer64 support")
}

# make sure the query is terminated
query <- paste(query, "\n;", sep="")
res <- .Call(MonetDBLite:::monetdb_query_R, conn, query, execute, resultconvert, interactive() &&
getOption("monetdb.progress", FALSE), int64)
resp <- list()
if (is.character(res)) { # error
resp$type <- "!" # MSG_MESSAGE
res <- iconv(res, to = 'UTF-8')
resp$message <- gsub("\n", " ", res, fixed=TRUE)
}
if (is.numeric(res)) { # no result set, but successful
resp$type <- 2 # Q_UPDATE
resp$rows <- res
}
if (is.list(res)) {
resp$type <- 1 # Q_TABLE
if ("__prepare" %in% names(attributes(res))) {
resp$type <- Q_PREPARE
resp$prepare = attr(res, "__prepare")
attr(res, "__prepare") <- NULL
}
attr(res, "row.names") <- c(NA_integer_, as.integer(-1 * attr(res, "__rows")))
class(res) <- "data.frame"
names(res) <- gsub("\\", "", names(res), fixed=T)
resp$tuples <- res
}
resp
}

monetdb_embedded_append <- function(conn, table, tdata, schema="sys") {
Expand Down

0 comments on commit 5ec80d4

Please # to comment.