Sparx Systems Forum

Enterprise Architect => General Board => Topic started by: tzafrir on March 18, 2016, 06:40:10 pm

Title: Sql query for retreiving all packages in model
Post by: tzafrir on March 18, 2016, 06:40:10 pm
Hi,

Is there an SQL query that I can get all (and only) packages in the model?

Title: Re: Sql query for retreiving all packages in model
Post by: Geert Bellekens on March 18, 2016, 06:41:53 pm
Select * from t_package (http://Select * from t_package) ???

Geert
Title: Re: Sql query for retreiving all packages in model
Post by: tzafrir on March 21, 2016, 04:49:16 pm
When I run the following command:
EA.Collection result = repository.GetElementSet("Select Package_id from t_package", 2);

I am getting the following error:
DAO.fields [3265] item not found in this collection

When running,
EA.Collection result = repository.GetElementsByQuery("Select Package_id from t_package","");
I am getting
"Search Not found"

This query extracts values using EA Builder with no errors, what is the correct way of getting those Ids?
Title: Re: Sql query for retreiving all packages in model
Post by: Helmut Ortmann on March 21, 2016, 05:03:05 pm
Hi Tzafrir,

GetElementSet() expects a list of IDs, comma separated, not a SQL query.

GetElementsByQuery() expects a EA Search, not a SQL Query, like 'Simple' or so. Have a look in the search window (CTRL+F) for available searches. For a start try Simple.

See documentation: http://sparxsystems.com/enterprise_architect_user_guide/12.1/automation_and_scripting/repository3.html

Regards,

Helmut
Title: Re: Sql query for retreiving all packages in model
Post by: Aaron B on March 21, 2016, 05:13:10 pm
Actually, GetElementSet() can use a SQL Query, but it can only return a collection of Element objects, not Package objects.

You might be able to use something like:
EA.Collection result = Repository.GetElementSet("select object_id from t_object where object_type = 'Package'", 2);

Then make sure to handle the contents of this collection as EA.Element types, not EA.Package.  To get the corresponding EA.Package for each of these elements, try calling Repository.GetPackageByGUID( element.ElementGUID ).
Title: Re: Sql query for retreiving all packages in model
Post by: tzafrir on March 21, 2016, 09:11:56 pm
thanks