Permalink
Browse files

Merge branch 'hotfix/3.2.5'

  • Loading branch information...
roji committed Jul 25, 2017
2 parents 2899048 + 1c9acdc commit 5460190bc87f6034dc57d56af7f86381f2454dcd
View
@@ -1,5 +1,5 @@
image: Visual Studio 2017
version: 3.2.4.1-{build}
image: Visual Studio 2017 Preview
version: 3.2.5-{build}
environment:
global:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
View
@@ -2,7 +2,7 @@ language: csharp
dist: trusty
sudo: false
mono: none
dotnet: 1.0.4
dotnet: 2.0.0-preview1-005977
services:
- postgresql
@@ -18,10 +18,17 @@ before_script:
- psql -U postgres -c "CREATE EXTENSION postgis" npgsql_tests
- dotnet restore -v Minimal
script:
- dotnet build "test/Npgsql.Tests" -c Debug -f netcoreapp1.1
- dotnet test "test/Npgsql.Tests/Npgsql.Tests.csproj" -c Debug -f netcoreapp1.1
- dotnet build "test/Npgsql.Tests" -c Debug -f netcoreapp2.0
- dotnet test "test/Npgsql.Tests/Npgsql.Tests.csproj" -c Debug -f netcoreapp2.0
cache:
directories:
- $HOME/.nuget/packages
# The following is necessary because of https://github.com/travis-ci/travis-ci/issues/6972
addons:
postgresql: 9.6
apt:
packages:
- postgresql-9.6-postgis-2.3
@@ -117,6 +117,12 @@ internal override Stream GetStream()
internal override async Task Consume(bool async)
{
if (_stream != null)
{
_stream.Dispose();
_stream = null;
}
// Skip to end of column if needed
var remainingInColumn = ColumnLen == -1 ? 0 : ColumnLen - PosInColumn;
if (remainingInColumn > 0)
View
@@ -6,7 +6,7 @@
<Copyright>Copyright 2017 © The Npgsql Development Team</Copyright>
<Company>Npgsql</Company>
<PackageTags>npgsql postgresql postgres ado ado.net database sql</PackageTags>
<VersionPrefix>3.2.4.1</VersionPrefix>
<VersionPrefix>3.2.5</VersionPrefix>
<TargetFrameworks>net45;net451;netstandard1.3;netstandard2.0</TargetFrameworks>
<WarningsAsErrors>true</WarningsAsErrors>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@@ -33,24 +33,13 @@
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<Reference Include="System.Transactions" />
<Reference Include="System.DirectoryServices" />
<Reference Include="System.Data" />
<Reference Include="System.Numerics" />
<Reference Include="System.Xml" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Transactions" Pack="false" />
<Reference Include="System.DirectoryServices" Pack="false" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
<Reference Include="System.Collections" />
<Reference Include="System.Transactions" />
<Reference Include="System.DirectoryServices" />
<Reference Include="System.Data" />
<Reference Include="System.Numerics" />
<Reference Include="System.Xml" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Transactions" Pack="false" />
<Reference Include="System.DirectoryServices" Pack="false" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
@@ -276,7 +276,13 @@ public void Close()
return;
if (_column != -1 && _column != NumColumns)
throw new InvalidOperationException("Can't close writer, a row is still in progress, end it first");
{
Log.Error("Binary importer closed in the middle of a row, cancelling import.");
_buf.Clear();
Cancel();
return;
}
WriteTrailer();
_buf.Flush();
_buf.EndCopyMode();
@@ -502,18 +502,28 @@ public new NpgsqlTransaction BeginTransaction(IsolationLevel level)
/// </summary>
public override void EnlistTransaction(Transaction transaction)
{
if (transaction == null)
throw new ArgumentNullException(nameof(transaction));
if (EnlistedTransaction == transaction)
return;
if (EnlistedTransaction != null)
throw new InvalidOperationException($"Already enlisted to transaction (localid={EnlistedTransaction.TransactionInformation.LocalIdentifier})");
{
if (EnlistedTransaction.Equals(transaction))
return;
try
{
if (EnlistedTransaction.TransactionInformation.Status == System.Transactions.TransactionStatus.Active)
throw new InvalidOperationException($"Already enlisted to transaction (localid={EnlistedTransaction.TransactionInformation.LocalIdentifier})");
}
catch (ObjectDisposedException)
{
// The MSDTC 2nd phase is asynchronous, so we may end up checking the TransactionInformation on
// a disposed transaction. To be extra safe we catch that, and understand that the transaction
// has ended - no problem for reenlisting.
}
}
var connector = CheckReadyAndGetConnector();
EnlistedTransaction = transaction;
if (transaction == null)
return;
// Until #1378 is implemented, we have no recovery, and so no need to enlist as a durable resource manager
// (or as promotable single phase).
@@ -622,7 +622,14 @@ void Connect(NpgsqlTimeout timeout)
}
// Give each endpoint an equal share of the remaining time
var perEndpointTimeout = timeout.IsSet ? (int)((timeout.TimeLeft.Ticks / endpoints.Length) / 10) : -1;
var perEndpointTimeout = -1; // Default to infinity
if (timeout.IsSet)
{
var timeoutTicks = timeout.TimeLeft.Ticks;
if (timeoutTicks <= 0)
throw new TimeoutException();
perEndpointTimeout = (int)(timeoutTicks / endpoints.Length / 10);
}
for (var i = 0; i < endpoints.Length; i++)
{
@@ -700,8 +707,16 @@ async Task ConnectAsync(NpgsqlTimeout timeout, CancellationToken cancellationTok
}
// Give each IP an equal share of the remaining time
var perIpTimespan = timeout.IsSet ? new TimeSpan(timeout.TimeLeft.Ticks / endpoints.Length) : TimeSpan.Zero;
var perIpTimeout = timeout.IsSet ? new NpgsqlTimeout(perIpTimespan) : timeout;
var perIpTimespan = default(TimeSpan);
var perIpTimeout = timeout;
if (timeout.IsSet)
{
var timeoutTicks = timeout.TimeLeft.Ticks;
if (timeoutTicks <= 0)
throw new TimeoutException();
perIpTimespan = new TimeSpan(timeoutTicks / endpoints.Length);
perIpTimeout = new NpgsqlTimeout(perIpTimespan);
}
for (var i = 0; i < endpoints.Length; i++)
{
@@ -959,7 +959,8 @@ public override long GetBytes(int ordinal, long dataOffset, [CanBeNull] byte[] b
throw new IndexOutOfRangeException($"length must be between {0} and {buffer.Length - bufferOffset}");
var fieldDescription = _rowDescription[ordinal];
var handler = fieldDescription.Handler as ByteaHandler;
var handler = fieldDescription.Handler as ByteaHandler ??
(fieldDescription.Handler as PostgisGeometryHandler)?.ByteaHandler;
if (handler == null)
throw new InvalidCastException("GetBytes() not supported for type " + fieldDescription.Name);
@@ -989,6 +990,29 @@ public override Stream GetStream(int ordinal)
return row.GetStream();
}
/// <summary>
/// Retrieves data as a <see cref="Stream"/>.
/// </summary>
/// <param name="ordinal">The zero-based column ordinal.</param>
/// <returns>The returned object.</returns>
public Task<Stream> GetStreamAsync(int ordinal)
{
CheckRowAndOrdinal(ordinal);
var fieldDescription = _rowDescription[ordinal];
var handler = fieldDescription.Handler as ByteaHandler;
if (handler == null)
throw new InvalidCastException("GetStream() not supported for type " + fieldDescription.Handler.PgDisplayName);
return SynchronizationContextSwitcher.NoContext(async () =>
{
var row = Row;
await row.SeekToColumnStart(ordinal, false);
row.CheckNotNull();
return row.GetStream();
});
}
#endregion
#region Special text getters
@@ -1044,6 +1068,29 @@ public override TextReader GetTextReader(int ordinal)
return handler.GetTextReader(row.GetStream());
}
/// <summary>
/// Retrieves data as a <see cref="TextReader"/>.
/// </summary>
/// <param name="ordinal">The zero-based column ordinal.</param>
/// <returns>The returned object.</returns>
public Task<TextReader> GetTextReaderAsync(int ordinal)
{
CheckRowAndOrdinal(ordinal);
var fieldDescription = _rowDescription[ordinal];
var handler = fieldDescription.Handler as ITextReaderHandler;
if (handler == null)
throw new InvalidCastException("GetTextReader() not supported for type " + fieldDescription.Handler.PgDisplayName);
return SynchronizationContextSwitcher.NoContext(async () =>
{
var row = Row;
await row.SeekToColumnStart(ordinal, false);
row.CheckNotNull();
return handler.GetTextReader(row.GetStream());
});
}
#endregion
#region IsDBNull
@@ -1449,7 +1449,7 @@ HandshakeType SendCertificateVerify(ref int offset)
var keyDsa = key as DSACryptoServiceProvider;
var keyRsa = key as RSACryptoServiceProvider;
#else
var keyRsa = new X509Certificate2(_clientCertificates[0].Export(X509ContentType.Cert)).GetRSAPrivateKey();
var keyRsa = ((X509Certificate2)_clientCertificates[0]).GetRSAPrivateKey();
#endif
byte[] signature = null, hash = null;
@@ -1543,7 +1543,7 @@ HandshakeType SendCertificateVerify(ref int offset)
}
else
{
SendAlertFatal(AlertDescription.HandshakeFailure);
SendAlertFatal(AlertDescription.HandshakeFailure, "No private key in provided certificate");
}
_handshakeData.CertificateVerifyHash_SHA1.Dispose();
_handshakeData.CertificateVerifyHash_SHA1 = null;
View
@@ -189,10 +189,13 @@ internal override async ValueTask<T2> Read<T2>(ReadBuffer buf, int len, bool asy
var asTypedHandler = this as ISimpleTypeHandler<T2>;
if (asTypedHandler == null)
throw new InvalidCastException(fieldDescription == null
{
buf.Skip(len); // Perform this in sync for performance
throw new SafeReadException(new InvalidCastException(fieldDescription == null
? "Can't cast database type to " + typeof(T2).Name
: $"Can't cast database type {fieldDescription.Handler.PgDisplayName} to {typeof(T2).Name}"
);
));
}
return asTypedHandler.Read(buf, len, fieldDescription);
}
@@ -268,10 +271,13 @@ internal override ValueTask<T2> Read<T2>(ReadBuffer buf, int len, bool async, Fi
{
var asTypedHandler = this as IChunkingTypeHandler<T2>;
if (asTypedHandler == null)
throw new InvalidCastException(fieldDescription == null
{
buf.Skip(len); // Perform this in sync for performance
throw new SafeReadException(new InvalidCastException(fieldDescription == null
? "Can't cast database type to " + typeof(T2).Name
: $"Can't cast database type {fieldDescription.Handler.PgDisplayName} to {typeof(T2).Name}"
);
));
}
return asTypedHandler.Read(buf, len, async, fieldDescription);
}
@@ -205,10 +205,18 @@ ELSE 0
static async Task<AvailablePostgresTypes> LoadBackendTypes(NpgsqlConnector connector, NpgsqlTimeout timeout, bool async)
{
var commandTimeout = 0; // Default to infinity
if (timeout.IsSet)
{
commandTimeout = (int)timeout.TimeLeft.TotalSeconds;
if (commandTimeout <= 0)
throw new TimeoutException();
}
var types = new AvailablePostgresTypes();
using (var command = new NpgsqlCommand(connector.SupportsRangeTypes ? TypesQueryWithRange : TypesQueryWithoutRange, connector.Connection))
{
command.CommandTimeout = timeout.IsSet ? (int)timeout.TimeLeft.TotalSeconds : 0;
command.CommandTimeout = commandTimeout;
command.AllResultTypesAreUnknown = true;
using (var reader = async ? await command.ExecuteReaderAsync() : command.ExecuteReader())
{
@@ -56,20 +56,20 @@ class PostgisGeometryHandler : ChunkingTypeHandler<PostgisGeometry>,
IChunkingTypeHandler<byte[]>
{
[CanBeNull]
readonly ByteaHandler _byteaHandler;
internal ByteaHandler ByteaHandler { get; }
static readonly NpgsqlLogger Log = NpgsqlLogManager.GetCurrentClassLogger();
internal PostgisGeometryHandler(PostgresType postgresType, TypeHandlerRegistry registry)
: base(postgresType)
{
var byteaHandler = registry[NpgsqlDbType.Bytea];
if (_byteaHandler == registry.UnrecognizedTypeHandler)
if (byteaHandler == registry.UnrecognizedTypeHandler)
{
Log.Warn("bytea type not present when setting up postgis geometry type. Writing as bytea will not work.");
return;
}
_byteaHandler = (ByteaHandler)byteaHandler;
ByteaHandler = (ByteaHandler)byteaHandler;
}
#region Read
@@ -209,8 +209,8 @@ async ValueTask<PostgisGeometry> DoRead(ReadBuffer buf, WkbIdentifier id, ByteOr
ValueTask<byte[]> IChunkingTypeHandler<byte[]>.Read(ReadBuffer buf, int len, bool async, FieldDescription fieldDescription)
{
Debug.Assert(_byteaHandler != null);
return _byteaHandler.Read(buf, len, async, fieldDescription);
Debug.Assert(ByteaHandler != null);
return ByteaHandler.Read(buf, len, async, fieldDescription);
}
#endregion Read
@@ -255,9 +255,9 @@ public override int ValidateAndGetLength(object value, ref LengthCache lengthCac
var bytes = value as byte[];
if (bytes != null)
{
if (_byteaHandler == null)
if (ByteaHandler == null)
throw new NpgsqlException("Bytea handler was not found during initialization of PostGIS handler");
return _byteaHandler.WriteInternal(bytes, buf, lengthCache, parameter, async, cancellationToken);
return ByteaHandler.WriteInternal(bytes, buf, lengthCache, parameter, async, cancellationToken);
}
return Write((PostgisGeometry)value, buf, lengthCache, parameter, async, cancellationToken);
Oops, something went wrong.

0 comments on commit 5460190

Please sign in to comment.