Joe Wilson a écrit :
> --- Xavier RAYNAUD <[EMAIL PROTECTED]> wrote:
>   
>> [...]
>> This bug occurs only with nested DB. Here is the stack trace (for Double 
>> values).
>>
>> java.lang.NullPointerException
>>    at 
>> sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:991)
>>    at java.lang.Double.parseDouble(Double.java:482)
>>    at org.sqlite.NestedDB.column_double(NestedDB.java:124)
>>    at org.sqlite.RS.getDouble(RS.java:203)
>>    at org.sqlite.RS.getDouble(RS.java:205)
>>    at com.st.sqlite.Main.main(Main.java:37)
>>
>> So the bug seems located in org.sqlite.NestedDB class. Did you know how 
>> I can patch it ?
>> Another solution can be to add try/catch blocks in org.sqlite.RS class, 
>> but I'm not convinced...
>>     
>
> I'd recommend to look at the code for wasNull() and fold that logic into
> RS.getDouble() and related functions. It's more efficient and accurate than
> just catching the exception and returning 0.
>   

Ok, I've done what you suggest.
(In fact, the NPE is thrown only with getFloat() and getDouble() ; why I 
incriminate getLong() ??? )
Please find attached a patch (RS.patch)

XR

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SQLiteJDBC" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlitejdbc?hl=en
-~----------~----~----~----~------~----~------~--~---

--- RS.java.orig        2007-03-02 09:13:48.000000000 +0100
+++ RS.java     2007-03-02 09:50:58.000000000 +0100
@@ -200,11 +200,13 @@
         return getDate(findColumn(col), cal); }
 
     public double getDouble(int col) throws SQLException {
+        if (db.column_type(pointer, markCol(col)) == SQLITE_NULL) return 0;
         return db.column_double(pointer, markCol(col)); }
     public double getDouble(String col) throws SQLException {
         return getDouble(findColumn(col)); }
 
     public float getFloat(int col) throws SQLException {
+        if (db.column_type(pointer, markCol(col)) == SQLITE_NULL) return 0;
         return (float)db.column_double(pointer, markCol(col)); }
     public float getFloat(String col) throws SQLException {
         return getFloat(findColumn(col)); }

Reply via email to