How to modify fieldgroup save function?

94 Views Asked by At

I created a page to insert and modify data of an existing mysql- table. But based on my requirements and the structure of the table I have to modify the sql for inserting data.

Because I am completly new on rapidclipse and java I need some hints/ examples how and where to modify this. Looking all rapidclipse videos did not give the right hint.

I would like to insert three fields into a mysql-table
One of the fields I have to edit manualy.
The second field contains always the same value.
The third field contains a calculated value, which I have to fetch while runtime from the database.

As sql I would use following code:

INSERT INTO OKM_DB_METADATA_VALUE (DMV_TABLE, DMV_COL00, DMV_COL01) 
VALUES ('T_supplier', (select * from (select max(cast(DMV_COL00 as
Integer)) +1 from OKM_DB_METADATA_VALUE as t2 where DMV_TABLE =
'T_supplier') as t3 ) , 'new suppliername');

The value for field DMV_Table will be always 'T_supplier'
The value for field DMV_COL00 is always the highest value in the col +1
The value for field DMV_COL01 will be always entered manually
(I am not able/ I don't want to modify/ use table form, -design and trigger, because it is a original table of OpenKM)

Thank you in advance!
best regards
OpaHeinz

2

There are 2 best solutions below

1
ScaisEdge On

Just a suggestion for sql code .. Your code could be refactored in a more SQL like code .. You could avoid the innner subquery .. and use a normal insert select

  INSERT INTO OKM_DB_METADATA_VALUE (DMV_TABLE, DMV_COL00, DMV_COL01) 
  select 'T_supplier', max(cast(DMV_COL00 asInteger)) +1 , 'new suppliername'
  from OKM_DB_METADATA_VALUE 
  where DMV_TABLE ='T_supplier'
0
Schwabenheinz On

The first step to solution

In the buttonClick event of save function I set the value of DMV_Table field with:

... this.txtDmvTable.setValue("T_supplier"); 

The second step; I created a view in the database wich delivers only the expected value:

 `CREATE
OR REPLACE
VIEW `okmdb`.`V_suppliers_newID` AS
select
    1 as "id",
    max(cast(DMV_COL00 as Integer)) +1 as "newSupId" 
from OKM_DB_METADATA_VALUE 
where DMV_TABLE = 'T_supplier'; `

After that I created an entity in rapidclipse, read the value out of the view and assigned it to the other field DMV_COL00.

This was all.