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: getString for PGObject columns returns null #1154

Merged
merged 9 commits into from Apr 11, 2018
@@ -1901,7 +1901,8 @@ public String getString(int columnIndex) throws SQLException {
Field field = fields[columnIndex - 1];
Object obj = internalGetObject(columnIndex, field);
if (obj == null) {
return null;
return getObject(columnIndex).toString();

This comment has been minimized.

Copy link
@vlsi

vlsi Apr 2, 2018

Member

This does look odd: why is it calling getObject twice?

This comment has been minimized.

Copy link
@KimBisgaardDmi

KimBisgaardDmi Apr 2, 2018

Author Contributor

Well spotted - corrected

// return null;
}
// hack to be compatible with text protocol
if (obj instanceof java.util.Date) {
@@ -0,0 +1,55 @@
package org.postgresql.test.jdbc4;

import static org.junit.Assert.assertNotNull;

import org.postgresql.PGStatement;
import org.postgresql.jdbc.PreferQueryMode;
import org.postgresql.test.TestUtil;
import org.postgresql.test.jdbc2.BaseTest4;

import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Binary2StringTest extends BaseTest4 {

This comment has been minimized.

Copy link
@vlsi

vlsi Mar 27, 2018

Member

Please add the test to the relevant test suite. Otherwise the test is not executed.


private PreparedStatement statement;

@Before
public void setUp() throws Exception {
super.setUp();
Assume.assumeTrue("Server-prepared statements are not supported in 'simple protocol only'",
preferQueryMode != PreferQueryMode.EXTENDED_FOR_PREPARED);
TestUtil.createTable(con, "testGeometric", "p point");
Statement stmt = con.createStatement();
stmt.execute("insert into testGeometric(p) values ('(1,1)'),('(2,2)')");
statement = con.prepareStatement("select p from testGeometric");

((PGStatement) statement).setPrepareThreshold(-1);

This comment has been minimized.

Copy link
@vlsi

vlsi Mar 27, 2018

Member

I've started to review this, however I ended up with augmenting the existing test: #1155

Note: there was a test for bunch of geometric types. The missing bits are binary/text and getString.

}

@After
public void tearDown() {
try {
TestUtil.dropTable(con, "testGeometric");
} catch (SQLException e) {
// ignore
}
}

@Test
public void test() throws Exception {
ResultSet rs = statement.executeQuery();
while (rs.next()) {
String p = rs.getString("p");
assertNotNull("Failed to convert to String", p);
}
}

}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.