Changeset: fd168cf44d8c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=fd168cf44d8c
Added Files:
ctest/tools/monetdbe/example_remote.c
Modified Files:
ctest/tools/monetdbe/CMakeLists.txt
monetdb5/mal/mal.c
monetdb5/mal/mal_embedded.c
monetdb5/mal/mal_profiler.c
monetdb5/mal/mal_session.c
Branch: default
Log Message:
more protection agains msab..
diffs (160 lines):
diff --git a/ctest/tools/monetdbe/CMakeLists.txt
b/ctest/tools/monetdbe/CMakeLists.txt
--- a/ctest/tools/monetdbe/CMakeLists.txt
+++ b/ctest/tools/monetdbe/CMakeLists.txt
@@ -62,3 +62,9 @@ target_link_libraries(example_connection
monetdbe)
add_test(run_example_connections example_connections)
+add_executable(example_remote example_remote.c)
+target_link_libraries(example_remote
+ PRIVATE
+ monetdb_config_header
+ monetdbe)
+add_test(run_example_remote example_remote)
diff --git a/ctest/tools/monetdbe/example_remote.c
b/ctest/tools/monetdbe/example_remote.c
new file mode 100644
--- /dev/null
+++ b/ctest/tools/monetdbe/example_remote.c
@@ -0,0 +1,75 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Copyright 1997 - July 2008 CWI, August 2008 - 2020 MonetDB B.V.
+ */
+
+#include "monetdbe.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <inttypes.h>
+
+#define error(msg) {fprintf(stderr, "Failure: %s\n", msg); return -1;}
+
+int
+main(void)
+{
+ char* err = NULL;
+ monetdbe_database mdbe = NULL;
+ monetdbe_result* result = NULL;
+
+ // second argument is a string for the db directory or NULL for
in-memory mode
+ if ((err = monetdbe_open(&mdbe,
"monetdb://localhost:5000/sf1?user=monetdb&password=monetdb", NULL)) != NULL)
+ error(err)
+ if ((err = monetdbe_query(mdbe, "CREATE TABLE test (x integer, y
string)", NULL, NULL)) != NULL)
+ error(err)
+ if ((err = monetdbe_query(mdbe, "INSERT INTO test VALUES (42, 'Hello'),
(NULL, 'World')", NULL, NULL)) != NULL)
+ error(err)
+ if ((err = monetdbe_query(mdbe, "SELECT x, y 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_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_close(mdbe)) != NULL)
+ error(err)
+ return 0;
+}
diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c
--- a/monetdb5/mal/mal.c
+++ b/monetdb5/mal/mal.c
@@ -96,7 +96,7 @@ void mal_reset(void)
setHeartbeat(-1);
stopProfiler(0);
AUTHreset();
- if (!GDKinmemory()) {
+ if (!GDKinmemory() && !GDKembedded()) {
str err = 0;
if ((err = msab_wildRetreat()) != NULL) {
diff --git a/monetdb5/mal/mal_embedded.c b/monetdb5/mal/mal_embedded.c
--- a/monetdb5/mal/mal_embedded.c
+++ b/monetdb5/mal/mal_embedded.c
@@ -119,7 +119,7 @@ malEmbeddedReset(void) //remove extra mo
setHeartbeat(-1);
stopProfiler(0);
AUTHreset();
- if (!GDKinmemory()) {
+ if (!GDKinmemory() && !GDKembedded()) {
str err = 0;
if ((err = msab_wildRetreat()) != NULL) {
diff --git a/monetdb5/mal/mal_profiler.c b/monetdb5/mal/mal_profiler.c
--- a/monetdb5/mal/mal_profiler.c
+++ b/monetdb5/mal/mal_profiler.c
@@ -175,15 +175,15 @@ renderProfilerEvent(Client cntxt, MalBlk
logadd(",\"barrier\":\"%s\"", operatorName(pci->barrier));
if( pci->token < FCNcall || pci->token > PATcall)
logadd(",\"operator\":\"%s\"", operatorName(pci->token));
- if (!GDKinmemory()) {
- char *uuid;
+ if (!GDKinmemory() && !GDKembedded()) {
+ char *uuid;
str c;
if ((c = msab_getUUID(&uuid)) == NULL) {
logadd(",\"session\":\"%s\"", uuid);
free(uuid);
} else
free(c);
- }
+ }
logadd(",\"state\":\"%s\"", start?"start":"done");
logadd(",\"usec\":"LLFMT, pci->ticks);
@@ -393,7 +393,7 @@ profilerHeartbeatEvent(char *alter)
lognew();
logadd("{"); // fill in later with the event counter
- if (GDKinmemory()) {
+ if (!GDKinmemory() && !GDKembedded()) {
char *uuid, *err;
if ((err = msab_getUUID(&uuid)) == NULL) {
logadd("\"session\":\"%s\",", uuid);
diff --git a/monetdb5/mal/mal_session.c b/monetdb5/mal/mal_session.c
--- a/monetdb5/mal/mal_session.c
+++ b/monetdb5/mal/mal_session.c
@@ -273,7 +273,7 @@ MSscheduleClient(str command, str challe
return;
}
- if (!GDKinmemory()) {
+ if (!GDKinmemory() && !GDKembedded()) {
err = msab_getMyStatus(&stats);
if (err != NULL) {
/* this is kind of awful, but we need to get
rid of this
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list