TabularFormatter: add support for SQLXML values v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Tue, 26 Feb 2019 16:36:45 +0100
branchv_0
changeset 234305871254838
parent 233 0fb3b92e01c5
child 235 8ce612cca4d8
TabularFormatter: add support for SQLXML values
java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java	Tue Feb 26 15:57:49 2019 +0100
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java	Tue Feb 26 16:36:45 2019 +0100
     1.3 @@ -26,7 +26,11 @@
     1.4  import info.globalcode.sql.dk.configuration.PropertyDeclaration;
     1.5  import static info.globalcode.sql.dk.formatting.CommonProperties.COLORFUL;
     1.6  import static info.globalcode.sql.dk.formatting.CommonProperties.COLORFUL_DESCRIPTION;
     1.7 +import java.sql.SQLException;
     1.8 +import java.sql.SQLXML;
     1.9  import java.util.List;
    1.10 +import java.util.logging.Level;
    1.11 +import java.util.logging.Logger;
    1.12  
    1.13  /**
    1.14   * <p>
    1.15 @@ -34,8 +38,8 @@
    1.16   * </p>
    1.17   *
    1.18   * <p>
    1.19 - * Longer values might break the table – overflow the cells – see alternative tabular formatters
    1.20 - * and the {@linkplain #PROPERTY_TRIM} property.
    1.21 + * Longer values might break the table – overflow the cells – see alternative tabular formatters and
    1.22 + * the {@linkplain #PROPERTY_TRIM} property.
    1.23   * </p>
    1.24   *
    1.25   * @author Ing. František Kučera (frantovo.cz)
    1.26 @@ -48,6 +52,7 @@
    1.27  @PropertyDeclaration(name = TabularFormatter.PROPERTY_HEADER_TYPE, defaultValue = "true", type = Boolean.class, description = "whether to print data types in column headers")
    1.28  public class TabularFormatter extends AbstractFormatter {
    1.29  
    1.30 +	private static final Logger log = Logger.getLogger(TabularFormatter.class.getName());
    1.31  	public static final String NAME = "tabular"; // bash-completion:formatter
    1.32  	private static final String HEADER_TYPE_PREFIX = " (";
    1.33  	private static final String HEADER_TYPE_SUFFIX = ")";
    1.34 @@ -139,10 +144,8 @@
    1.35  	}
    1.36  
    1.37  	/**
    1.38 -	 * Must be called before
    1.39 -	 * {@linkplain #updateColumnWidth(int, int)}
    1.40 -	 * and {@linkplain #getColumnWidth(int)}
    1.41 -	 * for each result set.
    1.42 +	 * Must be called before {@linkplain #updateColumnWidth(int, int)} and
    1.43 +	 * {@linkplain #getColumnWidth(int)} for each result set.
    1.44  	 *
    1.45  	 * @param columnCount number of columns in current result set
    1.46  	 */
    1.47 @@ -203,6 +206,15 @@
    1.48  		if (value instanceof Number || value instanceof Boolean) {
    1.49  			result = lpad(String.valueOf(value), width);
    1.50  		} else {
    1.51 +			if (value instanceof SQLXML) {
    1.52 +				// TODO: move to a common method, share with other formatters
    1.53 +				try {
    1.54 +					value = ((SQLXML) value).getString();
    1.55 +				} catch (SQLException e) {
    1.56 +					log.log(Level.SEVERE, "Unable to format XML", e);
    1.57 +				}
    1.58 +			}
    1.59 +
    1.60  			result = rpad(String.valueOf(value), width);
    1.61  		}
    1.62  		// ?	value = (boolean) value ? "✔" : "✗";