Fix handling of null values in AndroidDatabase

This commit is contained in:
2017-06-23 09:14:36 -04:00
parent f55dc0d811
commit 5d9563b9d8
7 changed files with 163 additions and 12 deletions

View File

@@ -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);
}
}

View File

@@ -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());