SmartSQL/SmartSQL.Framework/TsqlFormat.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using TSqlFormatter;
using TSqlFormatter.Formatters;
namespace SmartSQL.Framework
{
public static class TsqlFormatHelper
{
/// <summary>
/// Sql格式化
/// </summary>
/// <param name="strSql"></param>
/// <param name="caseWrite"></param>
/// <returns></returns>
public static string SqlFormat(this string strSql, bool caseWrite = true)
{
string result;
if (string.IsNullOrEmpty(strSql))
return strSql;
try
{
var errorsEncountered = false;
var formaterManager = new SqlFormattingManager();
var formater = (TSqlStandardFormatter)formaterManager.Formatter;
formater.Options.UppercaseKeywords = caseWrite;
result = formaterManager.Format(strSql, ref errorsEncountered);
}
catch (Exception)
{
result = strSql;
}
return result;
}
public static string SqlFormatToString(string strSql, bool caseWrite)
{
return SqlFormat(strSql, caseWrite);
}
/// <summary>
/// sql压缩
/// </summary>
/// <param name="strsql"></param>
/// <returns></returns>
public static string CompressToString(string strSql)
{
string result = string.Empty;
strSql = strSql.Replace("//", "");
strSql = strSql.Replace('\r', ' ');
strSql = strSql.Replace('\n', ' ');
char[] char_array = strSql.ToCharArray();
var char_list = new List<char>();
int space_count = 0;
for (int i = 0, len = char_array.Length; i < len; i++)
{
后面还有 21 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读 AI
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
