Hello,
Try this (by simple select)
Code: Select all
function Utworz_ID(P1,P2:string):string;
var
UP:TUniQuery;
begin
UQ:=TUniQuery.Create(nil);
UQ.Connection:=DM_01.UniConnection1;
UQ.SQL.Add('SELECT utworz_id('+P1+','+P2+') Res FROM Table');
UQ.Open;
Result:=UQ.FieldByName('Res').AsString;
UQ.Close;
UQ.free;
end;
or this (by calling a stored procedure)
Code: Select all
function Utworz_ID(P1,P2:string):string;
var
UP:TUniStoredProc;
begin
UP:=TUniStoredProc.Create(nil);
UP.Connection:=DM_01.UniConnection1;
UP.StoredProcName:='utworz_id';
UP.Prepare; //here UP reads parameters defined in stored procedure
UP.ParamByName('PP1').ParamType := ptInput;
UP.ParamByName('PP1').DataType := ftString;
UP.ParamByName('PP1').AsString := P1;
UP.ParamByName('PP2').ParamType := ptInput;
UP.ParamByName('PP2').DataType := ftString;
UP.ParamByName('PP2').AsString := P2;
UP.Execute;
Result:= UP.ParamByName('Result').AsString; // when procedure returns only one variable
Result:= UP.ParamByName('Res_1').AsString; //when procedure returns a few variables
Result:= UP.ParamByName('Res_2').AsString; //when procedure returns a few variables
UP.Close;
UP.Free;
end;
When function returns a dataset, you can navigate through them using standard EOF() loop
Code: Select all
function Utworz_ID(P1,P2:string):string;
var
UP:TUniQuery;
begin
UQ:=TUniQuery.Create(nil);
UQ.Connection:=DM_01.UniConnection1;
UQ.SQL.Add('SELECT utworz_id('+P1+','+P2+') FROM Table'); //returns dataset
UQ.Open;
while not UQ.EOF do begin
Field1:=UQ.FieldByName('Field1_name').AsString;
Field2:=UQ.FieldByName('Field2_name').AsInteger;
UQ.NEXT;
end;
UQ.Close;
UQ.free;
end;
Regards
Michal