]> granicus.if.org Git - postgresql/commitdiff
Additional SQLState work for JDBC - thanks to Kim Ho at Redhat for input on this
authorBarry Lind <barry@xythos.com>
Tue, 9 Sep 2003 10:49:16 +0000 (10:49 +0000)
committerBarry Lind <barry@xythos.com>
Tue, 9 Sep 2003 10:49:16 +0000 (10:49 +0000)
 Modified Files:
  jdbc/build.xml jdbc/org/postgresql/core/QueryExecutor.java
  jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java
  jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java
  jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java
  jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java
  jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java
  jdbc/org/postgresql/util/PSQLState.java

src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java
src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java
src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java
src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java
src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java
src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java
src/interfaces/jdbc/org/postgresql/util/PSQLState.java

index f2f9d29081aa8b3938418c192939e2fed082b45c..fcb1d0827e9eb960381ada80cca59fbf55301d25 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.24 2003/09/08 17:30:22 barry Exp $
+ *       $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/QueryExecutor.java,v 1.25 2003/09/09 10:49:16 barry Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -340,7 +340,7 @@ public class QueryExecutor
                }
                catch (IOException e)
                {
-                       throw new PSQLException("postgresql.con.ioerror", e);
+                       throw new PSQLException("postgresql.con.ioerror", PSQLState.CONNECTION_FAILURE_DURING_TRANSACTION, e);
                }
        }
 
@@ -370,7 +370,7 @@ public class QueryExecutor
                }
                catch (IOException e)
                {
-                       throw new PSQLException("postgresql.con.ioerror", e);
+                       throw new PSQLException("postgresql.con.ioerror", PSQLState.CONNECTION_FAILURE_DURING_TRANSACTION, e);
                }
        }
 
index ba9acb9e5ac774091f41a8adb531a831c5580254..34a0f3596ea03d852ebe9fc923150739dca95427 100644 (file)
@@ -9,7 +9,7 @@
  * Copyright (c) 2003, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.24 2003/09/08 17:30:22 barry Exp $
+ *       $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.25 2003/09/09 10:49:16 barry Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -252,7 +252,7 @@ public abstract class AbstractJdbc1Connection implements BaseConnection
                                                
                                        case 'N':
                                                // Server does not support ssl
-                                               throw new PSQLException("postgresql.con.sslnotsupported");
+                                               throw new PSQLException("postgresql.con.sslnotsupported", PSQLState.CONNECTION_FAILURE);
                                                
                                        case 'S':
                                                // Server supports ssl
@@ -262,7 +262,7 @@ public abstract class AbstractJdbc1Connection implements BaseConnection
                                                break;
 
                                        default:
-                                               throw new PSQLException("postgresql.con.sslfail");
+                                               throw new PSQLException("postgresql.con.sslfail", PSQLState.CONNECTION_FAILURE);
                                        }
                        }
                }
@@ -559,7 +559,7 @@ public abstract class AbstractJdbc1Connection implements BaseConnection
                                                
                                        case 'N':
                                                // Server does not support ssl
-                                               throw new PSQLException("postgresql.con.sslnotsupported");
+                                               throw new PSQLException("postgresql.con.sslnotsupported", PSQLState.CONNECTION_FAILURE);
                                                
                                        case 'S':
                                                // Server supports ssl
@@ -569,7 +569,7 @@ public abstract class AbstractJdbc1Connection implements BaseConnection
                                                break;
 
                                        default:
-                                               throw new PSQLException("postgresql.con.sslfail");
+                                               throw new PSQLException("postgresql.con.sslfail", PSQLState.CONNECTION_FAILURE);
                                        }
                        }
                }
@@ -1610,7 +1610,7 @@ public abstract class AbstractJdbc1Connection implements BaseConnection
                                }
                                BaseResultSet result = execSQL(sql);
                                if (result.getColumnCount() != 1 || result.getTupleCount() != 1) {
-                                       throw new PSQLException("postgresql.unexpected");
+                                       throw new PSQLException("postgresql.unexpected", PSQLState.UNEXPECTED_ERROR);
                                }
                                result.next();
                                pgType = result.getString(1);
@@ -1651,7 +1651,7 @@ public abstract class AbstractJdbc1Connection implements BaseConnection
                                }
                                BaseResultSet result = execSQL(sql);
                                if (result.getColumnCount() != 1 || result.getTupleCount() != 1)
-                                       throw new PSQLException("postgresql.unexpected");
+                                       throw new PSQLException("postgresql.unexpected", PSQLState.UNEXPECTED_ERROR);
                                result.next();
                                oid = Integer.parseInt(result.getString(1));
                                typeOidCache.put(typeName, new Integer(oid));
index 6afee490f06003a6f570a0d5eb676ec7fdc9a508..93b3938db9ad822eae603e67a39693b95cc9e5cb 100644 (file)
@@ -6,6 +6,7 @@ import java.util.*;
 import org.postgresql.core.BaseStatement;
 import org.postgresql.core.Field;
 import org.postgresql.util.PSQLException;
+import org.postgresql.util.PSQLState;
 import org.postgresql.Driver;
 
 public abstract class AbstractJdbc1DatabaseMetaData
@@ -43,7 +44,7 @@ public abstract class AbstractJdbc1DatabaseMetaData
                        String sql = "SELECT t1.typlen/t2.typlen FROM "+from+" t1.typelem=t2.oid AND t1.typname='oidvector'";
                        ResultSet rs = connection.createStatement().executeQuery(sql);
                        if (!rs.next()) {
-                               throw new PSQLException("postgresql.unexpected");
+                               throw new PSQLException("postgresql.unexpected", PSQLState.UNEXPECTED_ERROR);
                        }
                        INDEX_MAX_KEYS = rs.getInt(1);
                        rs.close();
@@ -61,7 +62,7 @@ public abstract class AbstractJdbc1DatabaseMetaData
                        }
                        ResultSet rs = connection.createStatement().executeQuery(sql);
                        if (!rs.next()) {
-                               throw new PSQLException("postgresql.unexpected");
+                               throw new PSQLException("postgresql.unexpected", PSQLState.UNEXPECTED_ERROR);
                        }
                        NAMEDATALEN = rs.getInt("typlen");
                        rs.close();
index 10d73d4c0439950928527c6eaa135e1b74401658..bb68437335a54858562c4e1134027925555d9c67 100644 (file)
@@ -9,7 +9,7 @@
  * Copyright (c) 2003, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.16 2003/09/08 17:30:22 barry Exp $
+ *       $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.17 2003/09/09 10:49:16 barry Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -242,7 +242,7 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
                        }
                        catch (NumberFormatException e)
                        {
-                               throw new PSQLException("postgresql.res.badshort", s);
+                               throw new PSQLException("postgresql.res.badshort", PSQLState.NUMERIC_VALUE_OUT_OF_RANGE, s);
                        }
                }
                return 0; // SQL NULL
@@ -368,7 +368,7 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
                        }
                        catch (UnsupportedEncodingException l_uee)
                        {
-                               throw new PSQLException("postgresql.unusual", l_uee);
+                               throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR, l_uee);
                        }
                }
                else
@@ -399,7 +399,7 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
                        }
                        catch (UnsupportedEncodingException l_uee)
                        {
-                               throw new PSQLException("postgresql.unusual", l_uee);
+                               throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR, l_uee);
                        }
                }
                else
@@ -814,7 +814,7 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
                        }
                        catch (NumberFormatException e)
                        {
-                               throw new PSQLException ("postgresql.res.badint", s);
+                               throw new PSQLException ("postgresql.res.badint", PSQLState.NUMERIC_VALUE_OUT_OF_RANGE, s);
                        }
                }
                return 0;               // SQL NULL
@@ -831,7 +831,7 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
                        }
                        catch (NumberFormatException e)
                        {
-                               throw new PSQLException ("postgresql.res.badlong", s);
+                               throw new PSQLException ("postgresql.res.badlong", PSQLState.NUMERIC_VALUE_OUT_OF_RANGE, s);
                        }
                }
                return 0;               // SQL NULL
@@ -849,7 +849,7 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
                        }
                        catch (NumberFormatException e)
                        {
-                               throw new PSQLException ("postgresql.res.badbigdec", s);
+                               throw new PSQLException ("postgresql.res.badbigdec", PSQLState.NUMERIC_VALUE_OUT_OF_RANGE, s);
                        }
                        if (scale == -1)
                                return val;
@@ -859,7 +859,7 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
                        }
                        catch (ArithmeticException e)
                        {
-                               throw new PSQLException ("postgresql.res.badbigdec", s);
+                               throw new PSQLException ("postgresql.res.badbigdec", PSQLState.NUMERIC_VALUE_OUT_OF_RANGE, s);
                        }
                }
                return null;            // SQL NULL
@@ -876,7 +876,7 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
                        }
                        catch (NumberFormatException e)
                        {
-                               throw new PSQLException ("postgresql.res.badfloat", s);
+                               throw new PSQLException ("postgresql.res.badfloat", PSQLState.NUMERIC_VALUE_OUT_OF_RANGE, s);
                        }
                }
                return 0;               // SQL NULL
@@ -893,7 +893,7 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
                        }
                        catch (NumberFormatException e)
                        {
-                               throw new PSQLException ("postgresql.res.baddouble", s);
+                               throw new PSQLException ("postgresql.res.baddouble", PSQLState.NUMERIC_VALUE_OUT_OF_RANGE, s);
                        }
                }
                return 0;               // SQL NULL
@@ -912,7 +912,7 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
                }
                catch (NumberFormatException e)
                {
-                       throw new PSQLException("postgresql.res.baddate", s);
+                       throw new PSQLException("postgresql.res.baddate",PSQLState.BAD_DATETIME_FORMAT, s);
                }
        }
 
@@ -954,7 +954,7 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
                }
                catch (NumberFormatException e)
                {
-                       throw new PSQLException("postgresql.res.badtime", s);
+                       throw new PSQLException("postgresql.res.badtime", PSQLState.BAD_DATETIME_FORMAT, s);
                }
        }
 
@@ -1055,7 +1055,7 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
                                                }
                                        catch (NumberFormatException e)
                                                {
-                                                       throw new PSQLException("postgresql.unusual", e);
+                                                       throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR, e);
                                                }
 
                                        // The nanos field stores nanoseconds. Adjust the parsed
@@ -1140,7 +1140,7 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet
                        }
                        catch (ParseException e)
                        {
-                               throw new PSQLException("postgresql.res.badtimestamp", PSQLState.UNKNOWN_STATE, new Integer(e.getErrorOffset()), s);
+                               throw new PSQLException("postgresql.res.badtimestamp", PSQLState.BAD_DATETIME_FORMAT, new Integer(e.getErrorOffset()), s);
                        }
                }
        }
index 4e2e369d8ca764c9561091ba500f562d2c2571db..2f35880effb7fe066075b0fbfa3a88329e25b4d5 100644 (file)
@@ -26,7 +26,7 @@ import java.sql.Timestamp;
 import java.sql.Types;
 import java.util.Vector;
 
-/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.34 2003/09/08 17:30:22 barry Exp $
+/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.35 2003/09/09 10:49:16 barry Exp $
  * This class defines methods of the jdbc1 specification.  This class is
  * extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2
  * methods.  The real Statement class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Statement
@@ -203,7 +203,7 @@ public abstract class AbstractJdbc1Statement implements BaseStatement
                while (result != null && !result.reallyResultSet())
                        result = (BaseResultSet) result.getNext();
                if (result == null)
-                       throw new PSQLException("postgresql.stat.noresult");
+                       throw new PSQLException("postgresql.stat.noresult", PSQLState.NO_DATA);
                return (ResultSet) result;
        }
 
@@ -443,9 +443,9 @@ public abstract class AbstractJdbc1Statement implements BaseStatement
                if (isFunction)
                {
                        if (!result.reallyResultSet())
-                               throw new PSQLException("postgresql.call.noreturnval");
+                               throw new PSQLException("postgresql.call.noreturnval", PSQLState.NO_DATA);
                        if (!result.next ())
-                               throw new PSQLException ("postgresql.call.noreturnval");
+                               throw new PSQLException ("postgresql.call.noreturnval", PSQLState.NO_DATA);
                        callResult = result.getObject(1);
                        int columnType = result.getMetaData().getColumnType(1);
                        if (columnType != functionReturnType)
@@ -1293,11 +1293,11 @@ public abstract class AbstractJdbc1Statement implements BaseStatement
                        }
                        catch (UnsupportedEncodingException l_uee)
                        {
-                               throw new PSQLException("postgresql.unusual", l_uee);
+                               throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR, l_uee);
                        }
                        catch (IOException l_ioe)
                        {
-                               throw new PSQLException("postgresql.unusual", l_ioe);
+                               throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR, l_ioe);
                        }
                }
                else
@@ -1342,11 +1342,11 @@ public abstract class AbstractJdbc1Statement implements BaseStatement
                        }
                        catch (UnsupportedEncodingException l_uee)
                        {
-                               throw new PSQLException("postgresql.unusual", l_uee);
+                               throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR, l_uee);
                        }
                        catch (IOException l_ioe)
                        {
-                               throw new PSQLException("postgresql.unusual", l_ioe);
+                               throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR, l_ioe);
                        }
                }
                else
@@ -1389,7 +1389,7 @@ public abstract class AbstractJdbc1Statement implements BaseStatement
                        }
                        catch (IOException l_ioe)
                        {
-                               throw new PSQLException("postgresql.unusual", l_ioe);
+                               throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR, l_ioe);
                        }
                        if (l_bytesRead == length)
                        {
@@ -1429,7 +1429,7 @@ public abstract class AbstractJdbc1Statement implements BaseStatement
                        }
                        catch (IOException se)
                        {
-                               throw new PSQLException("postgresql.unusual", se);
+                               throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR, se);
                        }
                        // lob is closed by the stream so don't call lob.close()
                        setInt(parameterIndex, oid);
@@ -2097,7 +2097,7 @@ public abstract class AbstractJdbc1Statement implements BaseStatement
                }
                catch (Exception e)
                {
-                       throw new PSQLException("postgresql.format.baddate", PSQLState.UNKNOWN_STATE, s , "yyyy-MM-dd[-tz]");
+                       throw new PSQLException("postgresql.format.baddate", PSQLState.BAD_DATETIME_FORMAT, s , "yyyy-MM-dd[-tz]");
                }
                timezone = 0;
                if (timezoneLocation>7 && timezoneLocation+3 == s.length())
@@ -2128,7 +2128,7 @@ public abstract class AbstractJdbc1Statement implements BaseStatement
                }
                catch (Exception e)
                {
-                       throw new PSQLException("postgresql.format.badtime", PSQLState.UNKNOWN_STATE, s, "HH:mm:ss[-tz]");
+                       throw new PSQLException("postgresql.format.badtime", PSQLState.BAD_DATETIME_FORMAT, s, "HH:mm:ss[-tz]");
                }
                timezone = 0;
                if (timezoneLocation != -1 && timezoneLocation+3 == s.length())
@@ -2167,7 +2167,7 @@ public abstract class AbstractJdbc1Statement implements BaseStatement
                }
                catch (Exception e)
                {
-                       throw new PSQLException("postgresql.format.badtimestamp", PSQLState.UNKNOWN_STATE, s, "yyyy-MM-dd HH:mm:ss[.xxxxxx][-tz]");
+                       throw new PSQLException("postgresql.format.badtimestamp", PSQLState.BAD_DATETIME_FORMAT, s, "yyyy-MM-dd HH:mm:ss[.xxxxxx][-tz]");
                }
                timezone = 0;
                if (nanospos != -1)
index 690741f64beaaf00f76eb9befbaa0018eaf8b0c2..41ffe49a65b9232017d323402430493a9641e0af 100644 (file)
@@ -10,7 +10,7 @@ import org.postgresql.largeobject.*;
 import org.postgresql.util.PSQLException;
 import org.postgresql.util.PSQLState;
 
-/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2Statement.java,v 1.16 2003/09/08 17:30:22 barry Exp $
+/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2Statement.java,v 1.17 2003/09/09 10:49:16 barry Exp $
  * This class defines methods of the jdbc2 specification.  This class extends
  * org.postgresql.jdbc1.AbstractJdbc1Statement which provides the jdbc1
  * methods.  The real Statement class (for jdbc2) is org.postgresql.jdbc2.Jdbc2Statement
@@ -227,7 +227,7 @@ public abstract class AbstractJdbc2Statement extends org.postgresql.jdbc1.Abstra
                }
                catch (IOException se)
                {
-                       throw new PSQLException("postgresql.unusual", se);
+                       throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR, se);
                }
                finally
                {
@@ -259,7 +259,7 @@ public abstract class AbstractJdbc2Statement extends org.postgresql.jdbc1.Abstra
                        }
                        catch (IOException l_ioe)
                        {
-                               throw new PSQLException("postgresql.unusual", l_ioe);
+                               throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR, l_ioe);
                        }
                        setString(i, new String(l_chars, 0, l_charsRead));
                }
@@ -289,7 +289,7 @@ public abstract class AbstractJdbc2Statement extends org.postgresql.jdbc1.Abstra
                        }
                        catch (IOException se)
                        {
-                               throw new PSQLException("postgresql.unusual", se);
+                               throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR, se);
                        }
                        // lob is closed by the stream so don't call lob.close()
                        setInt(i, oid);
@@ -321,7 +321,7 @@ public abstract class AbstractJdbc2Statement extends org.postgresql.jdbc1.Abstra
                }
                catch (IOException se)
                {
-                       throw new PSQLException("postgresql.unusual", se);
+                       throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR, se);
                }
                // lob is closed by the stream so don't call lob.close()
                setInt(i, oid);
index f5775ac95d6e51ef86c0fb795d76db3bc87b0074..96d14167a53ee13b307f6b49e8911924ecdf9395 100644 (file)
        // begin constant state codes
        public final static PSQLState UNKNOWN_STATE = new PSQLState("");
        public final static PSQLState COMMUNICATION_ERROR = new PSQLState("08S01");
+       public final static PSQLState NO_DATA = new PSQLState("02000");
+       public final static PSQLState CONNECTION_FAILURE_DURING_TRANSACTION = new PSQLState("08007");
+       public final static PSQLState UNEXPECTED_ERROR = new PSQLState("99999");
+       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 DATA_ERROR = new PSQLState("22000");
        public final static PSQLState CONNECTION_DOES_NOT_EXIST = new PSQLState("08003");
        public final static PSQLState CONNECTION_REJECTED = new PSQLState("08004");