Page 1 of 1
TMSQuery
Posted: Tue 15 Mar 2016 20:10
by nijazicitaku
Hi there,
is there any possibility to apply MSQuery calculated fields to a table with no calculate dfields?
Re: TMSQuery
Posted: Fri 18 Mar 2016 09:39
by azyk
You can write the value of the dataset calculated field to a table field using the BeforeUpdateExecute event handler by passing the value via query parameter. The below sample demonstrates how to do this on record adding.
Generate an INSERT query:
Code: Select all
INSERT INTO TestTable
(... , TestField)
VALUES
(... , :TestField)
...
Set the query as a value for the TMSQuery.SQLInsert.Text property. In the BeforeUpdateExecute event handler, set the calculated field of the dataset as a value for the parameter.
Code: Select all
procedure TMainForm.MSQueryBeforeUpdateExecute(Sender: TCustomMSDataSet;
StatementTypes: TStatementTypes; Params: TMSParams);
begin
if (StatementTypes = [stInsert]) then
Params.ParamByName('TestField').Value := MSQueryCalcField.Value;
...
Re: TMSQuery
Posted: Fri 18 Mar 2016 20:05
by nijazicitaku
Hi there,
thank you very much for your prompt reply, but my question was is it possible to
do on MSQuery.ApplyUpdates?
Thanks
Re: TMSQuery
Posted: Mon 21 Mar 2016 13:55
by AlexP
Hello,
When calling the ApplyUpdates method, the BeforeUpdateExecute event will be triggered for each changed record.
Re: TMSQuery
Posted: Mon 21 Mar 2016 21:11
by nijazicitaku
Hi,
ok but what if updated record already exists in table?
Cheers
Re: TMSQuery
Posted: Thu 24 Mar 2016 11:09
by azyk
Generate an UPDATE query:
Code: Select all
UPDATE TestTable SET
...
TestField = :TestField
WHERE
...
Set the retrieved query as a value for the TMSQuery.SQLUpdate.Text property in the BeforeUpdateExecute handler, add code that would set a value for the parameter on editing an existing record;
Code: Select all
procedure TMainForm.MSQueryBeforeUpdateExecute(Sender: TCustomMSDataSet;
StatementTypes: TStatementTypes; Params: TMSParams);
begin
...
if (StatementTypes = [stUpdate]) then
Params.ParamByName('TestField').Value := MSQueryCalcField.Value;
...
Re: TMSQuery
Posted: Sun 27 Mar 2016 19:41
by nijazicitaku
Hi,
As first HAPPY EASTER.
Here is the code I'm using.
Calculated fields are not recognized as parameters on BeforeUpdateExecute.
with QryMallDetal do begin
SQL.Clear;
SQL.Add('SELECT TOP 1 MHDUI, MHDViti, MHDNjOrg, MHDLlDok, MHDNum, MHDRen, MHDLldokt, MHDData, MHdKomId, MHDDudLloji, MHDDudZyra, MHDDudNum, MHDDudData, MHDKursi, MHDArtId,');
SQL.Add('MHDArtKodi, MHDArtEmri, MHDArtRap, MHDNrSerik, MHDDatSkad, MHDPeshaSpec, MHDRafti, MHDSasiPor, MHDSasia, MHDCmimFatV, MHDRabPrc, MHDRabVleV, MHDShpePrc, MHDShpeVleV,');
SQL.Add('MHDRivPrc, MHDRivVle, MHDTranPrc, MHDTranVle, MHDDogPrc, MHDDogVle, MHDAkcPrc, MHDAKcVle,');
SQL.Add('MHDTVShPrc, MHDTVShVle, MHDTVShKred, MHDTvsh, MHDShpenPrc, MHDShpenVle, MHDTatShit, MHDPakMarPrc, MHDPakMarVle, MHDPakCmim, MHDShumMarPrc,');
SQL.Add('MHDShumMarVle, MHDShumCmim, MHDProj, MHDShtoUser, MHDShtoKoha, MHDEditUser, MHDEDitKoha, MHDAktiv FROM tblMallHyrDetajet');
Prepared;
Open;
end;
QryMallDetal.Close;
QryMallDetal.FieldDefs.Update;
for i := 0 to QryMallDetal.FieldDefList.Count - 1 do
with QryMallDetal.FieldDefList do
if (DataType <> ftUnknown) and not (DataType in ObjectFieldTypes) then
CreateField( QryMallDetal, nil, QryMallDetal.FieldDefList.Strings);
with QryMallDetal do begin
FieldDefs.Update;
with TFloatField.Create(QryMallDetal) do begin
FieldKind := fkCalculated;
FieldName := 'MHDCmimiV';
DataSet := QryMallDetal;
Calculated:= true;
end;
with TFloatField.Create(QryMallDetal) do begin FieldKind := fkCalculated;
FieldName := 'MHDCmimiFat';
DataSet := QryMallDetal;
Calculated:= true;
end;
with TFloatField.Create(QryMallDetal) do begin
FieldKind := fkCalculated;
FieldName := 'MHDRabVle';
DataSet := QryMallDetal;
Calculated:= true;
end;
with TFloatField.Create(QryMallDetal) do begin
FieldKind := fkCalculated;
FieldName := 'MHDShpeVle';
DataSet := QryMallDetal;
Calculated:= true;
end;
with TFloatField.Create(QryMallDetal) do begin
FieldKind := fkCalculated;
FieldName := 'MHDCmimi';
DataSet := QryMallDetal;
Calculated:= true;
end;
with TFloatField.Create(QryMallDetal) do begin
FieldKind := fkCalculated;
FieldName := 'MHDBazaTVSh';
DataSet := QryMallDetal;
Calculated:= true;
end;
with TFloatField.Create(QryMallDetal) do begin
FieldKind := fkCalculated;
FieldName := 'MHDCmKost';
DataSet := QryMallDetal;
Calculated:= true;
end;
end;
Re: TMSQuery
Posted: Wed 30 Mar 2016 11:48
by azyk
Compose a small test project to demonstrate how you attempt to pass the value of the calculated field via parameter to BeforeUpdateExecute. Include CREATE scripts for test tables into the project and send the project to andreyz*devart*com .
Re: TMSQuery
Posted: Wed 25 May 2016 20:45
by nijazicitaku
Hi there,
does TMSQuery supports InternalCalc fields?
Re: TMSQuery
Posted: Thu 26 May 2016 11:24
by ViktorV
SDAC doesn't support FieldKind "fkInternalCalc". If you want us to implement the feature, please post it at our user voice forum:
https://devart.uservoice.com/forums/104 ... components. If the suggestion gets a lot of votes, we will consider the possibility to implement it.