Changeset: 3cb362fc9b8d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3cb362fc9b8d
Added Files:
embedded/embedded.c
embedded/embedded.h
Modified Files:
common/options/monet_options.c
common/stream/stream.c
common/stream/stream.h
monetdb_config.h.in
Branch: cmake-monetdblite
Log Message:
Back-porting MonetDBLite codebase, along with code cleanup.
diffs (truncated from 1358 to 300 lines):
diff --git a/common/options/monet_options.c b/common/options/monet_options.c
--- a/common/options/monet_options.c
+++ b/common/options/monet_options.c
@@ -75,7 +75,6 @@ mo_print_options(opt *set, int setlen)
}
}
-
char *
mo_find_option(opt *set, int setlen, const char *name)
{
@@ -200,7 +199,6 @@ mo_system_config(opt **Set, int setlen)
return setlen;
}
-
int
mo_builtin_settings(opt **Set)
{
@@ -210,15 +208,19 @@ mo_builtin_settings(opt **Set)
if (Set == NULL)
return 0;
-#define N_OPTIONS 8 /*MUST MATCH # OPTIONS BELOW */
+#ifdef HAVE_EMBEDDED
+#define N_OPTIONS 1 /*MUST MATCH # OPTIONS BELOW */
+#else
+#define N_OPTIONS 8
+#endif
set = malloc(sizeof(opt) * N_OPTIONS);
if (set == NULL)
return 0;
+#ifndef HAVE_EMBEDDED
set[i].kind = opt_builtin;
set[i].name = strdup("gdk_dbpath");
- set[i].value = strdup(LOCALSTATEDIR DIR_SEP_STR "monetdb5" DIR_SEP_STR
- "dbfarm" DIR_SEP_STR "demo");
+ set[i].value = strdup(LOCALSTATEDIR DIR_SEP_STR "monetdb5" DIR_SEP_STR
"dbfarm" DIR_SEP_STR "demo");
i++;
set[i].kind = opt_builtin;
set[i].name = strdup("monet_prompt");
@@ -244,6 +246,7 @@ mo_builtin_settings(opt **Set)
set[i].name = strdup("sql_optimizer");
set[i].value = strdup("default_pipe");
i++;
+#endif
set[i].kind = opt_builtin;
set[i].name = strdup("sql_debug");
set[i].value = strdup("0");
diff --git a/common/stream/stream.c b/common/stream/stream.c
--- a/common/stream/stream.c
+++ b/common/stream/stream.c
@@ -5440,39 +5440,6 @@ callback_stream(void *restrict private,
return s;
}
-static ssize_t
-stream_blackhole_write(stream *restrict s, const void *restrict buf, size_t
elmsize, size_t cnt)
-{
- (void) s;
- (void) buf;
- (void) elmsize;
- return (ssize_t) cnt;
-}
-
-static void
-stream_blackhole_close(stream *s)
-{
- (void) s;
- /* no resources to close */
-}
-
-stream *
-stream_blackhole_create(void)
-{
- stream *s;
- if ((s = create_stream("blackhole")) == NULL) {
- return NULL;
- }
-
- s->read = NULL;
- s->write = stream_blackhole_write;
- s->close = stream_blackhole_close;
- s->flush = NULL;
- s->readonly = false;
- return s;
-}
-
-
/* fixed-width format streams */
#define STREAM_FWF_NAME "fwf_ftw"
diff --git a/common/stream/stream.h b/common/stream/stream.h
--- a/common/stream/stream.h
+++ b/common/stream/stream.h
@@ -116,7 +116,6 @@ stream_export int mnstr_writeInt(stream
stream_export int mnstr_readLng(stream *restrict s, int64_t *restrict val);
stream_export int mnstr_writeLng(stream *s, int64_t val);
-
stream_export int mnstr_writeFlt(stream *s, float val);
stream_export int mnstr_writeDbl(stream *s, double val);
@@ -225,7 +224,6 @@ stream_export stream *block_stream(strea
stream_export bool isa_block_stream(stream *s);
stream_export stream *bs_stream(stream *s);
-
typedef enum {
PROTOCOL_AUTO = 0,
PROTOCOL_9 = 1,
@@ -244,7 +242,6 @@ stream_export int bs2_resizebuf(stream *
stream_export buffer bs2_buffer(stream *s);
stream_export void bs2_setpos(stream *ss, size_t pos);
-
/* read block of data including the end of block marker */
stream_export ssize_t mnstr_read_block(stream *restrict s, void *restrict buf,
size_t elmsize, size_t cnt);
@@ -282,8 +279,6 @@ stream_export stream *callback_stream(
void (*destroy)(void *priv),
const char *restrict name);
-stream_export stream *stream_blackhole_create(void);
-
stream_export stream *stream_fwf_create(stream *restrict s, size_t num_fields,
size_t *restrict widths, char filler);
#endif /*_STREAM_H_*/
diff --git a/embedded/embedded.c b/embedded/embedded.c
new file mode 100644
--- /dev/null
+++ b/embedded/embedded.c
@@ -0,0 +1,920 @@
+/*
+ * 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 - 2019 MonetDB B.V.
+ */
+
+/*
+ * H. Muehleisen, M. Raasveldt
+ * Inverse RAPI
+ */
+
+#include "monetdb_config.h"
+
+#include "embedded.h"
+
+#include "mal.h"
+#include "mal_client.h"
+#include "mal_builder.h"
+
+#include "mal_linker.h"
+#include "sql_scenario.h"
+#include "gdk_utils.h"
+#include "sql_scenario.h"
+#include "sql_execute.h"
+#include "sql.h"
+#include "sql_mvc.h"
+#include "res_table.h"
+#include "sql_scenario.h"
+#include "opt_prelude.h"
+#include "rel_semantic.h"
+#include "sql_gencode.h"
+#include "sql_optimizer.h"
+#include "rel_exp.h"
+#include "rel_rel.h"
+#include "rel_updates.h"
+
+#include "mtime.h"
+#include "blob.h"
+
+static int monetdb_embedded_initialized = 0;
+
+int
+monetdb_is_initialized(void)
+{
+ return monetdb_embedded_initialized > 0;
+}
+
+static str
+validate_connection(monetdb_connection conn, const char* call)
+{
+ if (!monetdb_is_initialized())
+ return createException(MAL, call, SQLSTATE(HY001) "Embedded
MonetDB is not started");
+ if (!MCvalid((Client) conn))
+ return createException(MAL, call, SQLSTATE(HY001) "Invalid
connection");
+ return MAL_SUCCEDED;
+}
+
+MT_Lock embedded_lock MT_LOCK_INITIALIZER("embedded_lock");
+
+static void monetdb_destroy_column(monetdb_column* column);
+
+typedef struct {
+ monetdb_result res;
+ res_table *monetdb_resultset;
+ monetdb_column **converted_columns;
+} monetdb_result_internal;
+
+str
+monetdb_connect(monetdb_connection *conn)
+{
+ mvc *m;
+ str msg = MAL_SUCCEED;
+ Client mc = NULL;
+
+ if (!monetdb_is_initialized()) {
+ msg = createException(MAL, "embedded.monetdb_connect",
SQLSTATE(42000) "Embedded MonetDB is not started");
+ goto cleanup;
+ }
+ if (!conn) {
+ msg = createException(MAL, "embedded.monetdb_connect",
SQLSTATE(42000) "monetdb_connection parameter is NULL");
+ goto cleanup;
+ }
+ mc = MCinitClient((oid) 0, 0, 0);
+ if (!MCvalid(mc)) {
+ msg = createException(MAL, "embedded.monetdb_connect",
SQLSTATE(HY001) "Failed to initialize client");
+ goto cleanup;
+ }
+ mc->curmodule = mc->usermodule = userModule();
+ if(c->usermodule == NULL) {
+ msg = createException(MAL, "embedded.monetdb_connect",
SQLSTATE(HY001) "Failed to initialize client MAL module");
+ goto cleanup;
+ }
+ if ((msg = SQLinitClient(mc)) != MAL_SUCCEED)
+ goto cleanup;
+ if ((msg = getSQLContext(mc, NULL, &m, NULL)) != MAL_SUCCEED)
+ goto cleanup;
+ m->session->auto_commit = 1;
+
+cleanup:
+ if (msg && mc) {
+ str other = monetdb_disconnect(mc);
+ if (other)
+ GDKfree(other);
+ *conn = NULL;
+ } else if(conn)
+ *conn = mc;
+ return msg;
+}
+
+str
+monetdb_disconnect(monetdb_connection conn)
+{
+ str msg = MAL_SUCCEED;
+
+ if ((msg = validate_connection(conn, "embedded.monetdb_disconnect")) !=
MAL_SUCCEED)
+ return msg;
+ SQLexitClient((Client) conn);
+ MCcloseClient((Client) conn);
+ return MAL_SUCCEED;
+}
+
+str
+monetdb_startup(char* dbdir, char silent, char sequential, char* library_path)
+{
+ str msg = MAL_SUCCEED;
+ monetdb_result* res = NULL;
+ void* c;
+ opt *set = NULL;
+ int setlen;
+ gdk_return gdk_res;
+
+ MT_lock_set(&embedded_lock);
+ GDKfataljumpenable = 1;
+ if(setjmp(GDKfataljump) != 0) {
+ msg = GDKfatalmsg;
+ // we will get here if GDKfatal was called.
+ if (msg == NULL)
+ msg = createException(MAL, "embedded.monetdb_startup",
SQLSTATE(HY002) "GDKfatal() with unspecified error");
+ goto cleanup;
+ }
+
+ if (monetdb_embedded_initialized)
+ goto cleanup;
+
+ if (!library_path) {
+ msg = createException(MAL, "embedded.monetdb_startup",
SQLSTATE(42000) "library_path parameter is NULL");
+ goto cleanup;
+ }
+
+ if (silent)
+ MT_fprintf_silent(true);
+
+ if ((setlen = mo_builtin_settings(&set)) == 0) {
+ msg = createException(MAL, "embedded.monetdb_startup",
SQLSTATE(HY001) MAL_MALLOC_FAIL);
+ goto cleanup;
+ }
+ if ((setlen = mo_add_option(&set, setlen, opt_cmdline, "gdk_dbpath",
dbdir)) == 0) {
+ mo_free_options(set, setlen);
+ msg = createException(MAL, "embedded.monetdb_startup",
SQLSTATE(HY001) MAL_MALLOC_FAIL);
+ goto cleanup;
+ }
+ if (sequential)
+ setlen = mo_add_option(&set, setlen, opt_cmdline,
"sql_optimizer", "sequential_pipe");
+ else
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list