Changeset: f1deed93c24d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f1deed93c24d
Added Files:
embedded/MonetDBLiteReadme.txt
Modified Files:
cmake/BuildMacros.cmake
embedded/monetdb_embedded.c
embedded/monetdb_embedded.h
monetdb5/mal/mal_linker.c
Branch: cmake-monetdblite
Log Message:
Added documentation about MonetDBLite compilation, set a different default
library for the MAL linker in MonetDBLite and fixed monetdb_result types.
diffs (226 lines):
diff --git a/cmake/BuildMacros.cmake b/cmake/BuildMacros.cmake
--- a/cmake/BuildMacros.cmake
+++ b/cmake/BuildMacros.cmake
@@ -38,7 +38,8 @@ macro(BUILD_EMBEDDED_SQL_SCRIPTS BUNDLE_
endif()
endmacro()
-# This macros sets the required system libraries besides the C standard
library. It should be used by
+# This macros sets the required system libraries besides the C standard
library. It should be used by the MonetDBLite
+# programing language bindings
macro(SET_SYSTEM_LIBRARIES)
if(NOT WIN32)
set(THREADS_PREFER_PTHREAD_FLAG ON) # We do prefer pthreads on
UNIX platforms
diff --git a/embedded/MonetDBLiteReadme.txt b/embedded/MonetDBLiteReadme.txt
new file mode 100644
--- /dev/null
+++ b/embedded/MonetDBLiteReadme.txt
@@ -0,0 +1,102 @@
+MonetDBLite is not set to compile by default, enable it by setting the cache
variable ENABLE_EMBEDDED to SHARED or
+OBJECT. The former is used to build MonetDBLite as a C shared library. The
latter compiles and generates the relocatable
+files without any linking. This will be the better approach to compile the
language bindings I think.
+
+To simplify the compilation process set the following variables:
+
+cmake -DCMAKE_INSTALL_PREFIX=<build dir> -DENABLE_EMBEDDED=SHARED
-DENABLE_ODBC=NO -DENABLE_MAPI=NO -DENABLE_GDK=NO \
+ -DENABLE_MONETDB5=NO -DENABLE_SQL=NO -DENABLE_TESTING=NO <source dir>
+
+The ABI is listed on the monetdb_embedded.h header file.
+- The major changes are more C99 compliance and most of the calls return a
char* which is set to non-NULL whenever an
+error is thrown. The error message must be freed with "void
freeException(str)" function call.
+- The append_data struct is gone, because the "colname" field was never used,
instead only the batids are passed as
+argument.
+- The functions monetdb_result_fetch and monetdb_result_fetch_rawcol take
monetdb_connection as the first parameter.
+- If libmonetdblite is on a different directory, related to the executable and
libmonetdblite's directory is not set on
+LD_LIBRARY_PATH or equivalent, use the "str initLinker(const char* path)"
function BEFORE starting the database to tell
+where it is located.
+
+The updated readme.c example:
+-----------------------------------------------------------------------------------------------------------------------
+#include "monetdb_embedded.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;
+ monetdb_connection conn = NULL;
+ monetdb_result* result = NULL;
+
+ // first argument is a string for the db directory or NULL for
in-memory mode
+ if ((err = monetdb_startup(NULL, 1, 0)) != NULL)
+ error(err)
+ if ((err = monetdb_connect(&conn)) != NULL)
+ error(err)
+ if ((err = monetdb_query(conn, "CREATE TABLE test (x integer, y
string)", NULL, NULL, NULL)) != NULL)
+ error(err)
+ if ((err = monetdb_query(conn, "INSERT INTO test VALUES (42, 'Hello'),
(NULL, 'World')", NULL, NULL, NULL)) != NULL)
+ error(err)
+ if ((err = monetdb_query(conn, "SELECT x, y FROM test; ", &result,
NULL, 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++) {
+ monetdb_column* rcol;
+ if ((err = monetdb_result_fetch(conn, &rcol, result,
c)) != NULL)
+ error(err)
+ switch (rcol->type) {
+ case monetdb_int32_t: {
+ monetdb_column_int32_t * col =
(monetdb_column_int32_t *) rcol;
+ if (col->data[r] == col->null_value) {
+ printf("NULL");
+ } else {
+ printf("%d", col->data[r]);
+ }
+ break;
+ }
+ case monetdb_str: {
+ monetdb_column_str * col =
(monetdb_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 = monetdb_cleanup_result(conn, result)) != NULL)
+ error(err)
+ if ((err = monetdb_disconnect(conn)) != NULL)
+ error(err)
+ if ((err = monetdb_shutdown()) != NULL)
+ error(err)
+ return 0;
+}
+-----------------------------------------------------------------------------------------------------------------------
+To compile with GCC on Linux do (note that cmake installs libraries on lib64
directory on 64-bit architectures on
+certain operating systems):
+
+gcc -o readme readme.c -I<build dir>/include/monetdb -L<build dir>/lib
-lmonetdblite
+
+It should produce the "readme" executable output the following:
+Query result with 2 cols and 2 rows
+42, Hello
+NULL, World
diff --git a/embedded/monetdb_embedded.c b/embedded/monetdb_embedded.c
--- a/embedded/monetdb_embedded.c
+++ b/embedded/monetdb_embedded.c
@@ -120,8 +120,7 @@ monetdb_cleanup_result_internal(monetdb_
res_tables_destroy(res->monetdb_resultset);
if (res->converted_columns) {
- size_t i;
- for (i = 0; i < res->res.ncols; i++)
+ for (size_t i = 0; i < res->res.ncols; i++)
monetdb_destroy_column(res->converted_columns[i]);
GDKfree(res->converted_columns);
}
@@ -208,17 +207,17 @@ monetdb_query_internal(monetdb_connectio
goto cleanup;
}
if (m->emode == m_execute)
- res_internal->res.type = (m->results) ? (char) Q_TABLE
: (char) Q_UPDATE;
+ res_internal->res.type = (m->results) ? Q_TABLE :
Q_UPDATE;
else if (m->emode & m_prepare)
- res_internal->res.type = (char) Q_PREPARE;
+ res_internal->res.type = Q_PREPARE;
else
- res_internal->res.type = (char) m->type;
- res_internal->res.id = (size_t) m->last_id;
+ res_internal->res.type = m->type;
+ res_internal->res.id = m->last_id;
*result = (monetdb_result*) res_internal;
m->reply_size = -2; /* do not clean up result tables */
if (m->results) {
- res_internal->res.ncols = m->results->nr_cols;
+ res_internal->res.ncols = (size_t) m->results->nr_cols;
if (m->results->nr_cols > 0 && m->results->order) {
BAT* bb = BATdescriptor(m->results->order);
if (!bb) {
diff --git a/embedded/monetdb_embedded.h b/embedded/monetdb_embedded.h
--- a/embedded/monetdb_embedded.h
+++ b/embedded/monetdb_embedded.h
@@ -69,10 +69,10 @@ typedef struct {
} monetdb_column;
typedef struct {
- size_t nrows;
+ int64_t nrows;
size_t ncols;
- char type;
- size_t id;
+ int type;
+ int64_t id;
} monetdb_result;
typedef void* monetdb_connection;
diff --git a/monetdb5/mal/mal_linker.c b/monetdb5/mal/mal_linker.c
--- a/monetdb5/mal/mal_linker.c
+++ b/monetdb5/mal/mal_linker.c
@@ -43,7 +43,8 @@ static int maxfiles = MAXMODULES;
static int lastfile = 0;
/*
- * In MonetDBLite, libmonetdb5 will be set dynamically.
+ * In MonetDBLite, libmonetdblite might be located on a different directory
location from the executable, nor not set on
+ * LD_LIBRARY_PATH. On this case the function initLinker sets monetdb_lib_path
variable with libmonetdblite location.
*/
static char* monetdb_lib_path = NULL;
@@ -52,8 +53,7 @@ initLinker(const char* path)
{
if (monetdb_lib_path)
GDKfree(monetdb_lib_path);
- monetdb_lib_path = GDKstrdup(path);
- if (!monetdb_lib_path)
+ if (!(monetdb_lib_path = GDKstrdup(path)))
throw(LOADER, "initLinker", MAL_MALLOC_FAIL);
return MAL_SUCCEED;
}
@@ -82,7 +82,12 @@ getAddress(str fcnname)
MALfcn adr;
int idx=0;
static int prev= -1;
- char *monetdb5library = monetdb_lib_path ? monetdb_lib_path :
"libmonetdb5";
+ char *monetdb5library = monetdb_lib_path ? monetdb_lib_path :
+#ifdef HAVE_EMBEDDED
+ "libmonetdblite";
+#else
+ "libmonetdb5";
+#endif
/* First try the last module loaded */
if( prev >= 0){
@@ -313,7 +318,6 @@ cmpstr(const void *_p1, const void *_p2)
return strcmp(f1?f1:p1, f2?f2:p2);
}
-
#define MAXMULTISCRIPT 48
char *
locate_file(const char *basename, const char *ext, bit recurse)
@@ -455,7 +459,6 @@ MSP_locate_sqlscript(const char *filenam
return locate_file(filename, SQL_EXT, recurse);
}
-
int
malLibraryEnabled(str name) {
if (strcmp(name, "pyapi") == 0) {
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list