author | František Kučera <franta-hg@frantovo.cz> |
Thu, 24 Oct 2019 21:43:08 +0200 | |
branch | v_0 |
changeset 250 | aae5009bd0af |
parent 238 | 4a1864c3e867 |
permissions | -rw-r--r-- |
32
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
/** |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
* SQL-DK |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
* Copyright © 2013 František Kučera (frantovo.cz) |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
* |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
250
aae5009bd0af
fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents:
238
diff
changeset
|
7 |
* the Free Software Foundation, version 3 of the License. |
32
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
* |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
* |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
*/ |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
package info.globalcode.sql.dk.formatting; |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
|
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
19 |
import info.globalcode.sql.dk.ColorfulPrintWriter; |
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
20 |
import static info.globalcode.sql.dk.ColorfulPrintWriter.*; |
218
8e38caf43ca8
SingleRecordFormatter: escape whitespace characters in the same way as in TabularFormatter
František Kučera <franta-hg@frantovo.cz>
parents:
207
diff
changeset
|
21 |
import info.globalcode.sql.dk.Functions; |
39
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
22 |
import static info.globalcode.sql.dk.Functions.lpad; |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
23 |
import static info.globalcode.sql.dk.Functions.rpad; |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
24 |
import static info.globalcode.sql.dk.Functions.repeat; |
206
e2f24eea8543
property annotations (documentation) for particular formatters
František Kučera <franta-hg@frantovo.cz>
parents:
185
diff
changeset
|
25 |
import info.globalcode.sql.dk.configuration.PropertyDeclaration; |
e2f24eea8543
property annotations (documentation) for particular formatters
František Kučera <franta-hg@frantovo.cz>
parents:
185
diff
changeset
|
26 |
import static info.globalcode.sql.dk.formatting.CommonProperties.COLORFUL; |
e2f24eea8543
property annotations (documentation) for particular formatters
František Kučera <franta-hg@frantovo.cz>
parents:
185
diff
changeset
|
27 |
import static info.globalcode.sql.dk.formatting.CommonProperties.COLORFUL_DESCRIPTION; |
234
305871254838
TabularFormatter: add support for SQLXML values
František Kučera <franta-hg@frantovo.cz>
parents:
227
diff
changeset
|
28 |
import java.sql.SQLException; |
305871254838
TabularFormatter: add support for SQLXML values
František Kučera <franta-hg@frantovo.cz>
parents:
227
diff
changeset
|
29 |
import java.sql.SQLXML; |
88
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
30 |
import java.util.List; |
234
305871254838
TabularFormatter: add support for SQLXML values
František Kučera <franta-hg@frantovo.cz>
parents:
227
diff
changeset
|
31 |
import java.util.logging.Level; |
305871254838
TabularFormatter: add support for SQLXML values
František Kučera <franta-hg@frantovo.cz>
parents:
227
diff
changeset
|
32 |
import java.util.logging.Logger; |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
33 |
|
32
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
/** |
185
087d8ec75109
Tabular formatter: fix problem with CR (carriage return).
František Kučera <franta-hg@frantovo.cz>
parents:
170
diff
changeset
|
35 |
* <p> |
087d8ec75109
Tabular formatter: fix problem with CR (carriage return).
František Kučera <franta-hg@frantovo.cz>
parents:
170
diff
changeset
|
36 |
* Prints human-readable output – tables of result sets and text messages with update counts. |
087d8ec75109
Tabular formatter: fix problem with CR (carriage return).
František Kučera <franta-hg@frantovo.cz>
parents:
170
diff
changeset
|
37 |
* </p> |
155 | 38 |
* |
185
087d8ec75109
Tabular formatter: fix problem with CR (carriage return).
František Kučera <franta-hg@frantovo.cz>
parents:
170
diff
changeset
|
39 |
* <p> |
234
305871254838
TabularFormatter: add support for SQLXML values
František Kučera <franta-hg@frantovo.cz>
parents:
227
diff
changeset
|
40 |
* Longer values might break the table – overflow the cells – see alternative tabular formatters and |
305871254838
TabularFormatter: add support for SQLXML values
František Kučera <franta-hg@frantovo.cz>
parents:
227
diff
changeset
|
41 |
* the {@linkplain #PROPERTY_TRIM} property. |
185
087d8ec75109
Tabular formatter: fix problem with CR (carriage return).
František Kučera <franta-hg@frantovo.cz>
parents:
170
diff
changeset
|
42 |
* </p> |
32
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
* |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
* @author Ing. František Kučera (frantovo.cz) |
155 | 45 |
* @see TabularPrefetchingFormatter |
46 |
* @see TabularWrappingFormatter |
|
32
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
47 |
*/ |
207
2bba68ef47c1
property annotations: default values
František Kučera <franta-hg@frantovo.cz>
parents:
206
diff
changeset
|
48 |
@PropertyDeclaration(name = COLORFUL, defaultValue = "true", type = Boolean.class, description = COLORFUL_DESCRIPTION) |
2bba68ef47c1
property annotations: default values
František Kučera <franta-hg@frantovo.cz>
parents:
206
diff
changeset
|
49 |
@PropertyDeclaration(name = TabularFormatter.PROPERTY_ASCII, defaultValue = "false", type = Boolean.class, description = "whether to use ASCII table borders instead of unicode ones") |
2bba68ef47c1
property annotations: default values
František Kučera <franta-hg@frantovo.cz>
parents:
206
diff
changeset
|
50 |
@PropertyDeclaration(name = TabularFormatter.PROPERTY_TRIM, defaultValue = "false", type = Boolean.class, description = "whether to trim the values to fit the column width") |
227
0094319a274a
headerTypes: new option to hide column types in tabular headers
František Kučera <franta-hg@frantovo.cz>
parents:
224
diff
changeset
|
51 |
@PropertyDeclaration(name = TabularFormatter.PROPERTY_HEADER_TYPE, defaultValue = "true", type = Boolean.class, description = "whether to print data types in column headers") |
32
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
52 |
public class TabularFormatter extends AbstractFormatter { |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
53 |
|
234
305871254838
TabularFormatter: add support for SQLXML values
František Kučera <franta-hg@frantovo.cz>
parents:
227
diff
changeset
|
54 |
private static final Logger log = Logger.getLogger(TabularFormatter.class.getName()); |
79
e19a13ed19a9
more bash completion tags
František Kučera <franta-hg@frantovo.cz>
parents:
76
diff
changeset
|
55 |
public static final String NAME = "tabular"; // bash-completion:formatter |
39
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
56 |
private static final String HEADER_TYPE_PREFIX = " ("; |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
57 |
private static final String HEADER_TYPE_SUFFIX = ")"; |
104
245f1b88a3e6
formatter/database properties
František Kučera <franta-hg@frantovo.cz>
parents:
103
diff
changeset
|
58 |
public static final String PROPERTY_ASCII = "ascii"; |
245f1b88a3e6
formatter/database properties
František Kučera <franta-hg@frantovo.cz>
parents:
103
diff
changeset
|
59 |
public static final String PROPERTY_TRIM = "trim"; |
227
0094319a274a
headerTypes: new option to hide column types in tabular headers
František Kučera <franta-hg@frantovo.cz>
parents:
224
diff
changeset
|
60 |
public static final String PROPERTY_HEADER_TYPE = "headerTypes"; |
123
248a98c13ca4
TabularWrappingFormatter – first version
František Kučera <franta-hg@frantovo.cz>
parents:
104
diff
changeset
|
61 |
protected ColorfulPrintWriter out; |
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
62 |
private boolean firstResult = true; |
39
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
63 |
private int[] columnWidth; |
87
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
64 |
/** |
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
65 |
* use ASCII borders instead of unicode ones |
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
66 |
*/ |
104
245f1b88a3e6
formatter/database properties
František Kučera <franta-hg@frantovo.cz>
parents:
103
diff
changeset
|
67 |
private final boolean asciiNostalgia; |
87
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
68 |
/** |
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
69 |
* Trim values if they are longer than cell size |
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
70 |
*/ |
104
245f1b88a3e6
formatter/database properties
František Kučera <franta-hg@frantovo.cz>
parents:
103
diff
changeset
|
71 |
private final boolean trimValues; |
227
0094319a274a
headerTypes: new option to hide column types in tabular headers
František Kučera <franta-hg@frantovo.cz>
parents:
224
diff
changeset
|
72 |
/** |
0094319a274a
headerTypes: new option to hide column types in tabular headers
František Kučera <franta-hg@frantovo.cz>
parents:
224
diff
changeset
|
73 |
* Print data type of each column in the header |
0094319a274a
headerTypes: new option to hide column types in tabular headers
František Kučera <franta-hg@frantovo.cz>
parents:
224
diff
changeset
|
74 |
*/ |
0094319a274a
headerTypes: new option to hide column types in tabular headers
František Kučera <franta-hg@frantovo.cz>
parents:
224
diff
changeset
|
75 |
private final boolean printHeaderTypes; |
32
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
76 |
|
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
77 |
public TabularFormatter(FormatterContext formatterContext) { |
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
78 |
super(formatterContext); |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
79 |
out = new ColorfulPrintWriter(formatterContext.getOutputStream()); |
104
245f1b88a3e6
formatter/database properties
František Kučera <franta-hg@frantovo.cz>
parents:
103
diff
changeset
|
80 |
asciiNostalgia = formatterContext.getProperties().getBoolean(PROPERTY_ASCII, false); |
245f1b88a3e6
formatter/database properties
František Kučera <franta-hg@frantovo.cz>
parents:
103
diff
changeset
|
81 |
trimValues = formatterContext.getProperties().getBoolean(PROPERTY_TRIM, false); |
227
0094319a274a
headerTypes: new option to hide column types in tabular headers
František Kučera <franta-hg@frantovo.cz>
parents:
224
diff
changeset
|
82 |
printHeaderTypes = formatterContext.getProperties().getBoolean(PROPERTY_HEADER_TYPE, true); |
206
e2f24eea8543
property annotations (documentation) for particular formatters
František Kučera <franta-hg@frantovo.cz>
parents:
185
diff
changeset
|
83 |
out.setColorful(formatterContext.getProperties().getBoolean(COLORFUL, true)); |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
84 |
} |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
85 |
|
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
86 |
@Override |
142
da1e38386d84
Formatters: structural change – new level „statement“ → query and parameters are no more duplicated into each result set or updates result
František Kučera <franta-hg@frantovo.cz>
parents:
124
diff
changeset
|
87 |
public void writeStartResultSet(ColumnsHeader header) { |
da1e38386d84
Formatters: structural change – new level „statement“ → query and parameters are no more duplicated into each result set or updates result
František Kučera <franta-hg@frantovo.cz>
parents:
124
diff
changeset
|
88 |
super.writeStartResultSet(header); |
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
89 |
printResultSeparator(); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
90 |
|
88
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
91 |
initColumnWidths(header.getColumnCount()); |
39
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
92 |
|
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
93 |
printTableIndent(); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
94 |
printTableBorder("╭"); |
88
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
95 |
|
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
96 |
List<ColumnDescriptor> columnDescriptors = header.getColumnDescriptors(); |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
97 |
|
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
98 |
for (ColumnDescriptor cd : columnDescriptors) { |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
99 |
// padding: make header cell at least same width as data cells in this column |
227
0094319a274a
headerTypes: new option to hide column types in tabular headers
František Kučera <franta-hg@frantovo.cz>
parents:
224
diff
changeset
|
100 |
int typeWidth = printHeaderTypes ? cd.getTypeName().length() + HEADER_TYPE_PREFIX.length() + HEADER_TYPE_SUFFIX.length() : 0; |
88
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
101 |
cd.setLabel(rpad(cd.getLabel(), getColumnWidth(cd.getColumnNumber()) - typeWidth)); |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
102 |
updateColumnWidth(cd.getColumnNumber(), cd.getLabel().length() + typeWidth); |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
103 |
|
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
104 |
if (!cd.isFirstColumn()) { |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
105 |
printTableBorder("┬"); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
106 |
} |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
107 |
printTableBorder(repeat('─', getColumnWidth(cd.getColumnNumber()) + 2)); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
108 |
} |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
109 |
printTableBorder("╮"); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
110 |
out.println(); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
111 |
|
88
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
112 |
for (ColumnDescriptor cd : columnDescriptors) { |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
113 |
if (cd.isFirstColumn()) { |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
114 |
printTableIndent(); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
115 |
printTableBorder("│ "); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
116 |
} else { |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
117 |
printTableBorder(" │ "); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
118 |
} |
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
119 |
out.print(TerminalStyle.Bright, cd.getLabel()); |
227
0094319a274a
headerTypes: new option to hide column types in tabular headers
František Kučera <franta-hg@frantovo.cz>
parents:
224
diff
changeset
|
120 |
if (printHeaderTypes) { |
0094319a274a
headerTypes: new option to hide column types in tabular headers
František Kučera <franta-hg@frantovo.cz>
parents:
224
diff
changeset
|
121 |
out.print(HEADER_TYPE_PREFIX); |
0094319a274a
headerTypes: new option to hide column types in tabular headers
František Kučera <franta-hg@frantovo.cz>
parents:
224
diff
changeset
|
122 |
out.print(cd.getTypeName()); |
0094319a274a
headerTypes: new option to hide column types in tabular headers
František Kučera <franta-hg@frantovo.cz>
parents:
224
diff
changeset
|
123 |
out.print(HEADER_TYPE_SUFFIX); |
0094319a274a
headerTypes: new option to hide column types in tabular headers
František Kučera <franta-hg@frantovo.cz>
parents:
224
diff
changeset
|
124 |
} |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
125 |
if (cd.isLastColumn()) { |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
126 |
printTableBorder(" │"); |
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
127 |
} |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
128 |
} |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
129 |
out.println(); |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
130 |
|
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
131 |
printTableIndent(); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
132 |
printTableBorder("├"); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
133 |
for (int i = 1; i <= header.getColumnCount(); i++) { |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
134 |
if (i > 1) { |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
135 |
printTableBorder("┼"); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
136 |
} |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
137 |
printTableBorder(repeat('─', getColumnWidth(i) + 2)); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
138 |
} |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
139 |
printTableBorder("┤"); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
140 |
out.println(); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
141 |
|
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
142 |
out.flush(); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
143 |
} |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
144 |
|
88
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
145 |
/** |
234
305871254838
TabularFormatter: add support for SQLXML values
František Kučera <franta-hg@frantovo.cz>
parents:
227
diff
changeset
|
146 |
* Must be called before {@linkplain #updateColumnWidth(int, int)} and |
305871254838
TabularFormatter: add support for SQLXML values
František Kučera <franta-hg@frantovo.cz>
parents:
227
diff
changeset
|
147 |
* {@linkplain #getColumnWidth(int)} for each result set. |
88
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
148 |
* |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
149 |
* @param columnCount number of columns in current result set |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
150 |
*/ |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
151 |
protected void initColumnWidths(int columnCount) { |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
152 |
if (columnWidth == null) { |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
153 |
columnWidth = new int[columnCount]; |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
154 |
} |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
155 |
} |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
156 |
|
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
157 |
protected void cleanColumnWidths() { |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
158 |
columnWidth = null; |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
159 |
} |
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
160 |
|
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
161 |
@Override |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
162 |
public void writeColumnValue(Object value) { |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
163 |
super.writeColumnValue(value); |
123
248a98c13ca4
TabularWrappingFormatter – first version
František Kučera <franta-hg@frantovo.cz>
parents:
104
diff
changeset
|
164 |
writeColumnValueInternal(value); |
248a98c13ca4
TabularWrappingFormatter – first version
František Kučera <franta-hg@frantovo.cz>
parents:
104
diff
changeset
|
165 |
} |
248a98c13ca4
TabularWrappingFormatter – first version
František Kučera <franta-hg@frantovo.cz>
parents:
104
diff
changeset
|
166 |
|
248a98c13ca4
TabularWrappingFormatter – first version
František Kučera <franta-hg@frantovo.cz>
parents:
104
diff
changeset
|
167 |
protected void writeColumnValueInternal(Object value) { |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
168 |
|
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
169 |
if (isCurrentColumnFirst()) { |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
170 |
printTableIndent(); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
171 |
printTableBorder("│ "); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
172 |
} else { |
90
ce2b7576ab67
TabularFormatter: no nonbreakable spaces in table cell padding
František Kučera <franta-hg@frantovo.cz>
parents:
89
diff
changeset
|
173 |
printTableBorder(" │ "); |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
174 |
} |
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
175 |
|
219
3b1733fb3793
SingleRecordFormatter: escape whitespace characters in the same way as in TabularFormatter (fixed)
František Kučera <franta-hg@frantovo.cz>
parents:
218
diff
changeset
|
176 |
printValueWithWhitespaceReplaced(toString(value)); |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
177 |
|
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
178 |
if (isCurrentColumnLast()) { |
90
ce2b7576ab67
TabularFormatter: no nonbreakable spaces in table cell padding
František Kučera <franta-hg@frantovo.cz>
parents:
89
diff
changeset
|
179 |
printTableBorder(" │"); |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
180 |
} |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
181 |
|
39
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
182 |
} |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
183 |
|
219
3b1733fb3793
SingleRecordFormatter: escape whitespace characters in the same way as in TabularFormatter (fixed)
František Kučera <franta-hg@frantovo.cz>
parents:
218
diff
changeset
|
184 |
protected void printValueWithWhitespaceReplaced(String text) { |
3b1733fb3793
SingleRecordFormatter: escape whitespace characters in the same way as in TabularFormatter (fixed)
František Kučera <franta-hg@frantovo.cz>
parents:
218
diff
changeset
|
185 |
Functions.printValueWithWhitespaceReplaced(out, text, TerminalColor.Cyan, TerminalColor.Red); |
3b1733fb3793
SingleRecordFormatter: escape whitespace characters in the same way as in TabularFormatter (fixed)
František Kučera <franta-hg@frantovo.cz>
parents:
218
diff
changeset
|
186 |
} |
3b1733fb3793
SingleRecordFormatter: escape whitespace characters in the same way as in TabularFormatter (fixed)
František Kučera <franta-hg@frantovo.cz>
parents:
218
diff
changeset
|
187 |
|
123
248a98c13ca4
TabularWrappingFormatter – first version
František Kučera <franta-hg@frantovo.cz>
parents:
104
diff
changeset
|
188 |
protected int getColumnWidth(int columnNumber) { |
39
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
189 |
return columnWidth[columnNumber - 1]; |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
190 |
} |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
191 |
|
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
192 |
private void setColumnWidth(int columnNumber, int width) { |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
193 |
columnWidth[columnNumber - 1] = width; |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
194 |
} |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
195 |
|
88
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
196 |
protected void updateColumnWidth(int columnNumber, int width) { |
39
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
197 |
int oldWidth = getColumnWidth(columnNumber); |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
198 |
setColumnWidth(columnNumber, Math.max(width, oldWidth)); |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
199 |
|
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
200 |
} |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
201 |
|
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
202 |
protected String toString(Object value) { |
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
203 |
final int width = getColumnWidth(getCurrentColumnsCount()); |
87
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
204 |
String result; |
43
2813d3409afd
TabularFormatter: also booleans will be aligned to the right
František Kučera <franta-hg@frantovo.cz>
parents:
40
diff
changeset
|
205 |
if (value instanceof Number || value instanceof Boolean) { |
98
4d420f8b3320
Value formatting: Object → String conversion is job for particular formatter
František Kučera <franta-hg@frantovo.cz>
parents:
90
diff
changeset
|
206 |
result = lpad(String.valueOf(value), width); |
39
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
207 |
} else { |
234
305871254838
TabularFormatter: add support for SQLXML values
František Kučera <franta-hg@frantovo.cz>
parents:
227
diff
changeset
|
208 |
if (value instanceof SQLXML) { |
305871254838
TabularFormatter: add support for SQLXML values
František Kučera <franta-hg@frantovo.cz>
parents:
227
diff
changeset
|
209 |
// TODO: move to a common method, share with other formatters |
305871254838
TabularFormatter: add support for SQLXML values
František Kučera <franta-hg@frantovo.cz>
parents:
227
diff
changeset
|
210 |
try { |
305871254838
TabularFormatter: add support for SQLXML values
František Kučera <franta-hg@frantovo.cz>
parents:
227
diff
changeset
|
211 |
value = ((SQLXML) value).getString(); |
305871254838
TabularFormatter: add support for SQLXML values
František Kučera <franta-hg@frantovo.cz>
parents:
227
diff
changeset
|
212 |
} catch (SQLException e) { |
305871254838
TabularFormatter: add support for SQLXML values
František Kučera <franta-hg@frantovo.cz>
parents:
227
diff
changeset
|
213 |
log.log(Level.SEVERE, "Unable to format XML", e); |
305871254838
TabularFormatter: add support for SQLXML values
František Kučera <franta-hg@frantovo.cz>
parents:
227
diff
changeset
|
214 |
} |
305871254838
TabularFormatter: add support for SQLXML values
František Kučera <franta-hg@frantovo.cz>
parents:
227
diff
changeset
|
215 |
} |
305871254838
TabularFormatter: add support for SQLXML values
František Kučera <franta-hg@frantovo.cz>
parents:
227
diff
changeset
|
216 |
|
98
4d420f8b3320
Value formatting: Object → String conversion is job for particular formatter
František Kučera <franta-hg@frantovo.cz>
parents:
90
diff
changeset
|
217 |
result = rpad(String.valueOf(value), width); |
39
be8db46a38c3
TabularFormatter: basic column padding
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
218 |
} |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
219 |
// ? value = (boolean) value ? "✔" : "✗"; |
87
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
220 |
|
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
221 |
if (trimValues && result.length() > width) { |
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
222 |
result = result.substring(0, width - 1) + "…"; |
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
223 |
} |
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
224 |
|
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
225 |
return result; |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
226 |
} |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
227 |
|
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
228 |
@Override |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
229 |
public void writeEndRow() { |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
230 |
super.writeEndRow(); |
123
248a98c13ca4
TabularWrappingFormatter – first version
František Kučera <franta-hg@frantovo.cz>
parents:
104
diff
changeset
|
231 |
writeEndRowInternal(); |
248a98c13ca4
TabularWrappingFormatter – first version
František Kučera <franta-hg@frantovo.cz>
parents:
104
diff
changeset
|
232 |
} |
248a98c13ca4
TabularWrappingFormatter – first version
František Kučera <franta-hg@frantovo.cz>
parents:
104
diff
changeset
|
233 |
|
248a98c13ca4
TabularWrappingFormatter – first version
František Kučera <franta-hg@frantovo.cz>
parents:
104
diff
changeset
|
234 |
public void writeEndRowInternal() { |
34
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
235 |
out.println(); |
9335cf31c0f2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
236 |
out.flush(); |
32
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
237 |
} |
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
238 |
|
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
239 |
@Override |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
240 |
public void writeEndResultSet() { |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
241 |
int columnCount = getCurrentColumnsHeader().getColumnCount(); |
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
242 |
super.writeEndResultSet(); |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
243 |
|
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
244 |
printTableIndent(); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
245 |
printTableBorder("╰"); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
246 |
for (int i = 1; i <= columnCount; i++) { |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
247 |
if (i > 1) { |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
248 |
printTableBorder("┴"); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
249 |
} |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
250 |
printTableBorder(repeat('─', getColumnWidth(i) + 2)); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
251 |
} |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
252 |
printTableBorder("╯"); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
253 |
out.println(); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
254 |
|
88
102ba0fcb07f
TabularPrefetchingFormatter: prefetch whole result set to avoid value overflow the cell
František Kučera <franta-hg@frantovo.cz>
parents:
87
diff
changeset
|
255 |
cleanColumnWidths(); |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
256 |
|
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
257 |
out.print(TerminalColor.Yellow, "Record count: "); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
258 |
out.println(getCurrentRowCount()); |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
259 |
out.bell(); |
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
260 |
out.flush(); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
261 |
} |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
262 |
|
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
263 |
@Override |
142
da1e38386d84
Formatters: structural change – new level „statement“ → query and parameters are no more duplicated into each result set or updates result
František Kučera <franta-hg@frantovo.cz>
parents:
124
diff
changeset
|
264 |
public void writeUpdatesResult(int updatedRowsCount) { |
da1e38386d84
Formatters: structural change – new level „statement“ → query and parameters are no more duplicated into each result set or updates result
František Kučera <franta-hg@frantovo.cz>
parents:
124
diff
changeset
|
265 |
super.writeUpdatesResult(updatedRowsCount); |
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
266 |
printResultSeparator(); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
267 |
out.print(TerminalColor.Red, "Updated records: "); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
268 |
out.println(updatedRowsCount); |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
269 |
out.bell(); |
37
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
270 |
out.flush(); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
271 |
} |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
272 |
|
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
273 |
@Override |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
274 |
public void writeEndDatabase() { |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
275 |
super.writeEndDatabase(); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
276 |
out.flush(); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
277 |
} |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
278 |
|
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
279 |
private void printResultSeparator() { |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
280 |
if (firstResult) { |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
281 |
firstResult = false; |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
282 |
} else { |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
283 |
out.println(); |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
284 |
} |
9e6f8e5d5f98
support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
285 |
} |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
286 |
|
123
248a98c13ca4
TabularWrappingFormatter – first version
František Kučera <franta-hg@frantovo.cz>
parents:
104
diff
changeset
|
287 |
protected void printTableBorder(String border) { |
76
fe23cea7542f
support for ACSII-nostalgia tables
František Kučera <franta-hg@frantovo.cz>
parents:
43
diff
changeset
|
288 |
if (asciiNostalgia) { |
fe23cea7542f
support for ACSII-nostalgia tables
František Kučera <franta-hg@frantovo.cz>
parents:
43
diff
changeset
|
289 |
border = border.replaceAll("─", "-"); |
fe23cea7542f
support for ACSII-nostalgia tables
František Kučera <franta-hg@frantovo.cz>
parents:
43
diff
changeset
|
290 |
border = border.replaceAll("│", "|"); |
fe23cea7542f
support for ACSII-nostalgia tables
František Kučera <franta-hg@frantovo.cz>
parents:
43
diff
changeset
|
291 |
border = border.replaceAll("[╭┬╮├┼┤╰┴╯]", "+"); |
fe23cea7542f
support for ACSII-nostalgia tables
František Kučera <franta-hg@frantovo.cz>
parents:
43
diff
changeset
|
292 |
} |
87
03bf24449c7a
TabularFormatter: support for value trim (if longer than cell size)
František Kučera <franta-hg@frantovo.cz>
parents:
79
diff
changeset
|
293 |
|
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
294 |
out.print(TerminalColor.Green, border); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
295 |
} |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
296 |
|
123
248a98c13ca4
TabularWrappingFormatter – first version
František Kučera <franta-hg@frantovo.cz>
parents:
104
diff
changeset
|
297 |
protected void printTableIndent() { |
40
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
298 |
out.print(" "); |
a9db7fb3ce65
TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents:
39
diff
changeset
|
299 |
} |
224
36db9fd27436
BarChartFormatter: first version
František Kučera <franta-hg@frantovo.cz>
parents:
219
diff
changeset
|
300 |
|
36db9fd27436
BarChartFormatter: first version
František Kučera <franta-hg@frantovo.cz>
parents:
219
diff
changeset
|
301 |
/** |
36db9fd27436
BarChartFormatter: first version
František Kučera <franta-hg@frantovo.cz>
parents:
219
diff
changeset
|
302 |
* @return whether should print only ASCII characters instead of unlimited Unicode. |
36db9fd27436
BarChartFormatter: first version
František Kučera <franta-hg@frantovo.cz>
parents:
219
diff
changeset
|
303 |
*/ |
36db9fd27436
BarChartFormatter: first version
František Kučera <franta-hg@frantovo.cz>
parents:
219
diff
changeset
|
304 |
protected boolean isAsciiNostalgia() { |
36db9fd27436
BarChartFormatter: first version
František Kučera <franta-hg@frantovo.cz>
parents:
219
diff
changeset
|
305 |
return asciiNostalgia; |
36db9fd27436
BarChartFormatter: first version
František Kučera <franta-hg@frantovo.cz>
parents:
219
diff
changeset
|
306 |
} |
32
5e412dbd9362
TabularFormatter: basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
307 |
} |