Ejemplo n.º 1
0
        public string FormatSQLTree(PoorMansTSqlFormatterLib.ParseStructure.Node sqlTree)
        {
            string formattedResult = _underlyingFormatter.FormatSQLTree(sqlTree);

            if (_underlyingFormatter.HTMLFormatted)
            {
                return(string.Format(HTML_OUTER_PAGE, formattedResult));
            }
            else
            {
                return(string.Format(HTML_OUTER_PAGE, Utils.HtmlEncode(formattedResult)));
            }
        }
        public void ContentUnchangedByIdentityTreeFormatter(string FileName)
        {
            string     inputSQL  = Utils.GetTestFileContent(FileName, Utils.INPUTSQLFOLDER);
            ITokenList tokenized = _tokenizer.TokenizeSQL(inputSQL);
            Node       parsed    = _parser.ParseSQL(tokenized);
            string     outputSQL = _treeFormatter.FormatSQLTree(parsed);

            Assert.AreEqual(inputSQL, outputSQL);
        }
Ejemplo n.º 3
0
        public void ContentUnchangedByIdentityTreeFormatter(string FileName)
        {
            string      inputSQL  = Utils.GetTestFileContent(FileName, Utils.INPUTSQLFOLDER);
            ITokenList  tokenized = _tokenizer.TokenizeSQL(inputSQL);
            XmlDocument parsed    = _parser.ParseSQL(tokenized);
            string      outputSQL = _treeFormatter.FormatSQLTree(parsed);

            if (!inputSQL.Contains(Utils.INVALID_SQL_WARNING))
            {
                Assert.AreEqual(outputSQL, inputSQL);
            }
        }
Ejemplo n.º 4
0
        public string FormatSQLTree(System.Xml.XmlDocument sqlTree)
        {
            string formattedResult = _underlyingFormatter.FormatSQLTree(sqlTree);

            if (_underlyingFormatter.HTMLFormatted)
            {
                return(string.Format(HTML_OUTER_PAGE, formattedResult));
            }
            else
            {
                return(string.Format(HTML_OUTER_PAGE, System.Web.HttpUtility.HtmlEncode(formattedResult)));
            }
        }
 public void CheckThatValidSqlRemainsUnchangedByIdentityTreeFormatter()
 {
     foreach (string inputSQL in Utils.FolderTextFileIterator(TestDataFolder))
     {
         ITokenList  tokenized = _tokenizer.TokenizeSQL(inputSQL);
         XmlDocument parsed    = _parser.ParseSQL(tokenized);
         string      outputSQL = _treeFormatter.FormatSQLTree(parsed);
         if (!inputSQL.Contains("THIS TEST FILE IS NOT VALID SQL"))
         {
             Assert.AreEqual <string>(outputSQL, inputSQL, "input and output should be the same, as this is a valid SQL file");
         }
     }
 }
Ejemplo n.º 6
0
        public string FormatSQLTree(BaiSqlFormatLib.ParseStructure.Node sqlTree)
        {
            string formattedResult = _underlyingFormatter.FormatSQLTree(sqlTree);
            string SqlHtml;

            if (_underlyingFormatter.HTMLFormatted)
            {
                SqlHtml = string.Format(HTML_OUTER_PAGE, formattedResult);
            }
            else
            {
                SqlHtml = string.Format(HTML_OUTER_PAGE, Utils.HtmlEncode(formattedResult));
            }


            return(SqlHtml);
        }
Ejemplo n.º 7
0
        private void DoFormatting()
        {
            var tokenizedSql = _tokenizer.TokenizeSQL(txt_Input.Text, txt_Input.SelectionStart);

            if (!splitContainer4.Panel2Collapsed && !splitContainer5.Panel1Collapsed)
            {
                txt_TokenizedSql.Text = tokenizedSql.PrettyPrint();
            }

            var parsedSql = _parser.ParseSQL(tokenizedSql);

            if (!splitContainer4.Panel2Collapsed && !splitContainer5.Panel2Collapsed)
            {
                txt_ParsedXml.Text = parsedSql.ToXmlDoc().OuterXml;
            }

            webBrowser_OutputSql.SetHTML(_formatter.FormatSQLTree(parsedSql));
        }
Ejemplo n.º 8
0
        private void DoFormatting()
        {
            strErrorReturn = "";
            const string  txtNewLine  = "\r\n---------------------------------------------------------------------------------------------------------------------------------------------------------\r\n\r\n";
            StringBuilder errorReturn = new StringBuilder();

            errorReturn.Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n");
            errorReturn.Append("输入SQL:\r\n" + txt_input.Text + txtNewLine);

            string _inputSql = txt_input.Text.ToLower();

            if (Properties.Settings.Default.AllUpper)
            {
                _inputSql = _inputSql.ToUpper();
            }

            string[] sqlInput = _inputSql.Split(new string[] { ";" }, StringSplitOptions.None);
            string   SqlHtml  = string.Empty;
            int      index    = 0;

            foreach (var sql in sqlInput)
            {
                string sql_new = string.Empty;
                if (sql.Trim() != "")
                {
                    index++;
                    sql_new = sql;
                    if (Properties.Settings.Default.addSemicolon)
                    {
                        sql_new += ";";
                    }
                    var    tokenizedSql = _tokenizer.TokenizeSQL(sql_new, sql_new.Length);
                    var    parsedSql    = _parser.ParseSQL(tokenizedSql);
                    string subSqlHtml   = _formatter.FormatSQLTree(parsedSql);

                    if (!subSqlHtml.ToLower().Contains(">comment<") &&
                        !subSqlHtml.ToLower().Contains(">comment<") && !subSqlHtml.ToLower().Contains(">string<") &&
                        !subSqlHtml.ToLower().Contains(">int<") && !subSqlHtml.ToLower().Contains(">bigint<") &&
                        !subSqlHtml.ToLower().Contains(">partitioned<") &&
                        chk_default.Checked && SubstringCount(subSqlHtml, "\r\n") > 110)
                    {
                        Properties.Settings.Default.ExpandCommaLists     = false;
                        Properties.Settings.Default.ExpandCaseStatements = false;
                        Properties.Settings.Default.AsAlign = false;
                        SetFormatter();

                        subSqlHtml = _formatter.FormatSQLTree(parsedSql);

                        Properties.Settings.Default.ExpandCommaLists     = true;
                        Properties.Settings.Default.ExpandCaseStatements = true;
                        Properties.Settings.Default.AsAlign = true;
                        SetFormatter();
                    }
                    errorReturn.Append("第 " + index + " 个子SQL字段标记结果:\r\n" + tokenizedSql.PrettyPrint() + txtNewLine);
                    errorReturn.Append("第 " + index + " 个子SQL解析结果:\r\n" + parsedSql.ToXmlDoc().OuterXml + txtNewLine);
                    errorReturn.Append("第 " + index + " 个子SQL生成html结果:\r\n" + subSqlHtml + txtNewLine);
                    SqlHtml += subSqlHtml;
                }
            }

            if (!chk_coloring.Checked)
            {
                SqlHtml = SqlHtml.Replace("#00AA00;", "#000000;").Replace("#AA0000;", "#000000;").Replace("#AA00AA;", "#000000;").Replace("#0000AA;", "#000000;").Replace("#777777;", "#000000;");
            }

            webBrowser_output.SetHTML(SqlHtml);
            errorReturn.Append("最终生成html:\r\n" + SqlHtml);
            strErrorReturn = errorReturn.ToString();

            if (errorReturn.ToString().Contains(MessagingConstants.FormatErrorDefaultMessage))
            {
                string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "logs";
                WriteLog.WriteFormatLog(path, "formatErrLog.log", strErrorReturn);
            }
        }