IDEMPIERE-3842 Cannot run Synchronize Column on oracle CLOB columns

This commit is contained in:
Carlos Ruiz 2018-12-04 15:25:43 +01:00
parent 349c764730
commit 7c023a5ac3
5 changed files with 46 additions and 5 deletions

View File

@ -20,6 +20,7 @@ import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.Types;
import java.util.logging.Level;
import org.compiere.model.MColumn;
@ -110,6 +111,21 @@ public class ColumnSync extends SvrProcess
// update existing column
boolean notNull = DatabaseMetaData.columnNoNulls == rs.getInt("NULLABLE");
sql = column.getSQLModify(table, column.isMandatory() != notNull);
if (DB.isOracle()) {
// IDEMPIERE-3842 problem with oracle alter CLOB or BLOB
int actualType = rs.getInt("DATA_TYPE");
if (actualType == Types.CLOB) {
if (sql.contains(" MODIFY " + column.getColumnName() + " CLOB")) {
// trying to make CLOB a column that is already a CLOB
sql = sql.replaceFirst(" MODIFY " + column.getColumnName() + " CLOB", " MODIFY " + column.getColumnName());
}
} else if (actualType == Types.BLOB) {
if (sql.contains(" MODIFY " + column.getColumnName() + " BLOB")) {
// trying to make BLOB a column that is already a BLOB
sql = sql.replaceFirst(" MODIFY " + column.getColumnName() + " BLOB", " MODIFY " + column.getColumnName());
}
}
}
break;
}
DB.close(rs);

View File

@ -763,7 +763,7 @@ public class MColumn extends X_AD_Column
foreignTable = "M_AttributeSetInstance";
} else if (DisplayType.Assignment == refid) {
foreignTable = "S_ResourceAssignment";
} else if (DisplayType.Image == refid) {
} else if (DisplayType.Image == refid && !"BinaryData".equals(getColumnName())) {
foreignTable = "AD_Image";
} else if (DisplayType.Chart == refid) {
foreignTable = "AD_Chart";

View File

@ -20,6 +20,7 @@ import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
import java.util.logging.Level;
@ -245,10 +246,23 @@ public class ColumnElementHandler extends AbstractElementHandler {
if (rsc.next()) {
if (doAlter) {
// update existing column
boolean notNull = DatabaseMetaData.columnNoNulls == rsc
.getInt("NULLABLE");
sql = column.getSQLModify(table,
column.isMandatory() != notNull);
boolean notNull = DatabaseMetaData.columnNoNulls == rsc.getInt("NULLABLE");
sql = column.getSQLModify(table, column.isMandatory() != notNull);
if (DB.isOracle()) {
// IDEMPIERE-3842 problem with oracle alter CLOB or BLOB
int actualType = rsc.getInt("DATA_TYPE");
if (actualType == Types.CLOB) {
if (sql.contains(" MODIFY " + column.getColumnName() + " CLOB")) {
// trying to make CLOB a column that is already a CLOB
sql = sql.replaceFirst(" MODIFY " + column.getColumnName() + " CLOB", " MODIFY " + column.getColumnName());
}
} else if (actualType == Types.BLOB) {
if (sql.contains(" MODIFY " + column.getColumnName() + " BLOB")) {
// trying to make BLOB a column that is already a BLOB
sql = sql.replaceFirst(" MODIFY " + column.getColumnName() + " BLOB", " MODIFY " + column.getColumnName());
}
}
}
}
} else {
// No existing column

View File

@ -369,6 +369,9 @@ public class DB_Oracle implements AdempiereDatabase
public String convertStatement (String oraStatement)
{
Convert.logMigrationScript(oraStatement, null);
if ("true".equals(System.getProperty("org.idempiere.db.oracle.debug"))) {
log.warning("Oracle -> " + oraStatement);
}
return oraStatement;
} // convertStatement

View File

@ -2,14 +2,22 @@ package org.compiere.dbPort;
import java.util.ArrayList;
import org.compiere.util.CLogger;
public class Convert_Oracle extends Convert {
/** Logger */
private static CLogger log = CLogger.getCLogger(Convert_Oracle.class);
public Convert_Oracle() {}
@Override
protected ArrayList<String> convertStatement(String sqlStatement) {
ArrayList<String> result = new ArrayList<String>();
result.add(sqlStatement);
if ("true".equals(System.getProperty("org.idempiere.db.oracle.debug"))) {
log.warning("Oracle -> " + sqlStatement);
}
return result;
}