I am needing to convert a large amount of SQL queries into stored procedures. I have some code that updates about 20 or 30 values at one time in one Delphi procedure. I can handle creating a stored procedures to do such a thing. The problem is my way to pass parameters to stored procedures is very bulky like this:
with stored_procedure do......
Param := Parameters.AddParameter;
Param.Name := '@SSN';
Param.Value := edtSSN.text;
Param := Parameters.AddParameter;
Param.Name := '@FirstName';
Param.Value := edtFirstName.Text;
Param := Parameters.AddParameter;
Param.Name := '@LastName';
Param.Value := edtLastName.Text;
Param := Parameters.AddParameter;
Param.Name := '@UserRID';
Param.Value:= GetRIDFromCombo(cbUser);
I also am not sure if that causes a memory leak(is it necessary to free such TParameter objects?)
Anyone have a better way of handling a large amount of parameters? (I can not use a new library. I must use ADO, and the SQL I use is MSSQL) (also, I'm NOT using ADO.net)
To pass one or more arguments to a procedure In the calling statement, follow the procedure name with parentheses. Inside the parentheses, put an argument list. Include an argument for each required parameter the procedure defines, and separate the arguments with commas.
As a program, a stored procedure can take parameters. There are three types of parameters: IN, OUT and INOUT.
A parameter represents a value that the procedure expects you to supply when you call it. The procedure's declaration defines its parameters. You can define a procedure with no parameters, one parameter, or more than one. The part of the procedure definition that specifies the parameters is called the parameter list.
To execute a stored procedure, drop a TFDStoredProc component on a form. TFDStoredProc. Connection will be automatically set to point to a TFDConnection on this form, if any. Then, optionally set the CatalogName, SchemaName, and PackageName properties or choose their values from a dropdown list.
There's an accepted answer :-), but I want to point you to simpler and easier way to define and use the parameters with one line :
stored_procedure.Parameters.CreateParameter('SSN',ftString,pdInput,30,edtSSN.text);
It's simple and flexible, because you can define the input and output parameters with same line.
and from Delphi help:
function CreateParameter(const Name: WideString; DataType: TDataType;
Direction: TParameterDirection; Size: Integer;
Value: OleVariant): TParameter;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With