Closed GoogleCodeExporter closed 9 years ago
You also need to modify ReadCol (bug found by Anders Rune Jensen), adding the
same two lines to unpack the generic nullable (the actual "null" case is
handled in the if just before):
if (type == SQLite3.ColType.Null) {
return null;
} else {
if (clrType.IsGenericType && clrType.GetGenericTypeDefinition() == typeof(Nullable<>))
clrType = clrType.GetGenericArguments()[0];
if (clrType == typeof(String)) {
...
Original comment by olau%iol...@gtempaccount.com
on 9 Jul 2010 at 12:04
The latter comment is wrong - I didn't understand the logic completely.
Actually, the "type" we get here is only computed once for all rows in a
multiple-row result (up in ExecuteQuery), hence if the type is nullable, we
can't rely on it since it might be SQLite3.ColType.Null in the first row and
Integer in the second.
What we need instead of my latter comment is either a revamp of this logic, or
the following little piece of code that unpacks the generic type immediately
and resets the SQLite3 column type:
object ReadCol (IntPtr stmt, int index, SQLite3.ColType type, Type clrType)
{
if (clrType.IsGenericType && clrType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
type = SQLite3.ColumnType(stmt, index); // don't trust the predefined type
clrType = clrType.GetGenericArguments()[0];
}
if (type == SQLite3.ColType.Null)
{
return null;
} else {
if (clrType == typeof(String)) {
I'm surprised sqlite-net doesn't support nullable types out of the box, they're
handy for foreign keys. Maybe you're just using 0 instead of null?
Original comment by olau%iol...@gtempaccount.com
on 10 Aug 2010 at 1:21
Actually, as it turns out, my previous comment was fine, it's the logic that's
broken. It won't work for string columns with null values either. So comment 1
still applies. I'll open a separate issue.
Original comment by olau%iol...@gtempaccount.com
on 13 Aug 2010 at 5:06
Ah, I can see you fixed it now in SVN. So no need to open another issue. :)
Original comment by olau%iol...@gtempaccount.com
on 13 Aug 2010 at 5:14
Original comment by frank.al...@gmail.com
on 14 Nov 2010 at 12:31
Sorry yes I fixed this a while back :-)
Original comment by elite.da...@gmail.com
on 19 Nov 2011 at 4:35
Original issue reported on code.google.com by
olau%iol...@gtempaccount.com
on 8 Jul 2010 at 6:58