Repository navigation
Target .NET 5, SDK 5.0.0-rc1 - #3148
Conversation
roji
commented
Sep 16, 2020
- Implement some new System.Data APIs
- Nullability fixes
* Implement some new System.Data APIs * Nullability fixes
| public new string BaseCatalogName | ||
| { | ||
| get => base.BaseCatalogName; | ||
| get => base.BaseCatalogName!; |
There was a problem hiding this comment.
Why a bang instead of adding the nullability attribute to the return type?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
So why not just do
[NotNull] public override string? BaseCatalogName { get => ... }🤣
| public new string DataTypeName | ||
| { | ||
| get => base.DataTypeName; | ||
| get => base.DataTypeName!; |
There was a problem hiding this comment.
And how this could be nullable in .NET?
There was a problem hiding this comment.
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...
| /// <PermissionSet> | ||
| /// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" PathDiscovery="*AllFiles*" /> | ||
| /// </PermissionSet> | ||
| [AllowNull] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
| /// <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 ?? ""; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
PostgresException with SQLSTATE = 40001 or 40P01 are probably the archetypes of transient exceptions in a database.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Yes. I'll open an issue so that I don't forget it.