Board index » delphi » SQLStoredProc & Params

SQLStoredProc & Params


2003-10-12 01:00:54 AM
delphi16
Hi,
At design time, setting StoredProcName
will load the Params, which is just fine.
But, at run time, setting StoredProcName
just clears the Params.
How can the stored proc name be changed
at runtime and have the params loaded
as well (as the doc states)?
Thanks,
Roger
 
 

Re:SQLStoredProc & Params

It is case sensitive (using Firebird).
"Roger" <XXXX@XXXXX.COM>writes
Quote
Hi,
At design time, setting StoredProcName
will load the Params, which is just fine.
But, at run time, setting StoredProcName
just clears the Params.

How can the stored proc name be changed
at runtime and have the params loaded
as well (as the doc states)?

Thanks,
Roger


 

Re:SQLStoredProc & Params

I believe TParams is just some sort of a TCollection, so simply add the
appropriate Items to it and set their properties to accomplish your goal.
Look up ClientDataSet's Params property in the help.
HTH
Martin
Roger writes:
Quote
Hi,
At design time, setting StoredProcName
will load the Params, which is just fine.
But, at run time, setting StoredProcName
just clears the Params.

How can the stored proc name be changed
at runtime and have the params loaded
as well (as the doc states)?

Thanks,
Roger


 

Re:SQLStoredProc & Params

If you want you can try this, I Hope that it will be a good solution for you
there is two units plus one sample.
{ ************************ DBXGlobal
******************************************}
unit DBXGlobal;
interface
uses Classes,DB,SQLExpr;
function
InitialiseDbxProcParams(aConnection:TSQLConnection;aStoredProc:TSQLStoredPro
c):boolean;
implementation
function
InitialiseDbxProcParams(aConnection:TSQLConnection;aStoredProc:TSQLStoredPro
c):boolean;
var
paramList : TParams;
procParams : TList;
begin
result := false;
if Assigned(aConnection) and Assigned(aStoredProc) and
(aStoredProc.StoredProcName <>'') then
begin
procParams := TList.Create;
try
aConnection.GetProcedureParams(aStoredProc.StoredProcName,
aStoredProc.PackageName,
procParams);
paramList := TParams.Create;
try
LoadParamListItems(ParamList, ProcParams);
aStoredProc.Params.Assign(ParamList);
result := true;
finally
ParamList.Free;
end;
finally
FreeProcParams(ProcParams);
end;
end;
end;
end.
{ ************************ DBXStd
******************************************}
unit DBXStd;
interface
uses SQLExpr;
type
TBTSQLConnection = Class(TSQLConnection)
end;
TBTSQLMonitor = Class(TSQLMonitor)
protected
{ Can i have Béta Version, How Can I Rebuild Dbexpress package}
{ Why Desc^.eTraceCat Allways 256 and CallType Allways 1 with
OracleDriver
in function TSQLMonitor.InvokeCallBack(CallType: TRACECat; CBInfo:
Pointer): CBRType; stdcall;
Finally where is DBexpress 2.0 ???
}
// procedure Trace(Desc: pSQLTraceDesc; var LogTrace: Boolean);
override;
end;
TBTSQLDataset = Class(TSQLDataset)
end;
TBTSQLQuery = Class(TSQLQuery)
end;
TBTSQLStoredProc = Class(TSQLStoredProc)
private
fInitParms : boolean;
public
procedure PrepareStatement; override;
end;
implementation
uses DBXGlobal;
procedure TBTSQLStoredProc.PrepareStatement;
begin
if Assigned(SQLConnection) and (not fInitParms) then
begin
if InitialiseDbxProcParams(SQLConnection,self) then
fInitParms := true;
end;
inherited;
end;
end.
// And Now :
p := TBTSQLStoredProc.Create(self);
try
with p do
begin
SQLConnection := SQLConnection1;
SchemaName := 'Schema_Name';
PackageName := 'Pack_Name';
StoredProcName := 'Stored_Name';
Prepared; // For prepareStatement
ParamByName('P_Name1').AsInteger := 1;
ParamByName('P_Name2').AsInteger := 2;
ParamByName('P_Name3').AsInteger := 3;
execProc; // or Open
end;
finally
p.Free;
end;
 

Re:SQLStoredProc & Params

Would you mine if I added this to dbExpress Plus?
Eric Chauvet writes:
Quote
If you want you can try this, I Hope that it will be a good solution for you
there is two units plus one sample.

{ ************************ DBXGlobal
******************************************}
unit DBXGlobal;

interface
uses Classes,DB,SQLExpr;

function
InitialiseDbxProcParams(aConnection:TSQLConnection;aStoredProc:TSQLStoredPro
c):boolean;

implementation


function
InitialiseDbxProcParams(aConnection:TSQLConnection;aStoredProc:TSQLStoredPro
c):boolean;
var
paramList : TParams;
procParams : TList;
begin
result := false;
if Assigned(aConnection) and Assigned(aStoredProc) and
(aStoredProc.StoredProcName <>'') then
begin
procParams := TList.Create;
try
aConnection.GetProcedureParams(aStoredProc.StoredProcName,
aStoredProc.PackageName,
procParams);
paramList := TParams.Create;
try
LoadParamListItems(ParamList, ProcParams);
aStoredProc.Params.Assign(ParamList);
result := true;
finally
ParamList.Free;
end;
finally
FreeProcParams(ProcParams);
end;
end;
end;

end.


{ ************************ DBXStd
******************************************}
unit DBXStd;

interface
uses SQLExpr;

type
TBTSQLConnection = Class(TSQLConnection)
end;

TBTSQLMonitor = Class(TSQLMonitor)
protected
{ Can i have Béta Version, How Can I Rebuild Dbexpress package}
{ Why Desc^.eTraceCat Allways 256 and CallType Allways 1 with
OracleDriver
in function TSQLMonitor.InvokeCallBack(CallType: TRACECat; CBInfo:
Pointer): CBRType; stdcall;
Finally where is DBexpress 2.0 ???
}
// procedure Trace(Desc: pSQLTraceDesc; var LogTrace: Boolean);
override;
end;

TBTSQLDataset = Class(TSQLDataset)
end;

TBTSQLQuery = Class(TSQLQuery)
end;

TBTSQLStoredProc = Class(TSQLStoredProc)
private
fInitParms : boolean;
public
procedure PrepareStatement; override;

end;
implementation
uses DBXGlobal;

procedure TBTSQLStoredProc.PrepareStatement;
begin
if Assigned(SQLConnection) and (not fInitParms) then
begin
if InitialiseDbxProcParams(SQLConnection,self) then
fInitParms := true;
end;

inherited;
end;

end.


// And Now :

p := TBTSQLStoredProc.Create(self);
try
with p do
begin
SQLConnection := SQLConnection1;
SchemaName := 'Schema_Name';
PackageName := 'Pack_Name';
StoredProcName := 'Stored_Name';

Prepared; // For prepareStatement

ParamByName('P_Name1').AsInteger := 1;
ParamByName('P_Name2').AsInteger := 2;
ParamByName('P_Name3').AsInteger := 3;

execProc; // or Open
end;
finally
p.Free;
end;


--
Thomas Miller
Delphi Client/Server Certified Developer
BSS Accounting & Distribution Software
BSS Enterprise Accounting FrameWork
www.bss-software.com
sourceforge.net/projects/dbexpressplus