Пример #1
0
        public static string FormatTSql(this string tSql, string sqlHash)
        {
            if (string.IsNullOrWhiteSpace(tSql))
            {
                return(string.Empty);
            }

            string formattedTSql;

            if (_formattedSql.TryGetValue(sqlHash, out formattedTSql))
            {
                return(formattedTSql);
            }

            var sqlFragment = SqlFragmentProvider.GetSqlFragment(tSql, sqlHash, readFromCache: false);

            if (sqlFragment == null)
            {
                return(tSql);
            }

            var scriptGenerator = new Sql120ScriptGenerator(new SqlScriptGeneratorOptions
            {
                SqlVersion    = SqlVersion.Sql120,
                KeywordCasing = KeywordCasing.Uppercase
            });

            scriptGenerator.GenerateScript(sqlFragment, out formattedTSql);
            formattedTSql = !string.IsNullOrWhiteSpace(formattedTSql) ? formattedTSql.Trim() : tSql;

            _formattedSql.Add(sqlHash, formattedTSql);
            return(formattedTSql);
        }
Пример #2
0
        public static TSqlScript AnalyzeFragmentVisitor(string tSql, string sqlHash, TSqlFragmentVisitor visitor)
        {
            var sqlFragment = SqlFragmentProvider.GetSqlFragment(tSql, sqlHash);

            if (sqlFragment == null)
            {
                throw new InvalidOperationException(string.Format("Failed to get sqlFragment of \n{0}", tSql));
            }

            sqlFragment.Accept(visitor);
            return(sqlFragment);
        }
Пример #3
0
        public static void AnalyzeFragmentVisitor(string tSql, string sqlHash, TSqlFragmentVisitor visitor)
        {
            var sqlFragment = SqlFragmentProvider.GetSqlFragment(tSql, sqlHash);

            sqlFragment.Accept(visitor);
        }