Skip to content
Permalink
Browse files

fix: treatment of SQL_TSI_YEAR, SQL_TSI_WEEK, SQL_TSI_MINUTE (#1250)

  • Loading branch information
vlsi committed Jul 14, 2018
1 parent 6287c95 commit 4668f43fa11fabce9d12d8c9ade73b9426061284
@@ -8,11 +8,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- PreparedStatement.setNull(int parameterIndex, int t, String typeName) no longer ignores the typeName
argument if it is not null [PR 1160](https://github.com/pgjdbc/pgjdbc/pull/1160)

### Added

### Fixed
- Fix treatment of SQL_TSI_YEAR, SQL_TSI_WEEK, SQL_TSI_MINUTE [PR 1250](https://github.com/pgjdbc/pgjdbc/pull/1250)

## [42.2.3] (2018-07-12)
### Known issues
- SQL_TSI_YEAR is treated as hour, SQL_TSI_WEEK is treated as hour, SQL_TSI_MINUTE is treated as minute

### Changed
- Reduce the severity of the error log messages when an exception is re-thrown. The error will be
thrown to caller to be dealt with so no need to log at this verbosity by pgjdbc [PR 1187](https://github.com/pgjdbc/pgjdbc/pull/1187)
@@ -545,7 +545,7 @@ private static boolean appendSingleIntervalCast(StringBuilder buf, String cmp, S
*/
private static boolean areSameTsi(String a, String b) {
return a.length() == b.length() && b.length() > SQL_TSI_ROOT.length()
&& a.regionMatches(true, SQL_TSI_ROOT.length(), b, SQL_TSI_ROOT.length(), SQL_TSI_ROOT.length() - b.length());
&& a.regionMatches(true, SQL_TSI_ROOT.length(), b, SQL_TSI_ROOT.length(), b.length() - SQL_TSI_ROOT.length());
}

/**
@@ -82,6 +82,7 @@
ReturningParserTest.class,
CommandCompleteParserTest.class,
CommandCompleteParserNegativeTest.class,
ReplaceProcessingTest.class,

OidToStringTest.class,
OidValueOfTest.class,
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2018, PostgreSQL Global Development Group
* See the LICENSE file in the project root for more information.
*/

package org.postgresql.test.jdbc2;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.sql.SQLException;
import java.util.Arrays;

@RunWith(Parameterized.class)
public class ReplaceProcessingTest extends BaseTest4 {

@Parameterized.Parameter(0)
public String input;
@Parameterized.Parameter(1)
public String expected;


@Parameterized.Parameters(name = "input={0}, expected={1}")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{"{fn timestampadd(SQL_TSI_YEAR, ?, {fn now()})}", "(CAST( $1||' year' as interval)+ now())"},
{"{fn timestampadd(SQL_TSI_MONTH, ?, {fn now()})}", "(CAST( $1||' month' as interval)+ now())"},
{"{fn timestampadd(SQL_TSI_DAY, ?, {fn now()})}", "(CAST( $1||' day' as interval)+ now())"},
{"{fn timestampadd(SQL_TSI_WEEK, ?, {fn now()})}", "(CAST( $1||' week' as interval)+ now())"},
{"{fn timestampadd(SQL_TSI_MINUTE, ?, {fn now()})}", "(CAST( $1||' minute' as interval)+ now())"},
{"{fn timestampadd(SQL_TSI_SECOND, ?, {fn now()})}", "(CAST( $1||' second' as interval)+ now())"},
{"{fn user()}", "user"},
{"{fn ifnull(?,?)}", "coalesce($1,$2)"},
{"{fn database()}", "current_database()"},
// Not yet supported
// {"{fn timestampadd(SQL_TSI_QUATER, ?, {fn now()})}", "(CAST( $1||' quater' as interval)+ now())"},
// {"{fn timestampadd(SQL_TSI_FRAC_SECOND, ?, {fn now()})}", "(CAST( $1||' second' as interval)+ now())"},
});
}


@Test
public void run() throws SQLException {
Assert.assertEquals(input, expected, con.nativeSQL(input));
}
}

0 comments on commit 4668f43

Please sign in to comment.
You can’t perform that action at this time.