Skip to content

Commit

Permalink
0001295: Numeric type on postgres should be read in as a JDBC decimal…
Browse files Browse the repository at this point in the history
… type
  • Loading branch information
chenson42 committed Jun 25, 2013
1 parent c4b7214 commit 6543e0c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
Expand Up @@ -1749,15 +1749,21 @@ protected String getSqlType(Column column) {
}
if (sizeSpec != null) {
if (databaseInfo.hasSize(column.getMappedTypeCode())) {
sqlType.append("(");
sqlType.append(sizeSpec.toString());
sqlType.append(")");
if (!"0".equals(sizeSpec)) {
sqlType.append("(");
sqlType.append(sizeSpec.toString());
sqlType.append(")");
}
} else if (databaseInfo.hasPrecisionAndScale(column.getMappedTypeCode())) {
sqlType.append("(");
sqlType.append(column.getSizeAsInt());
sqlType.append(",");
sqlType.append(column.getScale());
sqlType.append(")");
StringBuilder precisionAndScale = new StringBuilder();
precisionAndScale.append("(");
precisionAndScale.append(column.getSizeAsInt());
precisionAndScale.append(",");
precisionAndScale.append(column.getScale());
precisionAndScale.append(")");
if (!"(0,0)".equals(precisionAndScale.toString())) {
sqlType.append(precisionAndScale);
}
}
}
sqlType.append(sizePos >= 0 ? nativeType.substring(sizePos + SIZE_PLACEHOLDER.length())
Expand Down
Expand Up @@ -142,7 +142,11 @@ else if (column.getSizeAsInt() == Integer.MAX_VALUE) {
} else if (column.getMappedTypeCode() == Types.BINARY) {
column.setMappedTypeCode(Types.LONGVARBINARY);
}
} else if (column.getSizeAsInt() == 131089 && column.getJdbcTypeCode() == Types.NUMERIC) {
column.setSizeAndScale(0, 0);
column.setMappedTypeCode(Types.DECIMAL);
}

}

String defaultValue = column.getDefaultValue();
Expand Down
Expand Up @@ -164,6 +164,23 @@ public void testCreateAndReadTestSimpleTable() throws Exception {
Assert.assertEquals("The id column was not read in as an autoincrement column", true, table
.getColumnWithName("id").isAutoIncrement());
}

@Test
public void testPostgresCreateAndReadNumericType() throws Exception {
if (platform.getName().equals(DatabaseNamesConstants.POSTGRESQL)) {
Table table = new Table("with_numeric");
table.addColumn(new Column("id", true, Types.DECIMAL, 0, 0));
platform.createTables(true, true, table);

Table fromDatabase = platform.readTableFromDatabase(null, null, table.getName());

Assert.assertNotNull(fromDatabase);
Assert.assertEquals(table.getName(), fromDatabase.getName());
Assert.assertEquals(Types.DECIMAL, fromDatabase.getColumn(0).getMappedTypeCode());

Assert.assertEquals(DatabaseXmlUtil.toXml(table), DatabaseXmlUtil.toXml(fromDatabase));
}
}

@Test
public void testReadTestUppercase() throws Exception {
Expand Down

0 comments on commit 6543e0c

Please sign in to comment.