解析SQL语句 [英] Parse SQL statement
本文介绍了解析SQL语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在不使用ActiveQueryBuilder的情况下解析SQL语句(用于SQL Server)以提取列和参数信息(名称,数据类型).
How can I parse a SQL statement (for SQL Server) to extract columns and parameters info (Name, DataType) without using ActiveQueryBuilder.
致谢
推荐答案
您可以尝试使用 TSql100Parser类
链接: http://msdn.microsoft.com/fr-fr/library/microsoft.data.schema.scriptdom.sql.tsql100parser.aspx
样品:
bool fQuotedIdenfifiers = false;
var _parser = new TSql100Parser(fQuotedIdenfifiers);
SqlScriptGeneratorOptions options = new SqlScriptGeneratorOptions();
options.SqlVersion = SqlVersion.Sql100;
options.KeywordCasing = KeywordCasing.UpperCase;
_scriptGen = new Sql100ScriptGenerator(options);
IScriptFragment fragment;
IList<ParseError> errors;
using (StringReader sr = new StringReader(inputScript))
{
fragment = _parser.Parse(sr, out errors);
}
if (errors != null && errors.Count > 0)
{
StringBuilder sb = new StringBuilder();
foreach (var error in errors)
{
sb.AppendLine(error.Message);
sb.AppendLine("offset " + error.Offset.ToString());
}
var errorsList = sb.ToString();
}
else
{
String script;
_scriptGen.GenerateScript(fragment, out script);
var result = script;
}
这篇关于解析SQL语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文