Skip to content

Target .NET 5, SDK 5.0.0-rc1 - #3148

Merged
roji merged 1 commit into
npgsql:devfrom
roji:net5.0
Sep 17, 2020
Merged

roji merged 1 commit into
npgsql:devfrom
roji:net5.0

Conversation

@roji

@roji roji commented Sep 16, 2020

Copy link
Copy Markdown
Member
  • Implement some new System.Data APIs
  • Nullability fixes

@roji
roji requested a review from YohDeadfall as a code owner September 16, 2020 12:12
@roji
roji marked this pull request as draft September 16, 2020 12:13
@roji
roji marked this pull request as ready for review September 16, 2020 12:54
* Implement some new System.Data APIs
* Nullability fixes
public new string BaseCatalogName
{
get => base.BaseCatalogName;
get => base.BaseCatalogName!;

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 a bang instead of adding the nullability attribute to the return type?

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.

The idea is that with Npgsql specifically, the BaseCatalogName (which contains the database name) is never supposed to be null. So if someone is coding against NpgsqlDbColumn (as opposed to DbColumn) they're never supposed to see null on this property.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So why not just do

[NotNull] public override string? BaseCatalogName { get => ... }

🤣

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, I see, it's not virtual.

public new string DataTypeName
{
get => base.DataTypeName;
get => base.DataTypeName!;

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.

And how this could be nullable in .NET?

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.

Mostly because there's this sentence in the docs:

The name of the data type; otherwise, a null reference (Nothing in Visual Basic) if no value is set.

Maybe there could be a database where that information isn't available or whatever, who knows...

@Brar Brar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" PathDiscovery="*AllFiles*" />
/// </PermissionSet>
[AllowNull]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not really related to this change but I think that the only reason this API even has a setter is because SQL Server allows [ and " as prefix (and ] as suffix - that's why it even is prefix and suffix).
For PostgreSQL all of this doesn't make any sense. We have " period.
I think we should change the whole setter into a no-op. or even make it a new get-only property.
Same for Suffix.

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.

I think we should change the whole setter into a no-op. or even make it a new get-only property.

If you look closely, it already is almost a no-op - it's really weird, but it sets to double-quotes on everything except empty or null... None if it makes sense to me :/

We can definitely clean this up and hardwire it to always return double-quote, and make the setter a no-op. I don't think there's much value in a new hiding get-only property, considering we need to override the base one anyway...

Comment thread src/Npgsql/NpgsqlCommandBuilder.cs Resolved
/// <value>The name of the current database or the name of the database to be
/// used after a connection is opened. The default value is the empty string.</value>
public override string? Database => Settings.Database ?? Settings.Username;
public override string Database => Settings.Database ?? Settings.Username ?? "";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I actually like this null coalescing operator.
You can chain dozens of properties/fields if you want and it's still not messy and you can easily sort out the priority/precedence.

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.

Yeah, it's one of the really useful operator they've added over the years.

#else
public override bool IsTransient
#endif
=> InnerException is IOException || InnerException is SocketException || InnerException is TimeoutException;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

PostgresException with SQLSTATE = 40001 or 40P01 are probably the archetypes of transient exceptions in a database.

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, they're included in the PostgresException override of this property - but 40P01 is missing (and I agree should be there).

Do you want to do a quick pass on the current list and update it as appropriate?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes. I'll open an issue so that I don't forget it.

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