/** * Pass results of a COPY TO STDOUT query from database into an OutputStream. * @param sql COPY TO STDOUT statement * @param to the stream to write the results to (row by row) * @return number of rows updated for server 8.2 or newer; -1 for older * @throws SQLException on database usage errors * @throws IOException upon output stream or database connection failure */ public long copyOut(final String sql, OutputStream to) throws SQLException, IOException { byte[] buf; CopyOut cp = copyOut(sql); try { while( (buf = cp.readFromCopy()) != null ) { to.write(buf); } return cp.getHandledRowCount(); } finally { // see to it that we do not leave the connection locked if(cp.isActive()) cp.cancelCopy(); } }
public int getFieldCount() { return op.getFieldCount(); }
public int getFieldFormat(int field) { return op.getFieldFormat(field); }
public void close() throws IOException { // Don't complain about a double close. if (op == null) { return; } if (op.isActive()) { try { op.cancelCopy(); } catch (SQLException se) { IOException ioe = new IOException("Failed to close copy reader."); ioe.initCause(se); throw ioe; } } op = null; }
public long getHandledRowCount() { return op.getHandledRowCount(); } }
public void cancelCopy() throws SQLException { op.cancelCopy(); }
public int getFormat() { return op.getFormat(); }
public boolean isActive() { return op != null && op.isActive(); }
private boolean gotBuf() throws IOException { if (at >= len) { try { buf = op.readFromCopy(); } catch (SQLException sqle) { throw new IOException(GT.tr("Copying from database failed: {0}", sqle)); } if (buf == null) { at = -1; return false; } else { at = 0; len = buf.length; return true; } } return buf != null; }
public long getHandledRowCount() { return op.getHandledRowCount(); } }
public void cancelCopy() throws SQLException { op.cancelCopy(); }
public int getFormat() { return op.getFormat(); }
public boolean isActive() { return op.isActive(); }
private boolean gotBuf() throws IOException { if(at >= len) { try { buf = op.readFromCopy(); } catch(SQLException sqle) { throw new IOException(GT.tr("Copying from database failed: {0}", sqle)); } if(buf == null) { at = -1; return false; } else { at = 0; len = buf.length; return true; } } return buf != null; }
CopyOut cp = copyOut(sql); try { while ((buf = cp.readFromCopy()) != null) { to.write(buf); return cp.getHandledRowCount(); } catch (IOException ioEX) { if (cp.isActive()) { cp.cancelCopy(); while ((buf = cp.readFromCopy()) != null) { if (cp.isActive()) { cp.cancelCopy();
public long getHandledRowCount() { return op.getHandledRowCount(); } }
public void close() throws IOException { // Don't complain about a double close. if (op == null) return; try { op.cancelCopy(); } catch(SQLException se) { IOException ioe = new IOException("Failed to close copy reader."); ioe.initCause(se); throw ioe; } op = null; }
public int getFieldCount() { return op.getFieldCount(); }
public int getFieldFormat(int field) { return op.getFieldFormat(field); }
public int getFormat() { return op.getFormat(); }