ignite-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anil <anilk...@gmail.com>
Subject Re: Null column values - bug
Date Thu, 03 Nov 2016 18:45:55 GMT
following code i see in the JdbcResultSet. val is not null for null values
for string types. then val == null is false. correct ?

 T val = cls == String.class ? (T)String.valueOf(curr.get(colIdx - 1)) :
(T)curr.get(colIdx - 1);

 wasNull = val == null;

On 3 November 2016 at 23:48, Andrey Mashenkov <amashenkov@gridgain.com>
wrote:

> No, wasNull is true if column value is null otherwise false.
> You can have wasNull() is true but getInt() is zero. E.g. getInt() return
> type is primitive and default value (zero) shoud be return for NULL fields.
>
>
> On Thu, Nov 3, 2016 at 9:11 PM, Anil <anilklce@gmail.com> wrote:
>
>> wasNull is false all the time for string types. correct ?
>>
>> On 3 November 2016 at 20:39, Andrey Mashenkov <amashenkov@gridgain.com>
>> wrote:
>>
>>> Javadoc says that null value should be returned.
>>>
>>> But from the other side, there is wasNull() method, that should be use
>>> for null checks.
>>>
>>>
>>>
>>> On Thu, Nov 3, 2016 at 5:39 PM, Andrey Gura <agura@apache.org> wrote:
>>>
>>>> String.valuOf(null) return "null" string by contract.
>>>>
>>>> On Thu, Nov 3, 2016 at 5:33 PM, Anil <anilklce@gmail.com> wrote:
>>>>
>>>>> HI ,
>>>>>
>>>>> null values are returned as "null" with ignite jdbc result set.
>>>>>
>>>>>  private <T> T getTypedValue(int colIdx, Class<T> cls) throws
>>>>> SQLException {
>>>>>         ensureNotClosed();
>>>>>         ensureHasCurrentRow();
>>>>>
>>>>>         try {
>>>>>             T val = cls == String.class ?
>>>>> (T)String.valueOf(curr.get(colIdx - 1)) : (T)curr.get(colIdx - 1);
>>>>>
>>>>>             wasNull = val == null;
>>>>>
>>>>>             return val;
>>>>>         }
>>>>>         catch (IndexOutOfBoundsException ignored) {
>>>>>             throw new SQLException("Invalid column index: " + colIdx);
>>>>>         }
>>>>>         catch (ClassCastException ignored) {
>>>>>             throw new SQLException("Value is an not instance of " +
>>>>> cls.getName());
>>>>>         }
>>>>>     }
>>>>>
>>>>>
>>>>> if a column value is null (curr.get(colIdx - 1) return null but
>>>>> String.valueOf( (curr.get(colIdx - 1) ) is not null it is "null".
>>>>>
>>>>> ArrayList<String> obj = new ArrayList<String>();
>>>>>                           obj.add(null);
>>>>> System.out.println(null == (String)String.valueOf(obj.get(0)));
>>>>>
>>>>> above Sysout is false.
>>>>>
>>>>> Fix :
>>>>>
>>>>> Object colValue = curr.get(colIdx - 1);
>>>>>
>>>>> T val = cls == String.class ? (String) colValue : (T) colValue;
>>>>>
>>>>> or return (T) colValue
>>>>>
>>>>>
>>>>> please let me know if you see any issues. thanks
>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
>

Mime
View raw message