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:handle numeric domain types #1611

Merged
merged 2 commits into from Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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:
Expand All @@ -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);
Expand Down
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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());
}

Expand All @@ -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
Expand Down