[#7174] Add support for PostgreSQL ROWTYPE function parameters
This commit is contained in:
parent
b478e9ba6a
commit
093990e395
@ -147,6 +147,7 @@ import org.jooq.Row;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.Schema;
|
||||
import org.jooq.Scope;
|
||||
import org.jooq.TableRecord;
|
||||
import org.jooq.UDTRecord;
|
||||
import org.jooq.exception.ControlFlowSignal;
|
||||
import org.jooq.exception.DataTypeException;
|
||||
@ -2653,8 +2654,21 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
|
||||
}
|
||||
|
||||
@Override
|
||||
final void sqlInline0(BindingSQLContext<U> ctx, Record value) {
|
||||
ctx.render().sql("[UDT]");
|
||||
void sqlBind0(BindingSQLContext<U> ctx, Record value) throws SQLException {
|
||||
super.sqlBind0(ctx, value);
|
||||
|
||||
if (ctx.family() == POSTGRES && value != null)
|
||||
pgRenderRecordCast(ctx.render(), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
final void sqlInline0(BindingSQLContext<U> ctx, Record value) throws SQLException {
|
||||
if (ctx.family() == POSTGRES) {
|
||||
ctx.render().visit(inline(PostgresUtils.toPGString(value)));
|
||||
pgRenderRecordCast(ctx.render(), value);
|
||||
}
|
||||
else
|
||||
ctx.render().sql("[UDT]");
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@ -2672,7 +2686,10 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
|
||||
|
||||
@Override
|
||||
final void set0(BindingSetStatementContext<U> ctx, Record value) throws SQLException {
|
||||
ctx.statement().setObject(ctx.index(), value);
|
||||
if (ctx.family() == POSTGRES && value != null)
|
||||
ctx.statement().setString(ctx.index(), PostgresUtils.toPGString(value));
|
||||
else
|
||||
ctx.statement().setObject(ctx.index(), value);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@ -2735,6 +2752,13 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
|
||||
// interfaces. Instead, a string representation of a UDT has to be parsed
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
static final void pgRenderRecordCast(RenderContext render, Record value) {
|
||||
if (value instanceof UDTRecord)
|
||||
render.sql("::").visit(((UDTRecord<?>) value).getUDT().getQualifiedName());
|
||||
else if (value instanceof TableRecord)
|
||||
render.sql("::").visit(((TableRecord<?>) value).getTable().getQualifiedName());
|
||||
}
|
||||
|
||||
private static final <T> T pgFromString(Class<T> type, String string) {
|
||||
return pgFromString(Converters.identity(type), string);
|
||||
}
|
||||
|
||||
@ -72,6 +72,7 @@ import org.jooq.Field;
|
||||
import org.jooq.Nullability;
|
||||
import org.jooq.Result;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.TableRecord;
|
||||
import org.jooq.UDTRecord;
|
||||
import org.jooq.exception.MappingException;
|
||||
import org.jooq.exception.SQLDialectNotSupportedException;
|
||||
@ -847,6 +848,11 @@ public class DefaultDataType<T> implements DataType<T> {
|
||||
return (DataType<T>) ((UDTRecord<?>) type.newInstance()).getUDT().getDataType();
|
||||
}
|
||||
|
||||
// [#7174] PostgreSQL table records can be function argument types
|
||||
else if (TableRecord.class.isAssignableFrom(type)) {
|
||||
return (DataType<T>) ((TableRecord<?>) type.newInstance()).getTable().getDataType();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user