Changeset: a7463bc1f690 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a7463bc1f690
Modified Files:
        ctest/tools/embedded/example_append.c
        tools/monetdbe/monetdbe.c
Branch: default
Log Message:

merged


diffs (truncated from 416 to 300 lines):

diff --git a/ctest/tools/embedded/example_append.c 
b/ctest/tools/embedded/example_append.c
--- a/ctest/tools/embedded/example_append.c
+++ b/ctest/tools/embedded/example_append.c
@@ -23,12 +23,13 @@ main(void)
        // second argument is a string for the db directory or NULL for 
in-memory mode
        if ((err = monetdb_open(&mdbe, NULL)) != NULL)
                error(err)
-       if ((err = monetdb_query(mdbe, "CREATE TABLE test (x integer, y 
string)", NULL, NULL)) != NULL)
+       if ((err = monetdb_query(mdbe, "CREATE TABLE test (x integer, y string, 
ts timestamp, dt date, t time, bl blob)", NULL, NULL)) != NULL)
                error(err)
-       if ((err = monetdb_query(mdbe, "INSERT INTO test VALUES (42, 'Hello'), 
(NULL, 'World')", NULL, NULL)) != NULL)
+       if ((err = monetdb_query(mdbe, "INSERT INTO test VALUES (42, 'Hello', 
CURRENT_TIMESTAMP, '2008-11-11', '14:30:12', '123412'), \
+                                                                               
                                        (NULL, 'World', NULL, NULL, NULL, 
NULL)", NULL, NULL)) != NULL)
                error(err)
 
-       if ((err = monetdb_query(mdbe, "SELECT x, y FROM test; ", &result, 
NULL)) != NULL)
+       if ((err = monetdb_query(mdbe, "SELECT * FROM test; ", &result, NULL)) 
!= NULL)
                error(err)
        fprintf(stdout, "Query result with %zu cols and %"PRId64" rows\n", 
result->ncols, result->nrows);
        monetdb_column* rcol[2];
@@ -55,6 +56,43 @@ main(void)
                                        }
                                        break;
                                }
+                               case monetdb_timestamp: {
+                                       monetdb_column_timestamp * col = 
(monetdb_column_timestamp *) rcol[c];
+                                       if(col->is_null(col->data[r])) {
+                                               printf("NULL");
+                                       } else {
+                                               printf("%s-%s-%d %s:%s:%s.%d", 
col->data[r].date.day, col->data[r].date.month, col->data[r].date.year,
+                                                                               
                                col->data[r].time.hours, 
col->data[r].time.minutes, col->data[r].time.seconds, col->data[r].time.ms);
+                                       }
+                                       break;
+                               }
+                               case monetdb_date: {
+                                       monetdb_column_date * col = 
(monetdb_column_date *) rcol[c];
+                                       if(col->is_null(col->data[r])) {
+                                               printf("NULL");
+                                       } else {
+                                               printf("%s-%s-%d", 
col->data[r].day, col->data[r].month, col->data[r].year);
+                                       }
+                                       break;
+                               }
+                               case monetdb_time: {
+                                       monetdb_column_time * col = 
(monetdb_column_time *) rcol[c];
+                                       if(col->is_null(col->data[r])) {
+                                               printf("NULL");
+                                       } else {
+                                               printf("%s:%s:%s.%d", 
col->data[r].hours, col->data[r].minutes, col->data[r].seconds, 
col->data[r].ms);
+                                       }
+                                       break;
+                               }
+                               case monetdb_blob: {
+                                       monetdb_column_blob * col = 
(monetdb_column_blob *) rcol[c];
+                                       if(col->is_null(col->data[r])) {
+                                               printf("NULL");
+                                       } else {
+                                               printf("%s", col->data[r].data);
+                                       }
+                                       break;
+                               }
                                default: {
                                        printf("UNKNOWN");
                                }
@@ -72,7 +110,7 @@ main(void)
        if ((err = monetdb_cleanup_result(mdbe, result)) != NULL)
                error(err)
 
-       if ((err = monetdb_query(mdbe, "SELECT x, y FROM test; ", &result, 
NULL)) != NULL)
+       if ((err = monetdb_query(mdbe, "SELECT * FROM test; ", &result, NULL)) 
!= NULL)
                error(err)
        fprintf(stdout, "Query result after append with %zu cols and %"PRId64" 
rows\n", result->ncols, result->nrows);
        for (int64_t r = 0; r < result->nrows; r++) {
@@ -98,6 +136,43 @@ main(void)
                                        }
                                        break;
                                }
+                               case monetdb_timestamp: {
+                                       monetdb_column_timestamp * col = 
(monetdb_column_timestamp *) rcol[c];
+                                       if(col->is_null(col->data[r])) {
+                                               printf("NULL");
+                                       } else {
+                                               printf("%s-%s-%d %s:%s:%s.%d", 
col->data[r].date.day, col->data[r].date.month, col->data[r].date.year,
+                                                                               
                                col->data[r].time.hours, 
col->data[r].time.minutes, col->data[r].time.seconds, col->data[r].time.ms);
+                                       }
+                                       break;
+                               }
+                               case monetdb_date: {
+                                       monetdb_column_date * col = 
(monetdb_column_date *) rcol[c];
+                                       if(col->is_null(col->data[r])) {
+                                               printf("NULL");
+                                       } else {
+                                               printf("%s-%s-%d", 
col->data[r].day, col->data[r].month, col->data[r].year);
+                                       }
+                                       break;
+                               }
+                               case monetdb_time: {
+                                       monetdb_column_time * col = 
(monetdb_column_time *) rcol[c];
+                                       if(col->is_null(col->data[r])) {
+                                               printf("NULL");
+                                       } else {
+                                               printf("%s:%s:%s.%d", 
col->data[r].hours, col->data[r].minutes, col->data[r].seconds, 
col->data[r].ms);
+                                       }
+                                       break;
+                               }
+                               case monetdb_blob: {
+                                       monetdb_column_blob * col = 
(monetdb_column_blob *) rcol[c];
+                                       if(col->is_null(col->data[r])) {
+                                               printf("NULL");
+                                       } else {
+                                               printf("%s", col->data[r].data);
+                                       }
+                                       break;
+                               }
                                default: {
                                        printf("UNKNOWN");
                                }
diff --git a/tools/monetdbe/monetdbe.c b/tools/monetdbe/monetdbe.c
--- a/tools/monetdbe/monetdbe.c
+++ b/tools/monetdbe/monetdbe.c
@@ -836,112 +836,6 @@ monetdbe_cleanup_statement(monetdbe_data
 }
 
 char*
-monetdbe_append(monetdbe_database dbhdl, const char* schema, const char* 
table, monetdbe_column **input /*bat *batids*/, size_t column_count)
-{
-       Client c = (Client) dbhdl;
-       mvc *m;
-       char* msg = MAL_SUCCEED;
-
-       MT_lock_set(&embedded_lock);
-       if ((msg = validate_database_handle(dbhdl, "monetdbe.monetdbe_append")) 
!= MAL_SUCCEED) {
-               MT_lock_unset(&embedded_lock);
-               return msg; //The dbhdl is invalid, there is no transaction 
going
-       }
-
-       if ((msg = getSQLContext(c, NULL, &m, NULL)) != MAL_SUCCEED)
-               goto cleanup;
-        if ((msg = SQLtrans(m)) != MAL_SUCCEED)
-               goto cleanup;
-
-       if (schema == NULL) {
-               msg = createException(MAL, "monetdbe.monetdbe_append", "schema 
parameter is NULL");
-               goto cleanup;
-       }
-       if (table == NULL) {
-               msg = createException(MAL, "monetdbe.monetdbe_append", "table 
parameter is NULL");
-               goto cleanup;
-       }
-       if (input == NULL) {
-               msg = createException(MAL, "monetdbe.monetdbe_append", "input 
parameter is NULL");
-               goto cleanup;
-       }
-       if (column_count < 1) {
-               msg = createException(MAL, "monetdbe.monetdbe_append", 
"column_count must be higher than 0");
-               goto cleanup;
-       }
-
-       sql_schema *s;
-       sql_table *t;
-
-       if (schema) {
-               if (!(s = mvc_bind_schema(m, schema))) {
-                       msg = createException(MAL, "monetdbe.monetdbe_append", 
"Schema missing %s", schema);
-                       goto cleanup;
-               }
-       } else {
-               s = cur_schema(m);
-       }
-       if (!(t = mvc_bind_table(m, s, table))) {
-               msg = createException(SQL, "monetdbe.monetdbe_append", "Table 
missing %s.%s", schema, table);
-               goto cleanup;
-       }
-       
-       /* for now no default values, ie user should supply all columns */
-
-       if (column_count != (size_t)list_length(t->columns.set)) {
-               msg = createException(SQL, "monetdbe.monetdbe_append", 
"Incorrect number of columns");
-               goto cleanup;
-       }
-
-       /* small number of rows */
-       if (input[0]->count <= 16) {
-               size_t i, cnt = input[0]->count;
-               node *n;
-
-               for (i = 0, n = t->columns.set->h; i < column_count && n; i++, 
n = n->next) {
-                       sql_column *c = n->data;
-                       int mtype = monetdbe_type(input[i]->type);
-                       char *v = input[i]->data;
-                       int w = 1;
-
-                       if (mtype < 0) {
-                               msg = createException(SQL, 
"monetdbe.monetdbe_append", "Cannot find type for column %zu", i);
-                               goto cleanup;
-                       }
-                       if (mtype >= TYPE_bit && mtype <= TYPE_dbl) {
-                               w = BATatoms[mtype].size;
-                               for (size_t j=0; j<cnt; j++, v+=w){
-                                       if 
(store_funcs.append_col(m->session->tr, c, v, mtype) != 0) {
-                                               msg = createException(SQL, 
"monetdbe.monetdbe_append", "Cannot append values");
-                                               goto cleanup;
-                                       }
-                               }
-                       } else if (mtype == TYPE_str) {
-                               char **d = (char**)v;
-
-                               for (size_t j=0; j<cnt; j++){
-                                       char *s = d[j];
-                                       if (!s)
-                                               s = (char*)str_nil;
-                                       if 
(store_funcs.append_col(m->session->tr, c, s, mtype) != 0) {
-                                               msg = createException(SQL, 
"monetdbe.monetdbe_append", "Cannot append values");
-                                               goto cleanup;
-                                       }
-                               }
-                       }
-                       /* TODO blob, temperal */
-               }
-       } else { 
-               msg = createException(SQL, "monetdbe.monetdbe_append", "TODO 
bulk insert");
-               goto cleanup;
-       }
-cleanup:
-       msg = commit_action(m, msg, NULL, NULL, NULL);
-       MT_lock_unset(&embedded_lock);
-       return msg;
-}
-
-char*
 monetdbe_cleanup_result(monetdbe_database dbhdl, monetdbe_result* result)
 {
        char* msg = MAL_SUCCEED;
@@ -1136,6 +1030,156 @@ GENERATE_BASE_HEADERS(monetdbe_data_time
 static void data_from_date(date d, monetdbe_data_date *ptr);
 static void data_from_time(daytime d, monetdbe_data_time *ptr);
 static void data_from_timestamp(timestamp d, monetdbe_data_timestamp *ptr);
+static timestamp timestamp_from_data(monetdbe_data_timestamp *ptr);
+static date date_from_data(monetdbe_data_date *ptr);
+static daytime time_from_data(monetdbe_data_time *ptr);
+
+char*
+monetdbe_append(monetdbe_database dbhdl, const char* schema, const char* 
table, monetdbe_column **input /*bat *batids*/, size_t column_count)
+{
+       Client c = (Client) dbhdl;
+       mvc *m;
+       char* msg = MAL_SUCCEED;
+
+       MT_lock_set(&embedded_lock);
+       if ((msg = validate_database_handle(dbhdl, "monetdbe.monetdbe_append")) 
!= MAL_SUCCEED) {
+               MT_lock_unset(&embedded_lock);
+               return msg; //The dbhdl is invalid, there is no transaction 
going
+       }
+
+       if ((msg = getSQLContext(c, NULL, &m, NULL)) != MAL_SUCCEED)
+               goto cleanup;
+        if ((msg = SQLtrans(m)) != MAL_SUCCEED)
+               goto cleanup;
+
+       if (schema == NULL) {
+               msg = createException(MAL, "monetdbe.monetdbe_append", "schema 
parameter is NULL");
+               goto cleanup;
+       }
+       if (table == NULL) {
+               msg = createException(MAL, "monetdbe.monetdbe_append", "table 
parameter is NULL");
+               goto cleanup;
+       }
+       if (input == NULL) {
+               msg = createException(MAL, "monetdbe.monetdbe_append", "input 
parameter is NULL");
+               goto cleanup;
+       }
+       if (column_count < 1) {
+               msg = createException(MAL, "monetdbe.monetdbe_append", 
"column_count must be higher than 0");
+               goto cleanup;
+       }
+
+       sql_schema *s;
+       sql_table *t;
+
+       if (schema) {
+               if (!(s = mvc_bind_schema(m, schema))) {
+                       msg = createException(MAL, "monetdbe.monetdbe_append", 
"Schema missing %s", schema);
+                       goto cleanup;
+               }
+       } else {
+               s = cur_schema(m);
+       }
+       if (!(t = mvc_bind_table(m, s, table))) {
+               msg = createException(SQL, "monetdbe.monetdbe_append", "Table 
missing %s.%s", schema, table);
+               goto cleanup;
+       }
+       
+       /* for now no default values, ie user should supply all columns */
+
+       if (column_count != (size_t)list_length(t->columns.set)) {
+               msg = createException(SQL, "monetdbe.monetdbe_append", 
"Incorrect number of columns");
+               goto cleanup;
+       }
+
+       /* small number of rows */
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to