Uploaded image for project: 'Reported Issues'
  1. Reported Issues
  2. RI-22

Adding new struct does not work correctly when there is more than 1 parent node

    XMLWordPrintable

    Details

    • Type: Maintenance
    • Status: Under Review (View Workflow)
    • Resolution: Unresolved
    • Labels:
      None
    • Old bug number:
      31886
    • environment:
      Hide

      +Uniface:
      * Version 9.5.01 (and higher)

      +Operating System:
      * OS independent

      +Database:
      * DBMS independent

      Show
      +Uniface: * Version 9.5.01 (and higher) +Operating System: * OS independent +Database: * DBMS independent

      Description

      Summary:
      Creating a new struct does not work correctly when there is more than 1 parent
      node.

      Symptoms:
      The function $newstruct is used to explicitly create a new Struct with no
      members. In case the referenced Struct that should be created has a parent that
      is a collection of Struct nodes then this will not work as expected.

      Consider the following code:

      variables
      struct vStruct
      endvariables

      vStruct->Library = $newstruct
      vStruct->Library->Book = $newstruct
      vStruct->Library->Book->Title = "Book Title 1"
      vStruct->Library->Book->Author = "Author 1"
      vStruct->Library->Book->Published = 2018

      ;;;vStruct->Library{-1} = $newstruct

      vStruct->Library->Book

      {2} = $newstruct
      vStruct->Library->Book{2}

      ->Title = "Book Title 2"
      vStruct->Library->Book

      {2}->Author = "Author 2"
      vStruct->Library->Book{2}

      ->Published = 2018

      putmess vStruct->$dbgstringplain

      When this code is executed then the output (in the Message Frame) will be:

      []
      [Library]
      [Book]
      [Title] = "Book Title 1"
      [Author] = "Author 1"
      [Published] = 2018
      [Book]
      [Title] = "Book Title 2"
      [Author] = "Author 2"
      [Published] = 2018

      In case the $newstruct instruction in the middle (that is commented out) is
      enabled then the result is as follows:

      []
      [Library]
      [Book]
      [Title] = "Book Title 1"
      [] = ""
      [Published] = 2018
      [Library] = ""

      Instead of creating a second Book Struct the second member of the Book Struct
      is overwritten. As if the following line of code is executed:

      vStruct->Library

      {1}->Book{1}

      ->*

      {2}

      = $newstruct

      It has to be said that the $newstruct instruction in question is ambiguous and
      it would probably be better if Uniface would throw an error here. Maybe
      something like error (USTRUCTERR_NOT_A_SINGLE_STRUCT; Tried to assign a struct
      to multiple parents).

        Attachments