Skip to content

Commit

Permalink
[#5239] Read and write the time component as well in Oracle's DATE type
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaseder committed May 4, 2016
1 parent 87afd1f commit 089a3af
Showing 1 changed file with 92 additions and 36 deletions.
128 changes: 92 additions & 36 deletions jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java
Expand Up @@ -545,6 +545,7 @@ else if (type == Date.class) {







// [#1253] Derby doesn't support the standard literal // [#1253] Derby doesn't support the standard literal
else if (family == DERBY) { else if (family == DERBY) {
render.keyword("date('").sql(escape(val, render)).sql("')"); render.keyword("date('").sql(escape(val, render)).sql("')");
Expand Down Expand Up @@ -728,6 +729,19 @@ else if (type.isArray() && byte[].class != type) {
} }
} }















else { else {
render.sql(ctx.variable()); render.sql(ctx.variable());
} }
Expand Down Expand Up @@ -803,6 +817,11 @@ public void register(BindingRegisterContext<U> ctx) throws SQLException {

















Expand Down Expand Up @@ -980,27 +999,41 @@ else if (actualType == String.class) {
// There is potential for trouble when binding date time as such // There is potential for trouble when binding date time as such
// ------------------------------------------------------------- // -------------------------------------------------------------
else if (actualType == Date.class) { else if (actualType == Date.class) {
Date date = (Date) value;

if (dialect == SQLITE) { if (dialect == SQLITE) {
ctx.statement().setString(ctx.index(), ((Date) value).toString()); ctx.statement().setString(ctx.index(), date.toString());
} }








else { else {
ctx.statement().setDate(ctx.index(), (Date) value); ctx.statement().setDate(ctx.index(), date);
} }
} }
else if (actualType == Time.class) { else if (actualType == Time.class) {
Time time = (Time) value;

if (dialect == SQLITE) { if (dialect == SQLITE) {
ctx.statement().setString(ctx.index(), ((Time) value).toString()); ctx.statement().setString(ctx.index(), time.toString());
} }
else { else {
ctx.statement().setTime(ctx.index(), (Time) value); ctx.statement().setTime(ctx.index(), time);
} }
} }
else if (actualType == Timestamp.class) { else if (actualType == Timestamp.class) {
Timestamp timestamp = (Timestamp) value;

if (dialect == SQLITE) { if (dialect == SQLITE) {
ctx.statement().setString(ctx.index(), ((Timestamp) value).toString()); ctx.statement().setString(ctx.index(), timestamp.toString());
} }
else { else {
ctx.statement().setTimestamp(ctx.index(), (Timestamp) value); ctx.statement().setTimestamp(ctx.index(), timestamp);
} }
} }


Expand Down Expand Up @@ -1185,7 +1218,17 @@ else if (type == Clob.class) {
ctx.output().writeClob((Clob) value); ctx.output().writeClob((Clob) value);
} }
else if (type == Date.class) { else if (type == Date.class) {
ctx.output().writeDate((Date) value); Date date = (Date) value;









ctx.output().writeDate(date);
} }
else if (type == Double.class) { else if (type == Double.class) {
ctx.output().writeDouble((Double) value); ctx.output().writeDouble((Double) value);
Expand Down Expand Up @@ -1314,7 +1357,7 @@ else if (type == Clob.class) {
result = (T) ctx.resultSet().getClob(ctx.index()); result = (T) ctx.resultSet().getClob(ctx.index());
} }
else if (type == Date.class) { else if (type == Date.class) {
result = (T) getDate(ctx.configuration().dialect(), ctx.resultSet(), ctx.index()); result = (T) getDate(ctx.family(), ctx.resultSet(), ctx.index());
} }
else if (type == Double.class) { else if (type == Double.class) {
result = (T) wasNull(ctx.resultSet(), Double.valueOf(ctx.resultSet().getDouble(ctx.index()))); result = (T) wasNull(ctx.resultSet(), Double.valueOf(ctx.resultSet().getDouble(ctx.index())));
Expand All @@ -1327,13 +1370,13 @@ else if (type == Integer.class) {
} }


else if (type == LocalDate.class) { else if (type == LocalDate.class) {
result = (T) localDate(getDate(ctx.configuration().dialect(), ctx.resultSet(), ctx.index())); result = (T) localDate(getDate(ctx.family(), ctx.resultSet(), ctx.index()));
} }
else if (type == LocalTime.class) { else if (type == LocalTime.class) {
result = (T) localTime(getTime(ctx.configuration().dialect(), ctx.resultSet(), ctx.index())); result = (T) localTime(getTime(ctx.family(), ctx.resultSet(), ctx.index()));
} }
else if (type == LocalDateTime.class) { else if (type == LocalDateTime.class) {
result = (T) localDateTime(getTimestamp(ctx.configuration().dialect(), ctx.resultSet(), ctx.index())); result = (T) localDateTime(getTimestamp(ctx.family(), ctx.resultSet(), ctx.index()));
} }


else if (type == Long.class) { else if (type == Long.class) {
Expand All @@ -1354,10 +1397,10 @@ else if (type == String.class) {
result = (T) ctx.resultSet().getString(ctx.index()); result = (T) ctx.resultSet().getString(ctx.index());
} }
else if (type == Time.class) { else if (type == Time.class) {
result = (T) getTime(ctx.configuration().dialect(), ctx.resultSet(), ctx.index()); result = (T) getTime(ctx.family(), ctx.resultSet(), ctx.index());
} }
else if (type == Timestamp.class) { else if (type == Timestamp.class) {
result = (T) getTimestamp(ctx.configuration().dialect(), ctx.resultSet(), ctx.index()); result = (T) getTimestamp(ctx.family(), ctx.resultSet(), ctx.index());
} }
else if (type == YearToMonth.class) { else if (type == YearToMonth.class) {
if (ctx.family() == POSTGRES) { if (ctx.family() == POSTGRES) {
Expand Down Expand Up @@ -1536,6 +1579,15 @@ else if (type == Clob.class) {
result = (T) ctx.statement().getClob(ctx.index()); result = (T) ctx.statement().getClob(ctx.index());
} }
else if (type == Date.class) { else if (type == Date.class) {









result = (T) ctx.statement().getDate(ctx.index()); result = (T) ctx.statement().getDate(ctx.index());
} }
else if (type == Double.class) { else if (type == Double.class) {
Expand Down Expand Up @@ -1736,6 +1788,15 @@ else if (type == Clob.class) {
result = (T) ctx.input().readClob(); result = (T) ctx.input().readClob();
} }
else if (type == Date.class) { else if (type == Date.class) {









result = (T) ctx.input().readDate(); result = (T) ctx.input().readDate();
} }
else if (type == Double.class) { else if (type == Double.class) {
Expand Down Expand Up @@ -1919,54 +1980,49 @@ private static final Object[] convertArray(Array array, Class<? extends Object[]
return null; return null;
} }


private static final Date getDate(SQLDialect dialect, ResultSet rs, int index) throws SQLException { private static final Date getDate(SQLDialect family, ResultSet rs, int index) throws SQLException {


// SQLite's type affinity needs special care... // SQLite's type affinity needs special care...
if (dialect == SQLDialect.SQLITE) { if (family == SQLDialect.SQLITE) {
String date = rs.getString(index); String date = rs.getString(index);
return date == null ? null : new Date(parse(Date.class, date));
}








if (date != null) {
return new Date(parse(Date.class, date));
}


return null;
}


else { else {
return rs.getDate(index); return rs.getDate(index);
} }
} }


private static final Time getTime(SQLDialect dialect, ResultSet rs, int index) throws SQLException { private static final Time getTime(SQLDialect family, ResultSet rs, int index) throws SQLException {


// SQLite's type affinity needs special care... // SQLite's type affinity needs special care...
if (dialect == SQLDialect.SQLITE) { if (family == SQLDialect.SQLITE) {
String time = rs.getString(index); String time = rs.getString(index);

return time == null ? null : new Time(parse(Time.class, time));
if (time != null) {
return new Time(parse(Time.class, time));
}

return null;
} }


else { else {
return rs.getTime(index); return rs.getTime(index);
} }
} }


private static final Timestamp getTimestamp(SQLDialect dialect, ResultSet rs, int index) throws SQLException { private static final Timestamp getTimestamp(SQLDialect family, ResultSet rs, int index) throws SQLException {


// SQLite's type affinity needs special care... // SQLite's type affinity needs special care...
if (dialect == SQLDialect.SQLITE) { if (family == SQLDialect.SQLITE) {
String timestamp = rs.getString(index); String timestamp = rs.getString(index);
return timestamp == null ? null : new Timestamp(parse(Timestamp.class, timestamp));
}


if (timestamp != null) { else {
return new Timestamp(parse(Timestamp.class, timestamp));
}

return null;
} else {
return rs.getTimestamp(index); return rs.getTimestamp(index);
} }
} }
Expand Down

0 comments on commit 089a3af

Please sign in to comment.