Changeset: 48400c405c2b for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=48400c405c2b
Added Files:
        sql/test/BugTracker-2016/Tests/string-length.Bug-3999.sql
        sql/test/BugTracker-2016/Tests/string-length.Bug-3999.stable.err
        sql/test/BugTracker-2016/Tests/string-length.Bug-3999.stable.out
Modified Files:
        java/ChangeLog.Jul2015
        java/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
        java/src/main/java/nl/cwi/monetdb/util/SQLExporter.java
        monetdb5/mal/mal_namespace.c
        sql/jdbc/tests/Tests/Test_JdbcClient.stable.out
        sql/test/BugTracker-2016/Tests/All
        sql/test/BugTracker-2016/Tests/storagemodel.stable.out
        sql/test/BugTracker/Tests/authorization.SF-1430616.stable.out
        sql/test/BugTracker/Tests/bug_in_selection.SF-1892413.stable.out
        sql/test/Users/Tests/copyinto.SQL.py
        sql/test/Users/Tests/copyinto.stable.err
        sql/test/Users/Tests/dropManyUsers.Bug-3764.SQL.py
        sql/test/Users/Tests/dropManyUsers.Bug-3764.stable.out
        sql/test/Users/Tests/test_privs2_p1.stable.out
        sql/test/bugs/Tests/except-union-intersect-bug-sf-1146079.stable.out
Branch: default
Log Message:

Merge with Jun2016 branch.


diffs (truncated from 990 to 300 lines):

diff --git a/java/ChangeLog.Jul2015 b/java/ChangeLog.Jul2015
--- a/java/ChangeLog.Jul2015
+++ b/java/ChangeLog.Jul2015
@@ -1,7 +1,18 @@
 # ChangeLog file for java
 # This file is updated with Maddlog
 
+* Thu May 12 2016 Martin van Dinther <martin.van.dint...@monetdbsolutions.com>
+- Improved JdbcClient program when presenting query data to console.
+  It used to send an SQL catalog query for each query result column
+  which slowed down the interactive response considerably.
+  These additional SQL catalog queries have been eliminated.
+
+* Thu May 12 2016 Martin van Dinther <martin.van.dint...@monetdbsolutions.com>
+- Corrected MonetResultSet.getObject(String columnName). It no longer
+  throws a NullPointerException in cases where internally a
+  MonetVirtualResultSet is used.
+
 * Sun May  8 2016 Jennie Zhang <y.zh...@cwi.nl>
 - Fixed Connection.isValid(): this method should never attempt to
-  close the connection, even an error has occurred
+  close the connection, even if an error has occurred.
 
diff --git a/java/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java 
b/java/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
--- a/java/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
+++ b/java/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
@@ -2018,7 +2018,7 @@ public class MonetResultSet extends Mone
         */
        @Override
        public Object getObject(String columnName) throws SQLException {
-               return getObject(columnName, 
this.getStatement().getConnection().getTypeMap());
+               return getObject(findColumn(columnName));
        }
 
        /**
diff --git a/java/src/main/java/nl/cwi/monetdb/util/SQLExporter.java 
b/java/src/main/java/nl/cwi/monetdb/util/SQLExporter.java
--- a/java/src/main/java/nl/cwi/monetdb/util/SQLExporter.java
+++ b/java/src/main/java/nl/cwi/monetdb/util/SQLExporter.java
@@ -402,21 +402,22 @@ public class SQLExporter extends Exporte
        public void resultSetToTable(ResultSet rs) throws SQLException {
                ResultSetMetaData md = rs.getMetaData();
                int cols = md.getColumnCount();
-               // find the presentation widths of the columns
-               int[] width = new int[cols +1];
-               for (int j = 1; j <= cols; j++) {
-                       int displaySize = md.getColumnDisplaySize(j);
-                       int labelLength = md.getColumnLabel(j).length();
-                       width[j] = (displaySize > labelLength) ? displaySize : 
labelLength;
-                       if (md.isNullable(j) != 
ResultSetMetaData.columnNoNulls) {
-                               width[j] = Math.max("<NULL>".length(), 
width[j]);
-                       }
+               // find the optimal display widths of the columns
+               int[] width = new int[cols + 1];
+               boolean[] isSigned = new boolean[cols + 1];
+               for (int j = 1; j < width.length; j++) {
+                       int coldisplaysize = md.getColumnDisplaySize(j);
+                       int collabellength = md.getColumnLabel(j).length();
+                       int maxwidth = (coldisplaysize > collabellength) ? 
coldisplaysize : collabellength;
+                       // the minimum width should be 4 to represent: "NULL"
+                       width[j] = (maxwidth > 4) ? maxwidth : 4;
+                       isSigned[j] = md.isSigned(j);
                }
 
-               // print header
+               // print the header text
                out.print("+");
                for (int j = 1; j < width.length; j++)
-                       out.print(repeat('-', width[j] +1) + "-+");
+                       out.print(repeat('-', width[j] + 1) + "-+");
                out.println();
 
                out.print("|");
@@ -439,26 +440,33 @@ public class SQLExporter extends Exporte
                                Object rdata = rs.getObject(j);
                                String data;
                                if (rdata == null || rs.wasNull()) {
-                                       data = "<NULL>";
+                                       data = "NULL";
                                } else {
                                        data = rdata.toString();
+                                       if (data == null)
+                                               data = "NULL";
                                }
-                               String filler = repeat(' ', Math.max(width[j] - 
data.length(), 0));
-                               if (md.isSigned(j)) {
-                                       // we have a numeric type here, right 
align presented data
-                                       out.print(" " + filler + data +  " |");
+
+                               int filler_length = width[j] - data.length();
+                               if (filler_length <= 0) {
+                                       out.print(" " + data + " |");
                                } else {
-                                       // something else
-                                       out.print(" " + data + filler +  " |");
+                                       if (isSigned[j]) {
+                                               // we have a numeric type here, 
right align
+                                               out.print(" " + repeat(' ', 
filler_length) + data + " |");
+                                       } else {
+                                               // all other left align
+                                               out.print(" " + data + repeat(' 
', filler_length) + " |");
+                                       }
                                }
                        }
                        out.println();
                }
 
-               // print footer
+               // print the footer text
                out.print("+");
                for (int j = 1; j < width.length; j++)
-                       out.print(repeat('-', width[j] +1) + "-+");
+                       out.print(repeat('-', width[j] + 1) + "-+");
                out.println();
 
                out.println(count + " row" + (count != 1 ? "s" : ""));
diff --git a/monetdb5/mal/mal_namespace.c b/monetdb5/mal/mal_namespace.c
--- a/monetdb5/mal/mal_namespace.c
+++ b/monetdb5/mal/mal_namespace.c
@@ -36,9 +36,9 @@
 
 
 typedef struct NAME{
-       str nme;
        size_t length;
        struct NAME *next;
+       char nme[FLEXIBLE_ARRAY_MEMBER];
 } *NamePtr;
 
 static NamePtr *hash= NULL, *ehash = NULL;
@@ -64,8 +64,6 @@ void mal_namespace_reset(void) {
                hash[i] = ehash[i] = 0;
                for( ; n; n = m){
                        m = n->next;
-                       if (n->nme)
-                               GDKfree(n->nme);
                        GDKfree(n);
                }
        }
@@ -130,7 +128,6 @@ str putNameLen(const char *nme, size_t l
 {
        size_t l,k;
        int key;
-       char buf[MAXIDENTLEN];
        str fnd;
        NamePtr n;
 
@@ -142,24 +139,18 @@ str putNameLen(const char *nme, size_t l
                return NULL;
 
        /* construct a new entry */
-       n = (NamePtr) GDKzalloc(sizeof(*n));
+       if(len>=MAXIDENTLEN)
+               len = MAXIDENTLEN - 1;
+       n = GDKmalloc(offsetof(struct NAME, nme) + len + 1);
        if ( n == NULL) {
         /* absolute an error we can not recover from */
         showException(GDKout, MAL,"initNamespace",MAL_MALLOC_FAIL);
                mal_exit();
        }
-       if(len>=MAXIDENTLEN)
-               len = MAXIDENTLEN - 1;
-       memcpy(buf, nme, len);
-       buf[len]=0;
-       n->nme= GDKstrdup(buf);
-       if (n->nme == NULL) {
-        /* absolute an error we can not recover from */
-               GDKfree(n);
-        showException(GDKout, MAL,"initNamespace",MAL_MALLOC_FAIL);
-               mal_exit();
-       }
+       memcpy(n->nme, nme, len);
+       n->nme[len]=0;
        n->length = len;
+       n->next = NULL;
        l = len;
        NME_HASH(nme, k, l);
        key = (int) k;
diff --git a/sql/jdbc/tests/Tests/Test_JdbcClient.stable.out 
b/sql/jdbc/tests/Tests/Test_JdbcClient.stable.out
--- a/sql/jdbc/tests/Tests/Test_JdbcClient.stable.out
+++ b/sql/jdbc/tests/Tests/Test_JdbcClient.stable.out
@@ -86,30 +86,30 @@ 1 affected row
 
 1 affected row
 
-+----+---------+-----------+--------+----------+
-| id | subject | predicate | object | explicit |
-+====+=========+===========+========+==========+
-|  1 |       1 |         1 |      1 | false    |
-|  2 |       1 |         1 |      2 | false    |
-|  3 |       1 |         2 |      1 | false    |
-|  4 |       2 |         1 |      1 | false    |
-|  5 |       1 |         2 |      2 | false    |
-|  6 |       2 |         2 |      1 | false    |
-|  7 |       2 |         2 |      2 | false    |
-+----+---------+-----------+--------+----------+
++------+---------+-----------+--------+----------+
+| id   | subject | predicate | object | explicit |
++======+=========+===========+========+==========+
+|    1 |       1 |         1 |      1 | false    |
+|    2 |       1 |         1 |      2 | false    |
+|    3 |       1 |         2 |      1 | false    |
+|    4 |       2 |         1 |      1 | false    |
+|    5 |       1 |         2 |      2 | false    |
+|    6 |       2 |         2 |      1 | false    |
+|    7 |       2 |         2 |      2 | false    |
++------+---------+-----------+--------+----------+
 7 rows
 
-+----+---------+-----------+--------+
-| id | subject | predicate | object |
-+====+=========+===========+========+
-|  1 |       1 |         1 |      1 |
-|  2 |       2 |         2 |      2 |
-|  3 |       1 |         2 |      2 |
-|  4 |       2 |         2 |      1 |
-|  5 |       2 |         1 |      1 |
-|  6 |       1 |         2 |      1 |
-|  7 |       1 |         1 |      2 |
-+----+---------+-----------+--------+
++------+---------+-----------+--------+
+| id   | subject | predicate | object |
++======+=========+===========+========+
+|    1 |       1 |         1 |      1 |
+|    2 |       2 |         2 |      2 |
+|    3 |       1 |         2 |      2 |
+|    4 |       2 |         2 |      1 |
+|    5 |       2 |         1 |      1 |
+|    6 |       1 |         2 |      1 |
+|    7 |       1 |         1 |      2 |
++------+---------+-----------+--------+
 7 rows
 
 Operation successful
diff --git a/sql/test/BugTracker-2016/Tests/All 
b/sql/test/BugTracker-2016/Tests/All
--- a/sql/test/BugTracker-2016/Tests/All
+++ b/sql/test/BugTracker-2016/Tests/All
@@ -31,3 +31,4 @@ subcorr-missing.Bug-3978
 epoch.Bug-3979
 fk-smaller-pk.Bug-3983
 isaUUID_function.Bug-3997
+string-length.Bug-3999
diff --git a/sql/test/BugTracker-2016/Tests/string-length.Bug-3999.sql 
b/sql/test/BugTracker-2016/Tests/string-length.Bug-3999.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2016/Tests/string-length.Bug-3999.sql
@@ -0,0 +1,43 @@
+SELECT length('123 ') as "four";
+SELECT length('123       ') as "ten";
+SELECT length('1234567890') as "ten";
+SELECT length('     67890') as "ten";
+SELECT length(reverse('     67890')) as "ten";
+
+SELECT sys.length('123 ') as "four";
+SELECT sys.length('123       ') as "ten";
+SELECT sys.length('1234567890') as "ten";
+SELECT sys.length('     67890') as "ten";
+SELECT sys.length(reverse('     67890')) as "ten";
+
+-- test trailing spaces with VarChar
+CREATE TABLE tvarchar (val VARCHAR(9) NOT NULL);
+INSERT INTO tvarchar VALUES ('A'), (' BC ');
+SELECT val, length(val) FROM tvarchar;
+-- returned wrong length for second row
+
+UPDATE tvarchar SET val = val || '    ';
+SELECT val, length(val) FROM tvarchar;
+-- returned wrong length for both rows
+
+UPDATE tvarchar SET val = (val || 'x');
+SELECT val, length(val) FROM tvarchar;
+
+DROP TABLE tvarchar;
+
+
+-- test trailing spaces with Char
+CREATE TABLE tchar (val CHAR(9) NOT NULL);
+INSERT INTO tchar VALUES ('A'), (' BC ');
+SELECT val, length(val) FROM tchar;
+-- returned wrong length for second row
+
+UPDATE tchar SET val = val || '    ';
+SELECT val, length(val) FROM tchar;
+-- returned wrong length for both rows
+
+UPDATE tchar SET val = (val || 'x');
+SELECT val, length(val) FROM tchar;
+
+DROP TABLE tchar;
+
diff --git a/sql/test/BugTracker-2016/Tests/string-length.Bug-3999.stable.err 
b/sql/test/BugTracker-2016/Tests/string-length.Bug-3999.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2016/Tests/string-length.Bug-3999.stable.err
@@ -0,0 +1,38 @@
+stderr of test 'string-length.Bug-3999` in directory 
'sql/test/BugTracker-2016` itself:
+
+
+# 11:44:26 >  
+# 11:44:26 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=30837" "--set" 
"mapi_usock=/var/tmp/mtest-9650/.s.monetdb.30837" "--set" "monet_prompt=" 
"--forcemito" "--set" "mal_listing=2" 
"--dbpath=/export/scratch2/dinther/INSTALL/var/MonetDB/mTests_sql_test_BugTracker-2016"
 "--set" "mal_listing=0" "--set" "embedded_r=yes"
+# 11:44:26 >  
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to