111,046
社区成员
发帖
与我相关
我的任务
分享
Regex reg = new Regex(@"(?i)\bfrom\b(?![^\[\]]*\])\s+(\[[^\[\]]+\]|\S+)");
MatchCollection mc = reg.Matches(yourStr);
foreach (Match m in mc)
{
richTextBox2.Text += m.Groups[1].Value + "\n";
}
Regex reg = new Regex(@"(?in)\b(from|(left|right|INNER)\s+join)\b(?![^\[\]]*\])\s+(?<table>\[[^\[\]]+\]|\S+)");
MatchCollection mc = reg.Matches(yourStr);
foreach (Match m in mc)
{
richTextBox2.Text += m.Groups["table"].Value + "\n";
}
lblResult.Text = "";
TGSqlParser parser = new TGSqlParser(TDbVendor.DbVMssql);
parser.SqlText.Text = txtSQL.Text;
parser.Parse();
if (parser.ErrorCount > 0)
{
lblResult.Text += "发现了" + parser.ErrorCount.ToString() + "个错误。<br/>";
lblResult.Text += "错误信息:<br/>";
lblResult.Text += parser.ErrorMessages.Replace("\r\n", "<br/>");
lblResult.Text += "<br/><br/>";
}
TLzStatementList stmts = parser.SqlStatements;
for (int i = 0; i < stmts.Count(); i++)
{
TCustomSqlStatement stmt = stmts[i];
lblResult.Text += "第" + (i + 1).ToString() + "个语句:" + stmt.SqlStatementType.ToString() + "<br/>";
if (stmt.SqlStatementType == TSqlStatementType.sstSelect)
{
lblResult.Text += "查询结果字段:";
for (int j = 0; j < stmt.Fields.Count(); j++)
{
TLzField field = stmt.Fields[j];
if (field.IsHasAs && field.FieldAlias != "")
{
lblResult.Text += field.FieldAlias + ",";
}
else
{
lblResult.Text += field.FieldName + ",";
}
}
lblResult.Text += "<br/>";
}
lblResult.Text += "参数:";
for (int k = 0; k < stmt.SqlVars.Count(); k++)
{
TLzValue value = stmt.SqlVars[k];
lblResult.Text += value.ValueName + ",";
}
lblResult.Text += "<br/>";
lblResult.Text += "<br/>";
}