本文整理汇总了C#中IQueryContext.RegisterQuery方法的典型用法代码示例。如果您正苦于以下问题:C# IQueryContext.RegisterQuery方法的具体用法?C# IQueryContext.RegisterQuery怎么用?C# IQueryContext.RegisterQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IQueryContext
的用法示例。
在下文中一共展示了IQueryContext.RegisterQuery方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
/// <summary>
/// This method transforms the input SQL query into a set of statements,
/// prepares and executes them against the provided context.
/// </summary>
/// <param name="context">The context used to prepare and execute the statements
/// resolved from the compilation of the input query.</param>
/// <param name="query">The input SQL query with optional parameters, that is
/// compiled into a set of statements to be executed.</param>
/// <remarks>
/// The method first tries to resolve the compiled statements from the specialized
/// cache (<see cref="StatementCache"/>) from the system, to reduce the compilation time.
/// </remarks>
/// <returns>
/// Returns an array of <see cref="ITable"/> objects that represent the results
/// of the execution of the input query.
/// </returns>
public static ITable[] Execute(IQueryContext context, SqlQuery query)
{
if (query == null)
throw new ArgumentNullException("query");
var sqlSouce = query.Text;
// TODO: find it from the cache...
var statements = SqlStatement.Parse(sqlSouce);
// TODO: set it in cache ...
var preparer = new QueryPreparer(query);
bool statementSeen = false;
var results = new List<ITable>();
foreach (var statement in statements) {
context.RegisterQuery(statement);
// TODO: Invoke diagnostics for the preparation...
var prepared = statement.Prepare(preparer, context);
ITable result;
try {
result = prepared.Execute(context);
} catch(StatementException ex) {
context.RegisterError(ex);
throw;
} catch (Exception ex) {
var sex = new StatementException("An unhanded error occurred while executing the statement.", ex);
context.RegisterError(sex);
throw sex;
} finally {
statementSeen = true;
}
results.Add(result);
}
if (!statementSeen)
throw new SqlParseException("The input query was not parsed in any statements that could be executed.");
return results.ToArray();
}