Sparx Systems Forum

Enterprise Architect => General Board => Topic started by: SystemsTinkerer on January 27, 2022, 09:34:43 pm

Title: SQL Search within model - to find packages hierarchy of Diagrams (+ its GUID)
Post by: SystemsTinkerer on January 27, 2022, 09:34:43 pm
Hi EA Users,

I have had valuable input from Geert on package level search but I am stuck on modifying his script to:
Quote
from (t_package p
inner join t_object o on o.Package_ID = p.Package_ID)
where
p.Package_ID = #Package#
union
select p.name as PackageName ,p2.Name as PackageLevel2,null as PackageLevel3
,o.ea_guid as CLASSGUID,o.Object_Type as CLASSTYPE,o.Name as Name,o.Stereotype
from ((t_package p
inner join t_package p2 on p2.Parent_ID = p.Package_ID)
inner join t_object o on o.Package_ID = p2.Package_ID)
where
p.Package_ID = #Package#
union
select p.name as PackageName ,p2.Name as PackageLevel2,p3.Name as PackageLevel3
,o.ea_guid as CLASSGUID,o.Object_Type as CLASSTYPE,o.Name as Name,o.Stereotype
from (((t_package p
inner join t_package p2 on p2.Parent_ID = p.Package_ID)
inner join t_package p3 on p3.Parent_ID = p2.Package_ID)
inner join t_object o on o.Package_ID = p3.Package_ID)
where
p.Package_ID = #Package#
order by 1, 2, 3

Any help to get me going would be really appreciated AND/OR if I could get an idea of the tables related to my model, how they are accessed, viewed and parsed using SQL it will be an even bigger help.

Thank you for your consideration.

Best,
Oz





Title: Re: SQL Search within model - to find packages hierarchy of Diagrams (+ its GUID)
Post by: Geert Bellekens on January 27, 2022, 10:49:32 pm
You can join t_diagram on t_diagram.Package_ID = t_package.Package_ID
Adding more levels is simply a matter of adding another union with a extra join to t_package.

If you want to know more about the database structure you can simply reverse engineer it in EA itself.

More explanation in Thomas' book https://leanpub.com/InsideEA (https://leanpub.com/InsideEA)

Geert
Title: Re: SQL Search within model - to find packages hierarchy of Diagrams (+ its GUID)
Post by: SystemsTinkerer on January 28, 2022, 05:22:17 am
Hi Geert,

Many thanks for your guidance & the book reference. I will this a go & consult that book.

Cheers,
Oz
Title: Re: SQL Search within model - to find packages hierarchy of Diagrams (+ its GUID)
Post by: qwerty on January 28, 2022, 06:24:52 am
Should you find to not find something give me a note :-)

q.
Title: Re: SQL Search within model - to find packages hierarchy of Diagrams (+ its GUID)
Post by: SystemsTinkerer on January 28, 2022, 11:07:36 am
Hello!

The package hierarchy search throws up some strange results along with the good stuff.  The block and elements are coming up as packages, instead  of only real package/folder types - see the following screenshot of my result:
https://ibb.co/f4WNfGV
(https://ibb.co/f4WNfGV)

Thanks,


Title: Re: SQL Search within model - to find packages hierarchy of Diagrams (+ its GUID)
Post by: Geert Bellekens on January 28, 2022, 04:31:20 pm
I guess you must have used o.name in one of your selects.

Hard to tell without seeing the actual query you are using.

Geert
Title: Re: SQL Search within model - to find packages hierarchy of Diagrams (+ its GUID)
Post by: SystemsTinkerer on January 28, 2022, 09:01:48 pm
Sorry for not being clear - I am using your example code Geert from the discussion:
https://sparxsystems.com/forums/smf/index.php/topic,46543.0.html

Here is the exact SQL code I am running on my EA:
Code: [Select]
select p.name as PackageName ,null as PackageLevel2,null as PackageLevel3
,o.ea_guid as CLASSGUID,o.Object_Type as CLASSTYPE,o.Name as Name,o.Stereotype
from (t_package p
inner join t_object o on o.Package_ID = p.Package_ID)
where
p.Package_ID = #Package#
union
select p.name as PackageName ,p2.Name as PackageLevel2,null as PackageLevel3
,o.ea_guid as CLASSGUID,o.Object_Type as CLASSTYPE,o.Name as Name,o.Stereotype
from ((t_package p
inner join t_package p2 on p2.Parent_ID = p.Package_ID)
inner join t_object o on o.Package_ID = p2.Package_ID)
where
p.Package_ID = #Package#
union
select p.name as PackageName ,p2.Name as PackageLevel2,p3.Name as PackageLevel3
,o.ea_guid as CLASSGUID,o.Object_Type as CLASSTYPE,o.Name as Name,o.Stereotype
from (((t_package p
inner join t_package p2 on p2.Parent_ID = p.Package_ID)
inner join t_package p3 on p3.Parent_ID = p2.Package_ID)
inner join t_object o on o.Package_ID = p3.Package_ID)
where
p.Package_ID = #Package#
order by 1, 2, 3
Title: Re: SQL Search within model - to find packages hierarchy of Diagrams (+ its GUID)
Post by: qwerty on January 28, 2022, 11:20:07 pm
Actually I don't see anything duplictate in the picture.

q.
Title: Re: SQL Search within model - to find packages hierarchy of Diagrams (+ its GUID)
Post by: Geert Bellekens on January 29, 2022, 01:02:16 am
This query is mainly looking at the elements, not only packages.

If you need only packages you should only look at t_package, not at t_object.

Geert
Title: Re: SQL Search within model - to find packages hierarchy of Diagrams (+ its GUID)
Post by: SystemsTinkerer on January 29, 2022, 01:22:58 am
Thank you for the input gents! Geert, the object information & particularly the diagram (name & GUID) is of interest too, BUT I want the result gained from the search to clearly show:

Thanks again for your guidance.  :)
Title: Re: SQL Search within model - to find packages hierarchy of Diagrams (+ its GUID)
Post by: qwerty on January 29, 2022, 03:13:14 am
You would need to join the package.name from the package connected via the object.package_id. Will probably make the query even more bloated.

You can't create a tree view.

q.
Title: Re: SQL Search within model - to find packages hierarchy of Diagrams (+ its GUID)
Post by: SystemsTinkerer on January 29, 2022, 06:23:36 am
Hi q,

Thank you for your comments. I will play around & try out your suggestion. However, are you referring to my need to have a hierarchical package as a tree view, which is not doable? Why is it not doable using SQL? Would you suggest going down the route of JavaScript instead then?

Cheers,
Oz
Title: Re: SQL Search within model - to find packages hierarchy of Diagrams (+ its GUID)
Post by: qwerty on January 29, 2022, 07:30:56 am
Well, SQL only returns a list and not a hierarchy. You could decompose it programmatically. But the search window from EA only shows a list. You would need to write an add-in ith your own window/content.

q.
Title: Re: SQL Search within model - to find packages hierarchy of Diagrams (+ its GUID)
Post by: SystemsTinkerer on January 29, 2022, 08:23:51 am
Got it q! I will start getting acquainted with the add-in approach in parallel. Thank you for the chat & input.

Cheers!
Title: Re: SQL Search within model - to find packages hierarchy of Diagrams (+ its GUID)
Post by: qwerty on January 29, 2022, 10:38:37 am
Don't miss Geert's tutorial about add-ins in 10 minutes (that's not a lie since I did it this way to). Likely the *real* stuff is more complicated then.

q.
Title: Re: SQL Search within model - to find packages hierarchy of Diagrams (+ its GUID)
Post by: SystemsTinkerer on January 30, 2022, 12:37:37 am
Thanks q. Yes, I will definitely consult his stuff on this.

Best,
Oz