"Rick Hillegas (JIRA)" <[email protected]> writes:

>      [ 
> https://issues.apache.org/jira/browse/DERBY-4998?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
>  ]
>
> Rick Hillegas updated DERBY-4998:
> ---------------------------------
>
>               Priority: Minor  (was: Major)
>       Issue & fix info: [Repro attached, Workaround attached]  (was: 
> [Workaround attached, Newcomer])
>     Bug behavior facts: [Seen in production]
>                 Labels: derby_triage10_8  (was: )

Should this be marked as "deviation from standard", perhaps? I think the
context here is strong enough to allow the type inference needed.

Dag

>
>> Dynamic values in arithmetic operation must be explicitly casted to decimal 
>> when using PreparedStatement
>> --------------------------------------------------------------------------------------------------------
>>
>>                 Key: DERBY-4998
>>                 URL: https://issues.apache.org/jira/browse/DERBY-4998
>>             Project: Derby
>>          Issue Type: Bug
>>          Components: JDBC, SQL
>>    Affects Versions: 10.7.1.1
>>            Reporter: Marco Rico-Gomez
>>            Priority: Minor
>>              Labels: derby_triage10_8
>>         Attachments: DerbyArithmeticTest.java
>>
>>
>> The following SQL statement works as expected without an error:
>> ---
>> update T_Professor set weight_In_B_D = ((((weight_In_B_D + 10) - 5) *
>> 4) / 2) where (id = 1)
>> ---
>> But the same statement as a PreparedStatement throws an exception:
>> --
>> update T_Professor set weight_In_B_D = ((((weight_In_B_D + ?) - ?) *
>> ?) / ?) where (id = ?)
>> --
>> --
>> java.sql.SQLException: The resulting value is outside the range for the data 
>> type DECIMAL/NUMERIC(31,31).
>>      at 
>> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown
>> Source)
>>      at 
>> org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown
>> Source)
>>      ... 34 more
>> Caused by: ERROR 22003: The resulting value is outside the range for
>> the data type DECIMAL/NUMERIC(31,31).
>>      at org.apache.derby.iapi.error.StandardException.newException(Unknown 
>> Source)
>>      at org.apache.derby.iapi.types.SQLDecimal.setWidth(Unknown Source)
>>      at 
>> org.apache.derby.exe.ac0b5b0099x012dxe042x51f3x000000e17f003.e3(Unknown
>> Source)
>>      at org.apache.derby.impl.services.reflect.DirectCall.invoke(Unknown 
>> Source)
>>      at 
>> org.apache.derby.impl.sql.execute.ProjectRestrictResultSet.doProjection(Unknown
>> Source)
>>      at 
>> org.apache.derby.impl.sql.execute.ProjectRestrictResultSet.getNextRowCore(Unknown
>> Source)
>>      at 
>> org.apache.derby.impl.sql.execute.NormalizeResultSet.getNextRowCore(Unknown
>> Source)
>>      at 
>> org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(Unknown
>> Source)
>>      at 
>> org.apache.derby.impl.sql.execute.UpdateResultSet.collectAffectedRows(Unknown
>> Source)
>>      at org.apache.derby.impl.sql.execute.UpdateResultSet.open(Unknown 
>> Source)
>>      at 
>> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown
>> Source)
>>      at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown 
>> Source)
>>      ... 28 more
>> --
>> (The connection is made to an embedded in memory instance.)
>> The values must be explicitly casted to decimal to get it working (even when 
>> the values are set as BigDecimal):
>> --
>> update T_Professor set weight_In_B_D = ((((weight_In_B_D + cast(? as 
>> decimal)) - cast(? as decimal)) *
>> cast(? as decimal)) / cast(? as decimal)) where (id = ?)
>> --

Reply via email to