有没有办法在不安装R包的情况下在C++应用程序中使用MonetDBLite作为存储引擎?或者像SQLite一样使用MonetDB作为嵌入式数据库还有其他方法吗?
发布于 2016-05-23 15:28:01
您可以在C/C++等环境中使用它,如下所示:
从src https://github.com/hannesmuehleisen/MonetDBLite下载/克隆R包源,然后转到文件夹并运行configure:
./configure --enable-embedded --disable-fits --disable-geom --disable-rintegration --disable-gsl --disable-netcdf --disable-jdbc --disable-merocontrol --disable-odbc --disable-console --disable-microhttpd --without-openssl --without-uuid --without-curl --without-bz2 --without-lzma --without-libxml2 --without-perl --without-python2 --without-python3 --without-unixodbc --disable-mapi --without-samtools --without-sphinxclient --without-geos --without-samtools --without-readline --enable-optimize --enable-silent-rules --disable-int128
使用make -j构建它(这将需要一段时间)
然后,您可以按如下方式构建MonetDBLite共享库:
gcc -shared -o libmonetdb5.so `find common gdk mal/mal mal/modules mal/optimizer sql embedded -name "*.o" | tr "\n" " "` -lpthread -lpcre -lz -liconv
您最终应该得到一个大的(5MB)文件libmonetdb5.so,其中包含所有MonetDBLite代码。现在从你自己的程序中使用它:
下面是一个使用嵌入式MonetDB的示例C程序:
#include "monetdb_config.h"
#include "sql_scenario.h"
#include "mal.h"
#include "embedded.h"
int main() {
char* err = NULL;
void* conn = NULL;
res_table* result = NULL;
err = monetdb_startup("/tmp/embedded-dbfarm", 1, 0);
if (err != NULL) {
fprintf(stderr, "Init fail: %s\n", err);
return -1;
}
conn = monetdb_connect();
err = monetdb_query(conn, "SELECT * FROM tables;", 1, (void**) &result);
if (err != NULL) {
fprintf(stderr, "Query fail: %s\n", err);
return -2;
}
fprintf(stderr, "Query result with %i cols and %lu rows\n", result->nr_cols, BATcount(BATdescriptor(result->cols[0].b)));
monetdb_disconnect(conn);
monetdb_shutdown();
}将其保存到src文件夹(此处为test.c)中的一个文件中,并构建它:
gcc test.c -Icommon/options -Icommon/stream -Igdk -Imal/mal -Imal/modules/atoms -Imal/modules/mal -Isql/include -Isql/backends/monet5 -Isql/server -Isql/common -Isql/storage -Iembedded -lmonetdb5 -L.
这应该就是全部了,当你运行它(./a.out)时,它应该是Query result with 9 cols and 44 rows。请注意,您只需要将libmonetdb5.so文件与编译后的程序一起发布,而不是源树的其余部分。
作为附带说明,我们希望在未来简化这一过程。
https://stackoverflow.com/questions/37359507
复制相似问题