Skip to content
Permalink
Browse files

Merge branch 'hotfix/4.0.6'

  • Loading branch information...
roji committed Apr 11, 2019
2 parents c254996 + 54a6fab commit 0f1e91e6b6171d93ede2f3edb045d5a33a5cf6ec
@@ -1,13 +1,13 @@
image: Visual Studio 2017
version: 4.0.5-{build}
version: 4.0.6-{build}
environment:
global:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: 1
NPGSQL_TEST_DB: Host=localhost;Database=postgres;Username=postgres;Password=Password12!
PGUSER: postgres
PGPASSWORD: Password12!
POSTGIS_EXE: postgis-bundle-pg10x64-setup-2.5.0-1.exe
POSTGIS_EXE: postgis-bundle-pg10x64-setup-2.5.1-1.exe
NoPackageAnalysis: true # Suppresses warning about SemVer 2.0.0 version suffixes when packing
cache:
- '%USERPROFILE%\.nuget\packages -> **\*.csproj'
@@ -43,6 +43,7 @@
<ComponentRef Id="System.Threading.Tasks.Extensions" />
<ComponentRef Id="System.ValueTuple" />
<ComponentRef Id="System.Runtime.CompilerServices.Unsafe" />
<ComponentRef Id="System.Memory" />
<ComponentRef Id="MachineConfig_x86" />
<ComponentRef Id="MachineConfig_x64" />

@@ -133,6 +134,13 @@
KeyPath="yes"
Assembly=".net" />
</Component>
<Component Id="System.Memory" Guid="3cf4b30c-ccf9-4c65-b2ba-cf00684e35cb">
<File Id="System.Memory"
Name="System.Memory.dll"
Source="..\npgsql\bin\$(var.Configuration)\net451\System.Memory.dll"
KeyPath="yes"
Assembly=".net" />
</Component>
</Directory>

<!-- http://stackoverflow.com/questions/791455/how-do-i-modify-machine-config-via-an-msi-package -->
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>4.0.5</VersionPrefix>
<VersionPrefix>4.0.6</VersionPrefix>
<Description>GeoJSON plugin for Npgsql, allowing mapping of PostGIS geometry types to GeoJSON types.</Description>
<Authors>Yoh Deadfall, Shay Rojansky</Authors>
<Copyright>Copyright 2019 © The Npgsql Development Team</Copyright>
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>4.0.5</VersionPrefix>
<VersionPrefix>4.0.6</VersionPrefix>
<Description>Json.NET plugin for Npgsql, allowing transparent serialization/deserialization of JSON objects directly to and from the database.</Description>
<Authors>Shay Rojansky</Authors>
<Copyright>Copyright 2019 © The Npgsql Development Team</Copyright>
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>4.0.5</VersionPrefix>
<VersionPrefix>4.0.6</VersionPrefix>
<Description>PostGIS plugin for Npgsql, allowing mapping of PostGIS types to the legacy types (e.g. PostgisPoint).</Description>
<Authors>Shay Rojansky</Authors>
<Copyright>Copyright 2019 © The Npgsql Development Team</Copyright>
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>4.0.5</VersionPrefix>
<VersionPrefix>4.0.6</VersionPrefix>
<Description>NetTopologySuite plugin for Npgsql, allowing mapping of PostGIS geometry types to NetTopologySuite types.</Description>
<Authors>Yoh Deadfall, Shay Rojansky</Authors>
<Copyright>Copyright 2019 © The Npgsql Development Team</Copyright>
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>4.0.5</VersionPrefix>
<VersionPrefix>4.0.6</VersionPrefix>
<Description>NodaTime plugin for Npgsql, allowing mapping of PostgreSQL date/time types to NodaTime types.</Description>
<Authors>Shay Rojansky</Authors>
<Copyright>Copyright 2019 © The Npgsql Development Team</Copyright>
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>4.0.5</VersionPrefix>
<VersionPrefix>4.0.6</VersionPrefix>
<Description>PostGIS plugin for Npgsql, allowing raw byte access to PostGIS ypes.</Description>
<Authors>Shay Rojansky</Authors>
<Copyright>Copyright 2019 © The Npgsql Development Team</Copyright>
@@ -149,7 +149,7 @@ internal SASLInitialResponseMessage(string mechanism, byte[] initialResponse)
internal override int Length =>
1 + 4 +
PGUtil.UTF8Encoding.GetByteCount(_mechanism) + 1 +
4 + _initialResponse?.Length ?? 0;
4 + (_initialResponse?.Length ?? 0);

internal override void WriteFully(NpgsqlWriteBuffer buf)
{
@@ -6,7 +6,7 @@
<Copyright>Copyright 2019 © The Npgsql Development Team</Copyright>
<Company>Npgsql</Company>
<PackageTags>npgsql postgresql postgres ado ado.net database sql</PackageTags>
<VersionPrefix>4.0.5</VersionPrefix>
<VersionPrefix>4.0.6</VersionPrefix>
<LangVersion>latest</LangVersion>
<TargetFrameworks>net45;net451;netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT' OR '$(CoreOnly)' == 'True'">netstandard2.0</TargetFrameworks>
@@ -323,8 +323,15 @@ public void Dispose()

void Cleanup()
{
Log.Debug("COPY operation ended", _connector.Id);
_connector = null;
var connector = _connector;
Log.Debug("COPY operation ended", connector?.Id ?? -1);

if (connector != null)
{
connector.CurrentCopyOperation = null;
_connector = null;
}

_typeMapper = null;
_buf = null;
_isDisposed = true;
@@ -367,9 +367,15 @@ public void Close()

void Cleanup()
{
Log.Debug("COPY operation ended", _connector.Id);
_connector.CurrentCopyOperation = null;
_connector = null;
var connector = _connector;
Log.Debug("COPY operation ended", connector?.Id ?? -1);

if (connector != null)
{
connector.CurrentCopyOperation = null;
_connector = null;
}

_buf = null;
_state = ImporterState.Disposed;
}
@@ -28,6 +28,7 @@
using System.Runtime.InteropServices.ComTypes;
using System.Threading.Tasks;
using Npgsql.PostgresTypes;
using Npgsql.Util;

namespace Npgsql
{
@@ -77,35 +78,35 @@ public abstract class NpgsqlDatabaseInfo
/// <summary>
/// Whether the backend supports range types.
/// </summary>
public virtual bool SupportsRangeTypes => Version >= new Version(9, 2, 0);
public virtual bool SupportsRangeTypes => Version.IsGreaterOrEqual(9, 2, 0);
/// <summary>
/// Whether the backend supports enum types.
/// </summary>
public virtual bool SupportsEnumTypes => Version >= new Version(8, 3, 0);
public virtual bool SupportsEnumTypes => Version.IsGreaterOrEqual(8, 3, 0);
/// <summary>
/// Whether the backend supports the CLOSE ALL statement.
/// </summary>
public virtual bool SupportsCloseAll => Version >= new Version(8, 3, 0);
public virtual bool SupportsCloseAll => Version.IsGreaterOrEqual(8, 3, 0);
/// <summary>
/// Whether the backend supports advisory locks.
/// </summary>
public virtual bool SupportsAdvisoryLocks => Version >= new Version(8, 2, 0);
public virtual bool SupportsAdvisoryLocks => Version.IsGreaterOrEqual(8, 2, 0);
/// <summary>
/// Whether the backend supports the DISCARD SEQUENCES statement.
/// </summary>
public virtual bool SupportsDiscardSequences => Version >= new Version(9, 4, 0);
public virtual bool SupportsDiscardSequences => Version.IsGreaterOrEqual(9, 4, 0);
/// <summary>
/// Whether the backend supports the UNLISTEN statement.
/// </summary>
public virtual bool SupportsUnlisten => Version >= new Version(6, 4, 0); // overridden by PostgresDatabase
public virtual bool SupportsUnlisten => Version.IsGreaterOrEqual(6, 4, 0); // overridden by PostgresDatabase
/// <summary>
/// Whether the backend supports the DISCARD TEMP statement.
/// </summary>
public virtual bool SupportsDiscardTemp => Version >= new Version(8, 3, 0);
public virtual bool SupportsDiscardTemp => Version.IsGreaterOrEqual(8, 3, 0);
/// <summary>
/// Whether the backend supports the DISCARD statement.
/// </summary>
public virtual bool SupportsDiscard => Version >= new Version(8, 3, 0);
public virtual bool SupportsDiscard => Version.IsGreaterOrEqual(8, 3, 0);

/// <summary>
/// Reports whether the backend uses the newer integer timestamp representation.
@@ -341,7 +341,7 @@ public bool Equals(NpgsqlRange<T> other)

/// <inheritdoc />
public override int GetHashCode()
=> unchecked((397 * (int)Flags) ^ (397 * LowerBound?.GetHashCode() ?? 0) ^ (397 * UpperBound?.GetHashCode() ?? 0));
=> unchecked((397 * (int)Flags) ^ (397 * (LowerBound?.GetHashCode() ?? 0)) ^ (397 * (UpperBound?.GetHashCode() ?? 0)));

/// <inheritdoc />
public override string ToString()
@@ -21,10 +21,12 @@
// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Npgsql.PostgresTypes;
using NpgsqlTypes;

@@ -35,19 +37,36 @@ class PostgresMinimalDatabaseInfoFactory : INpgsqlDatabaseInfoFactory
public Task<NpgsqlDatabaseInfo> Load(NpgsqlConnection conn, NpgsqlTimeout timeout, bool async)
=> Task.FromResult(
new NpgsqlConnectionStringBuilder(conn.ConnectionString).ServerCompatibilityMode == ServerCompatibilityMode.NoTypeLoading
? (NpgsqlDatabaseInfo)new PostgresMinimalDatabaseInfo()
? (NpgsqlDatabaseInfo)new PostgresMinimalDatabaseInfo(conn)
: null
);
}

class PostgresMinimalDatabaseInfo : PostgresDatabaseInfo
{
static readonly Version DefaultVersion = new Version(10, 0);

static readonly PostgresBaseType[] Types = typeof(NpgsqlDbType).GetFields()
.Select(f => f.GetCustomAttribute<BuiltInPostgresType>())
.Where(a => a != null)
.Select(a => new PostgresBaseType("pg_catalog", a.Name, a.OID))
.ToArray();

protected override IEnumerable<PostgresType> GetTypes() => Types;

internal PostgresMinimalDatabaseInfo([NotNull] NpgsqlConnection conn)
{
var csb = new NpgsqlConnectionStringBuilder(conn.ConnectionString);
Host = csb.Host;
Port = csb.Port;
Name = csb.Database;

Version = conn.PostgresParameters.TryGetValue("server_version", out string versionString)
? ParseServerVersion(versionString)
: DefaultVersion;

HasIntegerDateTimes = !conn.PostgresParameters.TryGetValue("integer_datetimes", out var intDateTimes) ||
intDateTimes == "on";
}
}
}
@@ -31,8 +31,8 @@ public bool Equals(PostgresFacets o)
public override int GetHashCode()
{
var hashcode = Size?.GetHashCode() ?? 0;
hashcode = (hashcode * 397) ^ Precision?.GetHashCode() ?? 0;
hashcode = (hashcode * 397) ^ Scale?.GetHashCode() ?? 0;
hashcode = (hashcode * 397) ^ (Precision?.GetHashCode() ?? 0);
hashcode = (hashcode * 397) ^ (Scale?.GetHashCode() ?? 0);
return hashcode;
}

@@ -25,6 +25,7 @@
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Npgsql.BackendMessages;
using Npgsql.TypeHandling;
@@ -38,7 +39,10 @@ namespace Npgsql.TypeHandlers.NetworkHandlers
/// <remarks>
/// http://www.postgresql.org/docs/current/static/datatype-net-types.html
/// </remarks>
[TypeMapping("inet", NpgsqlDbType.Inet, new[] { typeof(IPAddress), typeof((IPAddress Address, int Subnet)), typeof(NpgsqlInet) })]
[TypeMapping(
"inet",
NpgsqlDbType.Inet,
new[] { typeof(IPAddress), typeof((IPAddress Address, int Subnet)), typeof(NpgsqlInet) })]
class InetHandler : NpgsqlSimpleTypeHandlerWithPsv<IPAddress, (IPAddress Address, int Subnet)>,
INpgsqlSimpleTypeHandler<NpgsqlInet>
{
@@ -59,23 +63,25 @@ public override IPAddress Read(NpgsqlReadBuffer buf, int len, FieldDescription f
[CanBeNull] FieldDescription fieldDescription,
bool isCidrHandler)
{
buf.ReadByte(); // addressFamily
buf.ReadByte(); // addressFamily
var mask = buf.ReadByte();
var isCidr = buf.ReadByte() == 1;
Debug.Assert(isCidrHandler == isCidr);
var numBytes = buf.ReadByte();
var bytes = new byte[numBytes];
for (var i = 0; i < numBytes; i++) {
for (var i = 0; i < numBytes; i++)
bytes[i] = buf.ReadByte();
}

return (new IPAddress(bytes), mask);
}
#pragma warning restore CA1801 // Review unused parameters

protected override (IPAddress Address, int Subnet) ReadPsv(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription = null)
protected override (IPAddress Address, int Subnet) ReadPsv(NpgsqlReadBuffer buf, int len,
FieldDescription fieldDescription = null)
=> DoRead(buf, len, fieldDescription, false);

NpgsqlInet INpgsqlSimpleTypeHandler<NpgsqlInet>.Read(NpgsqlReadBuffer buf, int len, [CanBeNull] FieldDescription fieldDescription)
NpgsqlInet INpgsqlSimpleTypeHandler<NpgsqlInet>.Read(NpgsqlReadBuffer buf, int len,
[CanBeNull] FieldDescription fieldDescription)
{
var (address, subnet) = DoRead(buf, len, fieldDescription, false);
return new NpgsqlInet(address, subnet);
@@ -85,6 +91,44 @@ NpgsqlInet INpgsqlSimpleTypeHandler<NpgsqlInet>.Read(NpgsqlReadBuffer buf, int l

#region Write

protected internal override int ValidateObjectAndGetLength(object value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
{
switch (value)
{
case null:
return -1;
case DBNull _:
return -1;
case IPAddress ip:
return ValidateAndGetLength(ip, parameter);
case ValueTuple<IPAddress, int> tup:
return ValidateAndGetLength(tup, parameter);
case NpgsqlInet inet:
return ValidateAndGetLength(inet, parameter);
default:
throw new InvalidCastException($"Can't write CLR type {value.GetType().Name} to database type {PgDisplayName}");
}
}

protected internal override Task WriteObjectWithLength(object value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
{
switch (value)
{
case null:
return WriteWithLengthInternal<DBNull>(null, buf, lengthCache, parameter, async);
case DBNull _:
return WriteWithLengthInternal<DBNull>(null, buf, lengthCache, parameter, async);
case IPAddress ip:
return WriteWithLengthInternal(ip, buf, lengthCache, parameter, async);
case ValueTuple<IPAddress, int> tup:
return WriteWithLengthInternal(tup, buf, lengthCache, parameter, async);
case NpgsqlInet inet:
return WriteWithLengthInternal(inet, buf, lengthCache, parameter, async);
default:
throw new InvalidCastException($"Can't write CLR type {value.GetType().Name} to database type {PgDisplayName}");
}
}

public override int ValidateAndGetLength(IPAddress value, NpgsqlParameter parameter)
=> GetLength(value);

@@ -27,6 +27,7 @@
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Threading;
using Npgsql.NameTranslation;
@@ -230,6 +231,27 @@ void SetupGlobalTypeMapper()
}.Build());
}
}

// This is an extremely ugly hack to support ReadOnlyIPAddress, which as an internal subclass of IPAddress
// added to .NET Core 3.0 (see https://github.com/dotnet/corefx/issues/33373)
if (_typeToNpgsqlDbType.ContainsKey(typeof(IPAddress)) &&
Mappings.TryGetValue("inet", out var inetMapping) &&
typeof(IPAddress).GetNestedType("ReadOnlyIPAddress", BindingFlags.NonPublic) is Type readOnlyIpType)
{
_typeToNpgsqlDbType[readOnlyIpType] = _typeToNpgsqlDbType[typeof(IPAddress)];
var augmentedClrType = new Type[inetMapping.ClrTypes.Length + 1];
Array.Copy(inetMapping.ClrTypes, augmentedClrType, inetMapping.ClrTypes.Length);
augmentedClrType[augmentedClrType.Length - 1] = readOnlyIpType;
Mappings["inet"] = new NpgsqlTypeMappingBuilder
{
PgTypeName = "inet",
NpgsqlDbType = inetMapping.NpgsqlDbType,
DbTypes = inetMapping.DbTypes,
ClrTypes = augmentedClrType,
InferredDbType = inetMapping.InferredDbType,
TypeHandlerFactory = inetMapping.TypeHandlerFactory
}.Build();
}
}

#endregion Setup for built-in handlers
Oops, something went wrong.

0 comments on commit 0f1e91e

Please sign in to comment.
You can’t perform that action at this time.