Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
fix: avoid connection failure when DateStyle is set to ISO (#1081)
Default PostgreSQL configuration is DateStyle='iso, dmy', however pgjdbc should not raise errors if DateStyle is just ISO Note: PostgreSQL prints DateStyle value in upper case, and toUpperCase was added just in case. fixes #1080
- Loading branch information
Showing
with
68 additions
and 1 deletion.
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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.postgresql.test.TestUtil; | ||
import org.postgresql.util.PSQLState; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import java.util.Arrays; | ||
|
||
@RunWith(Parameterized.class) | ||
public class DateStyleTest extends BaseTest4 { | ||
|
||
@Parameterized.Parameter(0) | ||
public String dateStyle; | ||
|
||
@Parameterized.Parameter(1) | ||
public boolean shouldPass; | ||
|
||
|
||
@Parameterized.Parameters(name = "dateStyle={0}, shouldPass={1}") | ||
public static Iterable<Object[]> data() { | ||
return Arrays.asList(new Object[][]{ | ||
{"iso, mdy", true}, | ||
{"ISO", true}, | ||
{"ISO,ymd", true}, | ||
{"PostgreSQL", false} | ||
}); | ||
} | ||
|
||
@Test | ||
public void conenct() throws SQLException { | ||
This comment has been minimized.
This comment has been minimized. |
||
Statement st = con.createStatement(); | ||
try { | ||
st.execute("set DateStyle='" + dateStyle + "'"); | ||
if (!shouldPass) { | ||
Assert.fail("Set DateStyle=" + dateStyle + " should not be allowed"); | ||
} | ||
} catch (SQLException e) { | ||
if (shouldPass) { | ||
throw new IllegalStateException("Set DateStyle=" + dateStyle | ||
+ " should be fine, however received " + e.getMessage(), e); | ||
} | ||
if (PSQLState.CONNECTION_FAILURE.getState().equals(e.getSQLState())) { | ||
return; | ||
} | ||
throw new IllegalStateException("Set DateStyle=" + dateStyle | ||
+ " should result in CONNECTION_FAILURE error, however received " + e.getMessage(), e); | ||
} finally { | ||
TestUtil.closeQuietly(st); | ||
} | ||
} | ||
} |
connect typo