diff --git a/co.codewizards.cloudstore.local/src/main/java/co/codewizards/cloudstore/local/db/DatabaseMigrater.java b/co.codewizards.cloudstore.local/src/main/java/co/codewizards/cloudstore/local/db/DatabaseMigrater.java index a2828047..61a977af 100644 --- a/co.codewizards.cloudstore.local/src/main/java/co/codewizards/cloudstore/local/db/DatabaseMigrater.java +++ b/co.codewizards.cloudstore.local/src/main/java/co/codewizards/cloudstore/local/db/DatabaseMigrater.java @@ -12,6 +12,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.sql.Blob; +import java.sql.Clob; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.PreparedStatement; @@ -505,7 +506,7 @@ protected void copyTableData(Table sourceTable, Table targetTable, String sql = String.format("delete from \"%s\"", targetTable.name); logger.debug("copyTableData: Executing: {}", sql); int rowsAffected = deleteStatement.executeUpdate(sql); - logger.debug("copyTableData: rowsAffected: {}", rowsAffected); + logger.debug("copyTableData: Deleted {} rows from '{}'.", rowsAffected, targetTable.name); } targetConnection.commit(); @@ -644,10 +645,19 @@ protected String getJdbcTypeAsString(int dataType) { } protected Object convertValue(Column sourceColumn, Column targetColumn, Object sourceValue) throws Exception { - if (sourceValue == null - || sourceColumn.dataType == targetColumn.dataType) + if (sourceValue == null) return sourceValue; + if (sourceValue instanceof Clob) { + Clob sourceClob = (Clob) sourceValue; + long length = sourceClob.length(); + if (length > Integer.MAX_VALUE) + throw new IllegalStateException("sourceClob.length > Integer.MAX_VALUE!!!"); + + String string = sourceClob.getSubString(1, (int) length); + return string; + } + if (sourceValue instanceof Blob) { Blob sourceBlob = (Blob) sourceValue; long length = sourceBlob.length(); @@ -658,6 +668,9 @@ protected Object convertValue(Column sourceColumn, Column targetColumn, Object s return bytes; } + if (sourceColumn.dataType == targetColumn.dataType) + return sourceValue; + switch (targetColumn.dataType) { case Types.BOOLEAN: case Types.BIT: // PostgreSQL returns BIT even though it shows 'boolean' as data-type in the pgAdmin3 -- strange, but true.