Skip to content
Permalink
Browse files

Merge branch 'hotfix/4.0.5'

  • Loading branch information...
roji committed Mar 3, 2019
2 parents 80056a4 + e023fab commit 12f62263132f163bc2c04fabde5918a3bf4292d8
Showing with 278 additions and 189 deletions.
  1. +1 −1 .appveyor.yml
  2. +1 −0 Npgsql.sln.DotSettings
  3. +3 −2 src/Npgsql.GeoJSON/Npgsql.GeoJSON.csproj
  4. +3 −2 src/Npgsql.Json.NET/Npgsql.Json.NET.csproj
  5. +3 −2 src/Npgsql.LegacyPostgis/Npgsql.LegacyPostgis.csproj
  6. +3 −2 src/Npgsql.NetTopologySuite/Npgsql.NetTopologySuite.csproj
  7. +2 −2 src/Npgsql.NetTopologySuite/NpgsqlPostGisWriter.cs
  8. +4 −3 src/Npgsql.NodaTime/Npgsql.NodaTime.csproj
  9. +8 −1 src/Npgsql.NodaTime/TimestampTzHandler.cs
  10. +3 −2 src/Npgsql.RawPostgis/Npgsql.RawPostgis.csproj
  11. +8 −6 src/Npgsql/Npgsql.csproj
  12. +1 −1 src/Npgsql/NpgsqlConnector.cs
  13. +1 −0 src/Npgsql/NpgsqlDataReader.cs
  14. +27 −25 src/Npgsql/NpgsqlFactory.cs
  15. +7 −4 src/Npgsql/NpgsqlReadBuffer.cs
  16. +7 −6 src/Npgsql/NpgsqlWriteBuffer.cs
  17. +13 −7 src/Npgsql/PostgresException.cs
  18. +6 −1 src/Npgsql/TypeHandlers/NumericHandlers/DecimalRaw.cs
  19. +6 −30 src/Npgsql/TypeHandlers/NumericHandlers/MoneyHandler.cs
  20. +8 −32 src/Npgsql/TypeHandlers/NumericHandlers/NumericHandler.cs
  21. +15 −5 src/Npgsql/TypeHandlers/UnknownTypeHandler.cs
  22. +11 −0 src/Npgsql/TypeHandlers/UnmappedEnumHandler.cs
  23. +43 −41 src/Npgsql/TypeHandlers/UuidHandler.cs
  24. +15 −4 src/Npgsql/TypeMapping/ConnectorTypeMapper.cs
  25. +1 −1 src/VSIX/Properties/AssemblyInfo.cs
  26. +5 −6 src/VSIX/source.extension.vsixmanifest
  27. +1 −0 test/Npgsql.Benchmarks/Npgsql.Benchmarks.csproj
  28. +6 −0 test/Npgsql.PluginTests/NetTopologySuiteTests.cs
  29. +3 −2 test/Npgsql.PluginTests/Npgsql.PluginTests.csproj
  30. +59 −0 test/Npgsql.Tests/BugTests.cs
  31. +2 −0 test/Npgsql.Tests/CommandTests.cs
  32. +2 −1 test/Npgsql.Tests/Npgsql.Tests.csproj
@@ -1,5 +1,5 @@
image: Visual Studio 2017
version: 4.0.4-{build}
version: 4.0.5-{build}
environment:
global:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
@@ -9,6 +9,7 @@
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ACCESSORHOLDER_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=PGTZ/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GIS/@EntryIndexedValue">GIS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GSS/@EntryIndexedValue">GSS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MD/@EntryIndexedValue">MD</s:String>
@@ -1,13 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>4.0.4</VersionPrefix>
<VersionPrefix>4.0.5</VersionPrefix>
<Description>GeoJSON plugin for Npgsql, allowing mapping of PostGIS geometry types to GeoJSON types.</Description>
<Authors>Yoh Deadfall, Shay Rojansky</Authors>
<Copyright>Copyright 2018 © The Npgsql Development Team</Copyright>
<Copyright>Copyright 2019 © The Npgsql Development Team</Copyright>
<Company>Npgsql</Company>
<PackageTags>npgsql postgresql postgres postgis geojson spatial ado ado.net database sql</PackageTags>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT' OR '$(CoreOnly)' == 'True'">netstandard2.0</TargetFrameworks>
<AssemblyOriginatorKeyFile>../../Npgsql.snk</AssemblyOriginatorKeyFile>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
@@ -1,13 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>4.0.4</VersionPrefix>
<VersionPrefix>4.0.5</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 2018 © The Npgsql Development Team</Copyright>
<Copyright>Copyright 2019 © The Npgsql Development Team</Copyright>
<Company>Npgsql</Company>
<PackageTags>npgsql postgresql json postgres ado ado.net database sql</PackageTags>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT' OR '$(CoreOnly)' == 'True'">netstandard2.0</TargetFrameworks>
<AssemblyOriginatorKeyFile>../../Npgsql.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
@@ -1,12 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>4.0.4</VersionPrefix>
<VersionPrefix>4.0.5</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 2018 © The Npgsql Development Team</Copyright>
<Copyright>Copyright 2019 © The Npgsql Development Team</Copyright>
<Company>Npgsql</Company>
<PackageTags>npgsql postgresql postgres postgis spatial geometry geography ado ado.net database sql</PackageTags>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT' OR '$(CoreOnly)' == 'True'">netstandard2.0</TargetFrameworks>
<AssemblyOriginatorKeyFile>../../Npgsql.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
@@ -1,13 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>4.0.4.1</VersionPrefix>
<VersionPrefix>4.0.5</VersionPrefix>
<Description>NetTopologySuite plugin for Npgsql, allowing mapping of PostGIS geometry types to NetTopologySuite types.</Description>
<Authors>Yoh Deadfall, Shay Rojansky</Authors>
<Copyright>Copyright 2018 © The Npgsql Development Team</Copyright>
<Copyright>Copyright 2019 © The Npgsql Development Team</Copyright>
<Company>Npgsql</Company>
<PackageTags>npgsql postgresql postgres postgis nts ado ado.net database sql</PackageTags>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT' OR '$(CoreOnly)' == 'True'">netstandard2.0</TargetFrameworks>
<AssemblyOriginatorKeyFile>../../Npgsql.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
@@ -508,8 +508,8 @@ private static Ordinates CheckOrdinates(IGeometry geometry)
return CheckOrdinates(((ILineString)geometry).CoordinateSequence);
if (geometry is IPolygon)
return CheckOrdinates((((IPolygon)geometry).ExteriorRing).CoordinateSequence);
if (geometry is IGeometryCollection)
return CheckOrdinates(geometry.GetGeometryN(0));
if (geometry is IGeometryCollection collection)
return collection.Count == 0 ? Ordinates.None : CheckOrdinates(collection.GetGeometryN(0));

Assert.ShouldNeverReachHere();
return Ordinates.None;
@@ -1,13 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>4.0.4</VersionPrefix>
<VersionPrefix>4.0.5</VersionPrefix>
<Description>NodaTime plugin for Npgsql, allowing mapping of PostgreSQL date/time types to NodaTime types.</Description>
<Authors>Shay Rojansky</Authors>
<Copyright>Copyright 2018 © The Npgsql Development Team</Copyright>
<Copyright>Copyright 2019 © The Npgsql Development Team</Copyright>
<Company>Npgsql</Company>
<PackageTags>npgsql postgresql postgres nodatime date time ado ado.net database sql</PackageTags>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT' OR '$(CoreOnly)' == 'True'">netstandard2.0</TargetFrameworks>
<AssemblyOriginatorKeyFile>../../Npgsql.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
@@ -24,7 +25,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NodaTime" Version="2.4.2" />
<PackageReference Include="NodaTime" Version="2.4.4" />
<!-- Causes issues in Appveyor and Travis
<PackageReference Include="Microsoft.CodeQuality.Analyzers" Version="2.6.0-beta2" PrivateAssets="All" />
-->
@@ -93,7 +93,14 @@ ZonedDateTime INpgsqlSimpleTypeHandler<ZonedDateTime>.Read(NpgsqlReadBuffer buf,
return TimestampHandler.Decode(value).InZone(_dateTimeZoneProvider[buf.Connection.Timezone]);
}
}
catch (DateTimeZoneNotFoundException e)
catch (TimeZoneNotFoundException) when (string.Equals(buf.Connection.Timezone, "localtime", StringComparison.OrdinalIgnoreCase))
{
throw new NpgsqlSafeReadException(
new TimeZoneNotFoundException(
"The special PostgreSQL timezone 'localtime' is not supported when reading values of type 'timestamp with time zone'. " +
"Please specify a real timezone in 'postgresql.conf' on the server, or set the 'PGTZ' environment variable on the client."));
}
catch (TimeZoneNotFoundException e)
{
throw new NpgsqlSafeReadException(e);
}
@@ -1,12 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>4.0.4</VersionPrefix>
<VersionPrefix>4.0.5</VersionPrefix>
<Description>PostGIS plugin for Npgsql, allowing raw byte access to PostGIS ypes.</Description>
<Authors>Shay Rojansky</Authors>
<Copyright>Copyright 2018 © The Npgsql Development Team</Copyright>
<Copyright>Copyright 2019 © The Npgsql Development Team</Copyright>
<Company>Npgsql</Company>
<PackageTags>npgsql postgresql postgres postgis spatial geometry geography ado ado.net database sql</PackageTags>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT' OR '$(CoreOnly)' == 'True'">netstandard2.0</TargetFrameworks>
<AssemblyOriginatorKeyFile>../../Npgsql.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
@@ -2,13 +2,14 @@

<PropertyGroup>
<Description>Npgsql is the open source .NET data provider for PostgreSQL.</Description>
<Authors>Shay Rojansky;Emil Lenngren;Francisco Figueiredo Jr.;Kenji Uno</Authors>
<Copyright>Copyright 2018 © The Npgsql Development Team</Copyright>
<Authors>Shay Rojansky;Yoh Deadfall;Austin Drenski;Emil Lenngren;Francisco Figueiredo Jr.;Kenji Uno</Authors>
<Copyright>Copyright 2019 © The Npgsql Development Team</Copyright>
<Company>Npgsql</Company>
<PackageTags>npgsql postgresql postgres ado ado.net database sql</PackageTags>
<VersionPrefix>4.0.4</VersionPrefix>
<VersionPrefix>4.0.5</VersionPrefix>
<LangVersion>latest</LangVersion>
<TargetFrameworks>net45;net451;netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT' OR '$(CoreOnly)' == 'True'">netstandard2.0</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
@@ -30,10 +31,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.0" />
<PackageReference Include="System.Memory" Version="4.5.2" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.1" />
<!-- Causes issues in Appveyor and Travis
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.2" />
<!-- Causes issues in Appveyor and Travis
<PackageReference Include="Microsoft.CodeQuality.Analyzers" Version="2.6.0-beta2" PrivateAssets="All" />
-->
</ItemGroup>
@@ -1281,7 +1281,7 @@ void DoCancelRequest(int backendProcessId, int backendSecretKey)
// Now wait for the server to close the connection, better chance of the cancellation
// actually being delivered before we continue with the user's logic.
var count = _stream.Read(ReadBuffer.Buffer, 0, 1);
if (count != -1)
if (count > 0)
Log.Error("Received response after sending cancel request, shouldn't happen! First byte: " + ReadBuffer.Buffer[0]);
}
finally
@@ -483,6 +483,7 @@ async Task<bool> NextResult(bool async, bool isConsuming=false)
ProcessMessage(row);
PopulateOutputParameters();
Connector.ReadBuffer.ReadPosition = pos;
State = ReaderState.BetweenResults;
}
}
else
@@ -25,6 +25,7 @@
using System.Data.Common;
using System.Reflection;
using JetBrains.Annotations;
using Npgsql.Logging;

namespace Npgsql
{
@@ -34,6 +35,8 @@ namespace Npgsql
[Serializable]
public sealed class NpgsqlFactory : DbProviderFactory, IServiceProvider
{
static readonly NpgsqlLogger Log = NpgsqlLogManager.GetCurrentClassLogger();

/// <summary>
/// Gets an instance of the <see cref="NpgsqlFactory"/>.
/// This can be used to retrieve strongly typed data objects.
@@ -87,33 +90,32 @@ public object GetService([NotNull] Type serviceType)

// In legacy Entity Framework, this is the entry point for obtaining Npgsql's
// implementation of DbProviderServices. We use reflection for all types to
// avoid any dependencies on EF stuff in this project.

if (serviceType.FullName == "System.Data.Common.DbProviderServices")
{
// User has requested a legacy EF DbProviderServices implementation. Check our cache first.
if (_legacyEntityFrameworkServices != null)
return _legacyEntityFrameworkServices;

// First time, attempt to find the EntityFramework5.Npgsql assembly and load the type via reflection
var assemblyName = typeof(NpgsqlFactory).GetTypeInfo().Assembly.GetName();
assemblyName.Name = "EntityFramework5.Npgsql";
Assembly npgsqlEfAssembly;
try {
npgsqlEfAssembly = Assembly.Load(new AssemblyName(assemblyName.FullName));
} catch (Exception e) {
throw new Exception("Could not load EntityFramework5.Npgsql assembly, is it installed?", e);
}

Type npgsqlServicesType;
if ((npgsqlServicesType = npgsqlEfAssembly.GetType("Npgsql.NpgsqlServices")) == null ||
npgsqlServicesType.GetProperty("Instance") == null)
throw new Exception("EntityFramework5.Npgsql assembly does not seem to contain the correct type!");

return _legacyEntityFrameworkServices = npgsqlServicesType.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static).GetMethod.Invoke(null, new object[0]);
// avoid any dependencies on EF stuff in this project. EF6 (and of course EF Core) do not use this method.

if (serviceType.FullName != "System.Data.Common.DbProviderServices")
return null;

// User has requested a legacy EF DbProviderServices implementation. Check our cache first.
if (_legacyEntityFrameworkServices != null)
return _legacyEntityFrameworkServices;

// First time, attempt to find the EntityFramework5.Npgsql assembly and load the type via reflection
var assemblyName = typeof(NpgsqlFactory).GetTypeInfo().Assembly.GetName();
assemblyName.Name = "EntityFramework5.Npgsql";
Assembly npgsqlEfAssembly;
try {
npgsqlEfAssembly = Assembly.Load(new AssemblyName(assemblyName.FullName));
} catch (Exception e) {
Log.Debug("A service request was made for System.Data.Common.DbProviderServices, but the EntityFramework5.Npgsql assemby could not be loaded.", e);
return null;
}

return null;
Type npgsqlServicesType;
if ((npgsqlServicesType = npgsqlEfAssembly.GetType("Npgsql.NpgsqlServices")) == null ||
npgsqlServicesType.GetProperty("Instance") == null)
throw new Exception("EntityFramework5.Npgsql assembly does not seem to contain the correct type!");

return _legacyEntityFrameworkServices = npgsqlServicesType.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static).GetMethod.Invoke(null, new object[0]);
}

[CanBeNull]
@@ -357,13 +357,16 @@ public char[] ReadChars(int byteLen)
return result;
}

public void ReadBytes(byte[] output, int outputOffset, int len)
public void ReadBytes(Span<byte> output)
{
Debug.Assert(len <= ReadBytesLeft);
System.Buffer.BlockCopy(Buffer, ReadPosition, output, outputOffset, len);
ReadPosition += len;
Debug.Assert(output.Length <= ReadBytesLeft);
new Span<byte>(Buffer, ReadPosition, output.Length).CopyTo(output);
ReadPosition += output.Length;
}

public void ReadBytes(byte[] output, int outputOffset, int len)
=> ReadBytes(new Span<byte>(output, outputOffset, len));

#endregion

#region Read Complex
@@ -370,15 +370,16 @@ internal void WriteChars(char[] chars, int offset, int len)
WritePosition += TextEncoding.GetBytes(chars, offset, charCount, Buffer, WritePosition);
}

public void WriteBytes(byte[] buf) => WriteBytes(buf, 0, buf.Length);

public void WriteBytes(byte[] buf, int offset, int count)
public void WriteBytes(ReadOnlySpan<byte> buf)
{
Debug.Assert(count <= WriteSpaceLeft);
System.Buffer.BlockCopy(buf, offset, Buffer, WritePosition, count);
WritePosition += count;
Debug.Assert(buf.Length <= WriteSpaceLeft);
buf.CopyTo(new Span<byte>(Buffer, WritePosition, Buffer.Length - WritePosition));
WritePosition += buf.Length;
}

public void WriteBytes(byte[] buf, int offset, int count)
=> WriteBytes(new ReadOnlySpan<byte>(buf, offset, count));

public Task WriteBytesRaw(byte[] bytes, bool async)
{
if (bytes.Length <= WriteSpaceLeft)
@@ -52,7 +52,7 @@ namespace Npgsql
public sealed class PostgresException : NpgsqlException
{
[CanBeNull]
Dictionary<object, object> _data;
bool _dataInitialized;

#region Message Fields

@@ -278,19 +278,25 @@ public override IDictionary Data
{
get
{
// Remarks: return Dictionary with object keys although all our keys are string keys
// because System.Windows.Threading.Dispatcher relies on that
return _data ?? (_data = (
if (_dataInitialized)
return base.Data;

var data = base.Data;
foreach (var pair in
from p in typeof(PostgresException).GetProperties()
let k = p.Name
where p.Name != nameof(Data)
where p.GetCustomAttribute<PublicAPIAttribute>() != null
let v = p.GetValue(this)
where v != null
where k != nameof(Position) && k != nameof(InternalPosition) || (int)v != 0
select new { Key = k, Value = v }
).ToDictionary(kv => (object)kv.Key, kv => kv.Value)
);
select new KeyValuePair<string, object>(k, v))
{
data.Add(pair.Key, pair.Value);
}

_dataInitialized = true;
return data;
}
}

@@ -35,6 +35,8 @@ struct DecimalRaw
// Do not change the order in which these fields are declared. It
// should be same as in the System.Decimal struct.
[FieldOffset(0)]
decimal _value;
[FieldOffset(0)]
int _flags;
[FieldOffset(4)]
uint _high;
@@ -54,8 +56,11 @@ public int Scale
public uint High => _high;
public uint Mid => _mid;
public uint Low => _low;
public decimal Value => _value;

public DecimalRaw(decimal value) : this() => _value = value;

public DecimalRaw(long value)
public DecimalRaw(long value) : this()
{
if (value >= 0)
_flags = 0;
Oops, something went wrong.

0 comments on commit 12f6226

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