Chamomile Wiki
SQL tools for documentation, error handling, logging, and testing.
Brought to you by:
kelightsey
Command pattern - The command pattern is a behavioral design pattern in which an object is used to represent and encapsulate all the information needed to call a method at a later time. This information includes the method name, the object that owns the method and values for the method parameters.
Command pattern using [xml]
- command object
- receiver object
declare @command [xml] =
N'<command>
<receiver>
<parameters>@output [xml] output</parameters>
<sql>select @output = (<select statement>
for xml path(output'), root(N'output_tree'));</sql>
</receiver>
</command>';
Setter / Run
- invoker object
declare procedure [workflow].[run] @workflow [xml]
as
declare @output [xml];
execute sp_execute
@sql=@workflow.value(N'(/command/receiver/sql/text())[1]', N'[nvarchar](max)'),
@parameters=@workflow.value(
N'(/command/receiver/parameters/text())[1]', N'[nvarchar](max)'),
@output=@output output;
go
Getter
-client object
declare procedure [workflow].[get] @workflow [xml]
as
set @workflow = (select [workflow] from [<table>]
where [workflow].<id> = @workflow.<id>);
if (@workflow is not null)
[workflow].[run] @workflow=@workflow;
go