[jOOQ/jOOQ#9201] Corrects DefaultDayToSecondBinding for Postgres

In the case of Postgres the interval literal syntax requires each
component to have its own sign. This in contrast to the SQL standard,
where the leading sign applies to all components in the interval.

`DefaultDayToSecondBinding` now overrides `sqlInline0()` and implements
this Postgres-specific formatting when rendering interval literals.
This commit is contained in:
Knut Wannheden 2019-09-13 15:42:26 +02:00
parent 28677b252e
commit dbb1aba882

View File

@ -2118,6 +2118,29 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
super(converter, isLob);
}
@Override
void sqlInline0(BindingSQLContext<U> ctx, DayToSecond value) throws SQLException {
// [#566] Interval data types are best bound as Strings
if ( ctx.family() == POSTGRES) {
int sign = value.getSign();
int days = sign * value.getDays();
ctx.render().sql('\'')
.sql(days >= 0 ? '+' : '-')
.sql(Math.abs(days))
.sql(' ')
.sql(sign * value.getHours())
.sql(':')
.sql(sign * value.getMinutes())
.sql(':')
.sql(sign * value.getSeconds())
.sql('.')
.sql(StringUtils.leftPad(Integer.toString(value.getNano()), 9, '0'))
.sql('\'');
}
else
ctx.render().sql('\'').sql(value.toString()).sql('\'');
}
@Override
final void set0(BindingSetStatementContext<U> ctx, DayToSecond value) throws SQLException {