Changeset: ecabe46a4ec9 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ecabe46a4ec9
Modified Files:
        sql/backends/monet5/sql.c
        tools/embedded/embedded.c
        tools/reverserapi/R/monetdb.R
Branch: embedded
Log Message:

Inverse RAPI: It works!


diffs (89 lines):

diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -3143,6 +3143,9 @@ mvc_scalar_value_wrap(Client cntxt, MalB
        if ((msg = checkSQLContext(cntxt)) != NULL)
                return msg;
        b = cntxt->sqlcontext;
+       if (b->output_format == OFMT_NONE) {
+               return MAL_SUCCEED;
+       }
        if (ATOMextern(mtype))
                p = *(ptr *) p;
        if (b->out == NULL || mvc_export_value(b, b->out, 1, *tn, *cn, *type, 
*digits, *scale, *eclass, p, mtype, "", "NULL") != SQL_OK)
diff --git a/tools/embedded/embedded.c b/tools/embedded/embedded.c
--- a/tools/embedded/embedded.c
+++ b/tools/embedded/embedded.c
@@ -144,14 +144,16 @@ void monetdb_cleanup_result(void* output
 SEXP monetdb_query_R(SEXP query) {
        SEXP retlist = R_NilValue;
        res_table* output = monetdb_query((char*)CHAR(STRING_ELT(query, 0)));
-       SEXP varvalue = R_NilValue;
+       SEXP names, varvalue = R_NilValue;
        if (output && output->nr_cols > 0) {
                int i;
                retlist = PROTECT(allocVector(VECSXP, output->nr_cols));
+               names = PROTECT(NEW_STRING(output->nr_cols));
 
                for (i = 0; i < output->nr_cols; i++) {
                        res_col col = output->cols[i];
                        BAT* b = BATdescriptor(col.b);
+                       SET_STRING_ELT(names, i, mkCharCE(output->cols[i].name, 
CE_UTF8));
 
                        switch (ATOMstorage(getColumnType(b->T->type))) {
                                case TYPE_bte:
@@ -190,14 +192,14 @@ SEXP monetdb_query_R(SEXP query) {
                                default:
                                        // no clue what type to consider
                                        fprintf(stderr, "unknown argument 
type");
-                                       // TODO: cleanup result set
                                        return NULL;
                        }
 
                        SET_VECTOR_ELT(retlist, i, varvalue);
-                       // TODO: create a separate names vector and set names 
(names in cols struct)
                }
-               UNPROTECT(output->nr_cols + 1);
+               SET_NAMES(retlist, names);
+               UNPROTECT(output->nr_cols + 2);
+
                monetdb_cleanup_result(output);
        }
        return retlist;
diff --git a/tools/reverserapi/R/monetdb.R b/tools/reverserapi/R/monetdb.R
--- a/tools/reverserapi/R/monetdb.R
+++ b/tools/reverserapi/R/monetdb.R
@@ -1,13 +1,29 @@
 monetdb_startup <- function(dir=tempdir()) {
-       invisible(.Call("monetdb_startup_R", as.character(dir), 
PACKAGE="MonetDB"))
+       dir <- as.character(dir)
+       if (length(dir) != 1) {
+               stop("Need a single directory name as parameter.")
+       }
+       if (!dir.exists(dir) && !dir.create(dir, recursive=T)) {
+               stop("Cannot create ", dir)
+       }
+       if (file.access(dir, mode=2) < 0) {
+               stop("Cannot write to ", dir)
+       }
+       invisible(.Call("monetdb_startup_R", dir , PACKAGE="MonetDB"))
 }
 
 monetdb_query <- function(query) {
-       res <- .Call("monetdb_query_R", as.character(query), PACKAGE="MonetDB")
+       query <- as.character(query)
+       if (length(query) != 1) {
+               stop("Need a single query as parameter.")
+       }
+       # make sure the query is terminated
+       query <- paste(query, "\n;", sep="")
+       res <- .Call("monetdb_query_R", query, PACKAGE="MonetDB")
        if (is.null(res)) {
                return(invisible(FALSE))
        }
        else {
-               return(res)
+               return(as.data.frame(res, stringsAsFactors=F))
        }
 }
\ No newline at end of file
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to