aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Lind <barry@xythos.com>2003-09-09 10:49:16 +0000
committerBarry Lind <barry@xythos.com>2003-09-09 10:49:16 +0000
commit5cdf771d8a457273e7eb62c097f23f65082abe8f (patch)
tree4bb9afe6165fcad05fe40642d3d899e35d170a2f
parentfcdf0e22fcac4724c67bac18706d5c50931aa02d (diff)
downloadpostgresql-5cdf771d8a457273e7eb62c097f23f65082abe8f.tar.gz
postgresql-5cdf771d8a457273e7eb62c097f23f65082abe8f.zip
Additional SQLState work for JDBC - thanks to Kim Ho at Redhat for input on this
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
-rw-r--r--src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java6
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java14
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java5
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java28
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java26
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java10
-rw-r--r--src/interfaces/jdbc/org/postgresql/util/PSQLState.java5
7 files changed, 50 insertions, 44 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java b/src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java
index f2f9d29081a..fcb1d0827e9 100644
--- a/src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java
+++ b/src/interfaces/jdbc/org/postgresql/core/QueryExecutor.java
@@ -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);
}
}
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java
index ba9acb9e5ac..34a0f3596ea 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java
@@ -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));
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java
index 6afee490f06..93b3938db9a 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java
@@ -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();
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java
index 10d73d4c043..bb68437335a 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java
@@ -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);
}
}
}
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java
index 4e2e369d8ca..2f35880effb 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java
@@ -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)
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java
index 690741f64be..41ffe49a65b 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java
@@ -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);
diff --git a/src/interfaces/jdbc/org/postgresql/util/PSQLState.java b/src/interfaces/jdbc/org/postgresql/util/PSQLState.java
index f5775ac95d6..96d14167a53 100644
--- a/src/interfaces/jdbc/org/postgresql/util/PSQLState.java
+++ b/src/interfaces/jdbc/org/postgresql/util/PSQLState.java
@@ -28,6 +28,11 @@
// 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");