X-Git-Url: http://jaekl.net/gitweb/?p=squelch.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fjaekl%2Fsquelch%2Fstmt%2FTabular.java;h=af3d5da360933f8c37e48c216187236fd047bdde;hp=03c403ef3f037684977376d14e3f3dd3d8b8472b;hb=dde7f6828b7e2fc479d2285754e4a150be7958a5;hpb=dad47827334a0732966cc197dfe1e3ac303fb694 diff --git a/src/main/java/net/jaekl/squelch/stmt/Tabular.java b/src/main/java/net/jaekl/squelch/stmt/Tabular.java index 03c403e..af3d5da 100644 --- a/src/main/java/net/jaekl/squelch/stmt/Tabular.java +++ b/src/main/java/net/jaekl/squelch/stmt/Tabular.java @@ -38,7 +38,7 @@ abstract public class Tabular { } abstract Column[] getCols() throws SQLException; - abstract Row getNext(); + abstract Row getNext() throws SQLException; // Returns the number of (data) rows that were output public int printTable(PrintWriter pw) throws SQLException { @@ -66,6 +66,10 @@ abstract public class Tabular { rowCount += pending; } + if (rowCount > 0) { + writeDivider(pw, colWidths); + } + // TODO: Implement a String table for i18n pw.println("" + rowCount + " row(s) returned."); pw.flush(); @@ -119,7 +123,7 @@ abstract public class Tabular { // Examine and buffer up to rowBuf.length rows. // Returns the number of actual rows that were buffered (zero if no more rows are available). - RowBuffer bufferRows(int[] colWidths) + RowBuffer bufferRows(int[] colWidths) throws SQLException { RowBuffer rowBuf = new RowBuffer(); @@ -222,7 +226,7 @@ abstract public class Tabular { void writeHeader(PrintWriter pw, Column[] cols, int[] colWidths) { writeDivider(pw, colWidths); - for (int idx = 1; idx <= cols.length; ++idx) { + for (int idx = 0; idx < cols.length; ++idx) { Column col = cols[idx]; pw.print("|" + centrePad(col.getLabel(), colWidths[idx])); } @@ -236,7 +240,7 @@ abstract public class Tabular { for (int rowIdx = 0; rowIdx < rowBuf.getPending(); ++rowIdx) { Row row = rowBuf.getRow(rowIdx); for (int colIdx = 0; colIdx < colWidths.length; ++colIdx) { - String value = "" + row.getValue(colIdx); + String value = "" + row.getValue(colIdx + 1); String padding = repChar(' ', colWidths[colIdx] - value.length()); pw.print("|" + value + padding); }