Changeset: 2f8a7bf0190d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/2f8a7bf0190d
Modified Files:
        sql/backends/monet5/rel_bin.c
        sql/server/rel_unnest.c
Branch: reducedstack
Log Message:

merged with default


diffs (truncated from 926 to 300 lines):

diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -3770,12 +3770,13 @@ main(int argc, char **argv)
        mapi_setfilecallback2(mid, getfile, putfile, &priv);
 
        mapi_trace(mid, trace);
+       if (!has_fileargs && command == NULL && isatty(fileno(stdin)))
+               catch_interrupts(mid);
+
        /* give the user a welcome message with some general info */
        if (!quiet && !has_fileargs && command == NULL && 
isatty(fileno(stdin))) {
                char *lang;
 
-               catch_interrupts(mid);
-
                if (mode == SQL) {
                        lang = "/SQL";
                } else {
diff --git a/misc/selinux/monetdb.te b/misc/selinux/monetdb.te
--- a/misc/selinux/monetdb.te
+++ b/misc/selinux/monetdb.te
@@ -8,7 +8,7 @@
 # Copyright August 2008 - 2023 MonetDB B.V.;
 # Copyright 1997 - July 2008 CWI.
 
-policy_module(monetdb, 1.4)
+policy_module(monetdb, 1.5)
 # The above line declares that this file is a SELinux policy file. Its
 # name is monetdb, so the file should be saved as monetdb.te
 
@@ -28,7 +28,7 @@ require {
        class fifo_file { getattr read write };
        class file { entrypoint execute getattr manage_file_perms map open read 
};
        class netlink_selinux_socket create_socket_perms;
-       class process { rlimitinh siginh signal sigchld sigkill transition };
+       class process { rlimitinh siginh signal sigchld sigkill signull 
transition };
        class tcp_socket create_stream_socket_perms;
        class udp_socket create_stream_socket_perms;
        class unix_dgram_socket create_socket_perms;
@@ -58,7 +58,7 @@ type_transition monetdbd_t mserver5_exec
 allow monetdbd_t mserver5_t:process sigkill;
 # on EPEL 7 we need these as well
 allow mserver5_t monetdbd_t:process sigchld;
-allow monetdbd_t unconfined_service_t:process signal;
+allow monetdbd_t unconfined_service_t:process { signal signull };
 allow mserver5_t proc_t:file { open read getattr };      # read /proc/meminfo
 
 # declare a type for the systemd unit file (monetdbd.service)
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -1812,8 +1812,8 @@ exp_bin(backend *be, sql_exp *e, stmt *l
                                                orderby_grp = stmt_result(be, 
orderby, 2);
                                        }
                                        /* depending on type of aggr project 
input or ordered column */
-                                       stmt *h = l->h->data;
-                                       l->h->data = h = stmt_project(be, 
orderby_ids, h);
+                                       for (node *n = l->h; n; n = n->next)
+                                               n->data = stmt_project(be, 
orderby_ids, n->data);
                                        if (grp)
                                                grp = stmt_project(be, 
orderby_ids, grp);
                                        (void)orderby_vals;
diff --git a/sql/backends/monet5/vaults/odbc/odbc_loader.c 
b/sql/backends/monet5/vaults/odbc/odbc_loader.c
--- a/sql/backends/monet5/vaults/odbc/odbc_loader.c
+++ b/sql/backends/monet5/vaults/odbc/odbc_loader.c
@@ -37,9 +37,13 @@
 #define ODBC_RELATION 1
 #define ODBC_LOADER   2
 
+/* some generic limitations on ODBC query result and buffer sizes for getting 
variable length data values */
 #define QUERY_MAX_COLUMNS 4096
 #define MAX_COL_NAME_LEN  1023
 #define MAX_TBL_NAME_LEN  1023
+/* limit data size for one field value to 16 MB */
+#define MAX_CHAR_STR_SIZE 16777215
+#define MAX_BIN_DATA_SIZE 16777216
 
 #ifdef HAVE_HGE
 #define MAX_PREC  38
@@ -76,37 +80,37 @@ map_rescol_type(SQLSMALLINT dataType, SQ
        case SQL_WVARCHAR:
        case SQL_WLONGVARCHAR:
        default:        /* all other ODBC types are also mapped to varchar for 
now */
+       {
                /* all ODBC char datatypes are mapped to varchar. char and clob 
are internally not used anymore */
                if (columnSize > (SQLULEN) INT_MAX)
                        columnSize = INT_MAX;
                return sql_bind_subtype(sql->sa, "varchar", (unsigned int) 
columnSize, 0);
+       }
 
        case SQL_BINARY:
        case SQL_VARBINARY:
        case SQL_LONGVARBINARY:
+       {
                if (columnSize > (SQLULEN) INT_MAX)
                        columnSize = INT_MAX;
                return sql_bind_subtype(sql->sa, "blob", (unsigned int) 
columnSize, 0);
+       }
 
        case SQL_DECIMAL:
        case SQL_NUMERIC:
        {
                /* columnSize contains the defined number of digits, so 
precision. */
                /* decimalDigits contains the scale (which can be negative). */
-               if (columnSize > MAX_PREC || abs(decimalDigits) > MAX_PREC) {
-                       /* too large precision/scale, not supported by MonetDB. 
Map this column to a string */
-                       if (columnSize > (SQLULEN) INT_MAX)
-                               columnSize = INT_MAX;
+               if (columnSize > MAX_PREC || columnSize < 1 || decimalDigits < 0
+                || decimalDigits > MAX_PREC || (int) decimalDigits > (int) 
columnSize) {
+                       /* too large precision/scale or negative scale are NOT 
supported by MonetDB. Map this column to a string bat type */
+                       if (columnSize > (SQLULEN) INT_MAX -3)
+                               columnSize = INT_MAX -3;
                        return sql_bind_subtype(sql->sa, "varchar", (unsigned 
int) columnSize +3, 0);
                }
+               return sql_bind_subtype(sql->sa, "decimal", (unsigned int) 
columnSize, (unsigned int) decimalDigits);
+       }
 
-               return sql_bind_subtype(sql->sa, "varchar", (unsigned int) 
columnSize +3, 0);
-//             unsigned int prec = MAX(1, columnSize); /* precision must be >= 
1 */
-//             unsigned int scale = MAX(0, decimalDigits); /* negative scales 
are not supported by MonetDB */
-//             if (prec < scale)
-//                     prec = scale;   /* make precision large enough to 
contain all decimal digits */
-//             return sql_bind_subtype(sql->sa, "decimal", prec, scale);
-       }
        case SQL_GUID:
        {
                /* represents a uuid of length 36, such as: 
dbe7343c-1f11-4fa9-a9c8-a31cd26f92fe */
@@ -296,35 +300,6 @@ nameOfRetCode(SQLRETURN code)
        }
 }
 
-#ifdef HAVE_HGE
-static hge
-str_to_hge(const char *s) {
-       char c;
-       char sign = '+';
-       int i = 0;
-       hge ret = 0;
-
-       if (!s)
-               return 0;
-
-       c = s[i];
-       if (c == '-' || c == '+') {
-               sign = c;
-               c = s[++i];
-       }
-       while (c) {
-               if (c >= '0' && c <= '9') {
-                       ret *= 10;
-                       ret += (int) c - '0';
-               }
-               c = s[++i];
-       }
-       if (sign == '-')
-               ret = -ret;
-       return ret;
-}
-#endif
-
 /* an ODBC function call returned an error, get the error msg from the ODBC 
driver */
 static char *
 getErrMsg(SQLSMALLINT handleType, SQLHANDLE handle) {
@@ -407,6 +382,132 @@ bat_create(int adt, BUN nr)
        return b;
 }
 
+/* convert decimal values to lng as needed by MonetDB decimal storage type.
+ * we require the precision and scale specification of the column.
+ */
+static lng
+decstr_to_lng(const char *s, int prec, SQLSMALLINT scale) {
+       char c;
+       char sign = '+';
+       int i = 0;
+       int digits = 0;
+       SQLSMALLINT decdigits = -1;
+       int decsep = -1;
+       lng ret = 0;
+
+       if (!s)
+               return 0;
+
+       c = s[i];
+       if (c == '-' || c == '+') {
+               sign = c;
+               c = s[++i];
+       }
+       while (c) {
+               if (digits > prec || decdigits >= scale)
+                       break;  // we have read enough
+               if (c >= '0' && c <= '9') {
+                       ret *= 10;
+                       ret += (int) c - '0';
+                       digits++;
+                       if (decsep >= 0)
+                               decdigits++;
+               } else if (c == '.') {
+                       if (decsep < 0) {
+                               decsep = i;
+                               decdigits = 0;
+                       }
+               }
+               c = s[++i];
+       }
+       if (decdigits == -1)
+               decdigits = 0;
+       while (decdigits < scale) {
+               // align to the scale number of digits
+               ret *= 10;
+               decdigits++;
+       }
+       if (sign == '-')
+               ret = -ret;
+       return ret;
+}
+
+#ifdef HAVE_HGE
+static hge
+decstr_to_hge(const char *s, int prec, SQLSMALLINT scale) {
+       char c;
+       char sign = '+';
+       int i = 0;
+       int digits = 0;
+       SQLSMALLINT decdigits = -1;
+       int decsep = -1;
+       hge ret = 0;
+
+       if (!s)
+               return 0;
+
+       c = s[i];
+       if (c == '-' || c == '+') {
+               sign = c;
+               c = s[++i];
+       }
+       while (c) {
+               if (digits > prec || decdigits >= scale)
+                       break;  // we have read enough
+               if (c >= '0' && c <= '9') {
+                       ret *= 10;
+                       ret += (int) c - '0';
+                       digits++;
+                       if (decsep >= 0)
+                               decdigits++;
+               } else if (c == '.') {
+                       if (decsep < 0) {
+                               decsep = i;
+                               decdigits = 0;
+                       }
+               }
+               c = s[++i];
+       }
+       if (decdigits == -1)
+               decdigits = 0;
+       while (decdigits < scale) {
+               // align to the scale
+               ret *= 10;
+               decdigits++;
+       }
+       if (sign == '-')
+               ret = -ret;
+       return ret;
+}
+
+static hge
+str_to_hge(const char *s) {
+       char c;
+       char sign = '+';
+       int i = 0;
+       hge ret = 0;
+
+       if (!s)
+               return 0;
+
+       c = s[i];
+       if (c == '-' || c == '+') {
+               sign = c;
+               c = s[++i];
+       }
+       while (c) {
+               if (c >= '0' && c <= '9') {
+                       ret *= 10;
+                       ret += (int) c - '0';
+               }
+               c = s[++i];
+       }
+       if (sign == '-')
+               ret = -ret;
+       return ret;
+}
+#endif
+
 /* convert interval.day_second.fraction values to millisec fractions as needed 
by MonetDB interval types.
  * we need the columns decimalDigits specification to adjust the fractions 
value to millisec.
  */
@@ -678,7 +779,7 @@ odbc_query(int caller, mvc *sql, sql_sub
                int int_val = 0;
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to