Skip to content

Commit

Permalink
0001922: Incorrect conversion of values of type BIT in SQL Server 200…
Browse files Browse the repository at this point in the history
…5 to SQLite
  • Loading branch information
chenson42 committed Aug 21, 2014
1 parent eaf28f4 commit c63e066
Showing 1 changed file with 20 additions and 20 deletions.
Expand Up @@ -391,25 +391,12 @@ protected Object getObjectValue(String value, Column column, BinaryEncoding enco
.rightPad(value.toString(), column.getSizeAsInt(), ' ');
}
} else if (type == Types.BIGINT) {
if (StringUtils.isNumeric(value)) {
objectValue = parseBigInteger(value);
} else {
objectValue = Boolean.parseBoolean(value);
}
} else if (type == Types.INTEGER || type == Types.SMALLINT ||
type == Types.BIT) {
if (StringUtils.isNumeric(value)) {
objectValue = parseInteger(value);
} else {
objectValue = Boolean.parseBoolean(value);
}
objectValue = parseBigInteger(value);
} else if (type == Types.INTEGER || type == Types.SMALLINT || type == Types.BIT) {
objectValue = parseInteger(value);
} else if (type == Types.NUMERIC || type == Types.DECIMAL || type == Types.FLOAT
|| type == Types.DOUBLE || type == Types.REAL) {
if (StringUtils.isNumeric(value)) {
objectValue = parseBigDecimal(value);
} else {
objectValue = Boolean.parseBoolean(value);
}
|| type == Types.DOUBLE || type == Types.REAL) {
objectValue = parseBigDecimal(value);
} else if (type == Types.BOOLEAN) {
objectValue = value.equals("1") ? Boolean.TRUE : Boolean.FALSE;
} else if (!(column.getJdbcTypeName() != null && column.getJdbcTypeName().toUpperCase()
Expand Down Expand Up @@ -442,25 +429,38 @@ protected Object parseBigDecimal(String 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(',', '.').trim());
}
}

protected Object parseBigInteger(String value) {
try {
value = cleanNumber(value);
return new Long(value.trim());
} catch (NumberFormatException ex) {
} catch (NumberFormatException ex) {
return new BigInteger(value.trim());
}
}

protected Object parseInteger(String value) {
try {
value = cleanNumber(value);
return Integer.parseInt(value.trim());
} catch (NumberFormatException ex) {
return new BigInteger(value.trim());
}
}

protected String cleanNumber(String value) {
if (value.equalsIgnoreCase("true")) {
return "1";
} else if (value.equalsIgnoreCase("false")) {
return "0";
} else {
return value;
}
}

// TODO: this should be AbstractDdlBuilder.getInsertSql(Table table,
// Map<String, Object> columnValues, boolean genPlaceholders)
public String[] getStringValues(BinaryEncoding encoding, Column[] metaData, Row row,
Expand Down

0 comments on commit c63e066

Please sign in to comment.