Skip to content

Commit

Permalink
Merge branch 'master' into v9.4-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMpn authored Nov 10, 2024
2 parents 041befa + 72d9a9b commit 99d1f36
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
78 changes: 78 additions & 0 deletions MarkMpn.Sql4Cds.Engine.Tests/ExecutionPlanTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2976,6 +2976,36 @@ public void SimpleUpdate()
</fetch>");
}

[TestMethod]
public void CaseInsensitiveUpdate()
{
var planBuilder = new ExecutionPlanBuilder(new SessionContext(_localDataSources, this), this);

var query = "UPDATE Account SET Name = 'foo' WHERE name = 'bar'";

var plans = planBuilder.Build(query, null, out _);

Assert.AreEqual(1, plans.Length);

var update = AssertNode<UpdateNode>(plans[0]);
Assert.AreEqual("account", update.LogicalName);
Assert.AreEqual("Account.accountid", update.PrimaryIdAccessors.Single().SourceAttributes.Single());
Assert.AreEqual("Expr1", update.NewValueAccessors.Single(a => a.TargetAttribute == "name").SourceAttributes.Single());
var computeScalar = AssertNode<ComputeScalarNode>(update.Source);
Assert.AreEqual("'foo'", computeScalar.Columns["Expr1"].ToSql());
var fetch = AssertNode<FetchXmlScan>(computeScalar.Source);
Assert.AreEqual("Account", fetch.Alias);
AssertFetchXml(fetch, @"
<fetch>
<entity name='account'>
<attribute name='accountid' />
<filter>
<condition attribute='name' operator='eq' value='bar' />
</filter>
</entity>
</fetch>");
}

[TestMethod]
public void UpdateFromJoin()
{
Expand Down Expand Up @@ -3387,6 +3417,34 @@ public void SimpleDelete()
</fetch>");
}

[TestMethod]
public void CaseInsensitiveDelete()
{
var planBuilder = new ExecutionPlanBuilder(new SessionContext(_localDataSources, this), this);

var query = "DELETE FROM Account WHERE name = 'bar'";

var plans = planBuilder.Build(query, null, out _);

Assert.AreEqual(1, plans.Length);

var delete = AssertNode<DeleteNode>(plans[0]);
Assert.AreEqual("account", delete.LogicalName);
Assert.AreEqual("accountid", delete.PrimaryIdAccessors.Single().TargetAttribute);
Assert.AreEqual("Account.accountid", delete.PrimaryIdAccessors.Single().SourceAttributes.Single());
var fetch = AssertNode<FetchXmlScan>(delete.Source);
Assert.AreEqual("Account", fetch.Alias);
AssertFetchXml(fetch, @"
<fetch>
<entity name='account'>
<attribute name='accountid' />
<filter>
<condition attribute='name' operator='eq' value='bar' />
</filter>
</entity>
</fetch>");
}

[TestMethod]
public void SimpleInsertSelect()
{
Expand Down Expand Up @@ -3414,6 +3472,26 @@ public void SimpleInsertSelect()
</fetch>");
}

[TestMethod]
public void CaseInsensitiveInsert()
{
var planBuilder = new ExecutionPlanBuilder(new SessionContext(_localDataSources, this), this);

var query = "INSERT INTO Account (Name) VALUES ('Data8')";

var plans = planBuilder.Build(query, null, out _);

Assert.AreEqual(1, plans.Length);

var insert = AssertNode<InsertNode>(plans[0]);
Assert.AreEqual("account", insert.LogicalName);
Assert.AreEqual("name", insert.Accessors.Single().TargetAttribute);
Assert.AreEqual("Expr2", insert.Accessors.Single().SourceAttributes.Single());
var constantScan = AssertNode<ConstantScanNode>(insert.Source);
Assert.AreEqual("Expr2", constantScan.Schema.Single().Key);
Assert.AreEqual(1, constantScan.Values.Count);
}

[TestMethod]
public void SelectDuplicateColumnNames()
{
Expand Down
2 changes: 1 addition & 1 deletion MarkMpn.Sql4Cds.Engine/ExecutionPlanBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,7 @@ private InsertNode ConvertInsertSpecification(NamedTableReference target, IList<
var node = new InsertNode
{
DataSource = dataSource.Name,
LogicalName = logicalName,
LogicalName = metadata.LogicalName,
Source = reader.Source,
Accessors = reader.ValidateInsertColumnMapping(targetColumns, sourceColumns)
};
Expand Down

0 comments on commit 99d1f36

Please sign in to comment.