Forum > Databases

CALCULATED FIELD

(1/3) > >>

Medhome:
Hi All,

I  Designed a FB table as below:

CREATE TABLE LINES
(
  PK bigint NOT NULL,
  NDOC bigint,
  NART bigint,
  CLOT varchar(10),
  DATE_PER date,
  QTE numeric(18,2),
  Price numeric(7,2),
  PPA numeric(7,2),
  CONSTRAINT PK_LIGNES_0 PRIMARY KEY (PK)
);
ALTER TABLE LINES ADD MNT COMPUTED BY (qte*price);

I Show the  data via a dbgrid    when I update qte or price the field MNT does not !!!

REGARDS

Nicole:
Not sure, how this works in Lazarus.
I come from Delphi.

There it would be necessary to key in the fields into the query, which supplies the data of the DBGrid.
What is not in this DBGrid-Query did not shop up.

In Delphi I had an Editor which allowed to edit this supplied-grid-fields from the design-time DBGrid environment.
I know this, because I once searched half a day an error like yours.
It was needed to have this field listed / added in this very editor.

Should this be different in Lazarus, pls just ignore my posting.

MarkMLl:
I'm rather uncomfortable commenting since I'm not 100% sure of my facts. However on PostgreSQL (and, I suspect, Firebird) I think it would involve having a trigger which sent an asynchronous notification to the app that it needed to repeat the selection which underlay its displayed data.

MarkMLl

rvk:

--- Quote from: Medhome on August 14, 2022, 07:50:06 pm ---I Show the  data via a dbgrid    when I update qte or price the field MNT does not !!!

--- End quote ---
Did you update/refresh the dbgrid dataset after the update?
If not, then that record still has old values.

What happens if you commit the transaction, close the db and reopen the db? Is the MNT changed then?

BTW. I think this should be handled automatically by TDataSet.RefreshInternalCalcFields but it doesn't seem to be implemented yet:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TDataSet.RefreshInternalCalcFields(Buffer: TRecordBuffer);begin  //!! To be implementedend;

dje:
Looks like OP found their answer over on stackoverflow.

https://stackoverflow.com/questions/73354332/the-database-calculated-field-not-updated-for-example-total-qteprice-when-qte

Navigation

[0] Message Index

[#] Next page

Go to full version