/// <summary> Executes a D4 script. </summary> public static void ExecuteScript(string script, IServer server, SessionInfo sessionInfo) { IServerSession session = server.Connect(sessionInfo); try { IServerProcess process = session.StartProcess(new ProcessInfo(sessionInfo)); try { IServerScript localScript = process.PrepareScript(script); try { localScript.Execute(null); } finally { process.UnprepareScript(localScript); } } finally { session.StopProcess(process); } } finally { server.Disconnect(session); } }
public void ExecuteScript(IServerProcess process, string script, DAE.Runtime.DataParams paramsValue) { if (process == null) { process = DataSession.UtilityProcess; } DAE.IServerScript localScript = process.PrepareScript(script); try { foreach (DAE.IServerBatch batch in localScript.Batches) { if (batch.IsExpression()) { DAE.IServerExpressionPlan plan = batch.PrepareExpression(paramsValue); try { ErrorList errors = new ErrorList(); errors.AddRange(plan.Messages); ReportErrors(null, errors); if (plan.DataType is DAE.Schema.TableType) { plan.Close(plan.Open(paramsValue)); } else { plan.Evaluate(paramsValue).Dispose(); } } finally { batch.UnprepareExpression(plan); } } else { DAE.IServerStatementPlan plan = batch.PrepareStatement(paramsValue); try { ErrorList errors = new ErrorList(); errors.AddRange(plan.Messages); ReportErrors(null, errors); plan.Execute(paramsValue); } finally { batch.UnprepareStatement(plan); } } } } finally { process.UnprepareScript(localScript); } }
/// <summary>Executes the given script using the given process.</summary> public void ExecuteScript(IServerProcess process, string script, DAE.Runtime.DataParams paramsValue) { if (script != String.Empty) { CheckActive(); if (process == null) { process = UtilityProcess; } IServerScript localScript = process.PrepareScript(script); try { localScript.Execute(paramsValue); } finally { process.UnprepareScript(localScript); } } }
public void Prepare() { _resultPanel.Clear(); PrepareForExecute(); var result = new StringBuilder(); var errors = new ErrorList(); try { using (var statusForm = new StatusForm(Strings.ProcessingQuery)) { bool attemptExecute = true; try { DateTime startTime = DateTime.Now; try { IServerScript script; IServerProcess process = DataSession.ServerSession.StartProcess( new ProcessInfo(DataSession.ServerSession.SessionInfo)); try { script = process.PrepareScript(GetTextToExecute()); try { if (ScriptExecutionUtility.ConvertParserErrors(script.Messages, errors)) { foreach (IServerBatch batch in script.Batches) { if (batch.IsExpression()) { IServerExpressionPlan plan = batch.PrepareExpression(null); try { attemptExecute &= ScriptExecutionUtility.ConvertCompilerErrors(plan.Messages, errors); if (attemptExecute) { result.AppendFormat ( Strings.PrepareSuccessful, new object[] { plan.PlanStatistics.PrepareTime.ToString(), plan.PlanStatistics.CompileTime.ToString(), plan.PlanStatistics.OptimizeTime.ToString(), plan.PlanStatistics.BindingTime.ToString() } ); result.Append("\r\n"); } } finally { batch.UnprepareExpression(plan); } } else { IServerStatementPlan plan = batch.PrepareStatement(null); try { attemptExecute &= ScriptExecutionUtility.ConvertCompilerErrors(plan.Messages, errors); if (attemptExecute) { result.AppendFormat ( Strings.PrepareSuccessful, new object[] { plan.PlanStatistics.PrepareTime.ToString(), plan.PlanStatistics.CompileTime.ToString(), plan.PlanStatistics.OptimizeTime.ToString(), plan.PlanStatistics.BindingTime.ToString() } ); result.Append("\r\n"); } } finally { batch.UnprepareStatement(plan); } } AppendResultPanel(result.ToString()); result.Length = 0; } } } finally { process.UnprepareScript(script); } } finally { DataSession.ServerSession.StopProcess(process); } } finally { TimeSpan elapsed = DateTime.Now - startTime; _executionTimeStatus.Text = elapsed.ToString(); } if (attemptExecute) { SetStatus(Strings.ScriptPrepareSuccessful); } else { SetStatus(Strings.ScriptPrepareFailed); } } catch (Exception exception) { SetStatus(Strings.ScriptFailed); errors.Add(exception); } } } finally { ProcessErrors(errors); } }
public NativeResult Execute(string statement, NativeParam[] paramsValue, NativeExecutionOptions options) { IServerScript script = _process.PrepareScript(statement); try { if (script.Batches.Count != 1) { throw new ArgumentException("Execution statement must contain one, and only one, batch."); } IServerBatch batch = script.Batches[0]; DataParams dataParams = NativeMarshal.NativeParamsToDataParams((Server.ServerProcess)_process, paramsValue); NativeResult result = new NativeResult(); result.Params = paramsValue; if (batch.IsExpression()) { IServerExpressionPlan expressionPlan = batch.PrepareExpression(dataParams); try { if (expressionPlan.DataType is Schema.TableType) { if (options != NativeExecutionOptions.SchemaOnly) { IServerCursor cursor = expressionPlan.Open(dataParams); try { result.Value = NativeMarshal.ServerCursorToNativeValue(_process, cursor); } finally { expressionPlan.Close(cursor); } } else { result.Value = NativeMarshal.TableVarToNativeTableValue(_process, expressionPlan.TableVar); } } else { if (options != NativeExecutionOptions.SchemaOnly) { using (IDataValue tempValue = expressionPlan.Evaluate(dataParams)) { result.Value = NativeMarshal.DataValueToNativeValue(_process, tempValue); } } else { result.Value = NativeMarshal.DataTypeToNativeValue(_process, expressionPlan.DataType); } } } finally { batch.UnprepareExpression(expressionPlan); } } else { IServerStatementPlan statementPlan = batch.PrepareStatement(dataParams); try { if (options != NativeExecutionOptions.SchemaOnly) { statementPlan.Execute(dataParams); } } finally { batch.UnprepareStatement(statementPlan); } } if (options != NativeExecutionOptions.SchemaOnly) { NativeMarshal.SetNativeOutputParams(_process, result.Params, dataParams); } return(result); } finally { _process.UnprepareScript(script); } }
public static void ExecuteScript(IServerProcess process, string script, ScriptExecuteOption options, out ErrorList errors, out TimeSpan timeElapsed, ReportScriptProgressHandler reportScriptProgress, DebugLocator locator) { StringBuilder result = new StringBuilder(); errors = new ErrorList(); timeElapsed = TimeSpan.Zero; bool attemptExecute = true; DateTime startTime = DateTime.Now; try { IServerScript localScript = process.PrepareScript(script, locator); try { if (ConvertParserErrors(localScript.Messages, errors)) { foreach (IServerBatch batch in localScript.Batches) { PlanStatistics statistics = null; try { if (batch.IsExpression()) { IServerExpressionPlan plan = batch.PrepareExpression(null); try { attemptExecute &= ConvertCompilerErrors(plan.Messages, errors); if (attemptExecute) { int rowCount = ReadResult(result, plan); AppendStatistics(result, options, plan.PlanStatistics, plan.ProgramStatistics, rowCount); statistics = plan.PlanStatistics; } } finally { batch.UnprepareExpression(plan); } } else { IServerStatementPlan plan = batch.PrepareStatement(null); try { attemptExecute &= ConvertCompilerErrors(plan.Messages, errors); if (attemptExecute) { plan.Execute(null); AppendStatistics(result, options, plan.PlanStatistics, plan.ProgramStatistics, -1); statistics = plan.PlanStatistics; } } finally { batch.UnprepareStatement(plan); } } } finally { if (reportScriptProgress != null) { reportScriptProgress(statistics, result.ToString()); } result.Length = 0; } } // foreach batch... } // if (no parser errors)... } finally { process.UnprepareScript(localScript); } } catch (Exception exception) { errors.Add(exception); } timeElapsed = DateTime.Now - startTime; }
private DataFhirServerResult Execute(IServerProcess process, string statement, DataParam[] paramsValue) { IServerScript script = process.PrepareScript(statement); try { if (script.Batches.Count != 1) { throw new ArgumentException("Execution statement must contain one, and only one, batch."); } IServerBatch batch = script.Batches[0]; DataParams dataParams = DataFhirMarshal.ParamsArrayToDataParams(process, paramsValue); DataFhirServerResult result = new DataFhirServerResult(); result.Params = paramsValue; if (batch.IsExpression()) { IServerExpressionPlan expressionPlan = batch.PrepareExpression(dataParams); try { if (expressionPlan.DataType is TableType) { IServerCursor cursor = expressionPlan.Open(dataParams); try { result.Value = DataFhirMarshal.ServerCursorToValue(process, cursor); } finally { expressionPlan.Close(cursor); } } else { using (IDataValue tempValue = expressionPlan.Evaluate(dataParams)) { result.Value = DataFhirMarshal.DataValueToValue(process, tempValue); } } } finally { batch.UnprepareExpression(expressionPlan); } } else { IServerStatementPlan statementPlan = batch.PrepareStatement(dataParams); try { statementPlan.Execute(dataParams); } finally { batch.UnprepareStatement(statementPlan); } } //DotNetMarshal.SetNativeOutputParams(process, result.Params, dataParams); return(result); } finally { process.UnprepareScript(script); } }