@Override
	public boolean execute(final LineReader reader, final String[] parts, final SqlConfig sqlConfig,
			final Properties props) {
		PrintWriter writer = reader.getTerminal().writer();

		String tableNamePattern = parts.length > 1 ? parts[parts.length - 1] : "%";

		try {
			Connection conn = sqlConfig.getConnectionSupplier().getConnection();
			DatabaseMetaData md = conn.getMetaData();

			List<Map<String, String>> columns = new ArrayList<>();
			Map<String, Integer> labelLength = new HashMap<>();
			for (String label : DESC_COLUMN_LABELS) {
				labelLength.put(label, label.length());
			}
			try (ResultSet rs = md.getColumns(conn.getCatalog(), conn.getSchema(), tableNamePattern, null)) {
				while (rs.next()) {
					Map<String, String> column = new HashMap<>();
					for (String label : DESC_COLUMN_LABELS) {
						final String value = StringUtils.defaultString(rs.getString(label));
						column.put(label, value);
						labelLength.compute(
								label,
								(k, v) -> v == null ? getByteLength(value)
										: v.compareTo(getByteLength(value)) >= 0 ? v : getByteLength(value));
					}
					columns.add(column);
				}
			}

			// ラベル
			writer.print("-");
			for (String label : DESC_COLUMN_LABELS) {
				writer.print(StringUtils.rightPad("", labelLength.get(label), "-"));
				writer.print("-");
			}
			writer.println();
			writer.print("|");
			for (String label : DESC_COLUMN_LABELS) {
				writer.print(StringUtils.rightPad(label, labelLength.get(label)));
				writer.print("|");
			}
			writer.println();
			// カラムデータ
			String tableName = null;
			boolean breakFlag = false;
			for (Map<String, String> column : columns) {
				if (tableName == null || !tableName.equalsIgnoreCase(column.get("TABLE_NAME"))) {
					tableName = column.get("TABLE_NAME");
					breakFlag = true;
				}
				if (breakFlag) {
					writer.print("-");
					for (String label : DESC_COLUMN_LABELS) {
						writer.print(StringUtils.rightPad("", labelLength.get(label), "-"));
						writer.print("-");
					}
					writer.println();
					breakFlag = false;
				}

				writer.print("|");
				for (String label : DESC_COLUMN_LABELS) {
					String val = column.get(label);
					if (StringUtils.isNumeric(val)) {
						writer.print(StringUtils.leftPad(val, labelLength.get(label)));
					} else {
						writer.print(StringUtils.rightPad(val, labelLength.get(label)));
					}
					writer.print("|");
				}
				writer.println();
			}
			writer.print("-");
			for (String label : DESC_COLUMN_LABELS) {
				writer.print(StringUtils.rightPad("", labelLength.get(label), "-"));
				writer.print("-");
			}
			writer.println();
		} catch (SQLException ex) {
			ex.printStackTrace();
		}
		writer.flush();

		return true;
	}
@ Override public boolean execute ( final LineReader reader , final String [ ] parts , final SqlConfig sqlConfig , final Properties props ) { PrintWriter writer = reader . getTerminal ( ) . writer ( ) ; String tableNamePattern = parts . length > 1 ? parts [ parts . length - 1 ] : "%" ; try { Connection conn = sqlConfig . getConnectionSupplier ( ) . getConnection ( ) ; DatabaseMetaData md = conn . getMetaData ( ) ; List < Map < String , String > > columns = new ArrayList < > ( ) ; Map < String , Integer > labelLength = new HashMap < > ( ) ; for ( String label : DESC_COLUMN_LABELS ) { labelLength . put ( label , label . length ( ) ) ; } try ( ResultSet rs = md . getColumns ( conn . getCatalog ( ) , conn . getSchema ( ) , tableNamePattern , null ) ) { while ( rs . next ( ) ) { Map < String , String > column = new HashMap < > ( ) ; for ( String label : DESC_COLUMN_LABELS ) { final String value = StringUtils . defaultString ( rs . getString ( label ) ) ; column . put ( label , value ) ; labelLength . compute ( label , ( k , v ) -> v == null ? getByteLength ( value ) : v . compareTo ( getByteLength ( value ) ) >= 0 ? v : getByteLength ( value ) ) ; } columns . add ( column ) ; } } writer . print ( "-" ) ; for ( String label : DESC_COLUMN_LABELS ) { writer . print ( StringUtils . rightPad ( "" , labelLength . get ( label ) , "-" ) ) ; writer . print ( "-" ) ; } writer . println ( ) ; writer . print ( "|" ) ; for ( String label : DESC_COLUMN_LABELS ) { writer . print ( StringUtils . rightPad ( label , labelLength . get ( label ) ) ) ; writer . print ( "|" ) ; } writer . println ( ) ; String tableName = null ; boolean breakFlag = false ; for ( Map < String , String > column : columns ) { if ( tableName == null || ! tableName . equalsIgnoreCase ( column . get ( "TABLE_NAME" ) ) ) { tableName = column . get ( "TABLE_NAME" ) ; breakFlag = true ; } if ( breakFlag ) { writer . print ( "-" ) ; for ( String label : DESC_COLUMN_LABELS ) { writer . print ( StringUtils . rightPad ( "" , labelLength . get ( label ) , "-" ) ) ; writer . print ( "-" ) ; } writer . println ( ) ; breakFlag = false ; } writer . print ( "|" ) ; for ( String label : DESC_COLUMN_LABELS ) { String val = column . get ( label ) ; if ( StringUtils . isNumeric ( val ) ) { writer . print ( StringUtils . leftPad ( val , labelLength . get ( label ) ) ) ; } else { writer . print ( StringUtils . rightPad ( val , labelLength . get ( label ) ) ) ; } writer . print ( "|" ) ; } writer . println ( ) ; } writer . print ( "-" ) ; for ( String label : DESC_COLUMN_LABELS ) { writer . print ( StringUtils . rightPad ( "" , labelLength . get ( label ) , "-" ) ) ; writer . print ( "-" ) ; } writer . println ( ) ; } catch ( SQLException ex ) { ex . printStackTrace ( ) ; } writer . flush ( ) ; return true ; }
{@inheritDoc}

@see jp.co.future.uroborosql.client.command.ReplCommand#execute(org.jline.reader.LineReader, java.lang.String[], jp.co.future.uroborosql.config.SqlConfig, java.util.Properties)