Message1081

Author nobody
Recipients
Date 2005-12-16.17:29:09
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Jython is inaccurately reading double(s) from Database.

When a database column is defined as double and it is 
value is relatively big (~more than million), jython 
is inaccurately reading the value and it 
adds/subtracts 2,4,8 or 16 (power of 2) to the actual 
value.

The reason is that 
com.ziclix.python.sql.DataHanlder.java uses 
java.sql.ResultSet.getFloat() when reading double 
values instead of using java.sql.ResultSet.getDouble() 
and for large numbers, this has an unexpected behavior.

Here is the relevant piece fo code from 
com.ziclix.python.sql.DataHanlder.java 
public PyObject getPyObject(ResultSet set, int col, 
int type) throws SQLException {

// code here

		case Types.FLOAT :
		case Types.REAL :
		case Types.DOUBLE :
		   obj = Py.newFloat(set.getFloat
(col));
		   break;

// more code here 

}

In our case, we have an amount column defined as 
double in TRADE table. Below are the actual values for 
the amount field and the values retured by Jython. We 
are using zxJDBC to read from the database.

Actual Values in DataBase   Values Returned by Jython
482465000                   482464992
64563750                    64563752
129127500                   129127504


We are using:
- Sybase 12.5 as the database server
- JConnect 5.5 as the JDBC driver.
- Jython 2.1

To temporarly fix this, I had to change DataHandler 
case statement above and use getDouble(col) for 
Types.DOUBLE and the result matched what we have in 
the database.

This is our jython code :-

   d, u, p, v = dburl, dbUsername, dbPassword, 
jdbcDriverClassname
        db = zxJDBC.connect(d, u, p, v)

try:
    c1 = db.cursor()
    c1.execute(sql)
    if c1.rowcount<=0:
        print " NO ROWS TO PROCESS. EXITING NOW"
        c1.close()
        sys.exit(0)
except Exception, e:
    print >> sys.stderr,e
    sys.exit(-1)

for aRow in c1.fetchall():
        stringEntries=[]
        for i in range(len(columnNames)):
                if quotedColumns!=None and columnNames
[i] in quotedColumns:
                        isQuoted=1
                else:
                        isQuoted=0
                stringEntries+=[toString(aRow
[i],quotedChar,isQuoted,autoQuoteSt
rings)]
            print string.join(stringEntries,delimiter)



def toString
(aVariable,quotedString,forceQuote,autoQuoteStrings):
        if aVariable==None:
                returnValue=''
        else:
                   if (autoQuoteStrings and type
(aVariable)==types.StringType) or forceQuote:
                        returnValue=quotedString+str
(aVariable)+quotedString
                else:
                        returnValue=str(aVariable)
        return returnValue
History
Date User Action Args
2008-02-20 17:17:27adminlinkissue1382581 messages
2008-02-20 17:17:27admincreate