Dataset hasChanges() - Forum - Community Groups - Progress Community

Dataset hasChanges()

 Forum

Dataset hasChanges()

  • Hopefully this is something very simple that I'm missing here!

    Essentially I want to check whether my dataset has had any changes, which I thought I shpuld be able to do in the following manner:

    DEFINE DATASET dsDataset FOR ttData.

    MESSAGE dsDataset:hasChanges().

    However when I try this I simply get "Unknown attribute hasChanges used in widget:attribute phrase".

    Can anybody explain why I'm getting this?

    Thanks in adavance.

  • Can anybody explain why I'm getting this?

     

    To my knowledge there is no such method in the ABL.

    You may get confused because of this:

    http://msdn.microsoft.com/en-us/library/system.data.dataset.haschanges.aspx

    ADO.NET Dataset and the ProDataset have a lot in common - but not everything

  • Yes Mike, that's exactly what I'd been looking at. And I was worried that you were going to say that it didn't exist.

    Thanks anyway!

    Martin

    Advanced Computer Software Ltd.

  • Yes Mike, that's exactly what I'd been looking at. And I was worried that you were going to say that it didn't exist.

     

    It's not difficult to cook your own. You'll just have to (dynamically) search for a record in each before-table. We use code like this here to do so:

    DO i = 1 TO hDataset:NUM-BUFFERS:

    ASSIGN hBuffer = hDataset:GET-BUFFER-HANDLE .

    IF VALID-HANDLE(hBuffer:BEFORE-BUFFER) THEN DO:

    lFind = hBuffer:BEFORE-BUFFER:FIND-FIRST () NO-ERROR .

    IF lFind = TRUE THEN RETURN TRUE .

    END.

    END.

    RETURN FALSE .

    Now, the race is open for a better solution, Peter?

  • How about ...


    def temp-table ttOne no-undo before-table btOne
    field f1 as char.

    def dataset dsOne for ttOne.

    temp-table ttOne:tracking-changes= true.
    DO transaction:
    create ttOne.
    ttOne.f1 = 'a'.
    END.

    def var i as int.
    DO i = 1 TO dataset dsOne:NUM-BUFFERS:
    if dataset dsOne:GET-BUFFER-HANDLE(i):table-handle:BEFORE-TABLE:HAS-RECORDS then
    message dataset dsOne:GET-BUFFER-HANDLE(i):name 'has at least one change'
    VIEW-AS ALERT-BOX INFO BUTTONS OK.
    END.

    -- peter

  • How about ...

    Neat. Almost...

    Make the check

    IF VALID-HANDLE (dataset dsOne:GET-BUFFER-HANDLE(i):table-handle:BEFORE-TABLE) AND dataset dsOne:GET-BUFFER-HANDLE(i):TABLE-HANDLE:BEFORE-TABLE:HAS-RECORDS THEN ...

    You should not assume that every ProDataset member table has a before-table. There are good reasons not to have a before-table on some tables.

  • Thanks to both of you for your answers. I have used Mikes (mainly because it was there sooner), however it still hasn't solved the problem I had originally (and had hoped this solution would solve).

    Essentially I was using bindingSource:RowModified to see if any changes had occured, but for some reason RowModified reports changes even when none have been made/I have SAVE-ROW-CHANGES/REJECT-ROW-CHANGES.

  • mikefe wrote:

    You should not assume that every ProDataset member table has a before-table. There are good reasons not to have a before-table on some tables.

    On a related note, isn't it possible for a TT to get a BT even if it wasn't declared as such?

  • On a related note, isn't it possible for a TT to get a BT even if it wasn't declared as such?

    I doubt that.

  • On a related note, isn't it possible for a TT to get a BT even if

    it wasn't declared as such?

    I doubt that.

    You can turn on TRACKING-CHANGES for temp-tables that don't have BEFORE-TABLE in the DEFINE TEMP-TABLE statement.

    -- peter

  • You can turn on TRACKING-CHANGES for temp-tables that don't have BEFORE-TABLE in the DEFINE TEMP-TABLE statement.

     

    Are you serious? What is message # 12344 all about then?

    Cannot turn on TRACKING-CHANGES for a static temp-table unless DEFINED with a BEFORE-TABLE phrase. (12344)

    Sample code:

    DEFINE TEMP-TABLE ttTest NO-UNDO

    FIELD cTest AS CHARACTER .

    DEFINE DATASET dsTest FOR ttTest .

    TEMP-TABLE ttTest:TRACKING-CHANGES = TRUE .

    Knowing that you usually work on future releases of OE, will that change in any future release?

  • Cannot turn on TRACKING-CHANGES for a static temp-table unless

    DEFINED with a BEFORE-TABLE phrase. (12344)

    I've done it on a dynamic reference to a static temp-table. dsOrder in this case is a static PDS with static TT's with no before-tables.

        method override protected handle CopyStaticDataset (output dataset-handle phDataset):

            phDataset = dataset dsOrder:handle.

        end method.

    Tested recently with OrderEntity in AutoEdge|TheFactory. service_captureorder.p has a EnableDatasetForUpdate function which dynamically loops through the PDS's buffers/tables.

    This is in 10.2B04.

    -- peter

    Message was edited by: Peter Judge. Added OE version info.

  • I've done it on a dynamic reference to a static temp-table. dsOrder in this case is a static PDS with static TT's with no before-tables.

     

    And what is that error message all about, that claerly says, that you cannot turn on TRACKING-CHANGES without be BEFORE-TABLE???

  • mikefe wrote:

    I've done it on a dynamic reference to a static temp-table. dsOrder in this case is a static PDS with static TT's with no before-tables.

    And what is that error message all about, that claerly says, that you cannot turn on TRACKING-CHANGES without be BEFORE-TABLE???

    So it looks like the  DYNAMIC bit gets flipped, and so the check's not done: the returned dataset is now dynamic and so you can set TRACKING-CHANGES.

    class testDS:

        def temp-table eOrder no-undo

                field ordernum as int.

        def temp-table EORDERLINE no-undo

            field ordernum as int

            field linenum as int.

        def dataset dsOrder for eorder, eorderline.

        constructor public testDS():

            def var hPDS as handle.

            CopyStaticDataset(output dataset-handle hPDS).

            MESSAGE

                dataset dsOrder:dynamic skip

                hPDS:dynamic

            VIEW-AS ALERT-BOX INFO BUTTONS OK.

        END constructor.

        method protected handle CopyStaticDataset (output dataset-handle phDataset):

            phDataset = dataset dsOrder:handle.

        end method.

    END class.

    /*

    ---------------------------

    Information

    ---------------------------

    no

    yes

    ---------------------------

    OK  

    ---------------------------

    */

    -- peter

  • Ok - but that's a dynamic deep copy (of a static temp-table). I wouldn't call that a static temp-table anymore.