postgresql-jdbc.git / summary / log / commit / refs

commit    bfc8e5dfda80174e76f45c8ebcc09ac8bb02ca9b
Author:   Kris Jurka <books@ejurka.com>
Date:     Thu Apr 08 16:18:05 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 eef5630c..d79bacb3 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.2 2009/12/04 19:53:20 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 f9cc76ec..e8659eae 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.3 2009/12/04 19:53:20 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"; [parent: 63d2d8e9b87d]