[libpostgresql-jdbc-java] 83/93: backpatch fix for changing datestyle before copy
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:18:55 UTC 2017
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to annotated tag REL9_3_1102
in repository libpostgresql-jdbc-java.
commit afab0dce7f1e32e6ce3f22693fc36546c56fafa2
Author: Dave Cramer <davecramer at gmail.com>
Date: Thu Apr 24 17:13:45 2014 -0400
backpatch fix for changing datestyle before copy
---
org/postgresql/core/v3/QueryExecutorImpl.java | 37 +++++++++++++++++++++++++
org/postgresql/test/jdbc2/CopyTest.java | 40 +++++++++++++++++++++++++++
2 files changed, 77 insertions(+)
diff --git a/org/postgresql/core/v3/QueryExecutorImpl.java b/org/postgresql/core/v3/QueryExecutorImpl.java
index 83edac1..1b78707 100644
--- a/org/postgresql/core/v3/QueryExecutorImpl.java
+++ b/org/postgresql/core/v3/QueryExecutorImpl.java
@@ -1029,6 +1029,43 @@ public class QueryExecutorImpl implements QueryExecutor {
// keep receiving since we expect a CommandComplete
block = true;
break;
+ case 'S': // Parameter Status
+ {
+ int l_len = pgStream.ReceiveInteger4();
+ String name = pgStream.ReceiveString();
+ String value = pgStream.ReceiveString();
+ if (logger.logDebug())
+ logger.debug(" <=BE ParameterStatus(" + name + " = " + value + ")");
+
+ if (name.equals("client_encoding") && !value.equalsIgnoreCase("UTF8") && !allowEncodingChanges)
+ {
+ protoConnection.close(); // we're screwed now; we can't trust any subsequent string.
+ error = new PSQLException(GT.tr("The server''s client_encoding parameter was changed to {0}. The JDBC driver requires client_encoding to be UTF8 for correct operation.", value), PSQLState.CONNECTION_FAILURE);
+ endReceiving = true;
+ }
+
+ if (name.equals("DateStyle") && !value.startsWith("ISO,"))
+ {
+ protoConnection.close(); // we're screwed now; we can't trust any subsequent date.
+ error = new PSQLException(GT.tr("The server''s DateStyle parameter was changed to {0}. The JDBC driver requires DateStyle to begin with ISO for correct operation.", value), PSQLState.CONNECTION_FAILURE);
+ endReceiving = true;
+ }
+
+ if (name.equals("standard_conforming_strings"))
+ {
+ if (value.equals("on"))
+ protoConnection.setStandardConformingStrings(true);
+ else if (value.equals("off"))
+ protoConnection.setStandardConformingStrings(false);
+ else
+ {
+ protoConnection.close(); // we're screwed now; we don't know how to escape string literals
+ error = new PSQLException(GT.tr("The server''s standard_conforming_strings parameter was reported as {0}. The JDBC driver expected on or off.", value), PSQLState.CONNECTION_FAILURE);
+ endReceiving = true;
+ }
+ }
+ }
+ break;
case 'Z': // ReadyForQuery: After FE:CopyDone => BE:CommandComplete
diff --git a/org/postgresql/test/jdbc2/CopyTest.java b/org/postgresql/test/jdbc2/CopyTest.java
index 88cefe7..0f99f5c 100644
--- a/org/postgresql/test/jdbc2/CopyTest.java
+++ b/org/postgresql/test/jdbc2/CopyTest.java
@@ -8,6 +8,7 @@
package org.postgresql.test.jdbc2;
import java.sql.Connection;
+import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
@@ -17,6 +18,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.IOException;
+import java.io.PrintWriter;
import java.io.StringReader;
import junit.framework.TestCase;
@@ -54,6 +56,8 @@ public class CopyTest extends TestCase {
}
protected void setUp() throws Exception {
+
+
con = TestUtil.openDB();
TestUtil.createTable(con, "copytest", "stringvalue text, intvalue int, numvalue numeric(5,2)");
@@ -269,5 +273,41 @@ public class CopyTest extends TestCase {
con.rollback();
assertEquals(0, getCount());
}
+
+ public void testChangeDateStyle() throws SQLException {
+
+
+ try
+ {
+ con.setAutoCommit(false);
+ con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
+ CopyManager manager = con.unwrap(PGConnection.class).getCopyAPI();
+
+ Statement stmt = con.createStatement();
+
+ stmt.execute("SET DateStyle = 'ISO, DMY'");
+
+
+ // I expect an SQLException
+ String sql = "COPY copytest FROM STDIN with xxx (format 'csv')";
+ CopyIn cp = manager.copyIn(sql);
+ for(int i=0; i<origData.length; i++) {
+ byte[] buf = origData[i].getBytes();
+ cp.writeToCopy(buf, 0, buf.length);
+ }
+
+ long count1 = cp.endCopy();
+ long count2 = cp.getHandledRowCount();
+ con.commit();
+ }
+ catch (SQLException ex )
+ {
+
+ // the with xxx is a syntax error which shoud return a state of 42601
+ // if this fails the 'S' command is not being handled in the copy manager query handler
+ assertEquals("42601",ex.getSQLState());
+ con.rollback();
+ }
+ }
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git
More information about the pkg-java-commits
mailing list