java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java
branchv_0
changeset 234 305871254838
parent 227 0094319a274a
--- 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;
 
 /**
  * <p>
@@ -34,8 +38,8 @@
  * </p>
  *
  * <p>
- * 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.
  * </p>
  *
  * @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 ? "✔" : "✗";