db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kathey Marsden (JIRA)" <j...@apache.org>
Subject [jira] Commented: (DERBY-2073) Inserting BigDecimal value in PreparedStatement into double column loses fractional digits
Date Thu, 11 Oct 2007 17:59:50 GMT

    [ https://issues.apache.org/jira/browse/DERBY-2073?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12534105

Kathey Marsden commented on DERBY-2073:

I noticed this commented out code in NetStatementRequest.java
I think for DERBY we don't use describe input so we are going to need to determine precision
and scale from the data. The exception would be for a specified scale in:
oid setObject(int parameterIndex,
               Object x,
               int targetSqlType,
               int scaleOrLength)
               throws SQLException

Still the precision would have to be calculated.

   case java.sql.Types.NUMERIC:
                case java.sql.Types.DECIMAL:
                    // lid: PROTOCOL_TYPE_NDECIMAL
                    // dataFormat: java.math.BigDecimal
                    // input only:
                    //   if null and describe input - use describe input precision and scale
                    //   if not null and describe input - calculate precision and actual scale
from data
                    //   if null and no describe input - guess with precision 1 scale 0
                    //   if not null and no describe input - calculate precision and actual
scale from data
                    // output only:
                    //   use largest precision/scale based on registered scale from registerOutParameter
                    // inout:
                    //   if null - use largest precision/scale based on scale from registerOutParameter
                    //   if not null - write bigDecimal () pass registered scale so it can
pad, you don't even
                    //      have to look at the actual scale at this level.
                    if (parameterMetaData.isGuessed) {
                      java.math.BigDecimal bigDecimal = (java.math.BigDecimal) inputRow[i];
                      int precision = Utils.computeBigDecimalPrecision (bigDecimal);
                      lidAndLengths[i][1] = (precision << 8) + // use precision above
                                          (bigDecimal.scale() << 0);
                    // Split this entire method into two parts, the first method is called
only once and the inputRow is not passed,!!
                    // the second method is called for every inputRow and overrides inputDA
lengths/scales based upon the acutal data!
                    // for decimal and blob columns only
                    int precision = parameterMetaData.sqlPrecision_[i];
                    int scale = parameterMetaData.sqlScale_[i];
                    lidAndLengths[i][0] = DRDAConstants.DRDA_TYPE_NDECIMAL;
                    lidAndLengths[i][1] = (precision << 8) + (scale << 0);

> Inserting BigDecimal value in PreparedStatement into double column loses fractional digits
> ------------------------------------------------------------------------------------------
>                 Key: DERBY-2073
>                 URL: https://issues.apache.org/jira/browse/DERBY-2073
>             Project: Derby
>          Issue Type: Bug
>          Components: JDBC
>    Affects Versions:
>         Environment: windows xp
>            Reporter: Lukasz P
>            Assignee: Kathey Marsden
>         Attachments: BigDecimalProblemTester.java
> Create table with column of type double.
> Create a prepared statement which inserts value to this column.
> use preparedStatement#setBigDecimal method of the statement to set value of the column.
> Execution of such statement succeeds, but actual value in db has no fractional digits.
> You can use attached test class to reproduce this problem

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message