Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when calling ExecuteScalarAsync for a nullable integer when result is NULL #26

Closed
jameswilddev opened this issue Mar 29, 2016 · 3 comments

Comments

@jameswilddev
Copy link

When calling ExecuteScalarAsync for a nullable integer, there's a few possible scenarios I can think of:

  • One or more rows came back and the first contains an integer. The integer should be returned.
  • One or more rows came back and the first contains a non-integer. (string, etc.) I think this should probably throw an exception.
  • One or more rows came back and the first contains NULL. C# null should be returned.
  • No rows came back. C# null should be returned.

When the following is done: (this can also happen if you select data which is null, or when an aggregate contains no rows)

await database.ExecuteScalarAsync<int?>(Sql.Builder.Select("NULL"))

This generates an exception:

A first chance exception of type 'System.InvalidCastException' occurred in mscorlib.dll

Additional information: Object cannot be cast from DBNull to other types.

@tmenier
Copy link
Owner

tmenier commented Apr 23, 2016

I suspect this change needs to be back-ported: CollaboratingPlatypus#280

I'll see if I can tackle this soon.

@tmenier
Copy link
Owner

tmenier commented Aug 14, 2016

fixed and will be released shortly with 1.2

@tmenier
Copy link
Owner

tmenier commented Aug 14, 2016

@tmenier tmenier closed this as completed Aug 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants