Skip to content

Commit

Permalink
#45 WIP More work on batching, started building the SQL and reading t…
Browse files Browse the repository at this point in the history
…he results back.

- Changed the signature of the AddExecute* methods, to return the result as an out parameter, and returning the SqlBatch instead.
  This helps with type parameter inference for the TOut for AddExecuteScalar, as otherwise you would have to specify ALL the types.
- Added SqlStringBuilder to help building SQL strings.
- Added basic end-to-end batching test. Upgraded the test database files.
  • Loading branch information
billings7 committed Apr 28, 2017
1 parent c23d39b commit 3a86f26
Show file tree
Hide file tree
Showing 53 changed files with 3,698 additions and 1,842 deletions.
506 changes: 506 additions & 0 deletions Database/DbBatchDataReader.cs

Large diffs are not rendered by default.

72 changes: 71 additions & 1 deletion Database/Generated/SqlProgramGeneric.Generated.log
Original file line number Diff line number Diff line change
@@ -1 +1,71 @@
ErrorGeneratingOutput
© Copyright Web Applications (UK) Ltd, 2017.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Web Applications UK Ltd nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL WEB APPLICATIONS UK LTD BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*******************************************************************************
* WARNING: Do not have this file open during regeneration as it can slow down *
* Visual Studio considerably. *
*******************************************************************************

Schema code file generation
============================
Started : 04/28/2017 11:36:04
Saved helper template files:
CoreLibraries\Database\Generated\SqlProgramGeneric.Generated.txt4
Saved files:
CoreLibraries\Database\Generated\SqlProgramGeneric32.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric31.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric30.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric29.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric28.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric27.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric26.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric25.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric24.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric23.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric22.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric21.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric20.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric19.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric18.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric17.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric16.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric15.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric14.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric13.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric12.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric11.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric10.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric9.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric8.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric7.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric6.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric5.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric4.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric3.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric2.Generated.cs
CoreLibraries\Database\Generated\SqlProgramGeneric1.Generated.cs

Finished : 04/28/2017 11:36:06
Total Duration : 1,828.006 ms
55 changes: 31 additions & 24 deletions Database/Generated/SqlProgramGeneric.Generated.tt
Original file line number Diff line number Diff line change
Expand Up @@ -1124,31 +1124,37 @@ namespace WebApplications.Utilities.Database
<#= Strings.TypeComments #>
/// <typeparam name="TOut">The output type expected.</typeparam>
/// <param name="program">The program to add to the batch.</param>
/// <param name="result">A <see cref="SqlBatchResult{T}"/> which can be used to get the scalar value returned by the program.</param>
<#= Strings.ParameterComments #>
/// <param name="constraintMode">The constraint mode, if set will override the configured default for the program.</param>
/// <returns>A <see cref="SqlBatchResult{T}"/> which can be used to get the scalar value returned by the program.</returns>
public SqlBatchResult<TOut> AddExecuteScalar<<#= Strings.TypeParams#>, TOut>(
[NotNull] SqlProgram program,
/// <param name="constraintMode">The constraint mode. Overrides the configured default for the program.</param>
/// <returns>This <see cref="SqlBatch"/> instance.</returns>
[NotNull]
public SqlBatch AddExecuteScalar<<#= Strings.TypeParams#>, TOut>(
[NotNull] SqlProgram<<#= Strings.TypeParams#>> program,
[NotNull] out SqlBatchResult<TOut> result,
<#= Strings.InputParametersTypedDefault #>,
TypeConstraintMode? constraintMode = null)
{
return this.AddExecuteScalar<TOut>(program, c => c.SetParameters(<#= Strings.Parameters #>, (TypeConstraintMode)(constraintMode ?? program.ConstraintMode)));
return this.AddExecuteScalar<TOut>(program, c => c.SetParameters(<#= Strings.Parameters #>, constraintMode ?? program.ConstraintMode), out result);
}

/// <summary>
/// Adds the specified program to the batch. The number of rows affected will be returned by the <see cref="SqlBatchResult{T}"/>.
/// </summary>
<#= Strings.TypeComments #>
/// <param name="program">The program to add to the batch.</param>
/// <param name="result">A <see cref="SqlBatchResult{T}"/> which can be used to get the number of rows affected.</param>
<#= Strings.ParameterComments #>
/// <param name="constraintMode">The constraint mode, if set will override the configured default for the program.</param>
/// <returns>A <see cref="SqlBatchResult{T}"/> which can be used to get the number of rows affected.</returns>
public SqlBatchResult<int> AddExecuteNonQuery<<#= Strings.TypeParams#>>(
[NotNull] SqlProgram program,
/// <returns>This <see cref="SqlBatch"/> instance.</returns>
[NotNull]
public SqlBatch AddExecuteNonQuery<<#= Strings.TypeParams#>>(
[NotNull] SqlProgram<<#= Strings.TypeParams#>> program,
[NotNull] out SqlBatchResult<int> result,
<#= Strings.InputParametersTypedDefault #>,
TypeConstraintMode? constraintMode = null)
{
return this.AddExecuteNonQuery(program, c => c.SetParameters(<#= Strings.Parameters #>, (TypeConstraintMode)(constraintMode ?? program.ConstraintMode)));
return this.AddExecuteNonQuery(program, c => c.SetParameters(<#= Strings.Parameters #>, (TypeConstraintMode)(constraintMode ?? program.ConstraintMode)), out result);
}

/// <summary>
Expand All @@ -1157,20 +1163,21 @@ namespace WebApplications.Utilities.Database
<#= Strings.TypeComments #>
/// <param name="program">The program to add to the batch.</param>
/// <param name="resultAction">The action used to process the result.</param>
/// <param name="result">A <see cref="SqlBatchResult" /> which can be used to wait for the program to finish executing.</param>
<#= Strings.ParameterComments #>
/// <param name="behavior">The query's effect on the database.</param>
/// <param name="constraintMode">The constraint mode, if set will override the configured default for the program.</param>
/// <returns>
/// A <see cref="SqlBatchResult" /> which can be used to wait for the program to finish executing.
/// </returns>
public SqlBatchResult AddExecuteReader<<#= Strings.TypeParams#>>(
[NotNull] SqlProgram program,
/// <returns>This <see cref="SqlBatch"/> instance.</returns>
[NotNull]
public SqlBatch AddExecuteReader<<#= Strings.TypeParams#>>(
[NotNull] SqlProgram<<#= Strings.TypeParams#>> program,
[NotNull] ResultDelegateAsync resultAction,
[NotNull] out SqlBatchResult result,
<#= Strings.InputParametersTypedDefault #>,
CommandBehavior behavior = CommandBehavior.Default,
TypeConstraintMode? constraintMode = null)
{
return this.AddExecuteReader(program, resultAction, behavior, c => c.SetParameters(<#= Strings.Parameters #>, (TypeConstraintMode)(constraintMode ?? program.ConstraintMode)));
return this.AddExecuteReader(program, resultAction, behavior, c => c.SetParameters(<#= Strings.Parameters #>, (TypeConstraintMode)(constraintMode ?? program.ConstraintMode)), out result);
}

/// <summary>
Expand All @@ -1181,21 +1188,21 @@ namespace WebApplications.Utilities.Database
/// <typeparam name="TOut">The type of the result.</typeparam>
/// <param name="program">The program to add to the batch.</param>
/// <param name="resultFunc">The function used to process the result.</param>
/// <param name="result">A <see cref="SqlBatchResult" /> which can be used to get the value returned by the <paramref name="resultFunc"/>.</param>
<#= Strings.ParameterComments #>
/// <param name="behavior">The query's effect on the database.</param>
/// <param name="constraintMode">The constraint mode, if set will override the configured default for the program.</param>
/// <returns>
/// A <see cref="SqlBatchResult" /> which can be used to get the value returned by the <paramref name="resultFunc"/>.
/// </returns>
/// <exception cref="NotImplementedException"></exception>
public SqlBatchResult<TOut> AddExecuteReader<<#= Strings.TypeParams#>, TOut>(
[NotNull] SqlProgram program,
/// <returns>This <see cref="SqlBatch"/> instance.</returns>
[NotNull]
public SqlBatch AddExecuteReader<<#= Strings.TypeParams#>, TOut>(
[NotNull] SqlProgram<<#= Strings.TypeParams#>> program,
[NotNull] ResultDelegateAsync<TOut> resultFunc,
[NotNull] out SqlBatchResult<TOut> result,
<#= Strings.InputParametersTypedDefault #>,
CommandBehavior behavior = CommandBehavior.Default,
TypeConstraintMode? constraintMode = null)
{
return this.AddExecuteReader<TOut>(program, resultFunc, behavior, c => c.SetParameters(<#= Strings.Parameters #>, (TypeConstraintMode)(constraintMode ?? program.ConstraintMode)));
return this.AddExecuteReader<TOut>(program, resultFunc, behavior, c => c.SetParameters(<#= Strings.Parameters #>, (TypeConstraintMode)(constraintMode ?? program.ConstraintMode)), out result);
}
}
#endregion
Expand Down Expand Up @@ -1232,7 +1239,7 @@ namespace WebApplications.Utilities.Database
programParameter = parameters[<#= i #>];
parameter = GetOrAddParameter(programParameter);
parameter.SetParameterValue(programParameter, p<#= i+1 #>Value, mode);
AddOutParameter(parameter, p<#= i+1 #>Value as IOut);
AddOutParameter(parameter, p<#= i+1 #>Value.Value as IOut);
batchParameters[<#= i #>] = parameter;
<# } #>
}
Expand Down Expand Up @@ -1283,7 +1290,7 @@ namespace WebApplications.Utilities.Database
programParameter = parameters[<#= i #>];
parameter = GetOrAddParameter(programParameter);
parameter.SetParameterValue(programParameter, p<#= i+1 #>Value, mode);
AddOutParameter(parameter, p<#= i+1 #>Value as IOut);
AddOutParameter(parameter, p<#= i+1 #>Value.Value as IOut);
batchParameters[<#= i #>] = parameter;
<# } #>
}
Expand Down
Loading

0 comments on commit 3a86f26

Please sign in to comment.