Skip to content
This repository has been archived by the owner on Nov 1, 2018. It is now read-only.

Support reading Guid values from TEXT columns #191

Closed
rowanmiller opened this issue Dec 8, 2015 · 14 comments
Closed

Support reading Guid values from TEXT columns #191

rowanmiller opened this issue Dec 8, 2015 · 14 comments

Comments

@rowanmiller
Copy link
Contributor

Copied from dotnet/efcore#3950

Currently we assume GUID values are stored in BLOB columns, so you get an exception when we try to parse the value when it is stored as a STRING.

@RonFrick
Copy link

RonFrick commented Dec 8, 2015

Thanks Rowan! Is this something that I should jump on with a pull request or will you be able to knock it out fairly quickly?

@rowanmiller
Copy link
Contributor Author

Pull request would be great - we are swamped at the moment.

@RonFrick
Copy link

RonFrick commented Dec 9, 2015

First pull request created. :) Although I think I might have picked the wrong stream to pull from, can we change it on the fly before I start working?

@ErikEJ
Copy link
Contributor

ErikEJ commented Dec 9, 2015

Think you must start over. First fork, clone, branch

@bricelam
Copy link
Contributor

My thoughts on this: If the bytes returned by GetBlob are larger than expected, convert them to text and try creating a Guid from them.

@RonFrick
Copy link

Anyone had time to look at this?

RonFrick added a commit to RonFrick/Microsoft.Data.Sqlite that referenced this issue Apr 24, 2016
@RonFrick
Copy link

I have it working. I took your suggestion Brice and converted it to text to make sure the length was correct. Not sure if I did this correctly but I checked in my changes here.

https://github.com/aspnet/Microsoft.Data.Sqlite/compare/dev...RonFrick:ron?expand=1

@RonFrick
Copy link

RonFrick commented Apr 24, 2016

Here? public override Guid GetGuid(int ordinal) => new Guid(GetGuidBlob(ordinal));

This throws an exception…

public override Guid GetGuid(int ordinal) => new Guid(GetBlob(ordinal));

@RonFrick
Copy link

RonFrick commented Apr 24, 2016

Is it just the naming that is a problem? We could still call it GetBlob and use an overload?

public override Guid GetGuid(int ordinal) => new Guid(GetBlob(ordinal,true));

private string GetBlob(int ordinal,bool isGuid)
{
if (IsDBNull(ordinal))
{
throw new InvalidCastException();
}

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

@RonFrick
Copy link

This also works but it is not safe?

public override Guid GetGuid(int ordinal) => new Guid(GetBlob(ordinal).ToString().Substring(0,36));

@roklenardic
Copy link

I am using EntityFrameworkCore1.0.0 and this seems it's still not working. Any update on it?

@rowanmiller
Copy link
Contributor Author

This is on our backlog to enable in a future release. Currently, our SQLite provider requires that GUIDs be stored in binary. The workaround would be to map the column to a string property (which can be private) and then have an unmapped property that does the conversion to/from a GUID.

@RonFrick
Copy link

RonFrick commented Jul 9, 2016

Until this is supported out of the box, I have a working version of Microsoft.Data.Sqlite that will allow you to use Guids as strings with EF. Let me know if you want it and I can post it somewhere for you.

@roklenardic
Copy link

@RonFrick I would love to give it a try, please let me know where I can download it? Thanks!

@bricelam bricelam self-assigned this Jan 13, 2017
@bricelam bricelam modified the milestones: Backlog, 2.0.0 Jan 13, 2017
@bricelam bricelam changed the title Support reading GUID values from STRING columns Support reading GUID values from TEXT columns Jan 31, 2017
@bricelam bricelam changed the title Support reading GUID values from TEXT columns Support reading Guid values from TEXT columns Jan 31, 2017
@bricelam bricelam modified the milestones: Backlog, 2.0.0 Feb 10, 2017
@bricelam bricelam modified the milestones: 2.0.0, Backlog Mar 23, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants