Skip to content

Commit

Permalink
Merge pull request #115 from MarkMpn/execution-plan
Browse files Browse the repository at this point in the history
Integration
  • Loading branch information
MarkMpn authored Sep 25, 2021
2 parents a6c6a38 + fb435d9 commit 7f7a80e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion MarkMpn.Sql4Cds.Engine/ExecutionPlan/BaseDataNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ private bool TranslateFetchXMLCriteriaWithVirtualAttributes(EntityMetadata meta,
else
dto = new DateTimeOffset(dt, TimeSpan.Zero);

var formatted = dto.ToString("yyyy-MM-ddTHH:mm:ss.FFFzzz");
var formatted = dto.ToString("yyyy-MM-ddTHH':'mm':'ss.FFFzzz");

if (literals.Length == 1)
value = formatted;
Expand Down
40 changes: 26 additions & 14 deletions MarkMpn.Sql4Cds/PluginControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,14 @@ public void OnIncomingMessage(MessageBusEventArgs message)

if (param == null)
{
var xml = message.TargetArgument as string;
var str = message.TargetArgument as string;
param = new Dictionary<string, object>();
param["FetchXml"] = xml;

if (str.StartsWith("<"))
param["FetchXml"] = str;
else
param["SQL"] = str;

param["ConvertOnly"] = false;
}

Expand All @@ -255,24 +260,31 @@ public void OnIncomingMessage(MessageBusEventArgs message)
var con = _objectExplorer.SelectedConnection;
var metadata = _metadata[con];

var fetch = DeserializeFetchXml((string)param["FetchXml"]);
var options = new FetchXml2SqlOptions();
if (param.TryGetValue("FetchXml", out var xml) && xml is string xmlStr && !String.IsNullOrEmpty(xmlStr))
{
var fetch = DeserializeFetchXml(xmlStr);
var options = new FetchXml2SqlOptions();

if ((bool)param["ConvertOnly"])
options.ConvertFetchXmlOperatorsTo = FetchXmlOperatorConversion.SqlCalculations;
if ((bool)param["ConvertOnly"])
options.ConvertFetchXmlOperatorsTo = FetchXmlOperatorConversion.SqlCalculations;

_ai.TrackEvent("Convert", new Dictionary<string, string> { ["QueryType"] = "FetchXML", ["Source"] = "XrmToolBox" });
_ai.TrackEvent("Convert", new Dictionary<string, string> { ["QueryType"] = "FetchXML", ["Source"] = "XrmToolBox" });

var sql = FetchXml2Sql.Convert(con.ServiceClient, metadata, fetch, options, out _);
var sql = FetchXml2Sql.Convert(con.ServiceClient, metadata, fetch, options, out _);

if ((bool)param["ConvertOnly"])
{
param["Sql"] = sql;
OnOutgoingMessage(this, new MessageBusEventArgs(message.SourcePlugin) { TargetArgument = null });
if ((bool)param["ConvertOnly"])
{
param["Sql"] = sql;
OnOutgoingMessage(this, new MessageBusEventArgs(message.SourcePlugin) { TargetArgument = null });
}
else
{
CreateQuery(con, "-- Imported from " + message.SourcePlugin + "\r\n\r\n" + sql);
}
}
else
else if (param.TryGetValue("SQL", out var sql) && sql is string sqlStr && !String.IsNullOrEmpty(sqlStr))
{
CreateQuery(con, "-- Imported from " + message.SourcePlugin + "\r\n\r\n" + sql);
CreateQuery(con, "-- Imported from " + message.SourcePlugin + "\r\n\r\n" + sqlStr);
}
}

Expand Down

0 comments on commit 7f7a80e

Please sign in to comment.