Changeset: 34675b4fe229 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=34675b4fe229
Added Files:
ctest/tools/monetdbe/example_backup.c
tools/monetdbe/mapi.h
tools/monetdbe/monetdbe_mapi.c
Removed Files:
ctest/tools/monetdbe/mapi.c
ctest/tools/monetdbe/mapi.h
Modified Files:
ctest/tools/monetdbe/CMakeLists.txt
tools/monetdbe/CMakeLists.txt
tools/monetdbe/monetdbe.c
tools/monetdbe/monetdbe.h
Branch: default
Log Message:
moved backup into monetdbe library
diffs (truncated from 817 to 300 lines):
diff --git a/ctest/tools/monetdbe/CMakeLists.txt
b/ctest/tools/monetdbe/CMakeLists.txt
--- a/ctest/tools/monetdbe/CMakeLists.txt
+++ b/ctest/tools/monetdbe/CMakeLists.txt
@@ -48,21 +48,12 @@ target_link_libraries(example_append
monetdbe)
add_test(run_example_append example_append)
-add_executable(backup
- backup.c
- mapi.h
- mapi.c
- ${CMAKE_SOURCE_DIR}/clients/mapiclient/dump.c)
-target_include_directories(backup
- PRIVATE
- ${CMAKE_SOURCE_DIR}/clients/mapilib)
-target_link_libraries(backup
+add_executable(example_backup example_backup.c)
+target_link_libraries(example_backup
PRIVATE
monetdb_config_header
- monetdbe
- stream
- matomic)
-add_test(run_backup backup)
+ monetdbe)
+add_test(run_example_backup example_backup)
add_executable(example_connections example_connections.c)
target_link_libraries(example_connections
diff --git a/ctest/tools/monetdbe/example_backup.c
b/ctest/tools/monetdbe/example_backup.c
new file mode 100644
--- /dev/null
+++ b/ctest/tools/monetdbe/example_backup.c
@@ -0,0 +1,33 @@
+
+#include "monetdb_config.h"
+#include <monetdbe.h>
+
+#define error(msg) {fprintf(stderr, "Failure: %s\n", msg); return -1;}
+
+int
+main(void)
+{
+ char* err = NULL;
+ char *msg;
+ monetdbe_database mdbe;
+
+ if ((msg = monetdbe_open(&mdbe, NULL)) != NULL)
+ error(msg);
+
+ if ((err = monetdbe_query(mdbe, "CREATE TABLE test (b bool, t tinyint,
s smallint, x integer, l bigint, "
+#ifdef HAVE_HGE
+ "h hugeint, "
+#else
+ "h bigint, "
+#endif
+ "f float, d double, y string)", NULL, NULL)) != NULL)
+ error(err)
+ if ((err = monetdbe_query(mdbe, "INSERT INTO test VALUES (TRUE, 42, 42,
42, 42, 42, 42.42, 42.42, 'Hello'), (NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, 'World')", NULL, NULL)) != NULL)
+ error(err)
+
+ msg = monetdbe_backup(mdbe, "/tmp/backup");
+
+ if ((msg = monetdbe_close(mdbe)) != NULL)
+ error(msg);
+ return 0;
+}
diff --git a/ctest/tools/monetdbe/mapi.c b/ctest/tools/monetdbe/mapi.c
deleted file mode 100644
--- a/ctest/tools/monetdbe/mapi.c
+++ /dev/null
@@ -1,267 +0,0 @@
-
-#include "monetdb_config.h"
-#include "stream.h"
-#include "mapi.h"
-
-#define MAPIalloc(sz) malloc(sz)
-#define MAPIfree(p) free(p)
-
-char *
-mapi_error(Mapi mid)
-{
- return mid->msg;
-}
-
-MapiHdl
-mapi_query(Mapi mid, const char *query)
-{
- MapiHdl mh = (MapiHdl)MAPIalloc(sizeof(struct MapiStatement));
-
- mh->mid = mid;
- mh->query = (char*)query;
- mh->msg = monetdbe_query(mh->mid->mdbe, mh->query, &mh->result,
&mh->affected_rows);
- mh->current_row = 0;
- mh->mapi_row = NULL;
- if (mh->result && mh->result->ncols) {
- mh->mapi_row =
(char**)MAPIalloc(sizeof(char*)*mh->result->ncols);
- if (!mh->mapi_row) {
- mh->msg = "malloc failure";
- return mh;
- }
- memset(mh->mapi_row, 0, sizeof(char*)*mh->result->ncols);
- }
- return mh;
-}
-
-MapiMsg
-mapi_close_handle(MapiHdl hdl)
-{
- if (hdl) {
- if (hdl->mapi_row) {
- for (size_t i=0; i<hdl->result->ncols; i++) {
- if (hdl->mapi_row[i])
- MAPIfree(hdl->mapi_row[i]);
- }
- MAPIfree(hdl->mapi_row);
- }
-
- char *msg = monetdbe_cleanup_result(hdl->mid->mdbe,
hdl->result);
- MAPIfree(hdl);
- if (msg)
- hdl->mid->msg = msg;
- }
- return MOK;
-}
-
-int
-mapi_fetch_row(MapiHdl hdl)
-{
- int n = 0;
- if (hdl && hdl->current_row < hdl->result->nrows) {
- n = ++hdl->current_row;
- }
- return n;
-}
-
-#define SIMPLE_TYPE_SIZE 128
-
-char *
-mapi_fetch_field(MapiHdl hdl, int fnr)
-{
- if (hdl && fnr < (int)hdl->result->ncols && hdl->current_row > 0 &&
hdl->current_row <= hdl->result->nrows) {
- monetdbe_column *rcol = NULL;
- if (monetdbe_result_fetch(hdl->result, &rcol, fnr) == NULL) {
- size_t r = hdl->current_row - 1;
- if (rcol->type != monetdbe_str && !hdl->mapi_row[fnr]) {
- hdl->mapi_row[fnr] =
MAPIalloc(SIMPLE_TYPE_SIZE);
- if (!hdl->mapi_row[fnr]) {
- hdl->msg = "malloc failure";
- return NULL;
- }
- }
- switch(rcol->type) {
- case monetdbe_bool: {
- monetdbe_column_bool *icol =
(monetdbe_column_bool*)rcol;
- if (icol->data[r] == icol->null_value)
- snprintf(hdl->mapi_row[fnr],
SIMPLE_TYPE_SIZE, "NULL");
- else
- snprintf(hdl->mapi_row[fnr],
SIMPLE_TYPE_SIZE, "%s", icol->data[r]==1?"true":"false");
- return hdl->mapi_row[fnr];
- }
- case monetdbe_int8_t: {
- monetdbe_column_int8_t *icol =
(monetdbe_column_int8_t*)rcol;
- if (icol->data[r] == icol->null_value)
- snprintf(hdl->mapi_row[fnr],
SIMPLE_TYPE_SIZE, "NULL");
- else
- snprintf(hdl->mapi_row[fnr],
SIMPLE_TYPE_SIZE, "%d", icol->data[r]);
- return hdl->mapi_row[fnr];
- }
- case monetdbe_int16_t: {
- monetdbe_column_int16_t *icol =
(monetdbe_column_int16_t*)rcol;
- if (icol->data[r] == icol->null_value)
- snprintf(hdl->mapi_row[fnr],
SIMPLE_TYPE_SIZE, "NULL");
- else
- snprintf(hdl->mapi_row[fnr],
SIMPLE_TYPE_SIZE, "%d", icol->data[r]);
- return hdl->mapi_row[fnr];
- }
- case monetdbe_int32_t: {
- monetdbe_column_int32_t *icol =
(monetdbe_column_int32_t*)rcol;
- if (icol->data[r] == icol->null_value)
- snprintf(hdl->mapi_row[fnr],
SIMPLE_TYPE_SIZE, "NULL");
- else
- snprintf(hdl->mapi_row[fnr],
SIMPLE_TYPE_SIZE, "%d", icol->data[r]);
- return hdl->mapi_row[fnr];
- }
- case monetdbe_int64_t: {
- monetdbe_column_int64_t *icol =
(monetdbe_column_int64_t*)rcol;
- if (icol->data[r] == icol->null_value)
- snprintf(hdl->mapi_row[fnr],
SIMPLE_TYPE_SIZE, "NULL");
- else
- snprintf(hdl->mapi_row[fnr],
SIMPLE_TYPE_SIZE, "%" PRId64, icol->data[r]);
- return hdl->mapi_row[fnr];
- }
-#ifdef HAVE_HGE
- case monetdbe_int128_t: {
- monetdbe_column_int128_t *icol =
(monetdbe_column_int128_t*)rcol;
- if (icol->data[r] == icol->null_value)
- snprintf(hdl->mapi_row[fnr],
SIMPLE_TYPE_SIZE, "NULL");
- else
- snprintf(hdl->mapi_row[fnr],
SIMPLE_TYPE_SIZE, "%" PRId64, (int64_t)icol->data[r]);
- return hdl->mapi_row[fnr];
- }
-#endif
- case monetdbe_float: {
- monetdbe_column_float *icol =
(monetdbe_column_float*)rcol;
- if (icol->data[r] == icol->null_value)
- snprintf(hdl->mapi_row[fnr],
SIMPLE_TYPE_SIZE, "NULL");
- else
- snprintf(hdl->mapi_row[fnr],
SIMPLE_TYPE_SIZE, "%f", icol->data[r]);
- return hdl->mapi_row[fnr];
- }
- case monetdbe_double: {
- monetdbe_column_double *icol =
(monetdbe_column_double*)rcol;
- if (icol->data[r] == icol->null_value)
- snprintf(hdl->mapi_row[fnr],
SIMPLE_TYPE_SIZE, "NULL");
- else
- snprintf(hdl->mapi_row[fnr],
SIMPLE_TYPE_SIZE, "%f", icol->data[r]);
- return hdl->mapi_row[fnr];
- }
- case monetdbe_str: {
- monetdbe_column_str *icol =
(monetdbe_column_str*)rcol;
- return icol->data[r];
- }
- default:
- return NULL;
- }
- }
- }
- return NULL;
-}
-
-char *
-mapi_get_type(MapiHdl hdl, int fnr)
-{
- if (hdl && fnr < (int)hdl->result->ncols) {
- monetdbe_column *rcol = NULL;
- if (monetdbe_result_fetch(hdl->result, &rcol, fnr) == NULL) {
- switch(rcol->type) {
- case monetdbe_bool:
- return "boolean";
- case monetdbe_int8_t:
- return "tinyint";
- case monetdbe_int16_t:
- return "smallint";
- case monetdbe_int32_t:
- return "integer";
- case monetdbe_int64_t:
- return "bigint";
-#ifdef HAVE_HGE
- case monetdbe_int128_t:
- return "hugeint";
-#endif
- case monetdbe_float:
- return "float";
- case monetdbe_double:
- return "real";
- case monetdbe_str:
- return "varchar";
- default:
- return "unknown";
- }
- }
- }
- return NULL;
-}
-
-MapiMsg
-mapi_seek_row(MapiHdl hdl, int64_t rowne, int whence)
-{
- if (hdl && rowne == 0 && whence == MAPI_SEEK_SET) {
- hdl->current_row = 0;
- }
- return MOK;
-}
-
-int64_t
-mapi_get_row_count(MapiHdl hdl)
-{
- if (hdl) {
- return hdl->result->nrows;
- }
- return 0;
-}
-
-int64_t
-mapi_rows_affected(MapiHdl hdl)
-{
- if (hdl) {
- if (hdl->result)
- return hdl->result->nrows;
- return hdl->affected_rows;
- }
- return 0;
-}
-
-int
-mapi_get_field_count(MapiHdl hdl)
-{
- if (hdl) {
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list