Author Topic: Sql query for retreiving all packages in model  (Read 7283 times)

tzafrir

  • EA User
  • **
  • Posts: 127
  • Karma: +0/-0
    • View Profile
Sql query for retreiving all packages in model
« 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?


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Sql query for retreiving all packages in model
« Reply #1 on: March 18, 2016, 06:41:53 pm »

tzafrir

  • EA User
  • **
  • Posts: 127
  • Karma: +0/-0
    • View Profile
Re: Sql query for retreiving all packages in model
« Reply #2 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?

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: Sql query for retreiving all packages in model
« Reply #3 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
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Sql query for retreiving all packages in model
« Reply #4 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 ).

tzafrir

  • EA User
  • **
  • Posts: 127
  • Karma: +0/-0
    • View Profile
Re: Sql query for retreiving all packages in model
« Reply #5 on: March 21, 2016, 09:11:56 pm »
thanks