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)
3 * Copyright © 2013 František Kučera (frantovo.cz)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package info.globalcode.sql.dk.formatting;
20 import info.globalcode.sql.dk.ColorfulPrintWriter;
21 import static info.globalcode.sql.dk.ColorfulPrintWriter.*;
25 * @author Ing. František Kučera (frantovo.cz)
27 public class TabularFormatter extends AbstractFormatter {
29 public static final String NAME = "tabular";
30 private ColorfulPrintWriter out;
31 private boolean firstResult = true;
33 public TabularFormatter(FormatterContext formatterContext) {
34 super(formatterContext);
35 out = new ColorfulPrintWriter(formatterContext.getOutputStream());
39 public void writeStartResultSet() {
40 super.writeStartResultSet();
41 printResultSeparator();
45 public void writeColumnsHeader(ColumnsHeader header) {
46 super.writeColumnsHeader(header);
48 for (ColumnDescriptor cd : header.getColumnDescriptors()) {
49 out.print(TerminalStyle.Bright, cd.getLabel());
51 out.print(cd.getTypeName());
53 if (!cd.isLastColumn()) {
54 out.print(TerminalColor.Green, " | ");
62 public void writeColumnValue(Object value) {
63 super.writeColumnValue(value);
65 if (!isCurrentColumnFirst()) {
66 out.print(TerminalColor.Green, " | ");
69 out.print(TerminalColor.Cyan, String.valueOf(value));
73 public void writeEndRow() {
80 public void writeEndResultSet() {
81 super.writeEndResultSet();
82 out.print(TerminalColor.Yellow, "Record count: ");
83 out.println(getCurrentRowCount());
88 public void writeStartUpdatesResult() {
89 super.writeStartUpdatesResult();
90 printResultSeparator();
94 public void writeUpdatedRowsCount(int updatedRowsCount) {
95 super.writeUpdatedRowsCount(updatedRowsCount);
96 out.print(TerminalColor.Red, "Updated records: ");
97 out.println(updatedRowsCount);
102 public void writeEndDatabase() {
103 super.writeEndDatabase();
107 private void printResultSeparator() {