Ejemplo n.º 1
0
        private void GenerateSqlButton_Click(object sender, EventArgs e)
        {
            string xmlStr = PlanXMLText.Text;

            if (string.IsNullOrEmpty(xmlStr))
            {
                return;
            }
            SpExecuteSqlText.Text = "";
            DirectSqlText.Text    = "";

            try
            {
                foreach (var res in StatementExtractor.ConvertPlanToStatements(xmlStr))
                {
                    if (!string.IsNullOrEmpty(SpExecuteSqlText.Text))
                    {
                        SpExecuteSqlText.Text += Environment.NewLine + Environment.NewLine;
                    }
                    SpExecuteSqlText.Text += res.SpExecSql;

                    if (!string.IsNullOrEmpty(DirectSqlText.Text))
                    {
                        DirectSqlText.Text += Environment.NewLine + Environment.NewLine;
                    }
                    DirectSqlText.Text += res.DirectSql;
                }
            }
            catch (XmlException)
            {
                SpExecuteSqlText.Text = "Wrong showplan XML format!";
                DirectSqlText.Text    = "Wrong showplan XML format!";
            }
        }
Ejemplo n.º 2
0
        static StatementExtractor Create(XmlDocument planXml)
        {
            XmlNamespaceManager xmlnsManager = new XmlNamespaceManager(planXml.NameTable);

            xmlnsManager.AddNamespace("p", "http://schemas.microsoft.com/sqlserver/2004/07/showplan");

            XmlNode showPlanNode = planXml.SelectSingleNode("/p:ShowPlanXML", xmlnsManager);

            if (showPlanNode == null)
            {
                throw new InvalidOperationException("ShowPlanXML node missing.");
            }

            StatementExtractor extractor = null;

            var version = new Version(showPlanNode.Attributes["Build"].Value);

            if (version >= version2016SP1)
            {
                extractor = new StatementExtractor()
                {
                    PlanXml      = planXml,
                    XmlnsManager = xmlnsManager
                };
            }
            else
            {
                extractor = new StatementExtractorPre2016SP1()
                {
                    PlanXml      = planXml,
                    XmlnsManager = xmlnsManager
                };
            }

            return(extractor);
        }