db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r666174 - /db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
Date Tue, 10 Jun 2008 15:58:00 GMT
Author: kristwaa
Date: Tue Jun 10 08:58:00 2008
New Revision: 666174

URL: http://svn.apache.org/viewvc?rev=666174&view=rev
Log:
DERBY-3705: In Net Client mode, negative values for stream length are accepted without an
exception for PreparedStatement.setAsciiStream().
Added check to disallow specified stream length to be negative.
Refactored specified length checking into a single method.
Patch file: derby-3705-2b.diff

Patch contributed by Suran Jayathilaka.

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java?rev=666174&r1=666173&r2=666174&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java Tue
Jun 10 08:58:00 2008
@@ -1022,11 +1022,7 @@
                 
                 checkTypeForSetBinaryStream(parameterIndex);
 
-                 if(length > Integer.MAX_VALUE) {
-                    throw new SqlException(agent_.logWriter_,
-                        new ClientMessageId(SQLState.CLIENT_LENGTH_OUTSIDE_RANGE_FOR_DATATYPE),
-                        new Long(length), new Integer(Integer.MAX_VALUE)).getSQLException();
-                }
+                checkStreamLength(length);
                 setBinaryStreamX(parameterIndex, x, (int)length);
             }
         }
@@ -1088,7 +1084,8 @@
         {
             synchronized (connection_) {
                 if (agent_.loggingEnabled()) {
-                    agent_.logWriter_.traceEntry(this, "setAsciiStream", parameterIndex,
"<input stream>", new Long(length));
+                    agent_.logWriter_.traceEntry(this, "setAsciiStream",
+                            parameterIndex, "<input stream>", new Long(length));
                 }
                 
                 checkTypeForSetAsciiStream(parameterIndex);
@@ -1098,11 +1095,7 @@
                     setNull(parameterIndex, java.sql.Types.LONGVARCHAR);
                     return;
                 }
-                if(length > Integer.MAX_VALUE) {
-                    throw new SqlException(agent_.logWriter_,
-                        new ClientMessageId(SQLState.CLIENT_LENGTH_OUTSIDE_RANGE_FOR_DATATYPE),
-                        new Long(length), new Integer(Integer.MAX_VALUE)).getSQLException();
-                }
+                checkStreamLength(length);
                 setInput(parameterIndex, new Clob(agent_, x, "ISO-8859-1", (int)length));
             }
         }
@@ -1127,7 +1120,30 @@
         setAsciiStream(parameterIndex,x,(long)length);
     }
     
-
+    /**
+     * Check the length passed in for the stream that is to be set. If length is
+     * larger than Integer.MAX_VALUE or smaller that 0, we fail by throwing an 
+     * SQLException.
+     * @param length The length of the stream being set
+     * @throws SQLException Thrown for a negative or too large length.
+     */
+    private void checkStreamLength(long length) throws SQLException {
+        if(length > Integer.MAX_VALUE) {
+            throw new SqlException(
+                        agent_.logWriter_,
+                        new ClientMessageId(
+                            SQLState.CLIENT_LENGTH_OUTSIDE_RANGE_FOR_DATATYPE),
+                        new Long(length),
+                        new Integer(Integer.MAX_VALUE)
+                    ).getSQLException();
+        } else if (length < 0) {
+            throw new SqlException(
+                        agent_.logWriter_,
+                        new ClientMessageId(SQLState.NEGATIVE_STREAM_LENGTH)
+                    ).getSQLException();
+        }
+    }
+    
     private void checkTypeForSetAsciiStream(int parameterIndex)
             throws SqlException, SQLException {
         int paramType = getColumnMetaDataX().getColumnType(parameterIndex);
@@ -1276,11 +1292,7 @@
                     setNull(parameterIndex, java.sql.Types.LONGVARCHAR);
                     return;
                 }
-                if(length > Integer.MAX_VALUE) {
-                    throw new SqlException(agent_.logWriter_,
-                        new ClientMessageId(SQLState.CLIENT_LENGTH_OUTSIDE_RANGE_FOR_DATATYPE),
-                        new Long(length), new Integer(Integer.MAX_VALUE)).getSQLException();
-                }
+                checkStreamLength(length);
                 setInput(parameterIndex, new Clob(agent_, x, (int)length));
             }
         }



Mime
View raw message