From b62956edafece5a4e77556bb3ec02f5786629cfb Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 21 Dec 2009 15:12:34 -0800 Subject: [PATCH] gsql: Fix \d table missing first column We always skipped the first column of a table because we consumed one row in order to determine if the name given to us by the user actually existed in the database. Change-Id: I9910870ab7e649e93687599edca649a4eb9f736d Signed-off-by: Shawn O. Pearce --- .../com/google/gerrit/sshd/commands/QueryShell.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/QueryShell.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/QueryShell.java index 873d0ce3fc..b12176dcdc 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/QueryShell.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/QueryShell.java @@ -172,7 +172,7 @@ public class QueryShell { ResultSet rs = meta.getTables(null, null, null, types); try { println(" List of relations"); - showResultSet(rs, // + showResultSet(rs, false, // Identity.create(rs, "TABLE_SCHEM"), // Identity.create(rs, "TABLE_NAME"), // Identity.create(rs, "TABLE_TYPE")); @@ -209,7 +209,7 @@ public class QueryShell { } println(" Table " + tableName); - showResultSet(rs, // + showResultSet(rs, true, // Identity.create(rs, "COLUMN_NAME"), // new Function("TYPE") { @Override @@ -305,7 +305,7 @@ public class QueryShell { if (hasResultSet) { final ResultSet rs = statement.getResultSet(); try { - final int rowCount = showResultSet(rs); + final int rowCount = showResultSet(rs, false); final long ms = System.currentTimeMillis() - start; println("(" + rowCount + (rowCount == 1 ? " row" : " rows") // + "; " + ms + " ms)"); @@ -324,8 +324,8 @@ public class QueryShell { } } - private int showResultSet(final ResultSet rs, Function... show) - throws SQLException { + private int showResultSet(final ResultSet rs, boolean alreadyOnRow, + Function... show) throws SQLException { final ResultSetMetaData meta = rs.getMetaData(); final Function[] columnMap; @@ -349,7 +349,7 @@ public class QueryShell { } final List rows = new ArrayList(); - while (rs.next()) { + while (alreadyOnRow || rs.next()) { final String[] row = new String[columnMap.length]; for (int c = 0; c < colCnt; c++) { row[c] = columnMap[c].apply(rs); @@ -359,6 +359,7 @@ public class QueryShell { widths[c] = Math.max(widths[c], row[c].length()); } rows.add(row); + alreadyOnRow = false; } final StringBuilder b = new StringBuilder();