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

@@ -19,18 +19,50 @@
package org.isoron.uhabits.core.database;
import android.support.annotation.*;
public interface Cursor extends AutoCloseable
{
@Override
void close();
/**
* Moves the cursor forward one row from its current position. Returns
* true if the current position is valid, or false if the cursor is already
* past the last row. The cursor start at position -1, so this method must
* be called first.
*/
boolean moveToNext();
/**
* Retrieves the value of the designated column in the current row of this
* Cursor as an Integer. If the value is null, returns null. The first
* column has index zero.
*/
@Nullable
Integer getInt(int index);
/**
* Retrieves the value of the designated column in the current row of this
* Cursor as a Long. If the value is null, returns null. The first
* column has index zero.
*/
@Nullable
Long getLong(int index);
/**
* Retrieves the value of the designated column in the current row of this
* Cursor as a Double. If the value is null, returns null. The first
* column has index zero.
*/
@Nullable
Double getDouble(int index);
/**
* Retrieves the value of the designated column in the current row of this
* Cursor as a String. If the value is null, returns null. The first
* column has index zero.
*/
@Nullable
String getString(int index);
}

View File

@@ -63,7 +63,9 @@ public class JdbcCursor implements Cursor
{
try
{
return resultSet.getInt(index + 1);
Integer value = resultSet.getInt(index + 1);
if(resultSet.wasNull()) return null;
else return value;
}
catch (SQLException e)
{
@@ -76,7 +78,9 @@ public class JdbcCursor implements Cursor
{
try
{
return resultSet.getLong(index + 1);
Long value = resultSet.getLong(index + 1);
if(resultSet.wasNull()) return null;
else return value;
}
catch (SQLException e)
{
@@ -89,7 +93,9 @@ public class JdbcCursor implements Cursor
{
try
{
return resultSet.getDouble(index + 1);
Double value = resultSet.getDouble(index + 1);
if(resultSet.wasNull()) return null;
else return value;
}
catch (SQLException e)
{
@@ -102,7 +108,9 @@ public class JdbcCursor implements Cursor
{
try
{
return resultSet.getString(index + 1);
String value = resultSet.getString(index + 1);
if(resultSet.wasNull()) return null;
else return value;
}
catch (SQLException e)
{