static void DisplayUpdateCount(PrintStream out, int count, int indentLevel) { if (count == 1) { indentedPrintLine(out, indentLevel, "1 row inserted/updated/deleted"); } else if (count >= 0) { indentedPrintLine(out, indentLevel, count + " rows inserted/updated/deleted"); } else { indentedPrintLine(out, indentLevel, "Statement executed."); } }
/** * @param out the place to write to * @param count the update count to display * @param indentLevel number of tab stops to indent line */ static void DisplayUpdateCount(PrintWriter out, int count, int indentLevel) { if (count == 1) { indentedPrintLine(out, indentLevel, LocalizedResource.getMessage("UT_1RowInserUpdatDelet")); } else if (count >= 0) { indentedPrintLine( out, indentLevel, LocalizedResource.getMessage( "UT_0RowsInserUpdatDelet", LocalizedResource.getNumber(count))); } else { indentedPrintLine(out, indentLevel, LocalizedResource.getMessage("UT_StateExecu")); } }
private static void indent_DisplayNextRow( PrintWriter out, ResultSet rs, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException { Vector nestedResults; // autocommit must be off or the nested cursors // are closed when the outer statement completes. if (!conn.getAutoCommit()) nestedResults = new Vector(); else nestedResults = null; checkNotNull(rs, "ResultSet"); ResultSetMetaData rsmd = rs.getMetaData(); checkNotNull(rsmd, "ResultSetMetaData"); // Only print stuff out if there is a row to be had. if (rs.next()) { int rowLen = indent_DisplayBanner(out, rsmd, indentLevel, displayColumns, displayColumnWidths); DisplayRow(out, rs, rsmd, rowLen, nestedResults, conn, indentLevel, null, null); } else { indentedPrintLine(out, indentLevel, LocalizedResource.getMessage("UT_NoCurreRow")); } ShowWarnings(out, rs); DisplayNestedResults(out, nestedResults, conn, indentLevel); nestedResults = null; } // DisplayNextRow
private static void indent_DisplayCurrentRow( PrintStream out, ResultSet rs, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException { Vector nestedResults; if (rs == null) { indentedPrintLine(out, indentLevel, LocalizedResource.getMessage("UT_NoCurreRow_19")); return; } // autocommit must be off or the nested cursors // are closed when the outer statement completes. if (!conn.getAutoCommit()) nestedResults = new Vector(); else nestedResults = null; ResultSetMetaData rsmd = rs.getMetaData(); checkNotNull(rsmd, "ResultSetMetaData"); int rowLen = indent_DisplayBanner(out, rsmd, indentLevel, displayColumns, displayColumnWidths); DisplayRow( out, rs, rsmd, rowLen, nestedResults, conn, indentLevel, displayColumns, displayColumnWidths); ShowWarnings(out, rs); DisplayNestedResults(out, nestedResults, conn, indentLevel); nestedResults = null; } // DisplayNextRow
private static void indent_DisplayResults( PrintStream out, ResultSet rs, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException { ResultSetMetaData rsmd = rs.getMetaData(); checkNotNull(rsmd, "ResultSetMetaData"); Vector nestedResults; int numberOfRowsSelected = 0; // autocommit must be off or the nested cursors // are closed when the outer statement completes. if (!conn.getAutoCommit()) nestedResults = new Vector(); else nestedResults = null; if (displayColumnWidths == null) displayColumnWidths = getColumnDisplayWidths(rsmd, displayColumns, false); int len = indent_DisplayBanner(out, rsmd, indentLevel, displayColumns, displayColumnWidths); // When displaying rows, keep going past errors // unless/until the maximum # of errors is reached. boolean doNext = true; int retry = 0; while (doNext) { try { doNext = rs.next(); if (doNext) { DisplayRow( out, rs, rsmd, len, nestedResults, conn, indentLevel, displayColumns, displayColumnWidths); ShowWarnings(out, rs); numberOfRowsSelected++; } } catch (SQLException e) { // REVISIT: might want to check the exception // and for some, not bother with the retry. if (++retry > MAX_RETRIES) throw e; else ShowSQLException(out, e); } } if (showSelectCount == true) { if (numberOfRowsSelected == 1) { out.println(); indentedPrintLine(out, indentLevel, "1 row selected"); } else if (numberOfRowsSelected >= 0) { out.println(); indentedPrintLine(out, indentLevel, numberOfRowsSelected + " rows selected"); } } DisplayNestedResults(out, nestedResults, conn, indentLevel); nestedResults = null; }
/** * Print one row of a result set, padding each field to the display width and separating them with * '|'s * * @param out the place to write to * @param rs the ResultSet to use * @param rsmd the ResultSetMetaData to use * @param rowLen * @param nestedResults * @param conn * @param indentLevel number of tab stops to indent line * @param displayColumns A list of column numbers to display * @param displayColumnWidths If displayColumns is set, the width of columns to display, in * characters. * @exception SQLException thrown on JDBC access failure */ private static void DisplayRow( PrintWriter out, ResultSet rs, ResultSetMetaData rsmd, int rowLen, Vector nestedResults, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException { StringBuffer buf = new StringBuffer(); buf.ensureCapacity(rowLen); int numCols = displayColumnWidths.length; int i; // get column header info // truncate it to the column display width // add a bar between each item. for (i = 1; i <= numCols; i++) { int colnum = displayColumns == null ? i : displayColumns[i - 1]; if (i > 1) buf.append('|'); String s; switch (rsmd.getColumnType(colnum)) { default: s = LocalizedResource.getInstance().getLocalizedString(rs, rsmd, colnum); break; case Types.JAVA_OBJECT: case Types.OTHER: { Object o = rs.getObject(colnum); if (o == null) { s = "NULL"; } else if (o instanceof ResultSet && nestedResults != null) { s = LocalizedResource.getMessage( "UT_Resul0_20", LocalizedResource.getNumber(nestedResults.size())); nestedResults.addElement(o); } else { try { s = rs.getString(colnum); } catch (SQLException se) { // oops, they don't support refetching the column s = o.toString(); } } } break; } if (s == null) s = "NULL"; int w = displayColumnWidths[i - 1]; if (s.length() < w) { StringBuffer fullS = new StringBuffer(s); fullS.ensureCapacity(w); for (int k = s.length(); k < w; k++) fullS.append(' '); s = fullS.toString(); } else if (s.length() > w) // add the & marker to know it got cut off s = s.substring(0, w - 1) + "&"; buf.append(s); } indentedPrintLine(out, indentLevel, buf); } // DisplayRow
private static int indent_DisplayBanner( PrintWriter out, ResultSetMetaData rsmd, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException { StringBuffer buf = new StringBuffer(); int numCols = displayColumnWidths.length; int rowLen; // do some precalculation so the buffer is allocated only once // buffer is twice as long as the display length plus one for a newline rowLen = (numCols - 1); // for the column separators for (int i = 1; i <= numCols; i++) rowLen += displayColumnWidths[i - 1]; buf.ensureCapacity(rowLen); // get column header info // truncate it to the column display width // add a bar between each item. for (int i = 1; i <= numCols; i++) { int colnum = displayColumns == null ? i : displayColumns[i - 1]; if (i > 1) buf.append('|'); String s = rsmd.getColumnLabel(colnum); int w = displayColumnWidths[i - 1]; if (s.length() < w) { buf.append(s); // try to paste on big chunks of space at a time. int k = w - s.length(); for (; k >= 64; k -= 64) buf.append(" "); for (; k >= 16; k -= 16) buf.append(" "); for (; k >= 4; k -= 4) buf.append(" "); for (; k > 0; k--) buf.append(' '); } else if (s.length() > w) { if (w > 1) buf.append(s.substring(0, w - 1)); if (w > 0) buf.append('&'); } else { buf.append(s); } } buf.setLength(Math.min(rowLen, 1024)); indentedPrintLine(out, indentLevel, buf); // now print a row of '-'s for (int i = 0; i < Math.min(rowLen, 1024); i++) buf.setCharAt(i, '-'); indentedPrintLine(out, indentLevel, buf); buf = null; return rowLen; } // DisplayBanner
private static void indent_DisplayResults( PrintWriter out, List resultSets, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException { ResultSetMetaData rsmd = null; // get metadata from the first ResultSet if (resultSets != null && resultSets.size() > 0) rsmd = ((ResultSet) resultSets.get(0)).getMetaData(); checkNotNull(rsmd, "ResultSetMetaData"); Vector nestedResults; int numberOfRowsSelected = 0; // autocommit must be off or the nested cursors // are closed when the outer statement completes. if (!conn.getAutoCommit()) nestedResults = new Vector(); else nestedResults = null; if (displayColumnWidths == null) displayColumnWidths = getColumnDisplayWidths(rsmd, displayColumns, true); int len = indent_DisplayBanner(out, rsmd, indentLevel, displayColumns, displayColumnWidths); // When displaying rows, keep going past errors // unless/until the maximum # of errors is reached. int retry = 0; ResultSet rs = null; boolean doNext = true; for (int i = 0; i < resultSets.size(); i++) { rs = (ResultSet) resultSets.get(i); doNext = true; while (doNext) { try { doNext = rs.next(); if (doNext) { DisplayRow( out, rs, rsmd, len, nestedResults, conn, indentLevel, displayColumns, displayColumnWidths); ShowWarnings(out, rs); numberOfRowsSelected++; } } catch (SQLException e) { // REVISIT: might want to check the exception // and for some, not bother with the retry. if (++retry > MAX_RETRIES) throw e; else ShowSQLException(out, e); } } } if (showSelectCount == true) { if (numberOfRowsSelected == 1) { out.println(); indentedPrintLine(out, indentLevel, LocalizedResource.getMessage("UT_1RowSelec")); } else if (numberOfRowsSelected >= 0) { out.println(); indentedPrintLine( out, indentLevel, LocalizedResource.getMessage( "UT_0RowsSelec", LocalizedResource.getNumber(numberOfRowsSelected))); } } DisplayNestedResults(out, nestedResults, conn, indentLevel); nestedResults = null; }
private static int indent_DisplayBanner( PrintStream out, ResultSetMetaData rsmd, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException { StringBuffer buf = new StringBuffer(); int numCols = displayColumnWidths.length; int rowLen; // do some precalculation so the buffer is allocated only once // buffer is twice as long as the display length plus one for a newline rowLen = (numCols - 1); // for the column separators for (int i = 1; i <= numCols; i++) { rowLen += displayColumnWidths[i - 1]; } buf.ensureCapacity(rowLen); // get column header info // truncate it to the column display width // add a bar between each item. for (int i = 1; i <= numCols; i++) { int colnum = displayColumns == null ? i : displayColumns[i - 1]; if (i > 1) buf.append('|'); String s = rsmd.getColumnLabel(colnum); int w = displayColumnWidths[i - 1]; if (s.length() < w) { // build a string buffer to hold the whitespace StringBuffer blanks = new StringBuffer(s); blanks.ensureCapacity(w); // try to paste on big chunks of space at a time. for (int k = blanks.length() + 64; k <= w; k += 64) blanks.append(" "); for (int k = blanks.length() + 16; k <= w; k += 16) blanks.append(" "); for (int k = blanks.length() + 4; k <= w; k += 4) blanks.append(" "); for (int k = blanks.length(); k < w; k++) blanks.append(' '); buf.append(blanks); // REMIND: could do more cleverness, like keep around // past buffers to reuse... } else if (s.length() > w) { if (w > 1) buf.append(s.substring(0, w - 1)); if (w > 0) buf.append('&'); } else { buf.append(s); } } buf.setLength(Math.min(rowLen, 1024)); indentedPrintLine(out, indentLevel, buf); // now print a row of '-'s for (int i = 0; i < Math.min(rowLen, 1024); i++) buf.setCharAt(i, '-'); indentedPrintLine(out, indentLevel, buf); buf = null; return rowLen; } // DisplayBanner