2016-05-21 15 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 –