Basic Details
Insert into "DAMAGE" ( "SPEC_NUM", "WHEN_CALC" ) VALUES ( :SPEC_NUM, :WHEN_CALC )These methods add parameters to the query component
procedure TxxDataSet.StringPut(Field, A_Value: string); begin with Params.CreateParam(ftString, Field, ptInput) do AsString := A_Value; end; procedure TxxDataSet.FloatPut(Field: string; A_Value: Double); begin with Params.CreateParam(ftFloat, Field, ptInput) do AsFloat := A_Value; end; procedure TxxDataSet.IntegerPut(Field: string; A_Value: integer); begin with Params.CreateParam(ftInteger, Field, ptInput) do AsInteger := A_Value; end; procedure TxxDataSet.MemoSave(Field: string; AnArray: pointer; n: integer); begin with Params.CreateParam(ftBlob, Field, ptInput) do SetBlobData(AnArray, n); end;In general, you should test for the existance of a parameter before creating one (with the same name). The following method is based on the Delphi help.
procedure TxxDataSet.IntegerPut(Field: string; A_Value: integer); begin try Params.ParamByName(Field).AsInteger := A_Value; except on EDatabaseError do with Params.CreateParam(ftInteger, Field, ptInput) do AsInteger := A_Value; end; end;
Executing the query
self.Close; self.ParamCheck := True; // If false, the parameters are not used self.SQL.Text := 'Insert into "tablename" ...'; self.ExecSQL; // Used to modify the table self.SQL.Text := 'commit'; // Clears the Parms list and self.ExecSQL; // lets other users see the changesIf ParamCheck = false and the sql string contains parameters, then there is an
xsqlda index out of rangeerror - even if the number of parameters in the sql string matches the number of defined parameters.
Note: | In methods, I frequently use self (which is never required) because it tells the IDE to display a list of properties and methods after you type the period. (Use Ctrl-Space to display the list if the period is already typed.) |
Code Error
procedure TxxDataSet.StringPut(Field, value: string); begin with Params.CreateParam(ftString, Field, ptInput) do AsString := value; end;What a disaster