Permalink
Browse files

fix: getPGArrayType fails in when stringType=unspecified (#1036)

  • Loading branch information...
JamiePullar authored and vlsi committed Jan 23, 2018
1 parent 1a89290 commit d5f1cf7c35b05318947021d41e73b6953f623256
@@ -292,15 +292,15 @@ private PreparedStatement getOidStatement(String pgTypeName) throws SQLException
+ " FROM pg_catalog.pg_type t"
+ " JOIN pg_catalog.pg_namespace n ON t.typnamespace = n.oid"
+ " JOIN pg_catalog.pg_type arr ON arr.oid = t.typarray"
+ " WHERE t.typname = ? AND (n.nspname = ? OR ? IS NULL AND n.nspname = ANY (current_schemas(true)))"
+ " WHERE t.typname = ? AND (n.nspname = ? OR ? AND n.nspname = ANY (current_schemas(true)))"
+ " ORDER BY t.oid DESC LIMIT 1";
} else {
sql = "SELECT t.oid, t.typname "
+ " FROM pg_catalog.pg_type t"
+ " JOIN pg_catalog.pg_namespace n ON t.typnamespace = n.oid"
+ " WHERE t.typelem = (SELECT oid FROM pg_catalog.pg_type WHERE typname = ?)"
+ " AND substring(t.typname, 1, 1) = '_' AND t.typlen = -1"
+ " AND (n.nspname = ? OR ? IS NULL AND n.nspname = ANY (current_schemas(true)))"
+ " AND (n.nspname = ? OR ? AND n.nspname = ANY (current_schemas(true)))"
+ " ORDER BY t.typelem DESC LIMIT 1";
}
_getOidStatementComplexArray = _conn.prepareStatement(sql);
@@ -311,12 +311,14 @@ private PreparedStatement getOidStatement(String pgTypeName) throws SQLException
String sql = "SELECT t.oid, t.typname "
+ " FROM pg_catalog.pg_type t"
+ " JOIN pg_catalog.pg_namespace n ON t.typnamespace = n.oid"
+ " WHERE t.typname = ? AND (n.nspname = ? OR ? IS NULL AND n.nspname = ANY (current_schemas(true)))"
+ " WHERE t.typname = ? AND (n.nspname = ? OR ? AND n.nspname = ANY (current_schemas(true)))"
+ " ORDER BY t.oid DESC LIMIT 1";
_getOidStatementComplexNonArray = _conn.prepareStatement(sql);
}
oidStatementComplex = _getOidStatementComplexNonArray;
}
//type name requested may be schema specific, of the form "{schema}"."typeName",
//or may check across all schemas where a schema is not specified.
String fullName = isArray ? pgTypeName.substring(0, pgTypeName.length() - 2) : pgTypeName;
String schema;
String name;
@@ -352,7 +354,7 @@ private PreparedStatement getOidStatement(String pgTypeName) throws SQLException
}
oidStatementComplex.setString(1, name);
oidStatementComplex.setString(2, schema);
oidStatementComplex.setString(3, schema);
oidStatementComplex.setBoolean(3, schema == null);
return oidStatementComplex;
}
@@ -62,6 +62,7 @@
ResultSetTest.class,
ResultSetMetaDataTest.class,
StringTypeUnspecifiedArrayTest.class,
ArrayTest.class,
PrimitiveArraySupportTest.class,
RefCursorTest.class,
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2007, PostgreSQL Global Development Group
* See the LICENSE file in the project root for more information.
*/
package org.postgresql.test.jdbc2;
import org.postgresql.PGProperty;
import org.postgresql.geometric.PGbox;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.sql.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Properties;
@RunWith(Parameterized.class)
public class StringTypeUnspecifiedArrayTest extends BaseTest4 {
public StringTypeUnspecifiedArrayTest(BinaryMode binaryMode) {
setBinaryMode(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;
}
@Override
protected void updateProperties(Properties props) {
PGProperty.STRING_TYPE.set(props, "unspecified");
super.updateProperties(props);
}
@Test
public void testCreateArrayWithNonCachedType() throws Exception {
PGbox[] in = new PGbox[0];
Array a = con.createArrayOf("box", in);
Assert.assertEquals(1111, a.getBaseType());
}
}

0 comments on commit d5f1cf7

Please sign in to comment.