Subject | RE: [IBO] Pulling my hair out: ParamByName stopped working |
---|---|
Author | Jason Wharton |
Post date | 2006-11-22T05:12:38Z |
Mitch wrote:
resources.
Use Active when you want to open and maintain buffered records on the
client.
What may happen is the dataset may refresh. See the RefreshOnParamChange
property.
Also, it is possible to use code in the case of multiple parameters:
MyQuery.Params.BeginUpdate;
...
MyQuery.Params.EndUpdate( );
Here is a sample procedure.
procedure Set_Query_Parameters( query : TIB_Query;
const input_paramNames : array of string;
const input_ParamValues : array of const );
type
ParamCount_t = Integer;
var
param_i : ParamCount_t;
pName : string;
pValue : TVarRec;
fieldParam : TIB_Column;
begin
with query do
begin
Prepared := true;
Params.BeginUpdate;
try
for param_i := 0 to High(input_paramNames) do
begin
pName := input_paramNames[param_i];
pValue := input_ParamValues[param_i];
fieldParam := ParamByName(pname);
with pValue do
begin
case VType of
vtInteger : fieldParam.AsInteger := VInteger;
vtBoolean : fieldParam.AsBoolean := VBoolean;
vtChar : fieldParam.AsString := VChar;
vtExtended :
begin
case fieldParam.SQLType of
Sql_Date : fieldParam.AsDateTime := VExtended^;
Sql_Float,
Sql_DFloat : fieldParam.AsFloat := VExtended^;
Sql_Double : FieldParam.AsDouble := VExtended^;
end;
end;
vtString : fieldParam.AsString := VString^;
vtPChar : fieldParam.AsString := VPChar;
vtAnsiString : fieldParam.AsString := string(VAnsiString);
vtCurrency : fieldParam.AsCurrency := VCurrency^;
else
end;
end;
end;
finally
// Make it so that there is only a single change notification even when
// multiple parameters are modified.
// If RefreshOnParamChange is true then the dataset will be refreshed
// here if it was Active to start with.
Params.EndUpdate( true );
end;
end;
end;
HTH,
Jason Wharton
> In what circumstances would you need to use the uprepare/prepare andUse Unprepare when you are done with a query and you want to free up server
> active commands?
resources.
Use Active when you want to open and maintain buffered records on the
client.
> Does the following code automatically close the query/dataset if it isIBO does not close your dataset when you assign a value to a parameter.
> open, before redoing it?
>
> > with qryCurrProjSpecs do
> > begin
> > ParamByName('Var_PVERSION_ID').asinteger := curr_proj_version;
> > Open;
> > end;
What may happen is the dataset may refresh. See the RefreshOnParamChange
property.
Also, it is possible to use code in the case of multiple parameters:
MyQuery.Params.BeginUpdate;
...
MyQuery.Params.EndUpdate( );
Here is a sample procedure.
procedure Set_Query_Parameters( query : TIB_Query;
const input_paramNames : array of string;
const input_ParamValues : array of const );
type
ParamCount_t = Integer;
var
param_i : ParamCount_t;
pName : string;
pValue : TVarRec;
fieldParam : TIB_Column;
begin
with query do
begin
Prepared := true;
Params.BeginUpdate;
try
for param_i := 0 to High(input_paramNames) do
begin
pName := input_paramNames[param_i];
pValue := input_ParamValues[param_i];
fieldParam := ParamByName(pname);
with pValue do
begin
case VType of
vtInteger : fieldParam.AsInteger := VInteger;
vtBoolean : fieldParam.AsBoolean := VBoolean;
vtChar : fieldParam.AsString := VChar;
vtExtended :
begin
case fieldParam.SQLType of
Sql_Date : fieldParam.AsDateTime := VExtended^;
Sql_Float,
Sql_DFloat : fieldParam.AsFloat := VExtended^;
Sql_Double : FieldParam.AsDouble := VExtended^;
end;
end;
vtString : fieldParam.AsString := VString^;
vtPChar : fieldParam.AsString := VPChar;
vtAnsiString : fieldParam.AsString := string(VAnsiString);
vtCurrency : fieldParam.AsCurrency := VCurrency^;
else
end;
end;
end;
finally
// Make it so that there is only a single change notification even when
// multiple parameters are modified.
// If RefreshOnParamChange is true then the dataset will be refreshed
// here if it was Active to start with.
Params.EndUpdate( true );
end;
end;
end;
HTH,
Jason Wharton