Skip to content
Permalink
Browse files

fix:handle numeric domain types (#1611)

* fix:handle numeric domain types
  • Loading branch information
davecramer committed Nov 22, 2019
1 parent 00fa448 commit 7f1752a1f2853c88333b3ac75c2dc0212272b254
@@ -1595,7 +1595,7 @@ public ResultSet getColumns(String catalog, String schemaPattern, String tableNa
/*
From the docs if typtypmod is -1
*/
int domainLength = rs.getInt("typtypmod");
int typtypmod = rs.getInt("typtypmod");
decimalDigits = connection.getTypeInfo().getScale(baseTypeOid, typeMod);
/*
From the postgres docs:
@@ -1604,10 +1604,13 @@ base type (-1 if base type does not use a typmod). -1 if this type is not a doma
if it is -1 then get the precision from the basetype. This doesn't help if the basetype is
a domain, but for actual types this will return the correct value.
*/
if ( domainLength == -1 ) {
if ( typtypmod == -1 ) {
columnSize = connection.getTypeInfo().getPrecision(baseTypeOid, typeMod);
} else if (baseTypeOid == Oid.NUMERIC ) {
decimalDigits = connection.getTypeInfo().getScale(baseTypeOid, typtypmod);
columnSize = connection.getTypeInfo().getPrecision(baseTypeOid, typtypmod);
} else {
columnSize = domainLength;
columnSize = typtypmod;
}
} else {
decimalDigits = connection.getTypeInfo().getScale(typeOid, typeMod);
@@ -84,7 +84,9 @@ public void setUp() throws Exception {

TestUtil.createDomain(con, "nndom", "int not null");
TestUtil.createDomain(con, "varbit2", "varbit(3)");
TestUtil.createTable(con, "domaintable", "id nndom, v varbit2");
TestUtil.createDomain(con, "float83", "numeric(8,3)");

TestUtil.createTable(con, "domaintable", "id nndom, v varbit2, f float83");
stmt.close();
}

@@ -112,6 +114,9 @@ public void tearDown() throws Exception {
stmt.execute("DROP FUNCTION f3(int, varchar)");
TestUtil.dropTable(con, "domaintable");
TestUtil.dropDomain(con, "nndom");
TestUtil.dropDomain(con, "varbit2");
TestUtil.dropDomain(con, "float83");


TestUtil.closeDB(con);
}
@@ -672,6 +677,7 @@ public void testNotNullDomainColumn() throws SQLException {
assertEquals("id", rs.getString("COLUMN_NAME"));
assertEquals("NO", rs.getString("IS_NULLABLE"));
assertTrue(rs.next());
assertTrue(rs.next());
assertTrue(!rs.next());
}

@@ -685,6 +691,11 @@ public void testDomainColumnSize() throws SQLException {
assertTrue(rs.next());
assertEquals("v", rs.getString("COLUMN_NAME"));
assertEquals(3, rs.getInt("COLUMN_SIZE"));
assertTrue(rs.next());
assertEquals("f", rs.getString("COLUMN_NAME"));
assertEquals(8, rs.getInt("COLUMN_SIZE"));
assertEquals( 3, rs.getInt("DECIMAL_DIGITS"));

}

@Test

0 comments on commit 7f1752a

Please sign in to comment.
You can’t perform that action at this time.