Пример #1
0
        private void RewriteNonSargableIsNull(object sender, EventArgs e)
        {
            try
            {
                var oldDoc = GetCurrentDocumentText();
                var newDoc = oldDoc;

                var rewriter = new NonSargableRewrites(oldDoc);
                var queries  = ScriptDom.GetQuerySpecifications(oldDoc);
                foreach (var rep in rewriter.GetReplacements(queries))
                {
                    newDoc = newDoc.Replace(rep.Original, rep.Replacement);
                    OutputPane.WriteMessage("Non-Sargable IsNull re-written from \r\n\"{0}\" \r\nto\r\n\"{1}\"\r\n", rep.Original, rep.Replacement);
                }

                if (oldDoc != newDoc)
                {
                    SetCurrentDocumentText(newDoc);
                }
            }
            catch (Exception ex)
            {
                OutputPane.WriteMessage("Error re-writing non sargable isnulls {0}", ex.Message);
            }
        }
Пример #2
0
        private List <GlyphDefinition> GetGlyphDefinitions(List <TSqlStatement> statements, string script)
        {
            var definitions = new List <GlyphDefinition>();

            foreach (var statement in statements)
            {
                var definition = new GlyphDefinition();
                definition.Line            = statement.StartLine;
                definition.StatementOffset = statement.StartOffset;
                definition.Type            = GlyphDefinitonType.Normal;
                definition.LineCount       = statement.ScriptTokenStream.LastOrDefault().Line - definition.Line;
                definition.StatementLength = statement.FragmentLength;

                var fragment           = script.Substring(statement.StartOffset, statement.FragmentLength);
                var queriesInStatement = ScriptDom.GetQuerySpecifications(fragment);
                var deletes            = ScriptDom.GetDeleteStatements(fragment);

                foreach (var operation in _operations)
                {
                    try
                    {
                        definition = operation.GetDefintions(fragment, statement, definition, queriesInStatement);
                        definition = operation.GetDefintions(fragment, statement, definition, deletes);

                        definition = operation.GetDefinitions(fragment, statement, definition, new List <TSqlStatement>()
                        {
                            statement
                        });
                    }
                    catch (Exception e)
                    {
                    }
                }


                definitions.Add(definition);
            }

            return(definitions);
        }