[ 
https://issues.apache.org/jira/browse/DERBY-6902?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Bryan Pendleton updated DERBY-6902:
-----------------------------------
    Attachment: repro.java

Based on the code in the description section, I reproduced the
problem with the attached "repro.java".

When I run this program with the current Derby trunk, and with
the following 'println' statement inserted into the out-of-range
throw statement in SQLInteger.setValue(), I get the exception output
that I've pasted below.

{code}
        public void setValue(long theValue) throws StandardException
        {
                if (theValue > Integer.MAX_VALUE || theValue < 
Integer.MIN_VALUE) {
System.out.println("Value " + theValue + " is either > " + Integer.MAX_VALUE + 
"or < " + Integer.MIN_VALUE);
                        throw outOfRange();
                }

                value = (int)theValue;
                isnull = false;
        }
{code}

{quote}
C:\Users\Bryan\derby\issues\DERBY-6902>java -cp 
.;c:\Users\Bryan\derby\trunk\classes repro
Value 1470362049757 is either > 2147483647or < -2147483648
java.sql.SQLDataException: The resulting value is outside the range for the 
data type INTEGER.
        at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:84)
        at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Util.java:230)

        at 
org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:424)
        at 
org.apache.derby.impl.jdbc.EmbedResultSet.noStateChangeException(EmbedResultSet.java:4728)
        at 
org.apache.derby.impl.jdbc.EmbedPreparedStatement.setLong(EmbedPreparedStatement.java:453)
        at repro.main(repro.java:30)
Caused by: ERROR 22003: The resulting value is outside the range for the data 
type INTEGER.
        at 
org.apache.derby.iapi.error.StandardException.newException(StandardException.java:290)
        at 
org.apache.derby.iapi.error.StandardException.newException(StandardException.java:285)
        at org.apache.derby.iapi.types.DataType.outOfRange(DataType.java:1271)
        at org.apache.derby.iapi.types.SQLInteger.setValue(SQLInteger.java:329)
        at 
org.apache.derby.impl.jdbc.EmbedPreparedStatement.setLong(EmbedPreparedStatement.java:450)
        ... 1 more
SQLState:22003
Error Code:20000
Message:The resulting value is outside the range for the data type INTEGER.
Cause:ERROR 22003: The resulting value is outside the range for the data type 
INTEGER.
ERROR 22003: The resulting value is outside the range for the data type INTEGER.

        at 
org.apache.derby.iapi.error.StandardException.newException(StandardException.java:290)
        at 
org.apache.derby.iapi.error.StandardException.newException(StandardException.java:285)
        at org.apache.derby.iapi.types.DataType.outOfRange(DataType.java:1271)
        at org.apache.derby.iapi.types.SQLInteger.setValue(SQLInteger.java:329)
        at 
org.apache.derby.impl.jdbc.EmbedPreparedStatement.setLong(EmbedPreparedStatement.java:450)
        at repro.main(repro.java:30)
{quote}

I guess the part I don't totally understand is:

The program does 
{code}
                PreparedStatement delete = conn.prepareStatement(
                                "delete from test " +
                                "where big_number < ? - small_number * 1000");
                delete.setLong(1, System.currentTimeMillis());
{code}
Evidently the SQL compiler has decided that the '?' substitution parameter
should be a INTEGER type, but the user expects it to be a BIGINT, I think.

> Value out of range error (22003) on DELETE with expression in WHERE clause
> --------------------------------------------------------------------------
>
>                 Key: DERBY-6902
>                 URL: https://issues.apache.org/jira/browse/DERBY-6902
>             Project: Derby
>          Issue Type: Bug
>    Affects Versions: 10.12.1.1
>            Reporter: Vedran Pavic
>         Attachments: repro.java
>
>
> Hi,
> I've ran into the problem from the subject, which appears to be a bug, using 
> the latest 10.12.1.1 release.
> Given the table:
> {code:sql}
> create table test (
>   id bigint primary key,
>   big_number bigint not null,
>   small_number int not null
> )
> {code}
> The following DELETE statement will fail with _The resulting value is outside 
> the range for the data type INTEGER_ (22003) if there are records in table:
> {code:sql}
> delete from test
> where big_number < ? - small_number * 1000
> {code}
> {code:java}
> java.sql.SQLDataException: The resulting value is outside the range for the 
> data type INTEGER.
>     at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown 
> Source)
>     at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
>     at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>     at 
> org.apache.derby.impl.jdbc.EmbedResultSet.noStateChangeException(Unknown 
> Source)
>     at org.apache.derby.impl.jdbc.EmbedPreparedStatement.setLong(Unknown 
> Source)
>     at sample.PlainJdbcTest.delete(PlainJdbcTest.java:36)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>     at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>     at java.lang.reflect.Method.invoke(Method.java:498)
>     at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
>     at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>     at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
>     at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>     at 
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
>     at 
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
>     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
>     at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
>     at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
>     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
>     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
>     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
>     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
>     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
>     at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
>     at 
> org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:114)
>     at 
> org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:57)
>     at 
> org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:66)
>     at 
> org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>     at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>     at java.lang.reflect.Method.invoke(Method.java:498)
>     at 
> org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
>     at 
> org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
>     at 
> org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
>     at 
> org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
>     at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
>     at 
> org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:109)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>     at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>     at java.lang.reflect.Method.invoke(Method.java:498)
>     at 
> org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
>     at 
> org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
>     at 
> org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:377)
>     at 
> org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
>     at 
> org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
>     at 
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>     at 
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>     at java.lang.Thread.run(Thread.java:745)
> Caused by: ERROR 22003: The resulting value is outside the range for the data 
> type INTEGER.
>     at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>     at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>     at org.apache.derby.iapi.types.DataType.outOfRange(Unknown Source)
>     at org.apache.derby.iapi.types.SQLInteger.setValue(Unknown Source)
>     ... 47 more
> {code}
> Minimal project to reproduce the error is available here:
> https://github.com/vpavic-samples/derby-delete-error-22003
> Thanks,
> Vedran



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

Reply via email to