[ 
https://issues.apache.org/jira/browse/PHOENIX-1253?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14135779#comment-14135779
 ] 

James Taylor commented on PHOENIX-1253:
---------------------------------------

Thanks for the patch, [~gabriel.reid]. I've wanted to make this change for the 
longest time! One small item and then +1. Would you mind adding an enum to 
SQLExceptionCode and building/throwing the exception something like this?
{code}
    throw SQLExceptionInfo.Builder(SQLExceptionCode.PARAM_OUT_OF_BOUNDS)
        .setMessage("parameter index = " + parameterIndex)
        .build().buildException();
{code}
In this code:
{code}
+    private void setParameter(int parameterIndex, Object value) throws 
SQLException {
+        if (parameterIndex < 1 || parameterIndex > parameterCount) {
+            throw new SQLException("Can't set parameter at index " + 
parameterIndex + ", " +
+                    parameterCount + " bind parameters are defined");
+        }
+        if (parameterIndex < 1) {
+            throw new SQLException("Invalid bind parameter index " + 
parameterIndex);
+        }
+        this.parameters.set(parameterIndex - 1, value);
+    }
{code}


> Invalid PreparedStatement.setXXX call should throw SQLException
> ---------------------------------------------------------------
>
>                 Key: PHOENIX-1253
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-1253
>             Project: Phoenix
>          Issue Type: Bug
>    Affects Versions: 3.1, 4.1
>            Reporter: Gabriel Reid
>            Assignee: Gabriel Reid
>         Attachments: PHOENIX-1253.patch
>
>
> Calling PreparedStatement.setString (or any setXXX method) with an invalid 
> parameter index (less then 1 or greater than the number of bind parameters) 
> currently throws an IndexOutOfBoundsException based on the underlying List 
> used to collect parameters.
> According to the [JDBC API 
> docs|http://docs.oracle.com/javase/6/docs/api/java/sql/PreparedStatement.html#setString(int,
>  java.lang.String)], this situation should result in a SQLException being 
> thrown. This ticket is to change the behavior in Phoenix to be in line with 
> the JDBC API docs.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to