Skip to content

Commit

Permalink
Merge pull request #123 from MarkMpn/cross-instance
Browse files Browse the repository at this point in the history
Cross instance
+semver:minor
  • Loading branch information
MarkMpn authored Nov 13, 2021
2 parents cdd28bc + b815ac9 commit a8c170a
Show file tree
Hide file tree
Showing 75 changed files with 1,928 additions and 913 deletions.
19 changes: 19 additions & 0 deletions MarkMpn.Sql4Cds.Engine.FetchXml.Tests/FetchXml2SqlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,25 @@ public void EqBusinessId()
Assert.AreEqual($"SELECT firstname, lastname FROM contact WHERE parentcustomerid = '{WhoAmIHandler.BusinessUnitId:D}'", NormalizeWhitespace(converted));
}

[TestMethod]
public void EqUserId()
{
var metadata = new AttributeMetadataCache(_service);
var fetch = @"
<fetch>
<entity name='account'>
<attribute name='name' />
<filter>
<condition attribute='ownerid' operator='eq-userid' />
</filter>
</entity>
</fetch>";

var converted = FetchXml2Sql.Convert(_service, metadata, fetch, new FetchXml2SqlOptions { ConvertFetchXmlOperatorsTo = FetchXmlOperatorConversion.SqlCalculations }, out _);

Assert.AreEqual("SELECT name FROM account WHERE ownerid = CURRENT_USER", NormalizeWhitespace(converted));
}

private static string NormalizeWhitespace(string s)
{
return Regex.Replace(s, "\\s+", " ");
Expand Down
32 changes: 32 additions & 0 deletions MarkMpn.Sql4Cds.Engine.FetchXml/ScriptDom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,34 @@ enum UnaryExpressionType
Negative
}

class ParameterlessCall : ScalarExpression
{
public ParameterlessCallType ParameterlessCallType { get; set; }

public override void Accept(TSqlFragmentVisitor visitor)
{
visitor.ExplicitVisit(this);
}

public override void ToString(StringBuilder buf, int indent)
{
switch (ParameterlessCallType)
{
case ParameterlessCallType.CurrentUser:
buf.Append("CURRENT_USER");
break;

default:
throw new NotSupportedException();
}
}
}

enum ParameterlessCallType
{
CurrentUser
}

class ScalarSubquery
{
public QueryExpression QueryExpression { get; set; }
Expand Down Expand Up @@ -1642,6 +1670,10 @@ public virtual void ExplicitVisit(UnaryExpression unaryExpression)
{
}

public virtual void ExplicitVisit(ParameterlessCall unaryExpression)
{
}

public virtual void ExplicitVisit(FullTextPredicate fullTextPredicate)
{
}
Expand Down
33 changes: 13 additions & 20 deletions MarkMpn.Sql4Cds.Engine.Tests/ExecutionPlanNodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ namespace MarkMpn.Sql4Cds.Engine.Tests
[TestClass]
public class ExecutionPlanNodeTests : FakeXrmEasyTestsBase
{
private readonly IAttributeMetadataCache _metadata;

public ExecutionPlanNodeTests()
{
_metadata = new AttributeMetadataCache(_service);
}

[TestMethod]
public void ConstantScanTest()
{
Expand All @@ -42,7 +35,7 @@ public void ConstantScanTest()
}
};

var results = node.Execute(_service, _metadata, new StubOptions(), null, null).ToArray();
var results = node.Execute(_dataSources, new StubOptions(), null, null).ToArray();

Assert.AreEqual(1, results.Length);
Assert.AreEqual("Mark", ((SqlString)results[0]["firstname"]).Value);
Expand Down Expand Up @@ -82,7 +75,7 @@ public void FilterNodeTest()
}
};

var results = node.Execute(_service, _metadata, new StubOptions(), null, null).ToArray();
var results = node.Execute(_dataSources, new StubOptions(), null, null).ToArray();

Assert.AreEqual(1, results.Length);
Assert.AreEqual("Mark", ((SqlString)results[0]["firstname"]).Value);
Expand Down Expand Up @@ -137,7 +130,7 @@ public void MergeJoinInnerTest()
JoinType = QualifiedJoinType.Inner
};

var results = node.Execute(_service, _metadata, new StubOptions(), null, null).ToArray();
var results = node.Execute(_dataSources, new StubOptions(), null, null).ToArray();

Assert.AreEqual(2, results.Length);
Assert.AreEqual("Mark", ((SqlString)results[0]["f.firstname"]).Value);
Expand Down Expand Up @@ -197,7 +190,7 @@ public void MergeJoinLeftOuterTest()
JoinType = QualifiedJoinType.LeftOuter
};

var results = node.Execute(_service, _metadata, new StubOptions(), null, null).ToArray();
var results = node.Execute(_dataSources, new StubOptions(), null, null).ToArray();

Assert.AreEqual(3, results.Length);
Assert.AreEqual("Mark", ((SqlString)results[0]["f.firstname"]).Value);
Expand Down Expand Up @@ -259,7 +252,7 @@ public void MergeJoinRightOuterTest()
JoinType = QualifiedJoinType.RightOuter
};

var results = node.Execute(_service, _metadata, new StubOptions(), null, null).ToArray();
var results = node.Execute(_dataSources, new StubOptions(), null, null).ToArray();

Assert.AreEqual(3, results.Length);
Assert.AreEqual("Mark", ((SqlString)results[0]["f.firstname"]).Value);
Expand Down Expand Up @@ -287,7 +280,7 @@ public void AssertionTest()
ErrorMessage = "Only Mark is allowed"
};

var results = node.Execute(_service, _metadata, new StubOptions(), null, null).GetEnumerator();
var results = node.Execute(_dataSources, new StubOptions(), null, null).GetEnumerator();

Assert.IsTrue(results.MoveNext());
Assert.AreEqual("Mark", results.Current.GetAttributeValue<SqlString>("name").Value);
Expand Down Expand Up @@ -337,7 +330,7 @@ public void ComputeScalarTest()
}
};

var results = node.Execute(_service, _metadata, new StubOptions(), null, null)
var results = node.Execute(_dataSources, new StubOptions(), null, null)
.Select(e => e.GetAttributeValue<SqlInt32>("mul").Value)
.ToArray();

Expand Down Expand Up @@ -366,7 +359,7 @@ public void DistinctTest()
}
};

var results = node.Execute(_service, _metadata, new StubOptions(), null, null)
var results = node.Execute(_dataSources, new StubOptions(), null, null)
.Select(e => e.GetAttributeValue<SqlInt32>("value1").Value)
.ToArray();

Expand Down Expand Up @@ -395,7 +388,7 @@ public void DistinctCaseInsensitiveTest()
}
};

var results = node.Execute(_service, _metadata, new StubOptions(), null, null)
var results = node.Execute(_dataSources, new StubOptions(), null, null)
.Select(e => e.GetAttributeValue<SqlString>("value1").Value)
.ToArray();

Expand Down Expand Up @@ -437,7 +430,7 @@ public void SortNodeTest()
}
};

var results = node.Execute(_service, _metadata, new StubOptions(), null, null)
var results = node.Execute(_dataSources, new StubOptions(), null, null)
.Select(e => e.GetAttributeValue<SqlInt32>("expectedorder").Value)
.ToArray();

Expand Down Expand Up @@ -481,7 +474,7 @@ public void SortNodePresortedTest()
}
};

var results = node.Execute(_service, _metadata, new StubOptions(), null, null)
var results = node.Execute(_dataSources, new StubOptions(), null, null)
.Select(e => e.GetAttributeValue<SqlInt32>("expectedorder").Value)
.ToArray();

Expand All @@ -506,11 +499,11 @@ public void TableSpoolTest()

var spool = new TableSpoolNode { Source = source };

var results1 = spool.Execute(_service, _metadata, new StubOptions(), null, null)
var results1 = spool.Execute(_dataSources, new StubOptions(), null, null)
.Select(e => e.GetAttributeValue<SqlInt32>("value1").Value)
.ToArray();

var results2 = spool.Execute(_service, _metadata, new StubOptions(), null, null)
var results2 = spool.Execute(_dataSources, new StubOptions(), null, null)
.Select(e => e.GetAttributeValue<SqlInt32>("value1").Value)
.ToArray();

Expand Down
Loading

0 comments on commit a8c170a

Please sign in to comment.