Hi Armin,

I suspect the change needs to cover both ASA and ASE. I'm actually surprised
it doesn't occur on all database types given the documentation on
java.sql.PreparedStatement (see below). The setObject call made by the
default implementation is documented as setting scale specifically to zero
for both NUMERIC and DECIMAL sql types. Based on this, our testing of sybase
drivers using JDBC suggests they are correct according to the interface
documentation.

This being the case we may need the following change, or something like it,
to PlatformDefaultImpl:

    /*
     * @see Platform#setObject(PreparedStatement, int, Object, int)
     */
    public void setObjectForStatement(PreparedStatement ps, int index,
Object value, int sqlType)
            throws SQLException
    {
        if ((value instanceof String) && (sqlType == Types.LONGVARCHAR))
        {
            String s = (String) value;
            ps.setCharacterStream(index, new StringReader(s), s.length());
        }
        // PATCH for BigDecimal truncation problem.
        else if ( (value instanceof BigDecimal) && (sqlType == Types.DECIMAL
|| sqlType == Types.NUMERIC)) {
                ps.setObject(index, value, sqlType,
((BigDecimal)value).scale());
        }
        // END BigDecimal patch.
        else
        {
            ps.setObject(index, value, sqlType);
        }
    }


Java API Docs:
--------------
java.sql.PreparedStatement.setObject

public void setObject(int parameterIndex,
                      Object x,
                      int targetSqlType)
               throws SQLException

    Sets the value of the designated parameter with the given object. This
method is like the method setObject above, EXCEPT THAT IT ASSUMES A SCALE OF
ZERO.

    Parameters:
        parameterIndex - the first parameter is 1, the second is 2, ...
        x - the object containing the input parameter value
        targetSqlType - the SQL type (as defined in java.sql.Types) to be
sent to the database 
    Throws:
        SQLException - if a database access error occurs
--------------

Regards
Stuart

-----Original Message-----
From: Armin Waibel [mailto:[EMAIL PROTECTED]
Sent: Monday, 29 March 2004 10:55 PM
To: OJB Users List
Subject: Re: Loss of precsion with PersistenceBroker.store() and
BigDecima l on Sybase.


Hi Stuart/Danilo

I don't use Sybase ASA or Sybase ASE, so it's hard to decide which way 
to go. Can someone say what we should change in
PlatformSybaseImpl (Sybase base class)
PlatformSybaseASAImpl
PlatformSybaseASEImpl
classes to make OJB proper work with Sybase?
Does Sybase support NUMERIC (is mapped to BigDecimal too) type?

public void setObjectForStatement(PreparedStatement ps, int index,
           Object value, int sqlType) throws SQLException
{
     // Stuart's patch
     if (sqlType == Types.DECIMAL)
     {
        ps.setObject(index, value);
     }
     else
     {
        super.setObjectForStatement(ps, index, value, sqlType);
     }
}

regards,
Armin

Stuart Heriot wrote:
> Hi Danilo,
> 
> Can't say I have much confidence in Sybase providing a permanent solution
> given your experience. We'll stick with the OJB fix for now. The
> ps.setBigDecimal() works also. 
> 
> Cheers
> Stuart
> 
> -----Original Message-----
> From: Danilo Tommasina [mailto:[EMAIL PROTECTED]
> Sent: Friday, 26 March 2004 11:41 PM
> To: OJB Users List
> Subject: Re: Loss of precsion with PersistenceBroker.store() and
> BigDecima l on Sybase.
> 
> 
> Hi,
> 
> We have the same problem with Sybase, the bug seems not to be really an 
> OJB problem it is a bug in the JDBC dirver, however doing a special 
> handling for BigDecimal in OJB may be a good workaround.
> 
> The bug appears in several releases of the Sybase drivers and appears 
> and disappears in different builds of the same driver version.
> Driver file jconn2_v55_B25089.jar (also version 5.5 Build 25089) works 
> correctly for us. In the following release build, the bug is still 
> present. For some reason the bug seems to be fixed and reappear in new 
> driver releases on a regular basis, this is very annoying since we do 
> not always have the control over wich driver releases our customer are 
> using :(
> Probably using a ps.setBigDecimal(...) call (instead of 
> ps.setObject(...) ) if sqlType is equal to BIG_DECIMAL would solve the 
> problem.
> 
> cheers
> danilo
> 
> 
>>Hi Stuart,
>>
>>do we need this patch for both Sybase versions (Sybase ASA, Sybase ASE)?
>>
>>regards,
>>Armin
>>
>>Stuart Heriot wrote:
>>
>>
>>>I have implemented a fix for this issue locally by modifying the Sybase
>>>Plaform dependant class (see below). I picked this up from a posting 
>>>about a
>>>similar issue with DB2. The DB2 fix, however, is not in the rc5 
>>>release. We
>>>need a fix to be included in the official OJB release so that we don't
>>>reintroduce this problem when implementing future releases of OJB. Is 
>>>this
>>>possible? Please advise..
>>>
>>>Regards Stuart Heriot
>>>
>>>
>>>package org.apache.ojb.broker.platforms;
>>>public class PlatformSybaseASEImpl extends PlatformDefaultImpl {
>>>    
>>>    /**
>>>     * Platform specific fix to BigDecimal's being truncated when stored
>>>to Sybase db.
>>>     */
>>>    public void setObjectForStatement(PreparedStatement ps, int index,
>>>Object value, int sqlType) throws SQLException {
>>>
>>>        // Added code to fix problem with truncation occuring on 
>>>        // BigDecimals when setObject is used in PlatformDefaultImpl
>>>        // Copied from similar fix to DB2 implementation.
>>>        if (sqlType == Types.DECIMAL) {
>>>            ps.setObject(index, value);
>>>        } else {
>>>            super.setObjectForStatement(ps, index, value,
>>>sqlType);
>>>        }
>>>    }     
>>>    /**
>>>     * Get join syntax type for this RDBMS      * one on of the 
>>>constants from JoinSyntaxType interface
>>>     */
>>>    public byte getJoinSyntaxType() {
>>>        return SYBASE_JOIN_SYNTAX;
>>>    }
>>>}
>>>
>>>-----Original Message-----
>>>From: Stuart Heriot [mailto:[EMAIL PROTECTED]
>>>Sent: Friday, 26 March 2004 9:34 AM
>>>To: 'OJB Users List'
>>>Subject: Loss of precsion with PersistenceBroker.store() and BigDecimal
>>>on Sybase.
>>>
>>>
>>>Hi,
>>>We have come across a problem storing BigDecimals with values being
>>>truncated and all decimal places being set to zero. Our system has a 
>>>number
>>>of value types stored with 2, 4 or 6 decimal point precision. We are 
>>>using
>>>BigDecimals rather than floats or doubles to maintain accuracy in 
>>>financial
>>>calculations within our application. Repository mapping has JDBC-TYPE 
>>>set to
>>>DECIMAL and precision set as required. Old values in the database are
>>>retrieved Ok with the correct precision but new values we try and 
>>>store are
>>>all truncated.
>>>I came across a posting some months ago about a similar problem with 
>>>DB2 and
>>>using prepared statements. Is there a fix for this?
>>>
>>>Currently using OJB rc5 and a Sybase 12.5 database.
>>>
>>>Thanks in advance...
>>>
>>>Stuart Heriot
>>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>>
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to