From b24e3db98b6e78bfffcbb87f40dabd3b595ae2bb Mon Sep 17 00:00:00 2001 From: Mark Rotteveel Date: Wed, 25 Sep 2024 12:33:05 +0200 Subject: [PATCH] #822 Delegate to FBField for FBPreparedStatement and FBResultSet --- .../firebirdsql/jdbc/FBPreparedStatement.java | 8 +------- src/main/org/firebirdsql/jdbc/FBResultSet.java | 18 ++++-------------- .../org/firebirdsql/jdbc/field/FBField.java | 10 ++++++++++ 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/main/org/firebirdsql/jdbc/FBPreparedStatement.java b/src/main/org/firebirdsql/jdbc/FBPreparedStatement.java index 02ec5863f..fbe60c8ff 100644 --- a/src/main/org/firebirdsql/jdbc/FBPreparedStatement.java +++ b/src/main/org/firebirdsql/jdbc/FBPreparedStatement.java @@ -516,13 +516,7 @@ public void clearParameters() throws SQLException { @Override public void setObject(int parameterIndex, @Nullable Object x, int targetSqlType, int scaleOrLength) throws SQLException { - if (x instanceof InputStream) { - setBinaryStream(parameterIndex, (InputStream) x, scaleOrLength); - } else if (x instanceof Reader) { - setCharacterStream(parameterIndex, (Reader) x, scaleOrLength); - } else { - setObject(parameterIndex, x); - } + getField(parameterIndex).setObject(x, scaleOrLength); } /** diff --git a/src/main/org/firebirdsql/jdbc/FBResultSet.java b/src/main/org/firebirdsql/jdbc/FBResultSet.java index 05aacec08..b276b98b7 100644 --- a/src/main/org/firebirdsql/jdbc/FBResultSet.java +++ b/src/main/org/firebirdsql/jdbc/FBResultSet.java @@ -1111,13 +1111,8 @@ public void updateBinaryStream(String columnLabel, @Nullable InputStream x) thro */ @Override public void updateObject(int columnIndex, @Nullable Object x, int scaleOrLength) throws SQLException { - if (x instanceof InputStream) { - updateBinaryStream(columnIndex, (InputStream) x, scaleOrLength); - } else if (x instanceof Reader) { - updateCharacterStream(columnIndex, (Reader) x, scaleOrLength); - } else { - updateObject(columnIndex, x); - } + checkUpdatable(); + getField(columnIndex).setObject(x, scaleOrLength); } /** @@ -1410,13 +1405,8 @@ public void updateNCharacterStream(String columnLabel, @Nullable Reader reader) */ @Override public void updateObject(String columnName, @Nullable Object x, int scaleOrLength) throws SQLException { - if (x instanceof InputStream) { - updateBinaryStream(columnName, (InputStream) x, scaleOrLength); - } else if (x instanceof Reader) { - updateCharacterStream(columnName, (Reader) x, scaleOrLength); - } else { - updateObject(columnName, x); - } + checkUpdatable(); + getField(columnName).setObject(x, scaleOrLength); } /** diff --git a/src/main/org/firebirdsql/jdbc/field/FBField.java b/src/main/org/firebirdsql/jdbc/field/FBField.java index a06be29a1..bf601ad21 100644 --- a/src/main/org/firebirdsql/jdbc/field/FBField.java +++ b/src/main/org/firebirdsql/jdbc/field/FBField.java @@ -498,6 +498,16 @@ public void setObject(Object value) throws SQLException { } } + public void setObject(Object value, int scaleOrLength) throws SQLException { + if (value instanceof InputStream) { + setBinaryStream((InputStream) value, scaleOrLength); + } else if (value instanceof Reader) { + setCharacterStream((Reader) value, scaleOrLength); + } else { + setObject(value); + } + } + private void setObjectWithInstanceOf(Object value) throws SQLException { if (value instanceof BigDecimal bigDecimal) { setBigDecimal(bigDecimal);