public void handleWarning(SQLWarning warning) { // we don't want to ignore warnings and it would be tricky // to chain them back to the connection, so since we don't // expect to get them in the first place, we just consider // them errors. handleError(warning); }
ProtocolConnectionImpl(PGStream pgStream, String user, String database, Logger logger) { this.pgStream = pgStream; this.user = user; this.database = database; this.logger = logger; this.executor = new QueryExecutorImpl(this, pgStream, logger); }
public ParameterList createParameterList() { if (fragments.length == 1) return NO_PARAMETERS; return new SimpleParameterList(fragments.length - 1, useEStringSyntax); }
public synchronized byte[] fastpathCall(int fnid, ParameterList parameters, boolean suppressBegin) throws SQLException { if (protoConnection.getTransactionState() == ProtocolConnection.TRANSACTION_IDLE && !suppressBegin) V2Query query = (V2Query)createSimpleQuery(""); SimpleParameterList params = (SimpleParameterList)query.createParameterList(); sendQuery(query, params, "BEGIN"); processResults(query, handler, 0, 0); sendFastpathCall(fnid, (FastpathParameterList)parameters); return receiveFastpathResult();
parameters = (SimpleParameterList)query.createParameterList(); parameters.checkAllParametersSet(); if (protoConnection.getTransactionState() == ProtocolConnection.TRANSACTION_IDLE && (flags & QueryExecutor.QUERY_SUPPRESS_BEGIN) == 0) sendQuery(query, parameters, queryPrefix); processResults(query, handler, maxRows, flags); protoConnection.close(); handler.handleError(new PSQLException(GT.tr("An I/O error occured while sending to the backend."), PSQLState.CONNECTION_FAILURE, e));
public synchronized void processNotifies() throws SQLException { // Asynchronous notifies only arrive when we are not in a transaction if (protoConnection.getTransactionState() != ProtocolConnection.TRANSACTION_IDLE) return; try { while (pgStream.hasMessagePending()) { int c = pgStream.ReceiveChar(); switch (c) { case 'A': // Asynchronous Notify receiveAsyncNotify(); break; case 'E': // Error Message throw receiveErrorMessage(); // break; case 'N': // Error Notification protoConnection.addWarning(receiveNotification()); break; default: throw new PSQLException(GT.tr("Unknown Response Type {0}.", new Character((char) c)), PSQLState.CONNECTION_FAILURE); } } } catch (IOException ioe) { throw new PSQLException(GT.tr("An I/O error occured while sending to the backend."), PSQLState.CONNECTION_FAILURE, ioe); } }
protected void sendQuery(V2Query query, SimpleParameterList params, String queryPrefix) throws IOException { if (logger.logDebug()) logger.debug(" FE=> Query(\"" + (queryPrefix == null ? "" : queryPrefix) + query.toString(params) + "\")"); pgStream.SendChar('Q'); Writer encodingWriter = pgStream.getEncodingWriter(); if (queryPrefix != null) encodingWriter.write(queryPrefix); String[] fragments = query.getFragments(); for (int i = 0 ; i < fragments.length; ++i) { encodingWriter.write(fragments[i]); if (i < params.getParameterCount()) params.writeV2Value(i + 1, encodingWriter); } encodingWriter.write(0); pgStream.flush(); }
private void sendFastpathCall(int fnid, FastpathParameterList params) throws IOException { // Send call. int count = params.getParameterCount(); if (logger.logDebug()) logger.debug(" FE=> FastpathCall(fnid=" + fnid + ",paramCount=" + count + ")"); pgStream.SendChar('F'); pgStream.SendChar(0); pgStream.SendInteger4(fnid); pgStream.SendInteger4(count); for (int i = 1; i <= count; ++i) params.writeV2FastpathValue(i, pgStream); pgStream.flush(); }
public Query createSimpleQuery(String sql) { return new V2Query(sql, false, protoConnection); }
public void setIntParameter(int index, int value) throws SQLException { setLiteralParameter(index, "" + value, Oid.INT4); }
public ParameterList createFastpathParameters(int count) { return new FastpathParameterList(count); }
void writeV2Value(int index, Writer encodingWriter) throws IOException { if (paramValues[index - 1] instanceof StreamWrapper) { streamBytea((StreamWrapper)paramValues[index - 1], encodingWriter); } else { encodingWriter.write((String)paramValues[index - 1]); } }
public synchronized void execute(Query[] queries, ParameterList[] parameters, ResultHandler handler, int maxRows, int fetchSize, int flags) throws SQLException { final ResultHandler delegateHandler = handler; handler = new ResultHandler() { public void handleResultRows(Query fromQuery, Field[] fields, Vector tuples, ResultCursor cursor) { delegateHandler.handleResultRows(fromQuery, fields, tuples, cursor); } public void handleCommandStatus(String status, int updateCount, long insertOID) { delegateHandler.handleCommandStatus(status, updateCount, insertOID); } public void handleWarning(SQLWarning warning) { delegateHandler.handleWarning(warning); } public void handleError(SQLException error) { delegateHandler.handleError(error); } public void handleCompletion() throws SQLException { } }; for (int i = 0; i < queries.length; ++i) execute((V2Query)queries[i], (SimpleParameterList)parameters[i], handler, maxRows, flags); delegateHandler.handleCompletion(); }
public void handleCommandStatus(String status, int updateCount, long insertOID) { if (!sawBegin) { if (!status.equals("BEGIN")) handleError(new PSQLException(GT.tr("Expected command status BEGIN, got {0}.", status), PSQLState.PROTOCOL_VIOLATION)); sawBegin = true; } else { delegateHandler.handleCommandStatus(status, updateCount, insertOID); } }
private void receiveAsyncNotify() throws IOException { int pid = pgStream.ReceiveInteger4(); String msg = pgStream.ReceiveString(); if (logger.logDebug()) logger.debug(" <=BE AsyncNotify(pid=" + pid + ",msg=" + msg + ")"); protoConnection.addNotification(new org.postgresql.core.Notification(msg, pid)); }
public void handleCommandStatus(String status, int updateCount, long insertOID) { if (!sawBegin) { if (!status.equals("BEGIN")) handleError(new PSQLException(GT.tr("Expected command status BEGIN, got {0}.", status), PSQLState.PROTOCOL_VIOLATION)); sawBegin = true; } else { handleError(new PSQLException(GT.tr("Unexpected command status: {0}.", status), PSQLState.PROTOCOL_VIOLATION)); } }
public ParameterList copy() { SimpleParameterList newCopy = new SimpleParameterList(paramValues.length, useEStringSyntax); System.arraycopy(paramValues, 0, newCopy.paramValues, 0, paramValues.length); return newCopy; }
public Query createParameterizedQuery(String sql) { return new V2Query(sql, true, protoConnection); }
public void setStringParameter(int index, String value, int oid) throws SQLException { StringBuffer sbuf = new StringBuffer(2 + value.length() * 11 / 10); // Add 10% for escaping. if (useEStringSyntax) sbuf.append(' ').append('E'); sbuf.append('\''); Utils.appendEscapedLiteral(sbuf, value, false); sbuf.append('\''); setLiteralParameter(index, sbuf.toString(), oid); }
public ParameterList copy() { FastpathParameterList newCopy = new FastpathParameterList(paramValues.length); System.arraycopy(paramValues, 0, newCopy.paramValues, 0, paramValues.length); return newCopy; }