diff --git a/Source/Core/ChunkSizing.cs b/Source/Core/ChunkSizing.cs index 7ad7bcc4..4ca3019f 100644 --- a/Source/Core/ChunkSizing.cs +++ b/Source/Core/ChunkSizing.cs @@ -85,8 +85,6 @@ public ChunkSizes( LastStreamDoubling = ChunkSizing.Log2(StreamMaxRows / FirstRows); } - // The value when it is a power of two no larger than the maximum; - // otherwise the default. static int Fit(int value, int max, int fallback) => ChunkSizing.IsPowerOfTwo(value) && value <= max ? value diff --git a/Source/Core/ChunkStream.cs b/Source/Core/ChunkStream.cs index 6dcbd085..a4b83da4 100644 --- a/Source/Core/ChunkStream.cs +++ b/Source/Core/ChunkStream.cs @@ -163,7 +163,6 @@ async IAsyncEnumerator> Read( !cancellationToken.IsCancellationRequested && reader.TryRead(out ArrayLease chunk)) { - // The array goes back at the next step. using (chunk) yield return chunk.Memory; } diff --git a/Source/Core/Core/RowMap.cs b/Source/Core/Core/RowMap.cs index bac1c832..b711bd7b 100644 --- a/Source/Core/Core/RowMap.cs +++ b/Source/Core/Core/RowMap.cs @@ -456,8 +456,6 @@ RowMap Converting( /// The number of layouts a map keeps readers for before its cache is cleared. const int MaxLayouts = 128; - // The statics below are one immutable copy per model type: see TypeShape. - // Never throws: an unmappable T holds its error, so no static initializer here can fail with it. // The per-model-type statics (TypeShape, MappedSlots, ModelSlotIndex, Default) are one immutable copy per T, built once. // Any cache of compiled readers keyed by model type lives as long and costs a lookup per call; a static on the generic type is the cheapest place for it. @@ -1277,7 +1275,7 @@ public bool Matches(IDataRecord r) } } - #region Array rows (the route generated mappers and the Channel and Dataflow pipelines use) + #region Array rows (the route the output and capture reads use) /// The layout of the object[] rows most recently used. /// @@ -1303,7 +1301,7 @@ public bool Matches(ImmutableArray candidate) } /// Returns the mapper from object[] rows whose columns are, in order, . - /// For generated code. + /// For the output and capture reads, whose caller owns the loop. /// The names of the columns, in order. /// The delegate that maps a row to a . /// A required property has no column among . diff --git a/Source/Core/DbNonQuery.cs b/Source/Core/DbNonQuery.cs index bfeaaa07..1e36445a 100644 --- a/Source/Core/DbNonQuery.cs +++ b/Source/Core/DbNonQuery.cs @@ -134,13 +134,12 @@ public OutputDbNonQuery Output( /// /// The write, bound. public BoundCall Using(DbConnection connection) - // DbQuery.Using throws ArgumentNullException for a null source. + // Every Using overload of this type: DbQuery.Using throws ArgumentNullException for a null source. => new(_definition.Using(connection).ToCall()); /// /// The write, bound. public BoundCall Using(DbTransaction transaction) - // DbQuery.Using throws ArgumentNullException for a null source. => new(_definition.Using(transaction).ToCall()); /// @@ -148,7 +147,6 @@ public BoundCall Using(DbTransaction transaction) public BoundCall Using( IDbConnectionPool pool) where TConnection : DbConnection - // DbQuery.Using throws ArgumentNullException for a null source. => new(_definition.Using(pool).ToCall()); /// @@ -156,7 +154,6 @@ public BoundCall Using( public BoundCall Using( IDbConnectionFactory factory) where TConnection : DbConnection - // DbQuery.Using throws ArgumentNullException for a null source. => new(_definition.Using(factory).ToCall()); /// @@ -219,13 +216,12 @@ public PendingParams AddParams(TParams values) /// /// The write, bound. public BoundParams Using(DbConnection connection) - // DbQuery.Using throws ArgumentNullException for a null source. + // Every Using overload of this type: DbQuery.Using throws ArgumentNullException for a null source. => new(_definition.Using(connection)); /// /// The write, bound. public BoundParams Using(DbTransaction transaction) - // DbQuery.Using throws ArgumentNullException for a null source. => new(_definition.Using(transaction)); /// @@ -233,7 +229,6 @@ public BoundParams Using(DbTransaction transaction) public BoundParams Using( IDbConnectionPool pool) where TConnection : DbConnection - // DbQuery.Using throws ArgumentNullException for a null source. => new(_definition.Using(pool)); /// @@ -241,7 +236,6 @@ public BoundParams Using( public BoundParams Using( IDbConnectionFactory factory) where TConnection : DbConnection - // DbQuery.Using throws ArgumentNullException for a null source. => new(_definition.Using(factory)); /// diff --git a/Source/Core/DbQueryRunner.Output.cs b/Source/Core/DbQueryRunner.Output.cs index 5f7f5e65..d93342cf 100644 --- a/Source/Core/DbQueryRunner.Output.cs +++ b/Source/Core/DbQueryRunner.Output.cs @@ -265,7 +265,6 @@ static async ValueTask ExecuteWithOutputAsync( { // Cancelled awaited tasks throw, so this does too. cancellationToken.ThrowIfCancellationRequested(); - output.Token = cancellationToken; TValue value; // The run is a block of its own, so everything is released at its end. @@ -348,10 +347,7 @@ public static async ValueTask RunCapturedAsync( { // Cancelled awaited tasks throw, so this does too. cancellationToken.ThrowIfCancellationRequested(); - var output = new OutputRun(run.Set.Layout) - { - Token = cancellationToken, - }; + var output = new OutputRun(run.Set.Layout); TResult result; { diff --git a/Source/Core/DirectStream.cs b/Source/Core/DirectStream.cs index 41535cb1..82006a6a 100644 --- a/Source/Core/DirectStream.cs +++ b/Source/Core/DirectStream.cs @@ -92,7 +92,7 @@ public DirectStream( } // Whether the watchdog timer exists: it does not before the first row, nor after the stream is over. - internal bool HasTimer => Volatile.Read(ref _timer) is not null; + public bool HasTimer => Volatile.Read(ref _timer) is not null; TimeoutException ToException() => StallStream.TimeoutFor(_stall); diff --git a/Source/Core/ExpressiveCommandBase.cs b/Source/Core/ExpressiveCommandBase.cs index 03fd89e2..364baed9 100644 --- a/Source/Core/ExpressiveCommandBase.cs +++ b/Source/Core/ExpressiveCommandBase.cs @@ -994,7 +994,9 @@ await ProcedureParameterMetadata.EnsureAsync( // The @names the text declares, when it declares any. NameSet? TextNames() - => Type == CommandType.Text && Command is { Length: > 0 } text && TextNameCache.Get(text) is { Names.Length: > 0 } names + => Type == CommandType.Text + && Command is { Length: > 0 } text + && TextNameCache.Get(text) is { Names.Length: > 0 } names ? names : null; @@ -1230,7 +1232,8 @@ InvalidOperationException Collision(string name, Param first, Param second, Immu + " Name one of them explicitly: AddParam(\"name\", value)."); InvalidOperationException NoMatch(string expression, ImmutableArray real) - => DbQueryBinding.NoMatch(expression, Command, "The procedure declares", real); + => DbQueryBinding.NoMatch( + expression, Command, "The procedure declares", real); #endregion diff --git a/Source/Core/ExpressiveDbCommand.cs b/Source/Core/ExpressiveDbCommand.cs index bd9ce4f5..f21e1f44 100644 --- a/Source/Core/ExpressiveDbCommand.cs +++ b/Source/Core/ExpressiveDbCommand.cs @@ -63,7 +63,7 @@ public ExpressiveDbCommand( CommandType type, string command, IEnumerable? @params = null) - : base(connFactory, type, command, @params) + : base(connFactory, type, command, @params) { } diff --git a/Source/Core/Extensions/Command._.cs b/Source/Core/Extensions/Command._.cs index 4113629d..479363ad 100644 --- a/Source/Core/Extensions/Command._.cs +++ b/Source/Core/Extensions/Command._.cs @@ -7,16 +7,6 @@ namespace Open.Database.Extensions; public static partial class CommandExtensions { - #region Connection.EnsureOpen Shortcuts. - // A command with no connection is refused by the connection extension: ArgumentNullException named "connection". - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static ConnectionState EnsureOpen(this IDbCommand command) - => command.Connection!.EnsureOpen(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static ValueTask EnsureOpenAsync(this IDbCommand command, CancellationToken cancellationToken) - => command.Connection!.EnsureOpenAsync(cancellationToken); - /// /// Gets the scope of the command's own connection: /// it is opened if needed, and closed again if the scope opened it. @@ -60,7 +50,8 @@ internal static async ValueTask> EnsureOpenScopeA internal static TReader OpenAndExecuteReader(TCommand command, CommandBehavior behavior, Func execute) where TCommand : IDbCommand { - if (!ConnectionExtensions.NeedsOpen(command.EnsureOpen())) + // A command with no connection is refused by the connection extension: ArgumentNullException named "connection". + if (!ConnectionExtensions.NeedsOpen(command.Connection!.EnsureOpen())) return execute(command, behavior); // The connection this call opened is the one it closes if the execute fails. @@ -80,7 +71,7 @@ internal static TReader OpenAndExecuteReader(TCommand command internal static async ValueTask OpenAndExecuteReaderAsync(TCommand command, CommandBehavior behavior, Func> execute, CancellationToken cancellationToken) where TCommand : IDbCommand { - ConnectionState prior = await command.EnsureOpenAsync(cancellationToken).ConfigureAwait(false); + ConnectionState prior = await command.Connection!.EnsureOpenAsync(cancellationToken).ConfigureAwait(false); if (!ConnectionExtensions.NeedsOpen(prior)) return await execute(command, behavior, cancellationToken).ConfigureAwait(false); @@ -153,8 +144,6 @@ static async ValueTask ExecuteReaderCoreAsync( return await handle(reader, arg).ConfigureAwait(false); } - #endregion - /// public static ValueTask ExecuteReaderAsync(this IDbCommand command, CancellationToken cancellationToken = default) diff --git a/Source/Core/Extensions/DataReader.cs b/Source/Core/Extensions/DataReader.cs index d883f00e..1def227f 100644 --- a/Source/Core/Extensions/DataReader.cs +++ b/Source/Core/Extensions/DataReader.cs @@ -929,10 +929,6 @@ public static async ValueTask IterateWhileAsync(this DbDataReader reader, Func> predicate, CancellationToken cancellationToken) { - if (reader is null) throw new ArgumentNullException(nameof(reader)); - if (predicate is null) throw new ArgumentNullException(nameof(predicate)); - Contract.EndContractBlock(); - while (ReadNext(reader, cancellationToken)) { if (!await predicate(reader).ConfigureAwait(false)) break; diff --git a/Source/Core/Mapped.docs.xml b/Source/Core/Mapped.docs.xml index db7af9c2..7823bcaa 100644 --- a/Source/Core/Mapped.docs.xml +++ b/Source/Core/Mapped.docs.xml @@ -313,4 +313,22 @@ A cancel or a dispose stops the read promptly only as far as the provider honors the cancellation. + + + + A Map terminal returns the rows of the first result set + (a result here is one whole result set, what moves between; never a row) + and then reads through the later sets without reading their rows, + so a failure in a later statement is thrown as the provider raised it. + This is the one explicit opt-out of that. + It asserts nothing: it does not check that there is only one result set. + + + Call it before Map, as in command.SingleResult().Map<Post>().ToListAsync(cancellationToken). + + + A later failure can follow a write that already committed, + so a caller that retries can repeat it, and the opt-out hides that failure. + + diff --git a/Source/Core/MappedViews.cs b/Source/Core/MappedViews.cs index e0dcde6e..16a7a2ff 100644 --- a/Source/Core/MappedViews.cs +++ b/Source/Core/MappedViews.cs @@ -371,12 +371,13 @@ internal static MappedQueryCore ReaderCore( internal static MappedQueryCore CommandCore( IDbCommand command, IRowSource source) - { - var single = command as SingleResultDbCommand; - return NewCore( - new CommandExecutor(single?.Command ?? command), default, source, - single is null ? QueryOptions.None : QueryOptions.SingleResult); - } + => command is SingleResultDbCommand single + ? NewCore( + new CommandExecutor(single.Command), default, source, + QueryOptions.SingleResult) + : NewCore( + new CommandExecutor(command), default, source, + QueryOptions.None); internal static MappedQueryCore TableCore( DataTable table, diff --git a/Source/Core/ProcedureParameterMetadata.cs b/Source/Core/ProcedureParameterMetadata.cs index 90db1bdc..c9a03bfe 100644 --- a/Source/Core/ProcedureParameterMetadata.cs +++ b/Source/Core/ProcedureParameterMetadata.cs @@ -91,7 +91,8 @@ public static async ValueTask EnsureAsync( { #if NET10_0_OR_GREATER using DataTable table = await db.GetSchemaAsync( - ProcedureSchemaNames.Collection, restrictions, cancellationToken) + ProcedureSchemaNames.Collection, restrictions, + cancellationToken) .ConfigureAwait(false); #else // DbConnection.GetSchemaAsync does not exist on the netstandard @@ -100,8 +101,6 @@ public static async ValueTask EnsureAsync( using DataTable table = db.GetSchema( ProcedureSchemaNames.Collection, restrictions); #endif - // A table that tells nothing usable, or that spans schemas for a - // name given without one (ambiguous), leaves nothing known. bool schemaGiven = restrictions[1] is not null; metadata = table is null || (!schemaGiven && ProcedureSchemaNames.SpansSchemas(table)) @@ -203,7 +202,6 @@ static int ScaleOf(object value) ? scale : ParameterMetadata.NoScale; - // A value the database reports that is not a number is "not known". static bool TryInt(object value, out int result) { try diff --git a/Source/Core/ProcedureSchemaNames.cs b/Source/Core/ProcedureSchemaNames.cs index b88cce47..f7d5a856 100644 --- a/Source/Core/ProcedureSchemaNames.cs +++ b/Source/Core/ProcedureSchemaNames.cs @@ -34,7 +34,8 @@ internal static ImmutableArray Get(DbConnection connection, string proce try { - using DataTable table = connection.GetSchema(Collection, restrictions); + using DataTable table + = connection.GetSchema(Collection, restrictions); return Names(table, schemaGiven: restrictions[1] is not null); } catch (Exception ex) when (ex is NotSupportedException or NotImplementedException or ArgumentException) @@ -78,7 +79,9 @@ internal static async ValueTask> GetAsync(DbConnection co try { - using DataTable table = await connection.GetSchemaAsync(Collection, restrictions, cancellationToken).ConfigureAwait(false); + using DataTable table = await connection.GetSchemaAsync( + Collection, restrictions, cancellationToken) + .ConfigureAwait(false); return Names(table, schemaGiven: restrictions[1] is not null); } catch (Exception ex) when (ex is NotSupportedException or NotImplementedException or ArgumentException) @@ -206,7 +209,12 @@ public static bool SpansSchemas(DataTable table) { string current = row["SPECIFIC_SCHEMA"] as string ?? ""; schema ??= current; - if (!string.Equals(schema, current, StringComparison.OrdinalIgnoreCase)) return true; + if (!string.Equals( + schema, current, + StringComparison.OrdinalIgnoreCase)) + { + return true; + } } return false; diff --git a/Source/Core/ScalarDbQuery.cs b/Source/Core/ScalarDbQuery.cs index d478c440..1e2c0b75 100644 --- a/Source/Core/ScalarDbQuery.cs +++ b/Source/Core/ScalarDbQuery.cs @@ -41,26 +41,23 @@ public ScalarDbQuery Params() /// public BoundCall> Using(DbConnection connection) - // DbQuery.Using throws ArgumentNullException for a null source. + // Every Using overload of this type: DbQuery.Using throws ArgumentNullException for a null source. => new(_definition.Using(connection).ToCall()); /// public BoundCall> Using(DbTransaction transaction) - // DbQuery.Using throws ArgumentNullException for a null source. => new(_definition.Using(transaction).ToCall()); /// public BoundCall> Using( IDbConnectionPool pool) where TConnection : DbConnection - // DbQuery.Using throws ArgumentNullException for a null source. => new(_definition.Using(pool).ToCall()); /// public BoundCall> Using( IDbConnectionFactory factory) where TConnection : DbConnection - // DbQuery.Using throws ArgumentNullException for a null source. => new(_definition.Using(factory).ToCall()); /// @@ -109,25 +106,22 @@ public PendingParams, TParams> AddParams(TParams values) /// public BoundParams, TParams> Using(DbConnection connection) - // DbQuery.Using throws ArgumentNullException for a null source. + // Every Using overload of this type: DbQuery.Using throws ArgumentNullException for a null source. => new(_definition.Using(connection)); /// public BoundParams, TParams> Using(DbTransaction transaction) - // DbQuery.Using throws ArgumentNullException for a null source. => new(_definition.Using(transaction)); /// public BoundParams, TParams> Using( IDbConnectionPool pool) where TConnection : DbConnection - // DbQuery.Using throws ArgumentNullException for a null source. => new(_definition.Using(pool)); /// public BoundParams, TParams> Using( IDbConnectionFactory factory) where TConnection : DbConnection - // DbQuery.Using throws ArgumentNullException for a null source. => new(_definition.Using(factory)); } diff --git a/Source/Core/SingleResult.cs b/Source/Core/SingleResult.cs index c17bb998..ece1b943 100644 --- a/Source/Core/SingleResult.cs +++ b/Source/Core/SingleResult.cs @@ -8,19 +8,11 @@ public static partial class CoreExtensions /// Opts an expressive command out of the read-through, so that the query reads only the first result set. /// /// + /// /// - /// A Map terminal returns the rows of the first result set - /// (a result here is one whole result set, what moves between; never a row) - /// and then reads through the later sets without reading their rows, - /// so a failure in a later statement is thrown as the provider raised it. - /// This is the one explicit opt-out of that. - /// With it the reader is asked for + /// With the opt-out the reader is asked for /// (and too for First, FirstOrDefault and AnyAsync when nothing is skipped and CancelOnEarlyStop() was not called), /// which lets the provider stop early. - /// It asserts nothing: it does not check that there is only one result set. - /// - /// - /// Call it before Map, as in command.SingleResult().Map<Post>().ToListAsync(cancellationToken). /// /// /// command.SingleResult().Map<T>() is exactly @@ -30,10 +22,6 @@ public static partial class CoreExtensions /// The command is not changed, so it can be used again without the opt-out. /// /// - /// A later failure can follow a write that already committed, - /// so a caller that retries can repeat it, and the opt-out hides that failure. - /// - /// /// The result is a view of the command for Map. /// Used as an directly, /// it runs the command with added to each call. @@ -59,17 +47,7 @@ public static IExecuteReader SingleResult( /// Opts a command out of the read-through, so that the query reads only the first result set. /// /// - /// - /// A Map terminal returns the rows of the first result set - /// (a result here is one whole result set, what moves between; never a row) - /// and then reads through the later sets without reading their rows, - /// so a failure in a later statement is thrown as the provider raised it. - /// This is the one explicit opt-out of that. - /// It asserts nothing: it does not check that there is only one result set. - /// - /// - /// Call it before Map, as in command.SingleResult().Map<Post>().ToListAsync(cancellationToken). - /// + /// /// /// command.SingleResult().Map<T>() is exactly /// command.Map<T>().SingleResult(), which still works, @@ -80,10 +58,6 @@ public static IExecuteReader SingleResult( /// that disposing the view disposes the command, so dispose one or the other. /// /// - /// A later failure can follow a write that already committed, - /// so a caller that retries can repeat it, and the opt-out hides that failure. - /// - /// /// The result is a view of the command for Map: /// it is not a , so pass the command itself to anything else. /// Used as an directly, diff --git a/Source/Generator/Emitter.cs b/Source/Generator/Emitter.cs index c05cb1be..b3bb332a 100644 --- a/Source/Generator/Emitter.cs +++ b/Source/Generator/Emitter.cs @@ -217,10 +217,6 @@ file abstract class OdxLayout // reads like a hand-written selector. public int Mode; - // The column of each slot, -1 for none (in slot order); - // null when the runtime serves the layout. - public int[] Ordinals; - // The fed slots in column order: // the order a guarded read takes, as the runtime reads and sets // (and a SequentialAccess reader needs). @@ -561,7 +557,6 @@ static Layout Resolve({{DbReader}} r) // Every slot fed in ascending column order: constant ordinals when each sits at its declaration position (4, the identity: read in slot order, // which is column order), else the layout's (1). Anything else is guarded (2), read in column order. sb.AppendLine(""" - l.Ordinals = o; l.Mode = !full || !ascending ? 2 : literal ? 4 : 1; if (l.Mode == 2) l.Sequence = OdxMatch.Sequence(o, Slots); // The row reader of the mode, chosen here once: diff --git a/Source/Generator/ModelReader.cs b/Source/Generator/ModelReader.cs index 88ccd1ac..bf4f4bdc 100644 --- a/Source/Generator/ModelReader.cs +++ b/Source/Generator/ModelReader.cs @@ -172,8 +172,7 @@ [.. properties.Where(static p => p.SetMethod is { DeclaredAccessibility: Accessi // Whether the model or a base type is declared partial in this compilation. A type from a referenced assembly is already whole. static bool IsPartial(INamedTypeSymbol t) - => TypeAndBaseTypes(t).Any(static c => c.DeclaringSyntaxReferences - .Any(static r => r.GetSyntax() is TypeDeclarationSyntax type && type.Modifiers.Any(SyntaxKind.PartialKeyword))); + => TypeAndBaseTypes(t).Any(static c => c.DeclaringSyntaxReferences.Any(static r => r.GetSyntax() is TypeDeclarationSyntax type && type.Modifiers.Any(SyntaxKind.PartialKeyword))); // The type, then each base type up to object: the order reflection reads members in. static IEnumerable TypeAndBaseTypes(INamedTypeSymbol t) @@ -371,10 +370,12 @@ static bool IsNonNullableReference(IParameterSymbol p) return declared.NullableAnnotation == NullableAnnotation.NotAnnotated; } - static bool IsNullableValue(ITypeSymbol t) => t.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T; + static bool IsNullableValue(ITypeSymbol t) + => t.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T; // T of a Nullable, else the type itself. - static ITypeSymbol Underlying(ITypeSymbol t) => IsNullableValue(t) ? ((INamedTypeSymbol)t).TypeArguments[0] : t; + static ITypeSymbol Underlying(ITypeSymbol t) + => IsNullableValue(t) ? ((INamedTypeSymbol)t).TypeArguments[0] : t; static bool IsReference(ITypeSymbol t) => !t.IsValueType && t.TypeKind is not (TypeKind.TypeParameter or TypeKind.Pointer or TypeKind.FunctionPointer); diff --git a/Source/MSSqlClient/ExpressiveSqlCommand.cs b/Source/MSSqlClient/ExpressiveSqlCommand.cs index 05a411f4..51da18b1 100644 --- a/Source/MSSqlClient/ExpressiveSqlCommand.cs +++ b/Source/MSSqlClient/ExpressiveSqlCommand.cs @@ -194,7 +194,9 @@ SqlCommand ProcedureNamesCommand(SqlConnection connection, string procedure) SqlCommand command = connection.CreateCommand(); command.CommandText = "select name from sys.all_parameters where object_id = object_id(@procedure) and parsename(@procedure, 3) is null and parameter_id > 0 order by parameter_id"; command.CommandTimeout = Timeout; // the command's own timeout (SetTimeout), not the provider's default - command.Parameters.Add("@procedure", SqlDbType.NVarChar, ProcedureNameLength).Value = procedure; + command.Parameters.Add( + "@procedure", SqlDbType.NVarChar, ProcedureNameLength) + .Value = procedure; if (Transaction is SqlTransaction transaction) command.Transaction = transaction; return command; } diff --git a/Source/MSSqlClient/Synchronous/SyncSqlTransactionExtensions.cs b/Source/MSSqlClient/Synchronous/SyncSqlTransactionExtensions.cs index c66f2cf6..d60cc905 100644 --- a/Source/MSSqlClient/Synchronous/SyncSqlTransactionExtensions.cs +++ b/Source/MSSqlClient/Synchronous/SyncSqlTransactionExtensions.cs @@ -1,5 +1,3 @@ -using static Open.Database.Extensions.SqlTransactionExtensions; - namespace Open.Database.Extensions.Synchronous; ///