*** org/postgresql/core/v3/QueryExecutorImpl.java	2007-10-15 13:06:24.000000000 +0500
--- org/postgresql/core/v3/QueryExecutorImpl.java	2007-12-15 02:40:49.000000000 +0500
***************
*** 1425,1447 ****
                  break;
  
              case 'G':  // CopyInResponse
              case 'H':  // CopyOutResponse
              case 'c':  // CopyDone
!             case 'd':  // CopyData
!                 {
!                     // COPY FROM STDIN / COPY TO STDOUT, neither of which are currently
!                     // supported.
! 
!                     // CopyInResponse can only occur in response to an Execute we sent.
!                     // Every Execute we send is followed by either a Bind or a ClosePortal,
!                     // so we don't need to send a CopyFail; the server will fail the copy
!                     // automatically when it sees the next message.
! 
!                     int l_len = pgStream.ReceiveInteger4();
!                     /* discard */
!                     pgStream.Receive(l_len);
  
!                     handler.handleError(new PSQLException(GT.tr("The driver currently does not support COPY operations."), PSQLState.NOT_IMPLEMENTED));
                  }
                  break;
  
--- 1425,1469 ----
                  break;
  
              case 'G':  // CopyInResponse
+                 if (logger.logDebug()) {
+                 	logger.debug(" <=BE CopyInResponse");
+                 	logger.debug(" FE=> CopyFail");
+                 }
+ 
+                 //COPY sub-protocol is not implemented yet
+                 // We'll send a CopyFail message for COPY FROM STDIN so that server does not wait for the data
+                 // For COPY TO STDOUT we cannot abort the data transfer ... we'll just ignore the messages
+ 
+                 byte[] buf = GT.tr("The driver currently does not support COPY operations.").getBytes();
+                 pgStream.SendChar('f');
+                 pgStream.SendInteger4(buf.length + 4 + 1);
+                 pgStream.Send(buf);
+                 pgStream.SendChar(0);
+                 pgStream.flush();
+                 sendSync();	// send sync message
+                 skipCopyResponse();	// skip the response message
+                 break;
+ 
              case 'H':  // CopyOutResponse
+                 if (logger.logDebug())
+                 	logger.debug(" <=BE CopyOutResponse");
+  
+                 skipCopyResponse();
+                 //In case of CopyOutResponse  we cannot abort data transfer - we will just throw error and ignore CopyData messages
+                 handler.handleError(new PSQLException(GT.tr("The driver currently does not support COPY operations."), PSQLState.NOT_IMPLEMENTED));
+                 break;
+ 
              case 'c':  // CopyDone
!                 skipCopyResponse();	// skip the response message
!                 if (logger.logDebug()) {
!                 	logger.debug("<=BE CopyDone");
!                 }
!                 break;
  
!             case 'd':  // CopyData
!                 skipCopyResponse();	// skip the response message
!                 if (logger.logDebug()) {
!                 	logger.debug("<=BE CopyData");
                  }
                  break;
  
***************
*** 1452,1457 ****
--- 1474,1487 ----
          }
      }
  
+     // skipCopyResponse
+     // ignore the response message by just skipping the next n bytes where n is the message length in bytes
+     private void skipCopyResponse() throws IOException {
+         int l_len = pgStream.ReceiveInteger4();        
+         // skip l_len-4 (length includes the 4 bytes for message length itself
+         pgStream.Skip(l_len - 4);
+     }
+  
      public synchronized void fetch(ResultCursor cursor, ResultHandler handler, int fetchSize)
      throws SQLException {
          final Portal portal = (Portal)cursor;
