]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
patch to make PSQLState serializable, and a test case for it
authorDave Cramer <davec@fastcrypt.com>
Thu, 11 Dec 2003 03:59:37 +0000 (03:59 +0000)
committerDave Cramer <davec@fastcrypt.com>
Thu, 11 Dec 2003 03:59:37 +0000 (03:59 +0000)
added a test case for getLastOID

src/interfaces/jdbc/org/postgresql/test/jdbc2/MiscTest.java
src/interfaces/jdbc/org/postgresql/util/PSQLState.java

index 97ad814a674a808107c6d0df039c6153b42f0e6e..8450a0c171b3b1aeeda767cd950fe9797bded0d7 100644 (file)
@@ -3,9 +3,10 @@ package org.postgresql.test.jdbc2;
 import org.postgresql.test.TestUtil;
 import junit.framework.TestCase;
 import java.sql.*;
+import java.io.*;
 
 /*
- * $Id: MiscTest.java,v 1.10 2003/05/29 04:39:48 barry Exp $
+ * $Id: MiscTest.java,v 1.10.4.1 2003/12/11 03:59:37 davec Exp $
  *
  * Some simple tests based on problems reported by users. Hopefully these will
  * help prevent previous problems from re-occuring ;-)
@@ -65,8 +66,18 @@ public class MiscTest extends TestCase
                        fail( "Should not execute this, as a SQLException s/b thrown" );
                        con.commit();
                }
-               catch ( Exception ex )
-               {}
+               catch ( SQLException ex )
+               {
+                       // Verify that the SQLException is serializable.
+                       try {
+                               ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                               ObjectOutputStream oos = new ObjectOutputStream(baos);
+                               oos.writeObject(ex);
+                               oos.close();
+                       } catch (IOException ioe) {
+                               fail(ioe.getMessage());
+                       }
+               }
                try
                {
                        con.commit();
@@ -75,7 +86,31 @@ public class MiscTest extends TestCase
                catch ( Exception ex)
                {}
        }
+       public void testLastOID()
+       {
+               Connection con = null;
+               try
+               {
+                       con = TestUtil.openDB();
+                       TestUtil.createTable( con, "testoid","id int");
 
+                       Statement stmt = con.createStatement();
+                       con.setAutoCommit(false);
+                       stmt.executeUpdate( "insert into testoid values (1)" );
+                       con.commit();
+                       long insertedOid = ((org.postgresql.PGStatement)stmt).getLastOID();
+                       con.setAutoCommit(true);
+                       TestUtil.dropTable( con, "testoid");
+               }
+               catch ( Exception ex )
+               {
+                       fail( ex.getMessage() );
+               }
+               finally
+               {
+                       try{if (con !=null )con.close();}catch(Exception ex){}
+               }
+       }
        public void xtestLocking()
        {
 
index 152170e0c973a79d944b7e265cbf69c77be47d59..b1d1efa63e3aea61806902898ea2bac2b9977768 100644 (file)
@@ -10,7 +10,7 @@
  
  package org.postgresql.util;
  
- public class PSQLState
+ public class PSQLState implements java.io.Serializable
  {
        private String state;