Skip to content

Commit

Permalink
aspnet#191 Support reading GUID values from STRING columns
Browse files Browse the repository at this point in the history
  • Loading branch information
RonFrick committed Apr 24, 2016
1 parent 2c2a11c commit df3f416
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Microsoft.Data.Sqlite/SqliteDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public override IEnumerator GetEnumerator()
#if NET451
return new DbEnumerator(this);
#else
// TODO: Remove when the System.Data.Common includes DbEnumerator
// TODO: Remove when the System.Data.Common includes DbEnumerator
throw new NotImplementedException();
#endif
}
Expand Down Expand Up @@ -313,7 +313,7 @@ public override double GetDouble(int ordinal)
}

public override float GetFloat(int ordinal) => (float)GetDouble(ordinal);
public override Guid GetGuid(int ordinal) => new Guid(GetBlob(ordinal));
public override Guid GetGuid(int ordinal) => new Guid(GetGuidBlob(ordinal));
public override short GetInt16(int ordinal) => (short)GetInt64(ordinal);
public override int GetInt32(int ordinal) => (int)GetInt64(ordinal);

Expand Down Expand Up @@ -495,5 +495,19 @@ private byte[] GetBlob(int ordinal)

return NativeMethods.sqlite3_column_blob(_stmt, ordinal);
}

private string GetGuidBlob(int ordinal)
{
if (IsDBNull(ordinal))
{
throw new InvalidCastException();
}

string blob = System.Text.Encoding.UTF8.GetString(NativeMethods.sqlite3_column_blob(_stmt, ordinal));
if (blob.Length > 36)
return blob.Substring(0, 36);
else
return blob;
}
}
}

0 comments on commit df3f416

Please sign in to comment.