Skip to content

Numerous fixes to PG type name handling - #1945

Merged
roji merged 4 commits into
npgsql:devfrom
roji:typename
May 23, 2018
Merged

roji merged 4 commits into
npgsql:devfrom
roji:typename

Conversation

@roji

@roji roji commented May 22, 2018

Copy link
Copy Markdown
Member

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.

* 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
roji requested a review from YohDeadfall May 22, 2018 05:21
@Brar

Brar commented May 22, 2018

Copy link
Copy Markdown
Member

@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 YohDeadfall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good except a few nits. Will approve, when you answer my and @Brar's questions.

case "int8":
return "bigint";
case "int4":
return "integer";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Swap int4 and int8 cases.

public void GetDataTypeName(string typeName)
{
using (var conn = OpenConnection())
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Spaces.

Comment thread test/Npgsql.Tests/CopyTests.cs Outdated
}

[Test, IssueLink("https://github.com/npgsql/npgsql/issues/657")]
//[Test, IssueLink("https://github.com/npgsql/npgsql/issues/657")]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it commented?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PostgresFacets is a struct. It can't be null.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, was a leftover from an earlier version.

: Namespace + '.' + GetPartialNameWithFacets(typeModifier);

[CanBeNull]
internal virtual PostgresFacets GetFacets(int typeModifier) => PostgresFacets.None;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@roji

roji commented May 22, 2018

Copy link
Copy Markdown
Member Author

@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...

Comment thread test/Npgsql.Tests/CommandTests.cs Outdated
cmd.ExecuteNonQuery();
using (var cmd = new NpgsqlCommand("INSERT INTO foo (id) VALUES (1)", conn))
cmd.ExecuteNonQuery();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Indentation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was not supposed to be committed at all, thanks for catching.

switch (internalName)
{
case "bool":
return "boolean";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it causes test failures.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to update the handler's type name accordingly, thanks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please fix the Bool and UnrecognizedBinary tests:

Assert.That(reader.GetDataTypeName(i), Is.EqualTo("bool"));

conn.TypeMapper.RemoveMapping("bool");

@roji

roji commented May 22, 2018

Copy link
Copy Markdown
Member Author

Fixed the two failing boolean-related tests, everything should be green now. Let me know if you consider this mergeable.

@YohDeadfall YohDeadfall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mergeable (: Thanks!

@roji
roji merged commit fc1e183 into npgsql:dev May 23, 2018
@roji
roji deleted the typename branch May 23, 2018 06:11
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

Successfully merging this pull request may close these issues.

3 participants