[libpostgresql-jdbc-java] 02/10: Make ResultSetMetaData.getColumnType match the results of DatabaseMetaData.getColumns.DATA_TYPE for domain and composite types.
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:20:50 UTC 2017
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to tag REL8_3_607
in repository libpostgresql-jdbc-java.
commit 1437a536d091b78605b9fe20b0abdc7b3d7be959
Author: Kris Jurka <books at ejurka.com>
Date: Tue Aug 10 19:59:53 2010 +0000
Make ResultSetMetaData.getColumnType match the results of
DatabaseMetaData.getColumns.DATA_TYPE for domain and composite
types.
Per report from Thomas Kellerer.
---
org/postgresql/jdbc2/TypeInfoCache.java | 34 ++++++++++++++--------
.../test/jdbc2/ResultSetMetaDataTest.java | 12 +++++++-
2 files changed, 33 insertions(+), 13 deletions(-)
diff --git a/org/postgresql/jdbc2/TypeInfoCache.java b/org/postgresql/jdbc2/TypeInfoCache.java
index 20dc08a..cdf99c2 100644
--- a/org/postgresql/jdbc2/TypeInfoCache.java
+++ b/org/postgresql/jdbc2/TypeInfoCache.java
@@ -3,7 +3,7 @@
* Copyright (c) 2005-2008, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgjdbc/org/postgresql/jdbc2/TypeInfoCache.java,v 1.11 2007/12/02 06:48:43 jurka Exp $
+ * $PostgreSQL: pgjdbc/org/postgresql/jdbc2/TypeInfoCache.java,v 1.12 2008/01/08 06:56:29 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -51,7 +51,7 @@ public class TypeInfoCache {
private PreparedStatement _getOidStatement;
private PreparedStatement _getNameStatement;
private PreparedStatement _getArrayElementOidStatement;
- private PreparedStatement _isArrayStatement;
+ private PreparedStatement _getTypeInfoStatement;
// basic pg types info:
// 0 - type name
@@ -152,32 +152,42 @@ public class TypeInfoCache {
if (i != null)
return i.intValue();
- if (_isArrayStatement == null) {
+ if (_getTypeInfoStatement == null) {
// There's no great way of telling what's an array type.
// People can name their own types starting with _.
// Other types use typelem that aren't actually arrays, like box.
//
- String sql = "SELECT 1 FROM ";
+ String sql = "SELECT typinput='array_in'::regproc, typtype FROM ";
if (_conn.haveMinimumServerVersion("7.3")) {
sql += "pg_catalog.";
}
- sql += "pg_type WHERE typname = ? AND typinput='array_in'::regproc";
+ sql += "pg_type WHERE typname = ?";
- _isArrayStatement = _conn.prepareStatement(sql);
+ _getTypeInfoStatement = _conn.prepareStatement(sql);
}
- _isArrayStatement.setString(1, pgTypeName);
+ _getTypeInfoStatement.setString(1, pgTypeName);
// Go through BaseStatement to avoid transaction start.
- if (!((BaseStatement)_isArrayStatement).executeWithFlags(QueryExecutor.QUERY_SUPPRESS_BEGIN))
+ if (!((BaseStatement)_getTypeInfoStatement).executeWithFlags(QueryExecutor.QUERY_SUPPRESS_BEGIN))
throw new PSQLException(GT.tr("No results were returned by the query."), PSQLState.NO_DATA);
- ResultSet rs = _isArrayStatement.getResultSet();
+ ResultSet rs = _getTypeInfoStatement.getResultSet();
- Integer type;
+ Integer type = null;
if (rs.next()) {
- type = new Integer(Types.ARRAY);
- } else {
+ boolean isArray = rs.getBoolean(1);
+ String typtype = rs.getString(2);
+ if (isArray) {
+ type = new Integer(Types.ARRAY);
+ } else if ("c".equals(typtype)) {
+ type = new Integer(Types.STRUCT);
+ } else if ("d".equals(typtype)) {
+ type = new Integer(Types.DISTINCT);
+ }
+ }
+
+ if (type == null) {
type = new Integer(Types.OTHER);
}
rs.close();
diff --git a/org/postgresql/test/jdbc2/ResultSetMetaDataTest.java b/org/postgresql/test/jdbc2/ResultSetMetaDataTest.java
index e6d9843..c1da852 100644
--- a/org/postgresql/test/jdbc2/ResultSetMetaDataTest.java
+++ b/org/postgresql/test/jdbc2/ResultSetMetaDataTest.java
@@ -3,7 +3,7 @@
* Copyright (c) 2004-2008, PostgreSQL Global Development Group
*
* IDENTIFICATION
-* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/ResultSetMetaDataTest.java,v 1.15 2006/05/15 09:35:57 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/ResultSetMetaDataTest.java,v 1.16 2008/01/08 06:56:31 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -35,10 +35,12 @@ public class ResultSetMetaDataTest extends TestCase
TestUtil.createTable(conn, "serialtest", "a serial, b bigserial, c int");
TestUtil.createTable(conn, "alltypes", "bool boolean, i2 int2, i4 int4, i8 int8, num numeric(10,2), re real, fl float, ch char(3), vc varchar(3), tx text, d date, t time without time zone, tz time with time zone, ts timestamp without time zone, tsz timestamp with time zone, bt bytea");
TestUtil.createTable(conn, "sizetest", "fixedchar char(5), fixedvarchar varchar(5), unfixedvarchar varchar, txt text, bytearr bytea, num64 numeric(6,4), num60 numeric(6,0), num numeric, ip inet");
+ TestUtil.createTable(conn, "compositetest", "col rsmd1");
}
protected void tearDown() throws Exception
{
+ TestUtil.dropTable(conn, "compositetest");
TestUtil.dropTable(conn, "rsmd1");
TestUtil.dropTable(conn, "timetest");
TestUtil.dropTable(conn, "serialtest");
@@ -213,4 +215,12 @@ public class ResultSetMetaDataTest extends TestCase
}
}
+ public void testComposite() throws Exception {
+ Statement stmt = conn.createStatement();
+ ResultSet rs = stmt.executeQuery("SELECT col FROM compositetest");
+ ResultSetMetaData rsmd = rs.getMetaData();
+ assertEquals(Types.STRUCT, rsmd.getColumnType(1));
+ assertEquals("rsmd1", rsmd.getColumnTypeName(1));
+ }
+
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git
More information about the pkg-java-commits
mailing list