unit wsunidb;
//{$I wsdefs.inc}
interface
uses SysUtils, Classes, Dialogs,strutils,
Variants,
DB,wsDB, MemDS, DBAccess, Uni,
UniProvider;
type
TWorkflowUNIDB = class(TCustomWorkflowDB)
private
FConnection: TUniConnection;
procedure SetConnection(const Value: TUniConnection);
protected
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
function DoCreateQuery(SQL: string): TDataset; override;
function DoExecuteQuery(Dataset: TDataset): integer; override;
procedure DoAssignSQLParams(Dataset: TDataset; AParams: TParams); override;
function BlobFieldToString(AField: TField): string; override;
public
constructor Create(AOwner: TComponent); override;
published
property Connection: TUniConnection read FConnection write SetConnection;
end;
procedure Register;
implementation
uses wsRes;
function Max(A, B: Integer): Integer;
begin
if A > B then
Result := A
else
Result := B;
end;
{ TWorkflowUNIDB }
constructor TWorkflowUNIDB.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
DestroyQueries := true;
end;
function TWorkflowUNIDB.BlobFieldToString(AField: TField): string;
var
BlobField: TBlobField;
StrStream: TStringStream;
c: integer;
IsOleStr: boolean;
begin
if AField is TBlobField then
begin
BlobField := TBlobField(AField);
StrStream := TStringStream.Create('');
try
BlobField.SaveToStream(StrStream);
StrStream.Position := 0;
result := StrStream.ReadString(StrStream.Size);
finally
StrStream.Free;
end;
end else
result := AField.AsString;
//{workaround to "tell" if the string is an Ole string}
IsOleStr := true;
c := 2;
while c < length(result) do
begin
if result[c] <> chr(0) then
begin
IsOleStr := false;
break;
end;
c := c + 2;
end;
//{remove #0 characters}
if IsOleStr then
begin
c := 2;
while c < length(result) do
begin
Delete(result, c, 1);
inc(c);
end;
end;
end;
function TWorkflowUNIDB.DoExecuteQuery(Dataset: TDataset): integer;
begin
TUniQuery(Dataset).Execute;
end;
function TWorkflowUNIDB.DoCreateQuery(SQL: string): TDataset;
var
Q: TUniQuery;
begin
Q := TUniQuery.Create(nil);
Q.Connection := FConnection;
Q.Params.Clear;
Q.SQL.Text := SQL;
result := Q;
end;
procedure TWorkflowUNIDB.DoAssignSQLParams(Dataset: TDataset; AParams: TParams);
var
Q: TUniQuery;
c: integer;
AParam: TParam;
begin
Q := TUniQuery(Dataset);
q.Params.ParseSQL(Q.SQL.Text, true);
for c := 0 to Q.Params.Count - 1 do
begin
AParam := AParams.FindParam(Q.Params[c].Name);
if AParam = nil then
begin
wsDBError(Format(_str(SErrorParamNotFound),
[Q.Params[c].Name]));
end;
Q.Params[c].DataType := AParam.DataType;
Q.Params[c].Value := AParam.Value;
if Q.Params[c].DataType in [ftString] then
Q.Params[c].Size := Max(1, Length(VarToSTr(Q.Params[c].Value)));
end;
end;
procedure TWorkflowUNIDB.Notification(AComponent: TComponent;
Operation: TOperation);
begin
if (Operation = opRemove) and (AComponent = FConnection) then
FConnection := nil;
inherited Notification(AComponent, Operation);
end;
procedure TWorkflowUNIDB.SetConnection(const Value: TUniConnection);
begin
if (FConnection <> Value) then
begin
FConnection := Value;
if Value <> nil then
Value.FreeNotification(Self);
end;
end;
procedure Register;
begin
RegisterComponents('Workflow Studio', [TWorkflowUNIDB]);
end;
end.
2,for example:
rwww:=WorkflowStudio.WorkflowManager.FindWorkflowInstanceByKey(wkfid);
rwww must be free manually?