Uniface User Forum

 View Only
  • 1.  findkey statement generating unexected SQL, HELP needed

    Posted 12-21-2023 11:22

    Hi. I am new on this forum and I have a problem with a findkey statement

    Ik copied a programa,  made some adjustments and did a testrun with 2 records. Both programs (I will call them OLD and NEW)  refer tot a entity / table called MYTABLE (not real name). Only the entity is used, no local modification in the enitity definition. The validate key trigger uses findkey to check if the record already exists before store.

    Record 1 OLD

    "C: PROGRAM_5 S: 0 P: 0" (); VALIDATEKEY; 1; [0]; findkey $entname, $curkey

    I/O function: S, mode: 1, on file/table: MYTABLE index: 1 =

     Where ((NR_REKENING = 441202) And (DT_OVERZICHT = 09112023) And (NR_VOL = 5))

    SELECT 0 FROM "MYTABLE" WHERE  "NR_REKENING" = :"WNR_REKENING" AND "DT_OVERZICHT" = :"WDT_OVERZICHT" AND "NR_VOL" = :"

    WNR_VOL"

    -> Hits selected: 0 .

    Record 2 OLD

    C: PROGRAM_5 S: 0 P: 0" (); VALIDATEKEY; 1; [0]; findkey $entname, $curkey

    I/O function: S, mode: 1, on file/table: MYTABLE index: 1 =

     Where ((NR_REKENING = 441202) And (DT_OVERZICHT = 09112023) And (NR_VOL = 5))

    SELECT 0 FROM "MYTABLE" WHERE  "NR_REKENING" = :"WNR_REKENING" AND "DT_OVERZICHT" = :"WDT_OVERZICHT" AND "NR_VOL" = :"

    WNR_VOL"

    -> Hits selected: 0 .

    This seems correct to me

    Recod 1 NEW

    "C: PROGRAM_B S: 0 P: 0" (); LP_VERWERK_DETAILREGEL; 121; [0]; store

    "C: PROGRAM_B S: 0 P: 0" (); VALIDATEKEY; 6; [0]; findkey $entname, $curkey

    I/O function: S, mode: 1, on file/table: MYTABLE index: 1 =

     Where ((NR_REKENING = 441202) And (DT_OVERZICHT = 09112023) And (NR_VOL = 4))

    SELECT 0 FROM "MYTABLE" WHERE  "NR_REKENING" = :"WNR_REKENING" AND "DT_OVERZICHT" = :"WDT_OVERZICHT" AND "NR_VOL" = :"WNR_VOL"

    -> Hits selected: 0 .

    Record 2 NEW 

    "C: PROGRAM_B S: 0 P: 0" (); VALIDATEKEY; 6; [0]; findkey $entname, $curkey

    I/O function: S, mode: 1, on file/table: MYTABLE index: 1 >=

    SELECT COUNT(*) FROM "MYTABLE" <-- why does this happen.

    -> Hits selected: 871928 .

    The findkey for the second record generates different and unwanted SQL. It is the same statement findkey and $curkey is 1 , the entity/table has only 1 primary key. Strangely the recods written are different

    OLD

    I/O function: W, mode: 0, on file/table: MYTABLE length: 415

    INSERT INTO "MYTABLE" ( "NR_REKENING", "DT_OVERZICHT", "NR_VOL", "U_VERSION", "NAAM_FONDS", "CD_SYMBOOL", "CD_ISIN", "

    CD_TYPE", "CD_VALUTA", "BD_KOERS", "AANT_NOM_WAARDE", "BD_WISSELKOERS", "BD_WAARDE_EUR", "BD_WAARDE_VV", "BD_AANSCHAF", "BD_OPGE

    LOPEN_RENTE", "BD_LIQUIDITEIT", "OV_EXE_ASS_FACTOR", "DT_EXPIRATIE", "BD_EXPIRATIE", "OMS_BEL_INSTR_TYPE", "CD_FONDS", "OV_LAAGB

    R", "DT_LAAWYZ", "OV_BRON" ) VALUES ( :"XNR_REKENING", :"XDT_OVERZICHT", :"XNR_VOL", :"XU_VERSION", :"XNAAM_FONDS", :"XCD_SYMBOO

    L", :"XCD_ISIN", :"XCD_TYPE", :"XCD_VALUTA", :"XBD_KOERS", :"XAANT_NOM_WAARDE", :"XBD_WISSELKOERS", :"XBD_WAARDE_EUR", :"XBD_WAA

    RDE_VV", :"XBD_AANSCHAF", :"XBD_OPGELOPEN_RENTE", :"XBD_LIQUIDITEIT", :"XOV_EXE_ASS_FACTOR", :"XDT_EXPIRATIE", :"XBD_EXPIRATIE",

     :"XOMS_BEL_INSTR_TYPE", :"XCD_FONDS", :"XOV_LAAGBR", :"XDT_LAAWYZ", :"XOV_BRON" )

    NEW

    "C: PROGRAM_B S: 0 P: 0" (); WRITE; 3; [0]; write

    I/O function: W, mode: 0, on file/table: MYTABLE length: 340

    INSERT INTO "MYTABLE" ( "NR_REKENING", "DT_OVERZICHT", "NR_VOL", "U_VERSION", "NAAM_FONDS", "CD_SYMBOOL", "CD_ISIN", "

    CD_TYPE", "CD_VALUTA", "BD_KOERS", "AANT_NOM_WAARDE", "BD_WISSELKOERS", "BD_WAARDE_EUR", "BD_WAARDE_VV", "BD_AANSCHAF", "BD_OPGE

    LOPEN_RENTE", "BD_LIQUIDITEIT", "OV_EXE_ASS_FACTOR", "DT_EXPIRATIE", "BD_EXPIRATIE", "OMS_BEL_INSTR_TYPE", "CD_FONDS", "OV_LAAGB

    R", "DT_LAAWYZ" ) VALUES ( :"XNR_REKENING", :"XDT_OVERZICHT", :"XNR_VOL", :"XU_VERSION", :"XNAAM_FONDS", :"XCD_SYMBOOL", :"XCD_I

    SIN", :"XCD_TYPE", :"XCD_VALUTA", :"XBD_KOERS", :"XAANT_NOM_WAARDE", :"XBD_WISSELKOERS", :"XBD_WAARDE_EUR", :"XBD_WAARDE_VV", :"

    XBD_AANSCHAF", :"XBD_OPGELOPEN_RENTE", :"XBD_LIQUIDITEIT", :"XOV_EXE_ASS_FACTOR", :"XDT_EXPIRATIE", :"XBD_EXPIRATIE", :"XOMS_BEL

    _INSTR_TYPE", :"XCD_FONDS", :"XOV_LAAGBR", :"XDT_LAAWYZ" ).

    So despite both OLD and NEW referencing the same unmodifed entity MYTABLE, they generate different SQL statements. According tot he debugger all fields including ov_bron, were correctly filled in the entity before store. I made several variations of OLD and new using duplicate and export/import but the discrepantie was also for every variation of NEW.  I can anyone explain why the NEW program has a different interpreation of the entity?  Both OLD and NEW were recompiled today in the same environment. Does anybody have an explanation for this situation. Thanks in advance. 



    ------------------------------
    Rob Koppendraier
    Developer
    Waard Verzekeringen BV
    Wognum NL
    ------------------------------


  • 2.  RE: findkey statement generating unexected SQL, HELP needed

    PARTNER
    Posted 12-22-2023 06:22

    Check the field lists for the two components, if the field list is "Automatic", then it may not contain the field XOV_BRON and therefore neither read nor write it. 

    As for the $findkey, I don't know, the field list for any table should automatically contain the primary key. However, if checking/correcting the field list fixes the issue, then that was it. :) 

    Regards, 

    Iain



    ------------------------------
    Iain Sharp
    Head of Technical Services
    Pci Systems Ltd
    Sheffield GB
    ------------------------------



  • 3.  RE: findkey statement generating unexected SQL, HELP needed

    Posted 12-30-2023 05:50

    Hi Rob,

    Question is: Is the value of $curkey = 1 when your code is running?

    I feel that behaviour is related to findkey checking for another key, not the primary key...for really unknown reason(s).

    If you want to check explicitely for the primary key as quick&dirty solution you could try to force key 1 instead of using $curkey.

    If that will be the case, "why is happening" is a good question... probably your case should be analyzed from the ULab, following you in the process of duplicating the original component and applying the changes you've done.

    Hope it helps!

    Gianni

    P.S. Happy new year to everyone! :-)



    ------------------------------
    Gianni Sandigliano
    IT
    ------------------------------



  • 4.  RE: findkey statement generating unexected SQL, HELP needed

    Posted 01-04-2024 03:30
    Hi Gianni,
    Thanks for your reply. I found the reason and posted it on the forum.
    “Hi, I found the reason. In the first situation the records were written bij the program so it went all right. In the second situation before writing the record there was a call to a service which contained on older definition of the same entity and this service was not recompiled. While only used to compute a next sequence number the entity layout used the service gets somehow overwriten the layout of the entity the calling program. The calling program fills all fields but somehow the interfacce to de database is one field short. I never experienced it before. I hope this makes sense and is of some help to you all. “


    Van: Gianni Sandigliano via Rocket Forum <mail@forum.rocketsoftware.com>
    Verzonden: zaterdag 30 december 2023 11:52
    Aan: Rob Koppendraier <rob.koppendraier@waardverzekeringen.nl>
    Onderwerp: RE: Rocket Uniface : findkey statement generating unexected SQL, HELP needed

    U ontvangt niet vaak e-mail van mail@forum.rocketsoftware.com. Meer informatie over waarom dit belangrijk is<https: aka.ms/learnaboutsenderidentification="">
    Hi Rob, Question is: Is the value of $curkey = 1 when your code is running? I feel that behaviour is related to findkey checking for another... -posted to the "Rocket Uniface User Forum" forum
    Invite your colleagues to join the Rocket Forum and grow our expert network.
    ________________________________
    [Afbeelding verwijderd door afzender. Rocket Software]<https: community.rocketsoftware.com/="">
    Uniface User Forum<https: community.rocketsoftware.com/forums/forum-home/digestviewer?communitykey="edb92b7f-cb45-44f3-9782-c48a111007d6">
    Post New Message Online<http: community.rocketsoftware.com/participate/postmessage?groupid="217&ListKey=5286ab73-50a6-49ab-8f61-88047dfaabb8">
    Invite your colleagues to join the Rocket Forum and grow our expert network. Share this link.<https: community.rocketsoftware.com/register="">

    Re: findkey statement generating unexected SQL, HELP needed<https: community.rocketsoftware.com/discussion/findkey-statement-generating-unexected-sql-help-needed#bm2cc0ccb7-e602-4d01-882d-018cba509e0c="">
    Reply to Group Online<https: community.rocketsoftware.com/forums/all-discussions/postreply?messagekey="2cc0ccb7-e602-4d01-882d-018cba509e0c&ListKey=5286ab73-50a6-49ab-8f61-88047dfaabb8">
    Reply to Group<mailto:rocket_rocketuniface_2cc0ccb7-e602-4d01-882d-018cba509e0c@connectedcommunity.org?subject=re:%20findkey%20statement%20generating%20unexected%20sql,%20help%20needed>
    [Afbeelding verwijderd door afzender. Gianni Sandigliano]<https: community.rocketsoftware.com/network/members/profile?userkey="261472fc-88bc-4796-8265-4b2b9150c9ba">
    Dec 30, 2023 5:50 AM
    Gianni Sandigliano<https: community.rocketsoftware.com/network/members/profile?userkey="261472fc-88bc-4796-8265-4b2b9150c9ba">

    Hi Rob,

    Question is: Is the value of $curkey = 1 when your code is running?

    I feel that behaviour is related to findkey checking for another key, not the primary key...for really unknown reason(s).

    If you want to check explicitely for the primary key as quick&dirty solution you could try to force key 1 instead of using $curkey.

    If that will be the case, "why is happening" is a good question... probably your case should be analyzed from the ULab, following you in the process of duplicating the original component and applying the changes you've done.

    Hope it helps!

    Gianni

    P.S. Happy new year to everyone! :-)


    ------------------------------
    Gianni Sandigliano
    IT
    ------------------------------

    Reply to Group Online<https: community.rocketsoftware.com/forums/all-discussions/postreply?messagekey="2cc0ccb7-e602-4d01-882d-018cba509e0c&ListKey=5286ab73-50a6-49ab-8f61-88047dfaabb8"> View Thread<https: community.rocketsoftware.com/discussion/findkey-statement-generating-unexected-sql-help-needed#bm2cc0ccb7-e602-4d01-882d-018cba509e0c=""> Forward<https: community.rocketsoftware.com/forums/all-discussions/forwardmessages?messagekey="2cc0ccb7-e602-4d01-882d-018cba509e0c&ListKey=5286ab73-50a6-49ab-8f61-88047dfaabb8"> Flag as Inappropriate<https: community.rocketsoftware.com/discussion/findkey-statement-generating-unexected-sql-help-needed?markappropriate="2cc0ccb7-e602-4d01-882d-018cba509e0c#bm2cc0ccb7-e602-4d01-882d-018cba509e0c"> Post New Message Online<http: community.rocketsoftware.com/participate/postmessage?groupid="217&ListKey=5286ab73-50a6-49ab-8f61-88047dfaabb8">



  • 5.  RE: findkey statement generating unexected SQL, HELP needed

    PARTNER
    Posted 01-04-2024 07:29

    Yeah, ALWAYS recompile all components using a particular entity where the field list in the entity is changed. Bad things happen if the wrong component is used first as the entity definition is cached.



    ------------------------------
    Iain Sharp
    Head of Technical Services
    Pci Systems Ltd
    Sheffield GB
    ------------------------------