]> granicus.if.org Git - postgresql/commitdiff
V3 NotificationResonse messages were trying to be received as V2
authorKris Jurka <books@ejurka.com>
Tue, 3 Feb 2004 05:43:24 +0000 (05:43 +0000)
committerKris Jurka <books@ejurka.com>
Tue, 3 Feb 2004 05:43:24 +0000 (05:43 +0000)
messages.  Also the PID was being read in the wrong byte order.
Finally add a test case for listen/notify.

Per report from Hans Nather.

src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java
src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java
src/interfaces/jdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java
src/interfaces/jdbc/org/postgresql/test/jdbc2/NotifyTest.java [new file with mode: 0644]

index b7ea0ef2b6d9baff32f7cccc7f512e3530c6f39a..624a9fc1d6200ed4361f2d69020960721a9486e6 100644 (file)
@@ -6,7 +6,7 @@
  * Copyright (c) 2003, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/QueryExecutor.java,v 1.27 2003/09/17 08:21:36 barry Exp $
+ *       $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/QueryExecutor.java,v 1.27.2.1 2004/02/03 05:43:22 jurka Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -129,8 +129,10 @@ public class QueryExecutor
                                switch (c)
                                {
                                        case 'A':       // Asynchronous Notify
-                                               int pid = pgStream.ReceiveInteger(4);
+                                               int msglen = pgStream.ReceiveIntegerR(4);
+                                               int pid = pgStream.ReceiveIntegerR(4);
                                                String msg = pgStream.ReceiveString(connection.getEncoding());
+                                               String param = pgStream.ReceiveString(connection.getEncoding());
                                                connection.addNotification(new org.postgresql.core.Notification(msg, pid));
                                                break;
                                        case 'B':       // Binary Data Transfer
@@ -237,7 +239,7 @@ public class QueryExecutor
                                switch (c)
                                {
                                        case 'A':       // Asynchronous Notify
-                                               int pid = pgStream.ReceiveInteger(4);
+                                               int pid = pgStream.ReceiveIntegerR(4);
                                                String msg = pgStream.ReceiveString(connection.getEncoding());
                                                connection.addNotification(new org.postgresql.core.Notification(msg, pid));
                                                break;
index 5f46ad12068bda7cfec776816cde3f9263576027..dd0dd7f9f0beeed14f030507d4ab2d2ab92080c8 100644 (file)
@@ -6,7 +6,7 @@
  * Copyright (c) 2003, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/fastpath/Attic/Fastpath.java,v 1.16.2.2 2003/12/18 03:29:12 davec Exp $
+ *       $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/fastpath/Attic/Fastpath.java,v 1.16.2.3 2004/02/03 05:43:22 jurka Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -118,8 +118,10 @@ public class Fastpath
                                switch (c)
                                {
                                        case 'A':       // Asynchronous Notify
-                                               int pid = stream.ReceiveInteger(4);
+                                               int msglen = stream.ReceiveIntegerR(4);
+                                               int pid = stream.ReceiveIntegerR(4);
                                                String msg = stream.ReceiveString(conn.getEncoding());
+                                               String param = stream.ReceiveString(conn.getEncoding());
                                                conn.addNotification(new org.postgresql.core.Notification(msg, pid));
                                                break;
                                                //------------------------------
@@ -233,8 +235,9 @@ public class Fastpath
                                {
                                        case 'A':       // Asynchronous Notify
                                                //TODO: do something with this
-                                               int pid = stream.ReceiveInteger(4);
+                                               int pid = stream.ReceiveIntegerR(4);
                                                String msg = stream.ReceiveString(conn.getEncoding());
+                                               conn.addNotification(new org.postgresql.core.Notification(msg, pid));
                                                break;
 
                                                //------------------------------
index e1b480a1f1c168fb1a340d7323035b6eb8760efa..3eab8e6633812eedb46c0a0b11629a4e41bf2b5e 100644 (file)
@@ -55,6 +55,7 @@ public class Jdbc2TestSuite extends TestSuite
                // features some applications require.
                suite.addTestSuite(JBuilderTest.class);
                suite.addTestSuite(MiscTest.class);
+               suite.addTestSuite(NotifyTest.class);
 
                // Fastpath/LargeObject
                suite.addTestSuite(BlobTest.class);
diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/NotifyTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/NotifyTest.java
new file mode 100644 (file)
index 0000000..0871885
--- /dev/null
@@ -0,0 +1,43 @@
+package org.postgresql.test.jdbc2;
+
+import org.postgresql.test.TestUtil;
+import junit.framework.TestCase;
+import java.sql.*;
+
+import org.postgresql.PGConnection;
+import org.postgresql.PGNotification;
+
+public class NotifyTest extends TestCase
+{
+
+       private Connection conn;
+
+       public NotifyTest(String name)
+       {
+               super(name);
+       }
+
+       protected void setUp() throws SQLException
+       {
+               conn = TestUtil.openDB();
+       }
+
+       protected void tearDown() throws SQLException
+       {
+               TestUtil.closeDB(conn);
+       }
+
+       public void testNotify() throws SQLException
+       {
+               Statement stmt = conn.createStatement();
+               stmt.executeUpdate("LISTEN mynotification");
+               stmt.executeUpdate("NOTIFY mynotification");
+
+               PGNotification notifications[] = ((org.postgresql.PGConnection)conn).getNotifications();
+               assertNotNull(notifications);
+               assertEquals(notifications.length, 1);
+               assertEquals(notifications[0].getName(), "mynotification");
+
+               stmt.close();
+       }
+}