這裏非常感謝是演示代碼,他們提供...(taken from here):
「 這個演示說明如何快速查找腳本中的各種SQL語句查找PLSQL塊/ package/procedure/function中的所有SQL語句;在select/delete/update語句中查找嵌套的子查詢;查找union select中的查詢聲明;查找where子句中的子查詢,選擇列表等。 「
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using gudusoft.gsqlparser;
using gudusoft.gsqlparser.Units;
namespace findsubquerys
{
class prg
{
static void Main(string[] args)
{
int c = Environment.TickCount;
if (args.Length == 0)
{
Console.WriteLine("{0} scriptfile", "syntaxcheck");
return;
}
TGSqlParser sqlparser = new TGSqlParser(TDbVendor.DbVMssql);
sqlparser.Sqlfilename = args[0];
int iRet = sqlparser.Parse();
if (iRet == 0)
{
foreach (TCustomSqlStatement stmt in sqlparser.SqlStatements)
{
printStmt(stmt);
}
}
else
{
Console.WriteLine("Syntax error found in input sql:");
Console.WriteLine(sqlparser.ErrorMessages);
}
}
static void printStmt(TCustomSqlStatement pstmt)
{
Console.WriteLine(pstmt.AsText+"\n");
for (int j = 0; j < pstmt.ChildNodes.Count(); j++)
{
if (pstmt.ChildNodes[j] is TCustomSqlStatement)
{
printStmt((TCustomSqlStatement)(pstmt.ChildNodes[j]));
}
}
}
} //class
}
Thx例如,我設法運行您的代碼,printStmt以新行打印每條語句。這裏是輸出: –