Book a Demo

Author Topic: Loop on a class operation parameters: order issue  (Read 4301 times)

Guillaume

  • EA Practitioner
  • ***
  • Posts: 1405
  • Karma: +42/-2
    • View Profile
    • www.umlchannel.com
Loop on a class operation parameters: order issue
« on: September 08, 2023, 06:59:55 pm »
Hello,

I have a script to compare the order of parameters between the operations from 2 classes.
Having both EA.Method objects; op1 and op2, I have a loop as follows

Code: [Select]
for i = 0 to op1.Parameters.Count - 1
   set op1Param = op1.Parameters.GetAt(i)
   set op2Param = op2.Parameters.GetAt(i)
  if (op1Param.Name = op2Param.Name) then  ...
  end if
next

In EA the 2 operations have the same order for the parameters i.e. param1, param2
Running the script, op1 1st parameter is param1, whereas op2 1st parameter is param2...
Running a simple query on t_operationparams table, the parameters are not in this order. Since Pos = 0, there is no column to sort the values. They seem to appear in a default order controlled by the DB which may be linked with the order the parameters have been added to the table.

It's only if I manually change the order of the parameters in EA with Ctrl+up and down within each operation that it populates the Pos value and fixes the comparison issue.

I'm not sure there's a solution here, but I wonder why the order displayed in EA and available via the API are not consistent.
Any idea?
« Last Edit: September 08, 2023, 07:04:12 pm by Guillaume »
Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Loop on a class operation parameters: order issue
« Reply #1 on: September 08, 2023, 08:20:33 pm »
I have an idea why that happens.
Both methods (API and GUI) use a different path to access the data (maybe a different query).
If you don't specify an "order by" clause when getting data from a database, you are not guaranteed any order at all.

So what I would do to solve your issue:

- figure out how EA orders the parameters in the GUI
- use SQLQuery to get the data from your parameters in the correct order
- Once you have decided what needs to change, use the API to get the parameter object.

Added benefit: this will probably be (a lot?) faster as well.

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Loop on a class operation parameters: order issue
« Reply #2 on: September 08, 2023, 09:38:28 pm »
Generally ordering in EA is a bit of a mystery process. You probably need to be a native Sparxian to understand it. Try the steps Geert suggested - and have enough patience...

q.

Guillaume

  • EA Practitioner
  • ***
  • Posts: 1405
  • Karma: +42/-2
    • View Profile
    • www.umlchannel.com
Re: Loop on a class operation parameters: order issue
« Reply #3 on: September 09, 2023, 01:29:25 am »
Thank you for the suggestions. Using the PCS trace logs, I manage to find the following query:

Code: [Select]
SELECT t_operationparams.*  FROM t_operationparams,  t_operation  WHERE     (        (t_operationparams.OperationID = t_operation.OperationID)     and        (t_operation.Object_ID  in (1000,1001))     ) order by t_operation.OperationID, t_operationparams.Pos
I'm updating the script with the query to see if it sorts the issue.
Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com