Skip to content

Commit

Permalink
0003199: Support 'NaN' Datatype for Numeric Columns in Postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwellpettit committed Jul 18, 2017
1 parent 061dac2 commit 4cfc50b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Expand Up @@ -456,11 +456,17 @@ protected Object parseFloat(String value) {
}

protected Object parseBigDecimal(String value) {
value = cleanNumber(value);
/*
* In the case of a 'NaN' value, return a String
*/
if (value != null && value.equals("NaN")) {
return value;
}
/*
* The number will have either one period or one comma for the decimal
* point, but we need a period
*/
value = cleanNumber(value);
return new BigDecimal(value.replace(',', '.'));
}

Expand Down
Expand Up @@ -20,12 +20,17 @@
*/
package org.jumpmind.db.platform.postgresql;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;

import javax.sql.DataSource;

import org.jumpmind.db.platform.DatabaseInfo;
import org.jumpmind.db.sql.JdbcSqlTemplate;
import org.jumpmind.db.sql.SqlTemplateSettings;
import org.jumpmind.db.sql.SymmetricLobHandler;
import org.springframework.jdbc.core.StatementCreatorUtils;

public class PostgreSqlJdbcSqlTemplate extends JdbcSqlTemplate {

Expand Down Expand Up @@ -54,4 +59,9 @@ public String getSelectLastInsertIdSql(String sequenceName) {
protected boolean allowsNullForIdentityColumn() {
return false;
}

@Override
protected void setNanOrNull(PreparedStatement ps, int i, Object arg, int argType) throws SQLException {
StatementCreatorUtils.setParameterValue(ps, i, Types.FLOAT, Float.NaN);
}
}
Expand Up @@ -1024,7 +1024,15 @@ protected void setTinyIntValue(PreparedStatement ps, int i, Object arg, int argT
}

protected void setDecimalValue(PreparedStatement ps, int i, Object arg, int argType) throws SQLException {
StatementCreatorUtils.setParameterValue(ps, i, verifyArgType(arg, argType), arg);
if ((argType == Types.DECIMAL || argType == Types.NUMERIC) && arg != null && arg.equals("NaN")) {
setNanOrNull(ps, i, arg, argType);
} else {
StatementCreatorUtils.setParameterValue(ps, i, verifyArgType(arg, argType), arg);
}
}

protected void setNanOrNull(PreparedStatement ps, int i, Object arg, int argType) throws SQLException {
StatementCreatorUtils.setParameterValue(ps, i, verifyArgType(arg, argType), null);
}

protected int verifyArgType(Object arg, int argType) {
Expand Down

0 comments on commit 4cfc50b

Please sign in to comment.