-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #201 from bug/REL1_5_STABLE/issue199
Fix a regression in 1.5.1 that was not caught in pre-release testing, and could leave conversions between PostgreSQL date and java.sql.Date off by one day in certain timezones and times of the year (#199). Other issues in date/time conversion have also been uncovered that are of longer standing, not recent regressions. They are detailed in #200 and are not fixed in this PR, but can be addressed in another, later release.
- Loading branch information
Showing
4 changed files
with
138 additions
and
5 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
pljava-examples/src/main/java/org/postgresql/pljava/example/annotation/PreJSR310.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright (c) 2018- Tada AB and other contributors, as listed below. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the The BSD 3-Clause License | ||
* which accompanies this distribution, and is available at | ||
* http://opensource.org/licenses/BSD-3-Clause | ||
* | ||
* Contributors: | ||
* Chapman Flack | ||
*/ | ||
package org.postgresql.pljava.example.annotation; | ||
|
||
import java.sql.Connection; | ||
import java.sql.Date; | ||
import java.sql.DriverManager; | ||
import java.sql.Statement; | ||
import java.sql.ResultSet; | ||
import java.sql.Savepoint; | ||
import java.sql.SQLException; | ||
|
||
import static java.util.logging.Logger.getAnonymousLogger; | ||
import java.util.TimeZone; | ||
|
||
import org.postgresql.pljava.annotation.Function; | ||
import org.postgresql.pljava.annotation.SQLAction; | ||
|
||
/** | ||
* Some tests of pre-JSR 310 date/time/timestamp conversions. | ||
*<p> | ||
* For now, just {@code java.sql.Date}, thanks to issue #199. | ||
*<p> | ||
* This example relies on {@code implementor} tags reflecting the PostgreSQL | ||
* version, set up in the {@link ConditionalDDR} example. | ||
*/ | ||
@SQLAction(implementor="postgresql_ge_90300", // needs LATERAL | ||
requires="issue199", install={ | ||
"SELECT javatest.issue199()" | ||
}) | ||
public class PreJSR310 | ||
{ | ||
private static final String TZPRAGUE = "Europe/Prague"; | ||
|
||
/** | ||
* Test for a regression in PG date to/from java.sql.Date conversion | ||
* identified in issue #199. | ||
*<p> | ||
* Checks that two months of consecutive dates in October/November 2018 | ||
* are converted correctly in the Europe/Prague timezone. The actual issue | ||
* was by no means limited to that timezone, but this test reproducibly | ||
* detects it. | ||
*/ | ||
@Function(schema="javatest", provides="issue199") | ||
public static void issue199() throws SQLException | ||
{ | ||
TimeZone oldZone = TimeZone.getDefault(); | ||
TimeZone tzPrague = TimeZone.getTimeZone(TZPRAGUE); | ||
Connection c = DriverManager.getConnection("jdbc:default:connection"); | ||
Statement s = c.createStatement(); | ||
Savepoint svpt = c.setSavepoint(); | ||
boolean ok = true; | ||
try | ||
{ | ||
TimeZone.setDefault(tzPrague); | ||
s.execute("SET LOCAL TIME ZONE '" + TZPRAGUE + "'"); | ||
|
||
ResultSet rs = s.executeQuery( | ||
"SELECT" + | ||
" d, to_char(d, 'YYYY-MM-DD')" + | ||
" FROM" + | ||
" generate_series(0, 60) AS s(i)," + | ||
" LATERAL (SELECT date '2018-10-01' + i) AS t(d)"); | ||
while ( rs.next() ) | ||
{ | ||
Date dd = rs.getDate(1); | ||
String ds = rs.getString(2); | ||
if ( ! ds.equals(dd.toString()) ) | ||
ok = false; | ||
} | ||
} | ||
finally | ||
{ | ||
TimeZone.setDefault(oldZone); | ||
c.rollback(svpt); // restore prior PG timezone | ||
s.close(); | ||
c.close(); | ||
} | ||
|
||
if ( ok ) | ||
getAnonymousLogger().info("issue 199 test ok"); | ||
else | ||
getAnonymousLogger().warning("issue 199 test not ok"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters