Quantcast
Channel: NAV Three Tier — mibuso.com
Viewing all articles
Browse latest Browse all 10032

TryFunction and SQL Buffering

$
0
0
Hello,

I have been trying a bit TryFunction feature in NAV 2016 CU5 and I have found an issue which looks like the SQL buffers are not cleared when the logic in the TryFunction fails.

In the example I have created a TryFunction called TryInsert(int From,int To) which tries to insert records in the numeric range. It contains no COMMITs inside or explicit errors. I wanted to test what the TryFunction help means by Changes to the database that are made with a try function are not rolled back.

The scenario goes like
IF TryInsert(5,10) THEN ;
COMMIT;
IF TryInsert(1,7) THEN ;

As all the code is in the TryFunction block I would expect this code to pass without the failure, i.e. no error message should be shown to the user. Expected result is that records 1..10 are inserted in the end and that the second TryInsert run actually fails in the try block with consumed error message when trying to insert record number 5 which was already inserted in the first TryInsert call. This bit really happens. However the code fails in the end with the real error message thrown to the user The Test Record already exists. Identification fields and values: Entry No.='1'.
But there were no 2 attempts in that code to insert record 1 twice. Which according to me means that record 1 was inserted in TryInsert(1,7) as expected AND SQL buffers inserting it for the first time were not cleared once the record was inserted. And those SQL buffers seems to be actually cleared and executed again only once the code hits the end and implicit COMMIT occurs.

Is it a bug or expected behaviour? Can anybody explain to me what the TryFunction description in the help about no rollback really means?

Thanks,
Igor

The code sample is below. I was not able to attach it as a txt file with the error message Uploaded file type is not allowed.
OBJECT Table 50000 Test Record
{
  OBJECT-PROPERTIES
  {
    Date=12/04/16;
    Time=00:00:00;
    Modified=Yes;
    Version List=Test Try Function;
  }
  PROPERTIES
  {
  }
  FIELDS
  {
    { 1   ;   ;Entry No.           ;Integer        }
  }
  KEYS
  {
    {    ;Entry No.                               ;Clustered=Yes }
  }
  FIELDGROUPS
  {
  }
  CODE
  {

    BEGIN
    END.
  }
}

OBJECT Codeunit 50000 Test Try Function
{
  OBJECT-PROPERTIES
  {
    Date=12/04/16;
    Time=09:37:35;
    Modified=Yes;
    Version List=Test Try Function;
  }
  PROPERTIES
  {
    OnRun=VAR
            TestRecord@1000000000 : Record 50000;
          BEGIN
            // initialize test
            TestRecord.DELETEALL;
            CLEARLASTERROR;
            COMMIT;

            IF NOT TryInsert(5,10) THEN
              MESSAGE('Failed 5-10 with ' + GETLASTERRORTEXT);
            COMMIT;
            IF NOT TryInsert(1,7) THEN
              MESSAGE('Failed 1-7 with ' + GETLASTERRORTEXT);

            // but why does it fail here again? With error Test Record 1 already inserted?
            MESSAGE('Count %1',TestRecord.COUNT);
          END;

  }
  CODE
  {

    [TryFunction]
    LOCAL PROCEDURE TryInsert@1000000001(FromNo@1000000000 : Integer;ToNo@1000000001 : Integer);
    VAR
      TestRecord@1000000002 : Record 50000;
      Loop@1000000003 : Integer;
    BEGIN
      FOR Loop := FromNo TO ToNo DO BEGIN
        TestRecord."Entry No." := Loop;
        TestRecord.INSERT;
      END;
    END;

    BEGIN
    END.
  }
}

Viewing all articles
Browse latest Browse all 10032

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>