ExecuteScalar throws exception #171

Open
ghost opened this Issue Mar 2, 2013 · 0 comments

Projects

None yet

0 participants

@ghost
ghost commented Mar 2, 2013

I tried to compute sum from some table. If the table is empty, ExecuteScalar throws NullReferenceException. The solution was to check if ReadCol* is not null before casting it.

@nexussays nexussays pushed a commit to cloversoft/sqlite-net that referenced this issue Feb 9, 2014
@macu macu Use default value of T in ExecuteScalar when column type is Null
When executing a SUM query the method throws NullReferenceException if the
table is empty or no rows were selected by the WHERE clause or similar.
In these cases SQLite3.ColumnType returns ColType.Null, ReadCol returns null,
and the attempted cast to T throws the exception.

This fixes #171.
7c5792a
@oysteinkrog oysteinkrog referenced this issue in oysteinkrog/SQLite.Net-PCL Jan 7, 2015
@macu macu Use default value of T in ExecuteScalar when column type is Null
When executing a SUM query the method throws NullReferenceException if the
table is empty or no rows were selected by the WHERE clause or similar.
In these cases SQLite3.ColumnType returns ColType.Null, ReadCol returns null,
and the attempted cast to T throws the exception.

This fixes #171.

(cherry picked from commit 7c5792a)

Conflicts:
	src/SQLite.cs
d916c5d
@MontakOleg MontakOleg referenced this issue in oysteinkrog/SQLite.Net-PCL Feb 19, 2015
Merged

Fix typo in d916c5d and add test #126

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment