Skip to content

Commit

Permalink
- Fix trigger template on ASE to handle decimals.
Browse files Browse the repository at this point in the history
- Fix issue where ASA was truncating numbers to the right of the decimal point.
  • Loading branch information
abrougher committed Jul 13, 2013
1 parent 8797813 commit a3d9b86
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
Expand Up @@ -202,7 +202,9 @@ protected String buildKeyVariablesDeclare(Column[] columns, String prefix) {
break;
case Types.NUMERIC:
case Types.DECIMAL:
text += "decimal\n";
// Use same default scale and precision used by Sybase ASA
// for a decimal with unspecified scale and precision.
text += "decimal(30,6)\n";
break;
case Types.FLOAT:
case Types.REAL:
Expand Down
Expand Up @@ -109,15 +109,15 @@ protected DatabaseWriterSettings buildDatabaseWriterSettings(
settings.setTreatDateTimeFieldsAsVarchar(parameterService
.is(ParameterConstants.DATA_LOADER_TREAT_DATETIME_AS_VARCHAR));
settings.setSaveCurrentValueOnError(parameterService.is(ParameterConstants.DATA_LOADER_ERROR_RECORD_CUR_VAL, false));

Map<String, Conflict> byChannel = new HashMap<String, Conflict>();
Map<String, Conflict> byTable = new HashMap<String, Conflict>();
boolean multipleDefaultSettingsFound = false;
if (conflictSettings != null) {
for (Conflict conflictSetting : conflictSettings) {
String qualifiedTableName = conflictSetting.toQualifiedTableName();
if (StringUtils.isNotBlank(qualifiedTableName)) {
byTable.put(qualifiedTableName, conflictSetting);
byTable.put(qualifiedTableName, conflictSetting); // ADB
} else if (StringUtils.isNotBlank(conflictSetting.getTargetChannelId())) {
byChannel.put(conflictSetting.getTargetChannelId(), conflictSetting);
} else {
Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.jumpmind.db.platform.mysql.MySqlDmlStatement;
import org.jumpmind.db.platform.oracle.OracleDmlStatement;
import org.jumpmind.db.platform.postgresql.PostgreSqlDmlStatement;
import org.jumpmind.db.platform.sqlanywhere.SqlAnywhereDmlStatement;
import org.jumpmind.db.platform.sqlite.SqliteDmlStatement;
import org.jumpmind.db.sql.DmlStatement;
import org.jumpmind.db.sql.DmlStatement.DmlType;
Expand Down Expand Up @@ -68,7 +69,11 @@ public static DmlStatement createDmlStatement(String databaseName, DmlType dmlTy
} else if (DatabaseNamesConstants.SQLITE.equals(databaseName)) {
return new SqliteDmlStatement(dmlType, catalogName, schemaName, tableName, keys,
columns, nullKeyValues, ddlBuilder.getDatabaseInfo(),
ddlBuilder.isDelimitedIdentifierModeOn());
ddlBuilder.isDelimitedIdentifierModeOn());
} else if (DatabaseNamesConstants.SQLANYWHERE.equals(databaseName)) {
return new SqlAnywhereDmlStatement(dmlType, catalogName, schemaName, tableName, keys, columns,
nullKeyValues, ddlBuilder.getDatabaseInfo(),
ddlBuilder.isDelimitedIdentifierModeOn());
} else {
return new DmlStatement(dmlType, catalogName, schemaName, tableName, keys, columns,
nullKeyValues, ddlBuilder.getDatabaseInfo(),
Expand Down
@@ -0,0 +1,28 @@
package org.jumpmind.db.platform.sqlanywhere;

import java.sql.Types;

import org.jumpmind.db.model.Column;
import org.jumpmind.db.platform.DatabaseInfo;
import org.jumpmind.db.sql.DmlStatement;

public class SqlAnywhereDmlStatement extends DmlStatement {

public SqlAnywhereDmlStatement(DmlType type, String catalogName,
String schemaName, String tableName, Column[] keysColumns,
Column[] columns, boolean[] nullKeyValues,
DatabaseInfo databaseInfo, boolean useQuotedIdentifiers) {
super(type, catalogName, schemaName, tableName, keysColumns, columns,
nullKeyValues, databaseInfo, useQuotedIdentifiers);
}

@Override
protected int getTypeCode(Column column, boolean isDateOverrideToTimestamp) {
int type = column.getMappedTypeCode();
if (type == Types.DATE && isDateOverrideToTimestamp) {
type = Types.TIMESTAMP;
}
return type;
}

}
Expand Up @@ -88,6 +88,10 @@ protected Column readColumn(DatabaseMetaDataWrapper metaData, Map<String,Object>
&& (column.getScale() == 0)) {
// Back-mapping to BIGINT
column.setMappedTypeCode(Types.BIGINT);
} else if (column.getMappedTypeCode() == Types.NUMERIC) {
// ASA truncates everything to the right of the decimal point unless
// we map to DOUBLE.
column.setMappedTypeCode(Types.DOUBLE);
} else if (column.getDefaultValue() != null) {
if (column.getMappedTypeCode() == Types.TIMESTAMP) {
// Sybase maintains the default values for DATE/TIME jdbc types,
Expand Down

0 comments on commit a3d9b86

Please sign in to comment.