2016-05-21 14 views

回答

5

你可以使用这个从C/C++等,像这样:

下载/克隆从GitHub https://github.com/hannesmuehleisen/MonetDBLite将R包源,然后转到src文件夹和运行配置:

./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

你应该有一个大(5 MB)最终文件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文件与编译的程序一起发送,而不是源码树的其余部分。

作为一个旁注,我们希望在未来简化这一过程。

+0

另请参见新的MonetDBLite-C示例,这里:https://github.com/hannesmuehleisen/MonetDBLite-C#usage-example –