[libpostgresql-jdbc-java] 01/09: SQLWarning.getMessage wasn't reporting the message from a Notice message in the V3 protocol. Make the V2 and V3 cases return a consistent message and add a test.
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:19:10 UTC 2017
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to tag REL8_0_311
in repository libpostgresql-jdbc-java.
commit 8ae7299194771fd5cd6bffbaad8cb89a1db6e0fc
Author: Kris Jurka <books at ejurka.com>
Date: Thu Feb 10 19:52:46 2005 +0000
SQLWarning.getMessage wasn't reporting the message from a Notice
message in the V3 protocol. Make the V2 and V3 cases return a
consistent message and add a test.
Reported by NielsG.
---
org/postgresql/core/v2/QueryExecutorImpl.java | 11 +++++++++--
org/postgresql/test/jdbc2/CallableStmtTest.java | 18 +++++++++++++++++-
org/postgresql/util/PSQLWarning.java | 7 ++++++-
org/postgresql/util/ServerErrorMessage.java | 7 ++++++-
4 files changed, 38 insertions(+), 5 deletions(-)
diff --git a/org/postgresql/core/v2/QueryExecutorImpl.java b/org/postgresql/core/v2/QueryExecutorImpl.java
index 61e7945..fcb1b9b 100644
--- a/org/postgresql/core/v2/QueryExecutorImpl.java
+++ b/org/postgresql/core/v2/QueryExecutorImpl.java
@@ -4,7 +4,7 @@
* Copyright (c) 2004, Open Cloud Limited.
*
* IDENTIFICATION
-* $PostgreSQL: pgjdbc/org/postgresql/core/v2/QueryExecutorImpl.java,v 1.9 2005/01/14 01:20:15 oliver Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/core/v2/QueryExecutorImpl.java,v 1.10 2005/02/01 07:27:54 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -516,7 +516,14 @@ public class QueryExecutorImpl implements QueryExecutor {
}
private SQLWarning receiveNotification() throws IOException {
- String warnMsg = pgStream.ReceiveString().trim();
+ String warnMsg = pgStream.ReceiveString();
+
+ // Strip out the severity field so we have consistency with
+ // the V3 protocol. SQLWarning.getMessage should return just
+ // the actual message.
+ //
+ int severityMark = warnMsg.indexOf(":");
+ warnMsg = warnMsg.substring(severityMark+1).trim();
if (Driver.logDebug)
Driver.debug(" <=BE NoticeResponse(" + warnMsg + ")");
return new SQLWarning(warnMsg);
diff --git a/org/postgresql/test/jdbc2/CallableStmtTest.java b/org/postgresql/test/jdbc2/CallableStmtTest.java
index 58e8a12..eedbf91 100644
--- a/org/postgresql/test/jdbc2/CallableStmtTest.java
+++ b/org/postgresql/test/jdbc2/CallableStmtTest.java
@@ -3,7 +3,7 @@
* Copyright (c) 2004-2005, PostgreSQL Global Development Group
*
* IDENTIFICATION
-* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/CallableStmtTest.java,v 1.11 2005/01/05 00:54:48 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/CallableStmtTest.java,v 1.12 2005/01/11 08:25:48 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -47,6 +47,7 @@ public class CallableStmtTest extends TestCase
"RETURNS numeric AS ' " +
"begin return 42; end; ' LANGUAGE 'plpgsql';");
stmt.execute("CREATE OR REPLACE FUNCTION getarray() RETURNS int[] as 'SELECT ''{1,2}''::int[];' LANGUAGE 'sql'");
+ stmt.execute("CREATE OR REPLACE FUNCTION raisenotice() RETURNS int as 'BEGIN RAISE NOTICE ''hello''; RAISE NOTICE ''goodbye''; RETURN 1; END;' LANGUAGE 'plpgsql'");
stmt.close ();
}
@@ -59,6 +60,7 @@ public class CallableStmtTest extends TestCase
stmt.execute ("drop FUNCTION testspg__getNumeric (numeric);");
stmt.execute ("drop FUNCTION testspg__getNumericWithoutArg ();");
stmt.execute ("DROP FUNCTION getarray();");
+ stmt.execute ("DROP FUNCTION raisenotice();");
TestUtil.closeDB(con);
}
@@ -128,6 +130,20 @@ public class CallableStmtTest extends TestCase
assertTrue(!rs.next());
}
+ public void testRaiseNotice() throws SQLException
+ {
+ CallableStatement call = con.prepareCall("{? = call raisenotice()}");
+ call.registerOutParameter(1, Types.INTEGER);
+ call.execute();
+ SQLWarning warn = call.getWarnings();
+ assertNotNull(warn);
+ assertEquals("hello", warn.getMessage());
+ warn = warn.getNextWarning();
+ assertNotNull(warn);
+ assertEquals("goodbye", warn.getMessage());
+ assertEquals(1, call.getInt(1));
+ }
+
public void testBadStmt () throws Throwable
{
tryOneBadStmt ("{ ?= " + pkgName + "getString (?) }");
diff --git a/org/postgresql/util/PSQLWarning.java b/org/postgresql/util/PSQLWarning.java
index 1adb842..a4087c3 100644
--- a/org/postgresql/util/PSQLWarning.java
+++ b/org/postgresql/util/PSQLWarning.java
@@ -3,7 +3,7 @@
* Copyright (c) 2004-2005, PostgreSQL Global Development Group
*
* IDENTIFICATION
-* $PostgreSQL: pgjdbc/org/postgresql/util/PSQLWarning.java,v 1.3 2004/11/09 08:57:34 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/util/PSQLWarning.java,v 1.4 2005/01/11 08:25:49 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -30,4 +30,9 @@ public class PSQLWarning extends SQLWarning
{
return serverError.getSQLState();
}
+
+ public String getMessage()
+ {
+ return serverError.getMessage();
+ }
}
diff --git a/org/postgresql/util/ServerErrorMessage.java b/org/postgresql/util/ServerErrorMessage.java
index b143c3c..e6b8a64 100644
--- a/org/postgresql/util/ServerErrorMessage.java
+++ b/org/postgresql/util/ServerErrorMessage.java
@@ -3,7 +3,7 @@
* Copyright (c) 2004-2005, PostgreSQL Global Development Group
*
* IDENTIFICATION
-* $PostgreSQL: pgjdbc/org/postgresql/util/ServerErrorMessage.java,v 1.5 2004/11/09 08:57:36 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/util/ServerErrorMessage.java,v 1.6 2005/01/11 08:25:49 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -57,6 +57,11 @@ public class ServerErrorMessage
return (String)m_mesgParts.get(SQLSTATE);
}
+ public String getMessage()
+ {
+ return (String)m_mesgParts.get(MESSAGE);
+ }
+
public String toString()
{
//Now construct the message from what the server sent
--
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