From 5ec2bb28d661cb154f231496553b0e63cd9483de Mon Sep 17 00:00:00 2001 From: Mark Carrington <31017244+MarkMpn@users.noreply.github.com> Date: Thu, 16 May 2024 08:11:48 +0100 Subject: [PATCH] Store all parameter values as INullable --- .../ExecutionPlanTests.cs | 14 ++--- .../Sql2FetchXmlTests.cs | 62 +++++++++---------- .../Ado/Sql4CdsConnection.cs | 6 +- .../Ado/Sql4CdsDataReader.cs | 8 +-- .../Ado/Sql4CdsParameterCollection.cs | 5 +- .../ExecutionPlan/AssignVariablesNode.cs | 2 +- .../ExecutionPlan/InsertNode.cs | 3 +- .../ExecutionPlan/NestedLoopNode.cs | 7 ++- .../ExecutionPlan/PartitionedAggregateNode.cs | 2 +- .../ExecutionPlan/SelectDataReader.cs | 4 +- MarkMpn.Sql4Cds.Engine/NodeContext.cs | 7 ++- 11 files changed, 62 insertions(+), 58 deletions(-) diff --git a/MarkMpn.Sql4Cds.Engine.Tests/ExecutionPlanTests.cs b/MarkMpn.Sql4Cds.Engine.Tests/ExecutionPlanTests.cs index 854836db..1456b311 100644 --- a/MarkMpn.Sql4Cds.Engine.Tests/ExecutionPlanTests.cs +++ b/MarkMpn.Sql4Cds.Engine.Tests/ExecutionPlanTests.cs @@ -3714,7 +3714,7 @@ GROUP BY firstname }, }; - var result = select.Execute(new NodeExecutionContext(_localDataSources, this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var result = select.Execute(new NodeExecutionContext(_localDataSources, this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(result); @@ -4192,7 +4192,7 @@ DECLARE @test int Assert.AreEqual(1, selectConstantScan.Values.Count); var parameterTypes = new Dictionary(); - var parameterValues = new Dictionary(); + var parameterValues = new Dictionary(); foreach (var plan in plans) { @@ -4246,7 +4246,7 @@ public void SetVariableInDeclaration() Assert.AreEqual(1, selectConstantScan.Values.Count); var parameterTypes = new Dictionary(); - var parameterValues = new Dictionary(); + var parameterValues = new Dictionary(); foreach (var plan in plans) { @@ -4304,7 +4304,7 @@ DECLARE @test varchar(3) var plans = planBuilder.Build(query, null, out _); var parameterTypes = new Dictionary(); - var parameterValues = new Dictionary(); + var parameterValues = new Dictionary(); foreach (var plan in plans) { @@ -4338,7 +4338,7 @@ DECLARE @test varchar(3) var plans = planBuilder.Build(query, null, out _); var parameterTypes = new Dictionary(); - var parameterValues = new Dictionary(); + var parameterValues = new Dictionary(); foreach (var plan in plans) { @@ -4430,7 +4430,7 @@ DECLARE @test varchar(3) }; var parameterTypes = new Dictionary(); - var parameterValues = new Dictionary(); + var parameterValues = new Dictionary(); foreach (var plan in plans) { @@ -4464,7 +4464,7 @@ DECLARE @test varchar var plans = planBuilder.Build(query, null, out _); var parameterTypes = new Dictionary(); - var parameterValues = new Dictionary(); + var parameterValues = new Dictionary(); foreach (var plan in plans) { diff --git a/MarkMpn.Sql4Cds.Engine.Tests/Sql2FetchXmlTests.cs b/MarkMpn.Sql4Cds.Engine.Tests/Sql2FetchXmlTests.cs index 8e601557..04c8c63f 100644 --- a/MarkMpn.Sql4Cds.Engine.Tests/Sql2FetchXmlTests.cs +++ b/MarkMpn.Sql4Cds.Engine.Tests/Sql2FetchXmlTests.cs @@ -702,7 +702,7 @@ public void SelectArithmetic() } }; - var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -752,7 +752,7 @@ public void WhereComparingTwoFields() } }; - var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -797,7 +797,7 @@ public void WhereComparingExpression() } }; - var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -838,7 +838,7 @@ public void BackToFrontLikeExpression() } }; - var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -873,7 +873,7 @@ public void UpdateFieldToField() } }; - ((UpdateNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), out _, out _); + ((UpdateNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), out _, out _); Assert.AreEqual("Carrington", _context.Data["contact"][guid]["firstname"]); } @@ -905,7 +905,7 @@ public void UpdateFieldToExpression() } }; - ((UpdateNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), out _, out _); + ((UpdateNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), out _, out _); Assert.AreEqual("Hello Carrington", _context.Data["contact"][guid]["firstname"]); } @@ -941,7 +941,7 @@ public void UpdateReplace() } }; - ((UpdateNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), out _, out _); + ((UpdateNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), out _, out _); Assert.AreEqual("--CDS--", _context.Data["contact"][guid]["firstname"]); } @@ -972,7 +972,7 @@ public void StringFunctions() } }; - var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -1012,7 +1012,7 @@ public void SelectExpression() } }; - var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -1062,7 +1062,7 @@ public void SelectExpressionNullValues() } }; - var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -1107,7 +1107,7 @@ public void OrderByExpression() } }; - var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -1152,7 +1152,7 @@ public void OrderByAliasedField() } }; - var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -1196,7 +1196,7 @@ public void OrderByCalculatedField() } }; - var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -1240,7 +1240,7 @@ public void OrderByCalculatedFieldByIndex() } }; - var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -1282,7 +1282,7 @@ public void DateCalculations() } }; - var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -1370,7 +1370,7 @@ public void CustomFilterAggregateHavingProjectionSortAndTop() } }; - var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -1433,7 +1433,7 @@ public void FilterCaseInsensitive() } }; - var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -1490,7 +1490,7 @@ public void GroupCaseInsensitive() } }; - var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -1543,7 +1543,7 @@ public void AggregateExpressionsWithoutGrouping() } }; - var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -1598,7 +1598,7 @@ public void AggregateQueryProducesAlternative() } }; - var dataReader = alternativeQuery.Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = alternativeQuery.Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -1654,7 +1654,7 @@ public void GuidEntityReferenceInequality() } }; - var dataReader = select.Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = select.Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -1706,7 +1706,7 @@ public void UpdateGuidToEntityReference() } }; - update.Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), out _, out _); + update.Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), out _, out _); Assert.AreEqual(new EntityReference("contact", contact1), _context.Data["account"][account1].GetAttributeValue("primarycontactid")); Assert.AreEqual(new EntityReference("contact", contact2), _context.Data["account"][account2].GetAttributeValue("primarycontactid")); @@ -1981,7 +1981,7 @@ public void ImplicitTypeConversion() } }; - var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -2014,7 +2014,7 @@ public void ImplicitTypeConversionComparison() } }; - var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -2038,7 +2038,7 @@ public void GlobalOptionSet() Assert.AreEqual("globaloptionset.name = 'test'", filterNode.Filter.ToSql()); var optionsetNode = (GlobalOptionSetQueryNode)filterNode.Source; - var dataReader = selectNode.Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = selectNode.Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -2059,7 +2059,7 @@ public void EntityDetails() var sortNode = (SortNode)selectNode.Source; var metadataNode = (MetadataQueryNode)sortNode.Source; - var dataReader = selectNode.Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = selectNode.Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -2077,7 +2077,7 @@ public void AttributeDetails() var planBuilder = new ExecutionPlanBuilder(_localDataSources.Values, this); var queries = planBuilder.Build(query, null, out _); - var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -2135,7 +2135,7 @@ public void OptionSetNameSelect() CollectionAssert.AreEqual(new[] { "new_optionsetvalue", "new_optionsetvaluename" }, select.ColumnSet.Select(c => c.OutputColumn).ToList()); - var dataReader = select.Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = select.Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -2459,7 +2459,7 @@ public void CharIndex() } }; - var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -2489,7 +2489,7 @@ public void CastDateTimeToDate() } }; - var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); @@ -2527,7 +2527,7 @@ public void GroupByPrimaryFunction() } }; - var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); + var dataReader = ((SelectNode)queries[0]).Execute(new NodeExecutionContext(GetDataSources(_context), this, new Dictionary(), new Dictionary(), null), CommandBehavior.Default); var dataTable = new DataTable(); dataTable.Load(dataReader); diff --git a/MarkMpn.Sql4Cds.Engine/Ado/Sql4CdsConnection.cs b/MarkMpn.Sql4Cds.Engine/Ado/Sql4CdsConnection.cs index 15578c28..167f66ac 100644 --- a/MarkMpn.Sql4Cds.Engine/Ado/Sql4CdsConnection.cs +++ b/MarkMpn.Sql4Cds.Engine/Ado/Sql4CdsConnection.cs @@ -29,7 +29,7 @@ public class Sql4CdsConnection : DbConnection private readonly IDictionary _dataSources; private readonly ChangeDatabaseOptionsWrapper _options; private readonly Dictionary _globalVariableTypes; - private readonly Dictionary _globalVariableValues; + private readonly Dictionary _globalVariableValues; private readonly TelemetryClient _ai; /// @@ -74,7 +74,7 @@ public Sql4CdsConnection(IDictionary dataSources) ["@@VERSION"] = DataTypeHelpers.NVarChar(Int32.MaxValue, _dataSources[_options.PrimaryDataSource].DefaultCollation, CollationLabel.CoercibleDefault), ["@@ERROR"] = DataTypeHelpers.Int, }; - _globalVariableValues = new Dictionary(StringComparer.OrdinalIgnoreCase) + _globalVariableValues = new Dictionary(StringComparer.OrdinalIgnoreCase) { ["@@IDENTITY"] = SqlEntityReference.Null, ["@@ROWCOUNT"] = (SqlInt32)0, @@ -291,7 +291,7 @@ public ColumnOrdering ColumnOrdering internal Dictionary GlobalVariableTypes => _globalVariableTypes; - internal Dictionary GlobalVariableValues => _globalVariableValues; + internal Dictionary GlobalVariableValues => _globalVariableValues; internal TelemetryClient TelemetryClient => _ai; diff --git a/MarkMpn.Sql4Cds.Engine/Ado/Sql4CdsDataReader.cs b/MarkMpn.Sql4Cds.Engine/Ado/Sql4CdsDataReader.cs index 3354c182..a88c27d0 100644 --- a/MarkMpn.Sql4Cds.Engine/Ado/Sql4CdsDataReader.cs +++ b/MarkMpn.Sql4Cds.Engine/Ado/Sql4CdsDataReader.cs @@ -22,7 +22,7 @@ class Sql4CdsDataReader : DbDataReader private readonly IQueryExecutionOptions _options; private readonly CommandBehavior _behavior; private readonly Dictionary _parameterTypes; - private readonly Dictionary _parameterValues; + private readonly Dictionary _parameterValues; private Dictionary _labelIndexes; private int _recordsAffected; private int _instructionPointer; @@ -57,7 +57,7 @@ public Sql4CdsDataReader(Sql4CdsCommand command, IQueryExecutionOptions options, Close(); } - internal Dictionary ParameterValues => _parameterValues; + internal Dictionary ParameterValues => _parameterValues; private Dictionary LabelIndexes { @@ -75,7 +75,7 @@ private Dictionary LabelIndexes } } - private bool ExecuteWithExceptionHandling(Dictionary parameterTypes, Dictionary parameterValues) + private bool ExecuteWithExceptionHandling(Dictionary parameterTypes, Dictionary parameterValues) { while (true) { @@ -109,7 +109,7 @@ private bool ExecuteWithExceptionHandling(Dictionary } } - private bool Execute(Dictionary parameterTypes, Dictionary parameterValues) + private bool Execute(Dictionary parameterTypes, Dictionary parameterValues) { IRootExecutionPlanNode logNode = null; var context = new NodeExecutionContext(_connection.DataSources, _options, parameterTypes, parameterValues, msg => _connection.OnInfoMessage(logNode, msg)); diff --git a/MarkMpn.Sql4Cds.Engine/Ado/Sql4CdsParameterCollection.cs b/MarkMpn.Sql4Cds.Engine/Ado/Sql4CdsParameterCollection.cs index c5ea90eb..705df781 100644 --- a/MarkMpn.Sql4Cds.Engine/Ado/Sql4CdsParameterCollection.cs +++ b/MarkMpn.Sql4Cds.Engine/Ado/Sql4CdsParameterCollection.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Data.Common; +using System.Data.SqlTypes; using System.Linq; using System.Text; using Microsoft.SqlServer.TransactSql.ScriptDom; @@ -50,11 +51,11 @@ internal Dictionary GetParameterTypes() .ToDictionary(param => param.FullParameterName, param => param.GetDataType(), StringComparer.OrdinalIgnoreCase); } - internal Dictionary GetParameterValues() + internal Dictionary GetParameterValues() { return _parameters .Cast() - .ToDictionary(param => param.FullParameterName, param => (object) param.GetValue(), StringComparer.OrdinalIgnoreCase); + .ToDictionary(param => param.FullParameterName, param => param.GetValue(), StringComparer.OrdinalIgnoreCase); } public override bool Contains(string value) diff --git a/MarkMpn.Sql4Cds.Engine/ExecutionPlan/AssignVariablesNode.cs b/MarkMpn.Sql4Cds.Engine/ExecutionPlan/AssignVariablesNode.cs index 7f65da59..af59ef61 100644 --- a/MarkMpn.Sql4Cds.Engine/ExecutionPlan/AssignVariablesNode.cs +++ b/MarkMpn.Sql4Cds.Engine/ExecutionPlan/AssignVariablesNode.cs @@ -54,7 +54,7 @@ public override void Execute(NodeExecutionContext context, out int recordsAffect foreach (var entity in entities) { foreach (var variable in Variables) - context.ParameterValues[variable.VariableName] = valueAccessors[variable.VariableName](entity); + context.ParameterValues[variable.VariableName] = (INullable)valueAccessors[variable.VariableName](entity); count++; } diff --git a/MarkMpn.Sql4Cds.Engine/ExecutionPlan/InsertNode.cs b/MarkMpn.Sql4Cds.Engine/ExecutionPlan/InsertNode.cs index c24ae1aa..1c15ba0a 100644 --- a/MarkMpn.Sql4Cds.Engine/ExecutionPlan/InsertNode.cs +++ b/MarkMpn.Sql4Cds.Engine/ExecutionPlan/InsertNode.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Data.SqlTypes; using System.Linq; using System.ServiceModel; using System.Threading; @@ -292,7 +293,7 @@ protected override bool FilterErrors(NodeExecutionContext context, OrganizationR return true; } - private void SetIdentity(OrganizationResponse response, IDictionary parameterValues) + private void SetIdentity(OrganizationResponse response, IDictionary parameterValues) { if (response is CreateResponse create) parameterValues["@@IDENTITY"] = new SqlEntityReference(DataSource, LogicalName, create.id); diff --git a/MarkMpn.Sql4Cds.Engine/ExecutionPlan/NestedLoopNode.cs b/MarkMpn.Sql4Cds.Engine/ExecutionPlan/NestedLoopNode.cs index de391dc0..069d9c91 100644 --- a/MarkMpn.Sql4Cds.Engine/ExecutionPlan/NestedLoopNode.cs +++ b/MarkMpn.Sql4Cds.Engine/ExecutionPlan/NestedLoopNode.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Data.SqlTypes; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -71,14 +72,14 @@ protected override IEnumerable ExecuteInternal(NodeExecutionContext cont if (OuterReferences != null) { if (innerParameters == null) - innerParameters = new Dictionary(); + innerParameters = new Dictionary(); else - innerParameters = new Dictionary(innerParameters); + innerParameters = new Dictionary(innerParameters); foreach (var kvp in OuterReferences) { left.Attributes.TryGetValue(kvp.Key, out var outerValue); - innerParameters[kvp.Value] = outerValue; + innerParameters[kvp.Value] = (INullable)outerValue; } } diff --git a/MarkMpn.Sql4Cds.Engine/ExecutionPlan/PartitionedAggregateNode.cs b/MarkMpn.Sql4Cds.Engine/ExecutionPlan/PartitionedAggregateNode.cs index 9041e45d..bbc31602 100644 --- a/MarkMpn.Sql4Cds.Engine/ExecutionPlan/PartitionedAggregateNode.cs +++ b/MarkMpn.Sql4Cds.Engine/ExecutionPlan/PartitionedAggregateNode.cs @@ -187,7 +187,7 @@ protected override IEnumerable ExecuteInternal(NodeExecutionContext cont Parent = this }; - var partitionParameterValues = new Dictionary + var partitionParameterValues = new Dictionary { ["@PartitionStart"] = minKey, ["@PartitionEnd"] = maxKey diff --git a/MarkMpn.Sql4Cds.Engine/ExecutionPlan/SelectDataReader.cs b/MarkMpn.Sql4Cds.Engine/ExecutionPlan/SelectDataReader.cs index ff5b55ab..1ceef794 100644 --- a/MarkMpn.Sql4Cds.Engine/ExecutionPlan/SelectDataReader.cs +++ b/MarkMpn.Sql4Cds.Engine/ExecutionPlan/SelectDataReader.cs @@ -17,12 +17,12 @@ class SelectDataReader : DbDataReader private readonly IDisposable _timer; private readonly INodeSchema _schema; private readonly IEnumerator _source; - private readonly IDictionary _parameterValues; + private readonly IDictionary _parameterValues; private Entity _row; private bool _closed; private int _rowCount; - public SelectDataReader(List columnSet, IDisposable timer, INodeSchema schema, IEnumerable source, IDictionary parameterValues) + public SelectDataReader(List columnSet, IDisposable timer, INodeSchema schema, IEnumerable source, IDictionary parameterValues) { _columnSet = columnSet; _timer = timer; diff --git a/MarkMpn.Sql4Cds.Engine/NodeContext.cs b/MarkMpn.Sql4Cds.Engine/NodeContext.cs index 22034f62..68b6c98d 100644 --- a/MarkMpn.Sql4Cds.Engine/NodeContext.cs +++ b/MarkMpn.Sql4Cds.Engine/NodeContext.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Data.SqlTypes; using System.Text; using MarkMpn.Sql4Cds.Engine.ExecutionPlan; using Microsoft.SqlServer.TransactSql.ScriptDom; @@ -105,7 +106,7 @@ public NodeExecutionContext( IDictionary dataSources, IQueryExecutionOptions options, IDictionary parameterTypes, - IDictionary parameterValues, + IDictionary parameterValues, Action log) : base(dataSources, options, parameterTypes, log) { @@ -115,7 +116,7 @@ public NodeExecutionContext( /// /// Returns the current value of each parameter /// - public IDictionary ParameterValues { get; } + public IDictionary ParameterValues { get; } public Sql4CdsError Error { get; set; } } @@ -191,7 +192,7 @@ public ExpressionExecutionContext( IDictionary dataSources, IQueryExecutionOptions options, IDictionary parameterTypes, - IDictionary parameterValues, + IDictionary parameterValues, Action log, Entity entity) : base(dataSources, options, parameterTypes, parameterValues, log)