Skip to content

Commit

Permalink
[bugfix][plugin][oraclewriter] Fix ora-03106 while updating clob colu…
Browse files Browse the repository at this point in the history
…mn, fix wgzhao#1030

When the "merge into" statement is executed, if the updated field is of CLOB type and the length of the updated content is too long, the ORA-03106 error will be given.
  • Loading branch information
wgzhao committed Aug 13, 2024
1 parent 821bc0e commit d3c694a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -470,16 +470,6 @@ protected PreparedStatement fillPreparedStatementColumnType(PreparedStatement pr
java.util.Date utilDate;
switch (columnSqlType) {
case Types.CLOB:
if (dataBaseType.equals(DataBaseType.Oracle) && column.asString().length() >= 4000) {
Clob clob = preparedStatement.getConnection().createClob();
clob.setString(1, column.asString());
preparedStatement.setClob(columnIndex, clob);
}
else {
preparedStatement.setString(columnIndex, column.asString());
}
break;

case Types.CHAR:
case Types.NCHAR:
case Types.NCLOB:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package com.wgzhao.addax.plugin.writer.oraclewriter;

import com.wgzhao.addax.common.base.Key;
import com.wgzhao.addax.common.element.Column;
import com.wgzhao.addax.common.exception.AddaxException;
import com.wgzhao.addax.common.plugin.RecordReceiver;
import com.wgzhao.addax.common.spi.Writer;
Expand All @@ -28,6 +29,10 @@
import com.wgzhao.addax.rdbms.util.DataBaseType;
import com.wgzhao.addax.rdbms.writer.CommonRdbmsWriter;

import java.sql.Clob;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;

public class OracleWriter
Expand Down Expand Up @@ -100,7 +105,21 @@ public static class Task
public void init()
{
this.writerSliceConfig = getPluginJobConf();
this.commonRdbmsWriterTask = new CommonRdbmsWriter.Task(DATABASE_TYPE);
this.commonRdbmsWriterTask = new CommonRdbmsWriter.Task(DATABASE_TYPE) {
@Override
protected PreparedStatement fillPreparedStatementColumnType(PreparedStatement preparedStatement, int columnIndex, int columnSqlType, Column column)
throws SQLException
{
if (writerSliceConfig.getString(Key.WRITE_MODE, "").startsWith("update") && columnSqlType == Types.CLOB ) {
Clob clob = preparedStatement.getConnection().createClob();
clob.setString(1, column.asString());
preparedStatement.setClob(columnIndex, clob);
return preparedStatement;
}

return super.fillPreparedStatementColumnType(preparedStatement, columnIndex, columnSqlType, column);
}
};
commonRdbmsWriterTask.init(writerSliceConfig);
}

Expand Down

0 comments on commit d3c694a

Please sign in to comment.