Skip to content
Browse files
fix: getString for PGObject columns returns null (#1154)
Fixes #1151
  • Loading branch information
KimBisgaardDmi authored and vlsi committed Apr 11, 2018
1 parent b1581e9 commit bbb6c1f8ac395fa793e09216ba3b710b0f6a2077
@@ -1901,7 +1901,13 @@ public String getString(int columnIndex) throws SQLException {
Field field = fields[columnIndex - 1];
Object obj = internalGetObject(columnIndex, field);
if (obj == null) {
return null;
// internalGetObject() knows jdbc-types and some extra like hstore. It does not know of
// PGobject based types like geometric types but getObject does
obj = getObject(columnIndex);
if (obj == null) {
return null;
return obj.toString();
// hack to be compatible with text protocol
if (obj instanceof java.util.Date) {
@@ -21,37 +21,46 @@
import org.postgresql.util.PGobject;
import org.postgresql.util.PSQLException;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

* Test case for geometric type I/O
public class GeometricTest {
private Connection con;
public class GeometricTest extends BaseTest4 {

public GeometricTest(BinaryMode binaryMode) {

@Parameterized.Parameters(name = "binary = {0}")
public static Iterable<Object[]> data() {
Collection<Object[]> ids = new ArrayList<Object[]>();
for (BinaryMode binaryMode : BinaryMode.values()) {
ids.add(new Object[]{binaryMode});
return ids;

// Set up the fixture for this testcase: a connection to a database with
// a table for this test.
public void setUp() throws Exception {
con = TestUtil.openDB();
TestUtil.createTable(con, "testgeometric",
"boxval box, circleval circle, lsegval lseg, pathval path, polygonval polygon, pointval point, lineval line");

// Tear down the fixture for this test case.
public void tearDown() throws Exception {
public void tearDown() throws SQLException {
TestUtil.dropTable(con, "testgeometric");

private void checkReadWrite(PGobject obj, String column) throws Exception {
@@ -64,7 +73,10 @@ private void checkReadWrite(PGobject obj, String column) throws Exception {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT " + column + " FROM testgeometric");
assertEquals(obj, rs.getObject(1));
assertEquals("PGObject#equals(rs.getObject)", obj, rs.getObject(1));
PGobject obj2 = (PGobject) obj.clone();
assertEquals("PGobject.toString vs rs.getString", obj, obj2);

stmt.executeUpdate("DELETE FROM testgeometric");

0 comments on commit bbb6c1f

Please sign in to comment.