Book a Demo

Author Topic: SQL help in finding missing operations  (Read 5298 times)

DarrenDickens

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
SQL help in finding missing operations
« on: February 07, 2017, 02:24:33 am »
Firstly, sorry for the long post.

Our model has standard classes with operations but we also have activity parameters representing the same operations. I am trying to locate missing ones via SQL.

As a test example, we have the following operations (listed as <class>::<operation>)
  • c1::MyOperation1
  • c1::MyOperation2
  • c2::MyOperation1
  • c2::MyOperation2
  • c2::MyOperation3
  • c2::MyOperation4
and the following activity parameters (listed as <activity>::<activityparameter>)
  • c1::MyOperation1
  • c1::MyOperation2
  • c1::MyOperation3
  • c2::MyOperation1
  • c2::MyOperation2

The errors are as follows
  • Class/operation c2::MyOperation3 has no corresponding activity/activityparameter
  • Class/operation c2::MyOperation4 has no corresponding activity/activityparameter
  • Activity/activityparameter c1::MyOperation3 has no corresponding class/operation

The first 2 are what I want my SQL query to detect. The 3rd one will be detected by a similar query (when I get the first one working). I have performed earlier queries that detected classes without identical named activities.

Therefore, the expected results from any query are

  • c2::MyOperation3
  • c2::MyOperation4

I have tried to write an SQL query that detects this but keep getting stuck. The query below is where I started from.

Code: [Select]
SELECT *
FROM
(((
t_object  o_class
INNER JOIN t_object o_activity ON
    (   o_activity.name = o_class.name
        AND
        o_class.object_type = 'class'
        AND
        o_activity.object_type = 'activity'
    )
)
INNER JOIN t_operation o_operation ON o_operation.object_id = o_class.object_id)
LEFT JOIN t_object o_actparam ON
    (   o_actparam.name = o_operation.name
        AND
        o_actparam.object_type = 'activityparameter'
        AND
        o_actparam.parentid = o_activity.object_id
    )
)
WHERE
o_actparam.name is NULL

The above aims to get a class, then an activity with the same name, then all operations belonging to the class, then for each operation try and find an activity parameter in this activity with the same name. Any that didn't match should return NULL (since it is a LEFT JOIN) and so the WHERE statement shows the operations that didn't have a related activityparameter, i.e. the errors.

The above does not work; I get a "JOIN expression not supported".

If I take out the "o_actparam.parentid = o_activity.object_id" then it returns no results at all. This is clearly wrong.

If I change the LEFT JOIN to
Code: [Select]
LEFT JOIN t_object o_actparam ON
    (   o_actparam.name = o_operation.name
        AND
        (   o_actparam.object_type = 'activityparameter'
            OR
            o_actparam.object_type is NULL
        )
    )
then I get the result

  • c2::MyOperation4

It has failed to find c2::MyOperation3. This is because operation c2::MyOperation3 matches activityparmater MyOperation3 (even though that belongs to class/activity c1). The comparison ignores the class/activity.

If I change the WHERE (and keep the above LEFT JOIN) to
Code: [Select]
WHERE
o_actparam.parentid <> o_activity.object_id
OR
o_actparam.parentid is NULL
then I get the result

  • c1::MyOperation1
  • c1::MyOperation2
  • c2::MyOperation1
  • c2::MyOperation2
  • c2::MyOperation3
  • c2::MyOperation4

It is now finding lots of wrong items since the same activityparameter name exists in different activities. The WHERE is too late to throw away items, however, putting the parentid in the LEFT JOIN gave me the "JOIN expression is not supported" error.

Is someone able to help me here?
Thanks
Darren

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: SQL help in finding missing operations
« Reply #1 on: February 07, 2017, 03:33:17 am »
Unless some SQL guru here will spot it, I guess you are better off asking this on StackOverflow since it looks like some basic SQL issue, not an EA issue.

q.

DarrenDickens

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: SQL help in finding missing operations
« Reply #2 on: February 07, 2017, 03:40:38 am »
OK, will do.

EDIT: Updated with link to StackOverflow post (for completeness) http://stackoverflow.com/questions/42087951/sql-left-join-join-expression-is-not-supported
« Last Edit: February 07, 2017, 10:07:17 pm by DarrenDickens »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: SQL help in finding missing operations
« Reply #3 on: February 07, 2017, 04:05:10 am »
Darren,

With all the left joins and inbetween tables you are safer to use a
where not exists clause.

That will also make reading the intend of the query clearer to the next person who comes across this one.

Geert

DarrenDickens

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: SQL help in finding missing operations
« Reply #4 on: April 27, 2017, 11:00:46 pm »
I found the answer to my problem. I posted the answer in my modified StackOverflow version of this question, see http://stackoverflow.com/questions/42087951/sql-left-join-join-expression-is-not-supported/