}
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 {
+ public int printTable(PrintWriter pw, String noRowsMessage)
+ throws SQLException
+ {
int rowCount = 0;
Column[] cols = getCols();
RowBuffer rowBuf;
rowCount += pending;
}
- // TODO: Implement a String table for i18n
- pw.println("" + rowCount + " row(s) returned.");
+ if (rowCount > 0) {
+ writeDivider(pw, colWidths);
+ // TODO: Implement a String table for i18n
+ pw.println("" + rowCount + " row(s) returned.");
+ }
+ else {
+ pw.println(noRowsMessage);
+ }
+
pw.flush();
return rowCount;
// 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();
}
return Object.class;
}
-
+
String repChar(char chr, int times)
{
StringBuffer sb = new StringBuffer();
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]));
}
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);
}