mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 01:28:52 -06:00
Fix handling of null values in AndroidDatabase
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
|
||||
package org.isoron.uhabits.database;
|
||||
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.core.database.*;
|
||||
|
||||
public class AndroidCursor implements Cursor
|
||||
@@ -45,26 +47,34 @@ public class AndroidCursor implements Cursor
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Integer getInt(int index)
|
||||
{
|
||||
return cursor.getInt(index);
|
||||
if(cursor.isNull(index)) return null;
|
||||
else return cursor.getInt(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Long getLong(int index)
|
||||
{
|
||||
return cursor.getLong(index);
|
||||
if(cursor.isNull(index)) return null;
|
||||
else return cursor.getLong(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Double getDouble(int index)
|
||||
{
|
||||
return cursor.getDouble(index);
|
||||
if(cursor.isNull(index)) return null;
|
||||
else return cursor.getDouble(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getString(int index)
|
||||
{
|
||||
return cursor.getString(index);
|
||||
if(cursor.isNull(index)) return null;
|
||||
else return cursor.getString(index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,8 +107,9 @@ public class AndroidDatabase implements Database
|
||||
ContentValues values = new ContentValues();
|
||||
for (Map.Entry<String, Object> entry : map.entrySet())
|
||||
{
|
||||
if (entry.getValue() == null) continue;
|
||||
if (entry.getValue() instanceof Integer)
|
||||
if (entry.getValue() == null)
|
||||
values.putNull(entry.getKey());
|
||||
else if (entry.getValue() instanceof Integer)
|
||||
values.put(entry.getKey(), (Integer) entry.getValue());
|
||||
else if (entry.getValue() instanceof Long)
|
||||
values.put(entry.getKey(), (Long) entry.getValue());
|
||||
|
||||
Reference in New Issue
Block a user