[libpostgresql-jdbc-java] 14/22: Fix a problem using the Copy API to copy data to the server from a Reader. After reading data out of the Reader and into a buffer, we were sending the entire buffer on to the server, not just the subset of it that was filled by the read operation.

Emmanuel Bourg ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:20:53 UTC 2017


This is an automated email from the git hooks/post-receive script.

ebourg-guest pushed a commit to tag REL8_4_702
in repository libpostgresql-jdbc-java.

commit ceafda2d41be3774698e6153e60b29958ff36ed8
Author: Kris Jurka <books at ejurka.com>
Date:   Thu Apr 8 16:18:11 2010 +0000

    Fix a problem using the Copy API to copy data to the server from a
    Reader.  After reading data out of the Reader and into a buffer, we
    were sending the entire buffer on to the server, not just the subset
    of it that was filled by the read operation.
    
    Leonardo F
---
 org/postgresql/copy/CopyManager.java    |  4 ++--
 org/postgresql/test/jdbc2/CopyTest.java | 10 +++++++++-
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/org/postgresql/copy/CopyManager.java b/org/postgresql/copy/CopyManager.java
index eef5630..b82a040 100644
--- a/org/postgresql/copy/CopyManager.java
+++ b/org/postgresql/copy/CopyManager.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2009, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/copy/CopyManager.java,v 1.1 2009/07/01 05:00:39 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/copy/CopyManager.java,v 1.1.2.1 2009/12/04 19:53:26 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -141,7 +141,7 @@ public class CopyManager {
         CopyIn cp = copyIn(sql);
         try {
             while ( (len = from.read(cbuf)) > 0) {
-                byte[] buf = encoding.encode(new String(cbuf));
+                byte[] buf = encoding.encode(new String(cbuf, 0, len));
                 cp.writeToCopy(buf, 0, buf.length);
             }
             return cp.endCopy();
diff --git a/org/postgresql/test/jdbc2/CopyTest.java b/org/postgresql/test/jdbc2/CopyTest.java
index f9cc76e..29ced69 100644
--- a/org/postgresql/test/jdbc2/CopyTest.java
+++ b/org/postgresql/test/jdbc2/CopyTest.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2008, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/CopyTest.java,v 1.2 2009/07/01 05:00:40 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/CopyTest.java,v 1.2.2.1 2009/12/04 19:53:27 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -19,6 +19,7 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintStream;
 import java.io.IOException;
+import java.io.StringReader;
 
 import junit.framework.TestCase;
 
@@ -136,6 +137,13 @@ public class CopyTest extends TestCase {
         assertEquals(0, rowCount);
     }
 
+    public void testCopyInFromReader() throws SQLException, IOException {
+        String sql = "COPY copytest FROM STDIN";
+        copyAPI.copyIn(sql, new StringReader(new String(getData(origData))), 3);
+        int rowCount = getCount();
+        assertEquals(dataRows, rowCount);
+    }
+
     public void testSkipping() {
         String sql = "COPY copytest FROM STDIN";
         String at = "init";

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git



More information about the pkg-java-commits mailing list