-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Data.SqlTypes; | ||
using System.Text; | ||
using Microsoft.SqlServer.TransactSql.ScriptDom; | ||
using Microsoft.Xrm.Sdk; | ||
|
||
namespace MarkMpn.Sql4Cds.Engine.ExecutionPlan | ||
{ | ||
class PrintNode : BaseNode, IDmlQueryExecutionPlanNode | ||
{ | ||
private int _executionCount; | ||
private readonly Timer _timer = new Timer(); | ||
private Func<Entity, IDictionary<string, object>, IQueryExecutionOptions, object> _expression; | ||
|
||
public override int ExecutionCount => _executionCount; | ||
|
||
public override TimeSpan Duration => _timer.Duration; | ||
|
||
[Browsable(false)] | ||
public string Sql { get; set; } | ||
|
||
[Browsable(false)] | ||
public int Index { get; set; } | ||
|
||
[Browsable(false)] | ||
public int Length { get; set; } | ||
|
||
[Category("Print")] | ||
[Description("The value to print")] | ||
public ScalarExpression Expression { get; set; } | ||
|
||
public override void AddRequiredColumns(IDictionary<string, DataSource> dataSources, IDictionary<string, DataTypeReference> parameterTypes, IList<string> requiredColumns) | ||
{ | ||
} | ||
|
||
public object Clone() | ||
{ | ||
return new PrintNode | ||
{ | ||
Expression = Expression, | ||
_expression = _expression | ||
}; | ||
} | ||
|
||
public string Execute(IDictionary<string, DataSource> dataSources, IQueryExecutionOptions options, IDictionary<string, DataTypeReference> parameterTypes, IDictionary<string, object> parameterValues, out int recordsAffected) | ||
{ | ||
_executionCount++; | ||
recordsAffected = -1; | ||
|
||
using (_timer.Run()) | ||
{ | ||
var value = (SqlString)_expression(null, parameterValues, options); | ||
|
||
if (value.IsNull) | ||
return null; | ||
|
||
return value.Value; | ||
} | ||
} | ||
|
||
public IRootExecutionPlanNodeInternal FoldQuery(IDictionary<string, DataSource> dataSources, IQueryExecutionOptions options, IDictionary<string, DataTypeReference> parameterTypes, IList<OptimizerHint> hints) | ||
{ | ||
_expression = Expression.Compile(null, parameterTypes); | ||
return this; | ||
} | ||
|
||
public override IEnumerable<IExecutionPlanNode> GetSources() | ||
{ | ||
return Array.Empty<IExecutionPlanNode>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters