Changeset: d5762f64b943 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d5762f64b943
Modified Files:
        ctest/tools/embedded/example1.c
        ctest/tools/embedded/example2.c
        ctest/tools/embedded/example_append.c
        ctest/tools/embedded/example_blob.c
        ctest/tools/embedded/example_connections.c
        ctest/tools/embedded/example_decimals.c
        ctest/tools/embedded/example_temporal.c
        ctest/tools/embedded/mapi.c
        tools/embedded/monetdb_embedded.c
        tools/embedded/monetdb_embedded.h
Branch: default
Log Message:

small api change, ie monetdb_result_fetch no longer needs the monetdb_database 
object (only the result set)


diffs (257 lines):

diff --git a/ctest/tools/embedded/example1.c b/ctest/tools/embedded/example1.c
--- a/ctest/tools/embedded/example1.c
+++ b/ctest/tools/embedded/example1.c
@@ -34,7 +34,7 @@ main(void)
        for (int64_t r = 0; r < result->nrows; r++) {
                for (size_t c = 0; c < result->ncols; c++) {
                        monetdb_column* rcol;
-                       if ((err = monetdb_result_fetch(mdbe, result, &rcol, 
c)) != NULL)
+                       if ((err = monetdb_result_fetch(result, &rcol, c)) != 
NULL)
                                error(err)
                        switch (rcol->type) {
                                case monetdb_int32_t: {
diff --git a/ctest/tools/embedded/example2.c b/ctest/tools/embedded/example2.c
--- a/ctest/tools/embedded/example2.c
+++ b/ctest/tools/embedded/example2.c
@@ -40,7 +40,7 @@ main(void)
        for (int64_t r = 0; r < result->nrows; r++) {
                for (size_t c = 0; c < result->ncols; c++) {
                        monetdb_column* rcol;
-                       if ((err = monetdb_result_fetch(mdbe, result, &rcol, 
c)) != NULL)
+                       if ((err = monetdb_result_fetch(result, &rcol, c)) != 
NULL)
                                error(err)
                        switch (rcol->type) {
                                case monetdb_bool: {
@@ -148,7 +148,7 @@ main(void)
                /* fetching the meta data should work */
                for (size_t c = 0; c < result->ncols; c++) {
                        monetdb_column* rcol;
-                       if ((err = monetdb_result_fetch(mdbe, result, &rcol, 
c)) != NULL)
+                       if ((err = monetdb_result_fetch(result, &rcol, c)) != 
NULL)
                                error(err)
                }
        }
diff --git a/ctest/tools/embedded/example_append.c 
b/ctest/tools/embedded/example_append.c
--- a/ctest/tools/embedded/example_append.c
+++ b/ctest/tools/embedded/example_append.c
@@ -34,7 +34,7 @@ main(void)
        monetdb_column* rcol[2];
        for (int64_t r = 0; r < result->nrows; r++) {
                for (size_t c = 0; c < result->ncols; c++) {
-                       if ((err = monetdb_result_fetch(mdbe, result, rcol+c, 
c)) != NULL)
+                       if ((err = monetdb_result_fetch(result, rcol+c, c)) != 
NULL)
                                error(err)
                        switch (rcol[c]->type) {
                                case monetdb_int32_t: {
@@ -77,7 +77,7 @@ main(void)
        fprintf(stdout, "Query result after append 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++) {
-                       if ((err = monetdb_result_fetch(mdbe, result, rcol+c, 
c)) != NULL)
+                       if ((err = monetdb_result_fetch(result, rcol+c, c)) != 
NULL)
                                error(err)
                        switch (rcol[c]->type) {
                                case monetdb_int32_t: {
diff --git a/ctest/tools/embedded/example_blob.c 
b/ctest/tools/embedded/example_blob.c
--- a/ctest/tools/embedded/example_blob.c
+++ b/ctest/tools/embedded/example_blob.c
@@ -36,7 +36,7 @@ main(void)
        for (int64_t r = 0; r < result->nrows; r++) {
                for (size_t c = 0; c < result->ncols; c++) {
                        monetdb_column* rcol;
-                       if ((err = monetdb_result_fetch(mdbe, result, &rcol, 
c)) != NULL)
+                       if ((err = monetdb_result_fetch(result, &rcol, c)) != 
NULL)
                                error(err)
                        switch (rcol->type) {
                                case monetdb_blob: {
diff --git a/ctest/tools/embedded/example_connections.c 
b/ctest/tools/embedded/example_connections.c
--- a/ctest/tools/embedded/example_connections.c
+++ b/ctest/tools/embedded/example_connections.c
@@ -36,7 +36,7 @@ main(void)
        for (int64_t r = 0; r < result->nrows; r++) {
                for (size_t c = 0; c < result->ncols; c++) {
                        monetdb_column* rcol;
-                       if ((err = monetdb_result_fetch(mdbe1, result, &rcol, 
c)) != NULL)
+                       if ((err = monetdb_result_fetch(result, &rcol, c)) != 
NULL)
                                error(err)
                        switch (rcol->type) {
                                case monetdb_int32_t: {
diff --git a/ctest/tools/embedded/example_decimals.c 
b/ctest/tools/embedded/example_decimals.c
--- a/ctest/tools/embedded/example_decimals.c
+++ b/ctest/tools/embedded/example_decimals.c
@@ -34,7 +34,7 @@ main(void)
        for (int64_t r = 0; r < result->nrows; r++) {
                for (size_t c = 0; c < result->ncols; c++) {
                        monetdb_column* rcol;
-                       if ((err = monetdb_result_fetch(mdbe, result, &rcol, 
c)) != NULL)
+                       if ((err = monetdb_result_fetch(result, &rcol, c)) != 
NULL)
                                error(err)
                        switch (rcol->type) {
                                case monetdb_bool: {
diff --git a/ctest/tools/embedded/example_temporal.c 
b/ctest/tools/embedded/example_temporal.c
--- a/ctest/tools/embedded/example_temporal.c
+++ b/ctest/tools/embedded/example_temporal.c
@@ -37,7 +37,7 @@ main(void)
        for (int64_t r = 0; r < result->nrows; r++) {
                for (size_t c = 0; c < result->ncols; c++) {
                        monetdb_column* rcol;
-                       if ((err = monetdb_result_fetch(mdbe, result, &rcol, 
c)) != NULL)
+                       if ((err = monetdb_result_fetch(result, &rcol, c)) != 
NULL)
                                error(err)
                        switch (rcol->type) {
                                case monetdb_int32_t: {
diff --git a/ctest/tools/embedded/mapi.c b/ctest/tools/embedded/mapi.c
--- a/ctest/tools/embedded/mapi.c
+++ b/ctest/tools/embedded/mapi.c
@@ -70,7 +70,7 @@ mapi_fetch_field(MapiHdl hdl, int fnr)
 {
        if (hdl && fnr < (int)hdl->result->ncols && hdl->current_row > 0 && 
hdl->current_row <= hdl->result->nrows) {
                monetdb_column *rcol = NULL;
-               if (monetdb_result_fetch(hdl->mid->mdbe, hdl->result,  &rcol, 
fnr) == NULL) {
+               if (monetdb_result_fetch(hdl->result,  &rcol, fnr) == NULL) {
                        size_t r = hdl->current_row - 1;
                        if (rcol->type != monetdb_str && !hdl->mapi_row[fnr]) {
                                hdl->mapi_row[fnr] = 
MAPIalloc(SIMPLE_TYPE_SIZE);
@@ -163,7 +163,7 @@ mapi_get_type(MapiHdl hdl, int fnr)
 {
        if (hdl && fnr < (int)hdl->result->ncols) {
                monetdb_column *rcol = NULL;
-               if (monetdb_result_fetch(hdl->mid->mdbe, hdl->result,  &rcol, 
fnr) == NULL) {
+               if (monetdb_result_fetch(hdl->result,  &rcol, fnr) == NULL) {
                        switch(rcol->type) {
                        case monetdb_bool:
                                return "boolean";
diff --git a/tools/embedded/monetdb_embedded.c 
b/tools/embedded/monetdb_embedded.c
--- a/tools/embedded/monetdb_embedded.c
+++ b/tools/embedded/monetdb_embedded.c
@@ -87,6 +87,7 @@ typedef struct {
        int type;
        res_table *monetdb_resultset;
        monetdb_column **converted_columns;
+       monetdb_database dbhdl;
 } monetdb_result_internal;
 
 typedef struct {
@@ -94,7 +95,7 @@ typedef struct {
        ValRecord *data;
        ValPtr *args;   /* only used during calls */
        int retc;
-       Client c;
+       monetdb_database dbhdl;
        cq *q;
 } monetdb_stmt_internal;
 
@@ -183,6 +184,7 @@ monetdb_cleanup_result_internal(monetdb_
 
        mvc* m = NULL;
 
+       assert(!res->dbhdl || res->dbhdl == dbhdl);
        if ((msg = validate_database_handle(dbhdl, 
"embedded.monetdb_cleanup_result_internal")) != MAL_SUCCEED)
                return msg;
        if ((msg = getSQLContext(c, NULL, &m, NULL)) != MAL_SUCCEED)
@@ -321,6 +323,7 @@ monetdb_query_internal(monetdb_database 
                        }
                        res_internal->monetdb_resultset = m->results;
                        res_internal->converted_columns = 
GDKzalloc(sizeof(monetdb_column*) * res_internal->res.ncols);
+                       res_internal->dbhdl = dbhdl;
                        if (!res_internal->converted_columns) {
                                msg = createException(MAL, 
"embedded.monetdb_query_internal", MAL_MALLOC_FAIL);
                                goto cleanup;
@@ -650,7 +653,7 @@ monetdb_prepare(monetdb_database dbhdl, 
                if (q && stmt_internal) {
                        Symbol s = (Symbol)q->code;
                        InstrPtr p = s->def->stmt[0];
-                       stmt_internal->c = db;
+                       stmt_internal->dbhdl = db;
                        stmt_internal->q = q;
                        stmt_internal->retc = p->retc;
                        stmt_internal->res.nparam = q->paramlen;
@@ -696,7 +699,9 @@ monetdb_execute(monetdb_statement *stmt,
 {
        monetdb_result_internal *res_internal = NULL;
        monetdb_stmt_internal *stmt_internal = (monetdb_stmt_internal*)stmt;
-       mvc *m = ((backend *) stmt_internal->c->sqlcontext)->mvc;
+       monetdb_database dbhdl = stmt_internal->dbhdl;
+       Client c = (Client)dbhdl;
+       mvc *m = ((backend *) c->sqlcontext)->mvc;
        cq *q = stmt_internal->q;
        str msg = MAL_SUCCEED;
 
@@ -710,7 +715,7 @@ monetdb_execute(monetdb_statement *stmt,
        }
        MalStkPtr glb = (MalStkPtr) (q->stk);
        Symbol s = (Symbol)q->code;
-       msg = callMAL(stmt_internal->c, s->def, &glb, stmt_internal->args, 0);
+       msg = callMAL(c, s->def, &glb, stmt_internal->args, 0);
 
        if (!m->results && m->rowcnt >= 0 && affected_rows)
                *affected_rows = m->rowcnt;
@@ -738,6 +743,7 @@ monetdb_execute(monetdb_statement *stmt,
                        }
                        res_internal->monetdb_resultset = m->results;
                        res_internal->converted_columns = 
GDKzalloc(sizeof(monetdb_column*) * res_internal->res.ncols);
+                       res_internal->dbhdl = dbhdl;
                        if (!res_internal->converted_columns) {
                                msg = createException(MAL, 
"embedded.monetdb_query_internal", MAL_MALLOC_FAIL);
                                goto cleanup;
@@ -746,7 +752,7 @@ monetdb_execute(monetdb_statement *stmt,
                }
        }
 cleanup:
-       return commit_action(m, msg, (monetdb_database)stmt_internal->c, 
result, res_internal);
+       return commit_action(m, msg, dbhdl, result, res_internal);
 }
 
 char*
@@ -754,15 +760,18 @@ monetdb_cleanup_statement(monetdb_databa
 {
        (void)dbhdl;
        monetdb_stmt_internal *stmt_internal = (monetdb_stmt_internal*)stmt;
-       mvc *m = ((backend *) stmt_internal->c->sqlcontext)->mvc;
+       Client c = (Client)dbhdl;
+       mvc *m = ((backend *) c->sqlcontext)->mvc;
        cq *q = stmt_internal->q;
 
+       assert(!stmt_internal->dbhdl || dbhdl == stmt_internal->dbhdl);
        GDKfree(stmt_internal->data);
        GDKfree(stmt_internal->args);
        GDKfree(stmt_internal->res.type);
        GDKfree(stmt_internal);
 
-       qc_delete(m->qc, q);
+       if (q)
+               qc_delete(m->qc, q);
        return MAL_SUCCEED;
 }
 
@@ -1082,7 +1091,7 @@ static void data_from_time(daytime d, mo
 static void data_from_timestamp(timestamp d, monetdb_data_timestamp *ptr);
 
 char*
-monetdb_result_fetch(monetdb_database dbhdl, monetdb_result* mres, 
monetdb_column** res, size_t column_index)
+monetdb_result_fetch(monetdb_result* mres, monetdb_column** res, size_t 
column_index)
 {
        BAT* b = NULL;
        int bat_type;
@@ -1092,6 +1101,7 @@ monetdb_result_fetch(monetdb_database db
        sql_subtype* sqltpe = NULL;
        monetdb_column* column_result = NULL;
        size_t j = 0;
+       monetdb_database dbhdl = result->dbhdl;
        Client c = (Client) dbhdl;
 
        MT_lock_set(&embedded_lock);
diff --git a/tools/embedded/monetdb_embedded.h 
b/tools/embedded/monetdb_embedded.h
--- a/tools/embedded/monetdb_embedded.h
+++ b/tools/embedded/monetdb_embedded.h
@@ -127,8 +127,9 @@ embedded_export char* monetdb_set_autoco
 embedded_export int   monetdb_in_transaction(monetdb_database dbhdl);
 
 embedded_export char* monetdb_query(monetdb_database dbhdl, char* query, 
monetdb_result** result, monetdb_cnt* affected_rows);
-embedded_export char* monetdb_result_fetch(monetdb_database dbhdl, 
monetdb_result *mres, monetdb_column** res, size_t column_index);
+embedded_export char* monetdb_result_fetch(monetdb_result *mres, 
monetdb_column** res, size_t column_index);
 embedded_export char* monetdb_cleanup_result(monetdb_database dbhdl, 
monetdb_result* result);
+
 embedded_export char* monetdb_prepare(monetdb_database dbhdl, char *query, 
monetdb_statement **stmt);
 embedded_export char* monetdb_bind(monetdb_statement *stmt, void *data, size_t 
parameter_nr);
 embedded_export char* monetdb_execute(monetdb_statement *stmt, monetdb_result 
**result, monetdb_cnt* affected_rows);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to