Skip to content

Commit

Permalink
0004902: Auto resolve when primary key has binary/varbinary
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Mar 17, 2021
1 parent b7d25d4 commit 1e832ed
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 5 deletions.
Expand Up @@ -90,6 +90,8 @@ public FirebirdDdlBuilder() {
databaseInfo.setBlankCharColumnSpacePadded(true);
databaseInfo.setCharColumnSpaceTrimmed(false);
databaseInfo.setEmptyStringNulled(false);
databaseInfo.setBinaryQuoteStart("X'");
databaseInfo.setBinaryQuoteEnd("'");

databaseInfo.setMinIsolationLevelToPreventPhantomReads(Connection.TRANSACTION_REPEATABLE_READ);

Expand Down
Expand Up @@ -130,7 +130,8 @@ protected void setup() {
databaseInfo.setCharColumnSpaceTrimmed(false);
databaseInfo.setEmptyStringNulled(false);
databaseInfo.setAutoIncrementUpdateAllowed(false);

databaseInfo.setBinaryQuoteStart("0x");
databaseInfo.setBinaryQuoteEnd("");
}

@Override
Expand Down
Expand Up @@ -106,6 +106,8 @@ public MySqlDdlBuilder() {
databaseInfo.setBlankCharColumnSpacePadded(false);
databaseInfo.setCharColumnSpaceTrimmed(true);
databaseInfo.setEmptyStringNulled(false);
databaseInfo.setBinaryQuoteStart("0x");
databaseInfo.setBinaryQuoteEnd("");

// MySql 5.0 returns an empty string for default values for pk columns
// which is different from the MySql 4 behaviour
Expand Down
Expand Up @@ -109,6 +109,8 @@ public OracleDdlBuilder() {
databaseInfo.setCharColumnSpaceTrimmed(false);
databaseInfo.setEmptyStringNulled(true);
databaseInfo.setTriggersCreateOrReplaceSupported(true);
databaseInfo.setBinaryQuoteStart("0x");
databaseInfo.setBinaryQuoteEnd("");
}

@Override
Expand Down
Expand Up @@ -96,6 +96,9 @@ public PostgreSqlDdlBuilder() {
databaseInfo.setBlankCharColumnSpacePadded(true);
databaseInfo.setCharColumnSpaceTrimmed(false);
databaseInfo.setEmptyStringNulled(false);
databaseInfo.setBinaryQuoteStart("0x");
databaseInfo.setBinaryQuoteEnd("");

// we need to handle the backslash first otherwise the other
// already escaped sequences would be affected
addEscapedCharSequence("\\", "\\\\");
Expand Down
Expand Up @@ -177,6 +177,7 @@ protected int[] buildTypes(Column[] keys, Column[] columns, boolean isDateOverri
case DELETE:
return buildTypes(keys, isDateOverrideToTimestamp);
case COUNT:
case SELECT:
return buildTypes(keys, isDateOverrideToTimestamp);
default:
break;
Expand Down
7 changes: 6 additions & 1 deletion symmetric-db/src/main/java/org/jumpmind/db/sql/Row.java
Expand Up @@ -31,6 +31,7 @@
import java.util.Date;
import java.util.Map;

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.io.IOUtils;
import org.jumpmind.exception.IoException;
import org.jumpmind.exception.ParseException;
Expand Down Expand Up @@ -158,8 +159,12 @@ public String getString(String columnName) {
public String getString(String columnName, boolean checkForColumn) {
Object obj = this.get(columnName);
if (obj != null) {
if(obj instanceof BigDecimal) {
if (obj instanceof String) {
return (String) obj;
} else if (obj instanceof BigDecimal) {
return ((BigDecimal) obj).toPlainString();
} else if (obj instanceof byte[]) {
return Hex.encodeHexString((byte[]) obj);
} else {
return obj.toString();
}
Expand Down
Expand Up @@ -1730,8 +1730,8 @@ public List<TableRow> getExportedForeignTableRows(ISqlTransaction transaction, L
DmlStatement selectSt = platform.createDmlStatement(DmlType.SELECT, foreignTable.getCatalog(),
foreignTable.getSchema(), foreignTable.getName(), keyColumns,
foreignTable.getColumns(), nullValues, null);
Object[] selectValues = selectRow.toArray(selectRow.keySet().toArray(new String[0]));
//platform.getObjectValues(BinaryEncoding.NONE, _defaultTableTypes, keyColumns);
Object[] selectValues = platform.getObjectValues(BinaryEncoding.HEX, selectRow.toStringArray(selectRow.keySet().toArray(new String[0])),
keyColumns);
List<Row> rows = transaction.query(selectSt.getSql(), new RowMapper(), selectValues, selectSt.getTypes());

if (rows != null) {
Expand All @@ -1740,7 +1740,7 @@ public List<TableRow> getExportedForeignTableRows(ISqlTransaction transaction, L
DmlStatement whereSt = platform.createDmlStatement(DmlType.WHERE, foreignTable.getCatalog(),
foreignTable.getSchema(), foreignTable.getName(), foreignTable.getPrimaryKeyColumns(),
foreignTable.getColumns(), nullValues, null);
String whereSql = whereSt.buildDynamicSql(BinaryEncoding.NONE, row, false, true,
String whereSql = whereSt.buildDynamicSql(BinaryEncoding.HEX, row, false, true,
foreignTable.getPrimaryKeyColumns()).substring(6);
String delimiter = platform.getDatabaseInfo().getSqlCommandDelimiter();
if (delimiter != null && delimiter.length() > 0) {
Expand Down

0 comments on commit 1e832ed

Please sign in to comment.