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); }
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); }
public static void AnalyzeFragmentVisitor(string tSql, string sqlHash, TSqlFragmentVisitor visitor) { var sqlFragment = SqlFragmentProvider.GetSqlFragment(tSql, sqlHash); sqlFragment.Accept(visitor); }