Changeset: 115fa9fc1d94 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=115fa9fc1d94
Modified Files:
        ctest/tools/monetdbe/example_proxy.c
        monetdb5/modules/mal/remote.c
        tools/monetdbe/monetdbe.c
Branch: monetdbe-proxy
Log Message:

work in process: more bug fixes.


diffs (245 lines):

diff --git a/ctest/tools/monetdbe/example_proxy.c 
b/ctest/tools/monetdbe/example_proxy.c
--- a/ctest/tools/monetdbe/example_proxy.c
+++ b/ctest/tools/monetdbe/example_proxy.c
@@ -33,6 +33,10 @@ main(void)
        if (monetdbe_open(&mdbe, 
"mapi:monetdb://127.0.0.1:50000?database=devdb", &opt))
                error("Failed to open database")
 
+
+       if ((err = monetdbe_query(mdbe, "DELETE FROM test WHERE x < 0; ", 
&result, NULL)) != NULL)
+               error(err)
+
        if ((err = monetdbe_query(mdbe, "SELECT * FROM test; ", &result, NULL)) 
!= NULL)
                error(err)
 
@@ -100,6 +104,67 @@ main(void)
        if ((err = monetdbe_cleanup_result(mdbe, result)) != NULL)
                error(err)
 
+       if ((err = monetdbe_query(mdbe, "SELECT * FROM test; ", &result, NULL)) 
!= NULL)
+               error(err)
+
+       fprintf(stdout, "Query result with %zu cols and %"PRId64" rows\n", 
result->ncols, result->nrows);
+       for (int64_t r = 0; r < result->nrows; r++) {
+               for (size_t c = 0; c < result->ncols; c++) {
+                       monetdbe_column* rcol;
+                       if ((err = monetdbe_result_fetch(result, &rcol, c)) != 
NULL)
+                               error(err)
+                       switch (rcol->type) {
+                               case monetdbe_int8_t: {
+                                       monetdbe_column_int8_t * col = 
(monetdbe_column_int8_t *) rcol;
+                                       if (col->data[r] == col->null_value) {
+                                               printf("NULL");
+                                       } else {
+                                               printf("%d", col->data[r]);
+                                       }
+                                       break;
+                               }
+                               case monetdbe_int16_t: {
+                                       monetdbe_column_int16_t * col = 
(monetdbe_column_int16_t *) rcol;
+                                       if (col->data[r] == col->null_value) {
+                                               printf("NULL");
+                                       } else {
+                                               printf("%d", col->data[r]);
+                                       }
+                                       break;
+                               }
+                               case monetdbe_int32_t: {
+                                       monetdbe_column_int32_t * col = 
(monetdbe_column_int32_t *) rcol;
+                                       if (col->data[r] == col->null_value) {
+                                               printf("NULL");
+                                       } else {
+                                               printf("%d", col->data[r]);
+                                       }
+                                       break;
+                               }
+                               case monetdbe_str: {
+                                       monetdbe_column_str * col = 
(monetdbe_column_str *) rcol;
+                                       if (col->is_null(&col->data[r])) {
+                                               printf("NULL");
+                                       } else {
+                                               printf("%s", (char*) 
col->data[r]);
+                                       }
+                                       break;
+                               }
+                               default: {
+                                       printf("UNKNOWN");
+                               }
+                       }
+
+                       if (c + 1 < result->ncols) {
+                               printf(", ");
+                       }
+               }
+               printf("\n");
+       }
+
+       if ((err = monetdbe_cleanup_result(mdbe, result)) != NULL)
+               error(err)
+/*
        if ((err = monetdbe_query(mdbe, "INSERT INTO test VALUES (100, 
'temp');", NULL, NULL)) != NULL)
                error(err)
 
@@ -299,7 +364,7 @@ main(void)
 
        if ((err = monetdbe_cleanup_result(mdbe, result)) != NULL)
                error(err)
-
+*/
        if (monetdbe_close(mdbe))
                error("Failed to close database")
        return 0;
diff --git a/monetdb5/modules/mal/remote.c b/monetdb5/modules/mal/remote.c
--- a/monetdb5/modules/mal/remote.c
+++ b/monetdb5/modules/mal/remote.c
@@ -1037,7 +1037,7 @@ static str RMTput(Client cntxt, MalBlkPt
 
                /* call our remote helper to do this more efficiently */
                mnstr_printf(sout,
-                               "%s := remote.batload(:%s, " BUNFMT ");\n",
+                               "%s := remote.batload(nil:%s, " BUNFMT ");\n",
                                ident, tail, (bid == 0 ? 0 : BATcount(b)));
                mnstr_flush(sout, MNSTR_FLUSH_DATA);
                GDKfree(tail);
@@ -1223,12 +1223,12 @@ static str RMTregisterInternal(Client cn
 }
 
 static str RMTregister(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci) {
-       char *fcn_id = *getArgReference_str(stk, pci, 0);
+       char **fcn_id = getArgReference_str(stk, pci, 0);
        const char *conn = *getArgReference_str(stk, pci, 1);
        const char *mod = *getArgReference_str(stk, pci, 2);
        const char *fcn = *getArgReference_str(stk, pci, 3);
        (void)mb;
-       return RMTregisterInternal(cntxt, &fcn_id, conn, mod, fcn);
+       return RMTregisterInternal(cntxt, fcn_id, conn, mod, fcn);
 }
 
 /**
@@ -1250,21 +1250,25 @@ static str RMTexec(Client cntxt, MalBlkP
 
        (void)cntxt;
        (void)mb;
+       bool no_return_arguments = 0;
 
        columnar_result_callback* rcb = NULL;
        ValRecord *v = &(stk)->stk[(pci)->argv[4]];
        if (pci->retc == 1 && (pci->argc >= 4) && (v->vtype == TYPE_ptr) ) {
                rcb = (columnar_result_callback*) v->val.pval;
-               i = 1; //There is only one (void) return argument.
        }
-       else {
-               for (i = 0; i < pci->retc; i++) {
+
+       for (i = 0; i < pci->retc; i++) {
+               if (stk->stk[pci->argv[i]].vtype == TYPE_str) {
                        tmp = *getArgReference_str(stk, pci, i);
                        if (tmp == NULL || strcmp(tmp, (str)str_nil) == 0)
                                throw(ILLARG, "remote.exec", ILLEGAL_ARGUMENT
                                                ": return value %d is NULL or 
nil", i);
                }
+               else
+                       no_return_arguments = 1;
        }
+
        conn = *getArgReference_str(stk, pci, i++);
        if (conn == NULL || strcmp(conn, (str)str_nil) == 0)
                throw(ILLARG, "remote.exec", ILLEGAL_ARGUMENT ": connection 
name is NULL or nil");
@@ -1281,19 +1285,19 @@ static str RMTexec(Client cntxt, MalBlkP
        /* this call should be a single transaction over the channel*/
        MT_lock_set(&c->lock);
 
-       if(!rcb && pci->argc - pci->retc < 3) /* conn, mod, func, ... */
+       if(!no_return_arguments && pci->argc - pci->retc < 3) /* conn, mod, 
func, ... */
                throw(MAL, "remote.exec", ILLEGAL_ARGUMENT  " MAL instruction 
misses arguments");
 
        len = 0;
        /* count how big a buffer we need */
        len += 2 * (pci->retc > 1);
-       if (!rcb)
+       if (!no_return_arguments)
                for (i = 0; i < pci->retc; i++) {
                        len += 2 * (i > 0);
                        len += strlen(*getArgReference_str(stk, pci, i));
                }
 
-       const int arg_index = rcb?4:3;
+       const int arg_index = rcb ? 4 : 3;
 
        len += strlen(mod) + strlen(func) + 6;
        for (i = arg_index; i < pci->argc - pci->retc; i++) {
@@ -1309,7 +1313,7 @@ static str RMTexec(Client cntxt, MalBlkP
 
        if (pci->retc > 1)
                qbuf[len++] = '(';
-       if (!rcb)
+       if (!no_return_arguments)
                for (i = 0; i < pci->retc; i++)
                        len += snprintf(&qbuf[len], buflen - len, "%s%s",
                                        (i > 0 ? ", " : ""), 
*getArgReference_str(stk, pci, i));
@@ -1318,7 +1322,7 @@ static str RMTexec(Client cntxt, MalBlkP
                qbuf[len++] = ')';
 
        /* build the function invocation string in qbuf */
-       if (!rcb && pci->retc > 0) {
+       if (!no_return_arguments && pci->retc > 0) {
                len += snprintf(&qbuf[len], buflen - len, " := %s.%s(", mod, 
func);
        }
        else {
@@ -1648,6 +1652,7 @@ mel_func remote_init_funcs[] = {
  pattern("remote", "exec", RMTexec, false, "remotely executes <mod>.<func> 
using the argument list of remote objects and returns the handle to its 
result", args(1,5, 
arg("",str),arg("conn",str),arg("mod",str),arg("func",str),vararg("",str))),
  pattern("remote", "exec", RMTexec, false, "remotely executes <mod>.<func> 
using the argument list of remote objects and returns the handle to its 
result", args(1,5, 
vararg("",str),arg("conn",str),arg("mod",str),arg("func",str),vararg("",str))),
  pattern("remote", "exec", RMTexec, false, "remotely executes <mod>.<func> 
using the argument list of remote objects and applying function pointer rcb as 
callback to handle any results.", args(0,5, 
arg("conn",str),arg("mod",str),arg("func",str),arg("rcb",ptr), vararg("",str))),
+ pattern("remote", "exec", RMTexec, false, "remotely executes <mod>.<func> 
using the argument list of remote objects and ignoring results.", args(0,4, 
arg("conn",str),arg("mod",str),arg("func",str), vararg("",str))),
  command("remote", "isalive", RMTisalive, false, "check if conn is still valid 
and connected", args(1,2, arg("",int),arg("conn",str))),
  pattern("remote", "batload", RMTbatload, false, "create a BAT of the given 
type and size, and load values from the input stream", args(1,3, 
batargany("",1),argany("tt",1),arg("size",int))),
  pattern("remote", "batbincopy", RMTbincopyto, false, "dump BAT b in binary 
form to the stream", args(1,2, arg("",void),batargany("b",0))),
diff --git a/tools/monetdbe/monetdbe.c b/tools/monetdbe/monetdbe.c
--- a/tools/monetdbe/monetdbe.c
+++ b/tools/monetdbe/monetdbe.c
@@ -1681,9 +1681,10 @@ monetdbe_append(monetdbe_database dbhdl,
                InstrPtr f = getInstrPtr(mb, 0);
                f->retc = f->argc = 0;
                f = pushReturn(mb, f, newTmpVariable(mb, TYPE_int));
-               InstrPtr c = newInstruction(mb, sqlRef, mvcRef);
-               c = pushReturn(mb, c, newTmpVariable(mb, TYPE_int));
-               pushInstruction(mb, c);
+               InstrPtr c = newFcnCall(mb, sqlRef, mvcRef);
+               setArgType(mb, c, 0, TYPE_int);
+
+               int mvc_id = getArg(c, 0);
 
                for (i = 0; i < column_count; i++) {
 
@@ -1713,22 +1714,26 @@ monetdbe_append(monetdbe_database dbhdl,
                        int idx = newTmpVariable(mb, 
newBatType(tpe->localtype));
                        f = pushArgument(mb, f, idx);
 
-                       InstrPtr a = newInstruction(mb, sqlRef, appendRef);
-                       setDestVar(a, newTmpVariable(mb, TYPE_any));
-                       a = pushArgument(mb, a, getArg(c, 0));
+                       InstrPtr a = newFcnCall(mb, sqlRef, appendRef);
+                       setArgType(mb, a, 0, TYPE_int);
+                       a = pushArgument(mb, a, mvc_id);
                        a = pushStr(mb, a, schema);
                        a = pushStr(mb, a, table);
                        a = pushStr(mb, a, actual_column_names[i]);
                        a = pushArgument(mb, a, idx);
-                       pushInstruction(mb, a);
+
+                       mvc_id = getArg(a, 0);
                }
 
                InstrPtr r = newInstruction(mb, NULL, NULL);
                r->barrier= RETURNsymbol;
                r->retc = r->argc = 0;
-               r = pushReturn(mb, r, getArg(c, 0));
+               r = pushReturn(mb, r, mvc_id);
+               r = pushArgument(mb, r, mvc_id);
                pushInstruction(mb, r);
 
+               pushEndInstruction(mb);
+
                if ( (mdbe->msg = chkProgram(mdbe->c->usermodule, mb)) != 
MAL_SUCCEED ) {
                        return mdbe->msg;
                }
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to