From 59a2c211b82400cc796d6ae73bab9fab156b7620 Mon Sep 17 00:00:00 2001 From: Dave Cramer Date: Thu, 11 Dec 2003 03:59:37 +0000 Subject: [PATCH] patch to make PSQLState serializable, and a test case for it added a test case for getLastOID --- .../org/postgresql/test/jdbc2/MiscTest.java | 39 +++++++++++++- .../jdbc/org/postgresql/util/PSQLState.java | 51 +++++++++++++++++++ 2 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 src/interfaces/jdbc/org/postgresql/util/PSQLState.java diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/MiscTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/MiscTest.java index 95ea077be8..32cd482c71 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/MiscTest.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/MiscTest.java @@ -3,6 +3,7 @@ package org.postgresql.test.jdbc2; import org.postgresql.test.TestUtil; import junit.framework.TestCase; import java.sql.*; +import java.io.*; /* * $Id$ @@ -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() { diff --git a/src/interfaces/jdbc/org/postgresql/util/PSQLState.java b/src/interfaces/jdbc/org/postgresql/util/PSQLState.java new file mode 100644 index 0000000000..b1d1efa63e --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/util/PSQLState.java @@ -0,0 +1,51 @@ +/*------------------------------------------------------------------------- + * + * PSQLState.java + * This class is used for holding SQLState codes. + * + * Copyright (c) 2003, PostgreSQL Global Development Group + * + *------------------------------------------------------------------------- + */ + + package org.postgresql.util; + + public class PSQLState implements java.io.Serializable + { + private String state; + + public String getState() + { + return this.state; + } + + public PSQLState(String state) + { + this.state = state; + } + + + // begin constant state codes + public final static PSQLState UNKNOWN_STATE = new PSQLState(""); + public final static PSQLState NO_DATA = new PSQLState("02000"); + public final static PSQLState INVALID_PARAMETER_TYPE = new PSQLState("07006"); + public final static PSQLState CONNECTION_UNABLE_TO_CONNECT = new PSQLState("08001"); + public final static PSQLState CONNECTION_DOES_NOT_EXIST = new PSQLState("08003"); + public final static PSQLState CONNECTION_REJECTED = new PSQLState("08004"); + public final static PSQLState CONNECTION_FAILURE = new PSQLState("08006"); + public final static PSQLState CONNECTION_FAILURE_DURING_TRANSACTION = new PSQLState("08007"); + public final static PSQLState COMMUNICATION_ERROR = new PSQLState("08S01"); + public final static PSQLState NOT_IMPLEMENTED = new PSQLState("0A000"); + public final static PSQLState DATA_ERROR = new PSQLState("22000"); + public final static PSQLState NUMERIC_VALUE_OUT_OF_RANGE = new PSQLState("22003"); + public final static PSQLState BAD_DATETIME_FORMAT = new PSQLState("22007"); + public final static PSQLState MOST_SPECIFIC_TYPE_DOES_NOT_MATCH = new PSQLState("2200G"); + public final static PSQLState INVALID_PARAMETER_VALUE = new PSQLState("22023"); + public final static PSQLState TRANSACTION_STATE_INVALID = new PSQLState("25000"); + public final static PSQLState STATEMENT_NOT_ALLOWED_IN_FUNCTION_CALL = new PSQLState("2F003"); + public final static PSQLState NUMERIC_CONSTANT_OUT_OF_RANGE = new PSQLState("42820'"); + public final static PSQLState DATA_TYPE_MISMATCH = new PSQLState("42821"); + public final static PSQLState SYSTEM_ERROR = new PSQLState("60000"); + public final static PSQLState UNEXPECTED_ERROR = new PSQLState("99999"); + +} -- 2.39.5