Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: PgSQLXML setCharacterStream() results in null value #1608

Merged
merged 2 commits into from Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pgjdbc/src/main/java/org/postgresql/jdbc/PgSQLXML.java
Expand Up @@ -175,6 +175,7 @@ public synchronized OutputStream setBinaryStream() throws SQLException {
public synchronized Writer setCharacterStream() throws SQLException {
checkFreed();
initialize();
active = true;
stringWriter = new StringWriter();
return stringWriter;
}
Expand Down
50 changes: 50 additions & 0 deletions pgjdbc/src/test/java/org/postgresql/jdbc/PgSQLXMLTest.java
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2019, PostgreSQL Global Development Group
* See the LICENSE file in the project root for more information.
*/

package org.postgresql.jdbc;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.postgresql.test.TestUtil;
import org.postgresql.test.jdbc2.BaseTest4;

import org.junit.Before;
import org.junit.Test;

import java.io.Writer;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLXML;
import java.sql.Statement;

public class PgSQLXMLTest extends BaseTest4 {

@Override
@Before
public void setUp() throws Exception {
super.setUp();
TestUtil.createTempTable(con, "xmltab","x xml");
}

@Test
public void setCharacterStream() throws Exception {
String exmplar = "<x>value</x>";
SQLXML pgSQLXML = con.createSQLXML();
Writer writer = pgSQLXML.setCharacterStream();
writer.write(exmplar);
PreparedStatement preparedStatement = con.prepareStatement("insert into xmltab values (?)");
preparedStatement.setSQLXML(1,pgSQLXML);
preparedStatement.execute();

Statement statement = con.createStatement();
ResultSet rs = statement.executeQuery("select * from xmltab");
assertTrue(rs.next());
SQLXML result = rs.getSQLXML(1);
assertNotNull(result);
assertEquals(exmplar, result.getString());
}
}
Expand Up @@ -13,6 +13,7 @@
import org.postgresql.core.ReturningParserTest;
import org.postgresql.core.v3.V3ParameterListTests;
import org.postgresql.jdbc.DeepBatchedInsertStatementTest;
import org.postgresql.jdbc.PgSQLXMLTest;
import org.postgresql.jdbc.PrimitiveArraySupportTest;
import org.postgresql.test.core.JavaVersionTest;
import org.postgresql.test.core.LogServerMessagePropertyTest;
Expand Down Expand Up @@ -82,6 +83,7 @@
PGPropertyTest.class,
PGTimestampTest.class,
PGTimeTest.class,
PgSQLXMLTest.class,
PreparedStatementTest.class,
PrimitiveArraySupportTest.class,
QuotationTest.class,
Expand Down