Repository navigation
Numerous fixes to PG type name handling - #1945
Conversation
* Return the standard, user-facing type names rather than the legacy names PostgreSQL uses internally (https://www.postgresql.org/docs/current/static/datatype.html#DATATYPE-TABLE). For example, we need to return `integer` rather than `int4`, and for arrays we need to return `text[]` rather than the internal `_text`. This should happen everywhere. * Include facet information in `NpgsqlDataReader.GetDataTypeName()`, returning `numeric(x,y)` instead of just `numeric`. * Column information returned by `NpgsqlDataReader.GetColumnSchema()` sometimes did not correctly populate the facets (size/precision/scale). Fixes npgsql#1919
|
@roji actually I'm pretty interested in this as I'm planning to submit a PR to provide some infrastructure for type handler testing (the amount of testing needed to ensure that every pg type<-> .Net type combination is working is immense and we don't really do it ATM). Any reason you didn't handle bool->boolean (personally I like bool better too but I consider consistency a higher goal) and didn't touch the type mapping docs? |
YohDeadfall
left a comment
There was a problem hiding this comment.
Looks good except a few nits. Will approve, when you answer my and @Brar's questions.
| case "int8": | ||
| return "bigint"; | ||
| case "int4": | ||
| return "integer"; |
There was a problem hiding this comment.
nit: Swap int4 and int8 cases.
| public void GetDataTypeName(string typeName) | ||
| { | ||
| using (var conn = OpenConnection()) | ||
| { |
There was a problem hiding this comment.
nit: There is no need to use curly brackets.
| [TestCase("bit(3)", 3)] | ||
| [TestCase("bit varying")] | ||
| [TestCase("bit varying(3)", 3)] | ||
| public void DataTypeName(string typeName, int? size=null, int? precision=null, int? scale=null) |
| } | ||
|
|
||
| [Test, IssueLink("https://github.com/npgsql/npgsql/issues/657")] | ||
| //[Test, IssueLink("https://github.com/npgsql/npgsql/issues/657")] |
There was a problem hiding this comment.
Oops, thanks for catching this. Resharper and Rider currently have a bug where they don't respect [Explicit] and always run the test. For this kind of heavy test it makes it impossible to run tests as part of development. Remove the comment.
| } | ||
|
|
||
| [CanBeNull] | ||
| internal override PostgresFacets GetFacets(int typeModifier) |
There was a problem hiding this comment.
PostgresFacets is a struct. It can't be null.
There was a problem hiding this comment.
Yep, was a leftover from an earlier version.
| : Namespace + '.' + GetPartialNameWithFacets(typeModifier); | ||
|
|
||
| [CanBeNull] | ||
| internal virtual PostgresFacets GetFacets(int typeModifier) => PostgresFacets.None; |
|
@Brar and @YohDeadfall, pushed a commit which addresses all of your comments, let me know if you see anything else. I'll just go ahead and say it's absolutely wonderful to have two smart people looking at my code before it's merged... |
| cmd.ExecuteNonQuery(); | ||
| using (var cmd = new NpgsqlCommand("INSERT INTO foo (id) VALUES (1)", conn)) | ||
| cmd.ExecuteNonQuery(); | ||
| } |
There was a problem hiding this comment.
Was not supposed to be committed at all, thanks for catching.
| switch (internalName) | ||
| { | ||
| case "bool": | ||
| return "boolean"; |
There was a problem hiding this comment.
Looks like it causes test failures.
There was a problem hiding this comment.
Forgot to update the handler's type name accordingly, thanks.
There was a problem hiding this comment.
Also please fix the Bool and UnrecognizedBinary tests:
|
Fixed the two failing boolean-related tests, everything should be green now. Let me know if you consider this mergeable. |
YohDeadfall
left a comment
There was a problem hiding this comment.
Mergeable (: Thanks!
Fixes #1919
This is the last functionality change I wanted to introduce for 4.0, from my side I don't have anything else (but we can still consider merging PRs depending on what they do).
@YohDeadfall, you may be interested in this PR, I think you haven't been around these areas of the code. But if you don't have enough time or aren't interested, let me know.
@Brar, you may be interested in this as well.