Changeset: e6a60eeea1cc for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e6a60eeea1cc
Modified Files:
        java/ChangeLog.Jul2015
        java/src/main/java/nl/cwi/monetdb/util/SQLExporter.java
        sql/jdbc/tests/Tests/Test_JdbcClient.stable.out
Branch: Jul2015
Log Message:

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 additonal SQL catalog queries have been eliminated.
This fixes Bug 3711


diffs (166 lines):

diff --git a/java/ChangeLog.Jul2015 b/java/ChangeLog.Jul2015
--- a/java/ChangeLog.Jul2015
+++ b/java/ChangeLog.Jul2015
@@ -1,6 +1,17 @@
 # ChangeLog file for java
 # This file is updated with Maddlog
 
+* Thu May 12 2016 Martin van Dinther <[email protected]>
+- 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 additonal SQL catalog queries have been eliminated.
+
+* Thu May 12 2016 Martin van Dinther <[email protected]>
+- 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 <[email protected]>
 - Fixed Connection.isValid(): this method should never attempt to
   close the connection, even an error has occurred
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
@@ -397,19 +397,19 @@ public class SQLExporter extends Exporte
         */
        public void resultSetToTable(ResultSet rs) throws SQLException {
                ResultSetMetaData md = rs.getMetaData();
-               // find the widths of the columns
+               // find the optimal display widths of the columns
                int[] width = new int[md.getColumnCount()];
-               for (int j = 0; j < md.getColumnCount(); j++) {
-                       if (md.getColumnDisplaySize(j + 1) == 0) {
-                               width[j] = md.getColumnLabel(j + 1).length();
-                       } else {
-                               width[j] = Math.max(md.getColumnDisplaySize(j + 
1), md.getColumnLabel(j + 1).length());
-                       }
-                       if (md.isNullable(j + 1) != 
ResultSetMetaData.columnNoNulls) {
-                               width[j] = Math.max("<NULL>".length(), 
width[j]);
-                       }
+               boolean[] isSigned = new boolean[md.getColumnCount()];
+               for (int j = 0; j < width.length; j++) {
+                       int coldisplaysize = md.getColumnDisplaySize(j + 1);
+                       int collabellength = md.getColumnLabel(j + 1).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 + 1);
                }
 
+               // print the header text
                out.print("+");
                for (int j = 0; j < width.length; j++)
                        out.print("-" + repeat('-', width[j]) + "-+");
@@ -417,7 +417,8 @@ public class SQLExporter extends Exporte
 
                out.print("|");
                for (int j = 0; j < width.length; j++) {
-                       out.print(" " + md.getColumnLabel(j + 1) + repeat(' ', 
width[j] - md.getColumnLabel(j + 1).length()) +  " |");
+                       String colLabel = md.getColumnLabel(j + 1);
+                       out.print(" " + colLabel + repeat(' ', width[j] - 
colLabel.length()) + " |");
                }
                out.println();
 
@@ -426,28 +427,38 @@ public class SQLExporter extends Exporte
                        out.print("=" + repeat('=', width[j]) + "=+");
                out.println();
 
+               // print the body text
                int count = 0;
                for (; rs.next(); count++) {
                        out.print("|");
                        for (int j = 0; j < width.length; j++) {
                                Object rdata = rs.getObject(j + 1);
                                String data;
-                               if (rdata == null) {
-                                       data = "<NULL>";
+                               if (rdata == null || rs.wasNull()) {
+                                       data = "NULL";
                                } else {
                                        data = rdata.toString();
+                                       if (data == null)
+                                               data = "NULL";
                                }
-                               if (md.isSigned(j + 1)) {
-                                       // we have a numeric type here
-                                       out.print(" " + repeat(' ', 
Math.max(width[j] - data.length(), 0)) + data +  " |");
+
+                               int filler_length = width[j] - data.length();
+                               if (filler_length <= 0) {
+                                       out.print(" " + data + " |");
                                } else {
-                                       // something else
-                                       out.print(" " + data + repeat(' ', 
Math.max(width[j] - data.length(), 0)) +  " |");
+                                       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 the footer text
                out.print("+");
                for (int j = 0; j < width.length; j++)
                        out.print("-" + repeat('-', width[j]) + "-+");
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
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to