# HG changeset patch # User František Kučera # Date 1551195405 -3600 # Node ID 3058712548389ef8079f8d43c7e63a45e0ca25bb # Parent 0fb3b92e01c573297a9e04f2c4f1cc1a32be1448 TabularFormatter: add support for SQLXML values diff -r 0fb3b92e01c5 -r 305871254838 java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java Tue Feb 26 15:57:49 2019 +0100 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java Tue Feb 26 16:36:45 2019 +0100 @@ -26,7 +26,11 @@ import info.globalcode.sql.dk.configuration.PropertyDeclaration; import static info.globalcode.sql.dk.formatting.CommonProperties.COLORFUL; import static info.globalcode.sql.dk.formatting.CommonProperties.COLORFUL_DESCRIPTION; +import java.sql.SQLException; +import java.sql.SQLXML; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; /** *

@@ -34,8 +38,8 @@ *

* *

- * Longer values might break the table – overflow the cells – see alternative tabular formatters - * and the {@linkplain #PROPERTY_TRIM} property. + * Longer values might break the table – overflow the cells – see alternative tabular formatters and + * the {@linkplain #PROPERTY_TRIM} property. *

* * @author Ing. František Kučera (frantovo.cz) @@ -48,6 +52,7 @@ @PropertyDeclaration(name = TabularFormatter.PROPERTY_HEADER_TYPE, defaultValue = "true", type = Boolean.class, description = "whether to print data types in column headers") public class TabularFormatter extends AbstractFormatter { + private static final Logger log = Logger.getLogger(TabularFormatter.class.getName()); public static final String NAME = "tabular"; // bash-completion:formatter private static final String HEADER_TYPE_PREFIX = " ("; private static final String HEADER_TYPE_SUFFIX = ")"; @@ -139,10 +144,8 @@ } /** - * Must be called before - * {@linkplain #updateColumnWidth(int, int)} - * and {@linkplain #getColumnWidth(int)} - * for each result set. + * Must be called before {@linkplain #updateColumnWidth(int, int)} and + * {@linkplain #getColumnWidth(int)} for each result set. * * @param columnCount number of columns in current result set */ @@ -203,6 +206,15 @@ if (value instanceof Number || value instanceof Boolean) { result = lpad(String.valueOf(value), width); } else { + if (value instanceof SQLXML) { + // TODO: move to a common method, share with other formatters + try { + value = ((SQLXML) value).getString(); + } catch (SQLException e) { + log.log(Level.SEVERE, "Unable to format XML", e); + } + } + result = rpad(String.valueOf(value), width); } // ? value = (boolean) value ? "✔" : "✗";