[jOOQ/jOOQ#11512] Correct data type binding for setNull() calls
This includes: - [jOOQ/jOOQ#11626] Add DefaultDataType.getDataType(SQLDialect, int) to lookup JDBC types
This commit is contained in:
parent
c71857c804
commit
158facf3b1
@ -49,10 +49,16 @@ import static org.jooq.SQLDialect.SQLITE;
|
||||
import static org.jooq.impl.CommentImpl.NO_COMMENT;
|
||||
import static org.jooq.impl.DSL.unquotedName;
|
||||
import static org.jooq.impl.DefaultBinding.binding;
|
||||
import static org.jooq.impl.SQLDataType.BIGINT;
|
||||
import static org.jooq.impl.SQLDataType.*;
|
||||
import static org.jooq.impl.SQLDataType.BIT;
|
||||
import static org.jooq.impl.SQLDataType.OTHER;
|
||||
import static org.jooq.tools.reflect.Reflect.wrapper;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.sql.SQLType;
|
||||
import java.sql.Types;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@ -586,6 +592,80 @@ public class DefaultDataType<T> extends AbstractDataTypeX<T> {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static final DataType<?> getDataType(SQLDialect dialect, SQLType sqlType) {
|
||||
Integer i = sqlType.getVendorTypeNumber();
|
||||
return i == null ? OTHER : getDataType(dialect, i);
|
||||
}
|
||||
|
||||
public static final DataType<?> getDataType(SQLDialect dialect, int sqlType) {
|
||||
switch (sqlType) {
|
||||
case Types.BIGINT:
|
||||
return BIGINT;
|
||||
case Types.BINARY:
|
||||
return BINARY;
|
||||
case Types.BIT:
|
||||
return BIT;
|
||||
case Types.BLOB:
|
||||
return BLOB;
|
||||
case Types.BOOLEAN:
|
||||
return BOOLEAN;
|
||||
case Types.CHAR:
|
||||
return CHAR;
|
||||
case Types.CLOB:
|
||||
return CLOB;
|
||||
case Types.DATE:
|
||||
return DATE;
|
||||
case Types.DECIMAL:
|
||||
return DECIMAL;
|
||||
case Types.DOUBLE:
|
||||
return DOUBLE;
|
||||
case Types.FLOAT:
|
||||
return FLOAT;
|
||||
case Types.INTEGER:
|
||||
return INTEGER;
|
||||
case Types.LONGNVARCHAR:
|
||||
return LONGNVARCHAR;
|
||||
case Types.LONGVARBINARY:
|
||||
return LONGVARBINARY;
|
||||
case Types.LONGVARCHAR:
|
||||
return LONGVARCHAR;
|
||||
case Types.NCHAR:
|
||||
return NCHAR;
|
||||
case Types.NCLOB:
|
||||
return NCLOB;
|
||||
case Types.NUMERIC:
|
||||
return NUMERIC;
|
||||
case Types.NVARCHAR:
|
||||
return NVARCHAR;
|
||||
case Types.REAL:
|
||||
return REAL;
|
||||
case Types.REF_CURSOR:
|
||||
return RESULT;
|
||||
case Types.SMALLINT:
|
||||
return SMALLINT;
|
||||
case Types.SQLXML:
|
||||
return XML;
|
||||
case Types.STRUCT:
|
||||
return RECORD;
|
||||
case Types.TIME:
|
||||
return TIME;
|
||||
case Types.TIME_WITH_TIMEZONE:
|
||||
return TIMEWITHTIMEZONE;
|
||||
case Types.TIMESTAMP:
|
||||
return TIMESTAMP;
|
||||
case Types.TIMESTAMP_WITH_TIMEZONE:
|
||||
return TIMESTAMPWITHTIMEZONE;
|
||||
case Types.TINYINT:
|
||||
return TINYINT;
|
||||
case Types.VARBINARY:
|
||||
return VARBINARY;
|
||||
case Types.VARCHAR:
|
||||
return VARCHAR;
|
||||
default:
|
||||
return OTHER;
|
||||
}
|
||||
}
|
||||
|
||||
public static final <T> DataType<T> getDataType(SQLDialect dialect, Class<T> type) {
|
||||
return getDataType(dialect, type, null);
|
||||
}
|
||||
|
||||
@ -417,14 +417,12 @@ final class ParsingStatement implements CallableStatement {
|
||||
|
||||
@Override
|
||||
public final void setNull(int parameterIndex, int sqlType) throws SQLException {
|
||||
// TODO: Type lookup
|
||||
set(parameterIndex, () -> val((Object) null));
|
||||
set(parameterIndex, () -> val(null, DefaultDataType.getDataType(connection.configuration.dialect(), sqlType)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException {
|
||||
// TODO: Type lookup
|
||||
set(parameterIndex, () -> val((Object) null));
|
||||
set(parameterIndex, () -> val(null, DefaultDataType.getDataType(connection.configuration.dialect(), sqlType)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -494,32 +492,27 @@ final class ParsingStatement implements CallableStatement {
|
||||
|
||||
@Override
|
||||
public final void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
|
||||
// TODO: Type lookup
|
||||
set(parameterIndex, () -> val(x));
|
||||
set(parameterIndex, () -> val(x, DefaultDataType.getDataType(connection.configuration.dialect(), targetSqlType)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setObject(int parameterIndex, Object x) throws SQLException {
|
||||
// TODO: Type lookup
|
||||
set(parameterIndex, () -> val(x));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException {
|
||||
// TODO: Type lookup
|
||||
set(parameterIndex, () -> val(x));
|
||||
set(parameterIndex, () -> val(x, DefaultDataType.getDataType(connection.configuration.dialect(), targetSqlType)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setObject(int parameterIndex, Object x, SQLType targetSqlType, int scaleOrLength) throws SQLException {
|
||||
// TODO: Type lookup
|
||||
set(parameterIndex, () -> val(x));
|
||||
set(parameterIndex, () -> val(x, DefaultDataType.getDataType(connection.configuration.dialect(), targetSqlType)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setObject(int parameterIndex, Object x, SQLType targetSqlType) throws SQLException {
|
||||
// TODO: Type lookup
|
||||
set(parameterIndex, () -> val(x));
|
||||
set(parameterIndex, () -> val(x, DefaultDataType.getDataType(connection.configuration.dialect(), targetSqlType)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
Reference in New Issue
Block a user