Author Topic: Can GetElementsByQuery run custom searches?  (Read 7764 times)

Dave_Bullet

  • EA User
  • **
  • Posts: 295
  • Karma: +0/-0
    • View Profile
Can GetElementsByQuery run custom searches?
« on: April 08, 2008, 07:37:17 am »
Hi there,

Can Repository.GetElementsByQuery() run custom (ie. SQL) searches?

If not - can this facility be added?  It would be quite useful to utilise custom searches already defined in the EA interface (especially SQL ones).  The other option is have both the add-in and the custom search call the same stored procedure

David.
"I know I'm close to a good design, but it's like the balloon animals, squeeze in one spot and the problem moves down the line"

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Can GetElementsByQuery run custom searches?
« Reply #1 on: April 08, 2008, 08:02:05 am »
Don't know Dave,

After staring at the query definitions from EA for a few hours I switched to the Repository.SQLQuery method instead. It returned an XMI stream that was very easy to parse.

David
No, you can't have it!

Dave_Bullet

  • EA User
  • **
  • Posts: 295
  • Karma: +0/-0
    • View Profile
Re: Can GetElementsByQuery run custom searches?
« Reply #2 on: April 08, 2008, 09:17:07 am »
Thanks David,

I missed that method.  Looks like a much better approach.  I'll change both the user's EA SQL search and my code to call the same stored proc.

Cheers,
David.
"I know I'm close to a good design, but it's like the balloon animals, squeeze in one spot and the problem moves down the line"

arose

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Can GetElementsByQuery run custom searches?
« Reply #3 on: April 15, 2008, 10:26:15 am »
I'm also interested in being able to execute home-grown "Model Search" queries, because the output is so convenient for the user, who can click on a result row, and immediately find the element in the project tree.

When I call Repository.GetElementsByQuery("Recently Modified Elements","2008/01/01") it works - ie. with a built-in SQL query.

If I make my own copy of the same SQL query and call it "RecentlyModifiedQElementsAlso", I can demonstrate that it works using the user interface.  But when I call Repository.GetElementsByQuery("RecentlyModifiedQElementsAlso", "2008/01/01"), it triggers an error: "EA_MenuClick: Search Not Found".

There is a facility to create a Model Search from within an addin, using Repository.AddDefinedSearches and passing a string containing an XML version of a model search (such as one exported from the Model Search Management dialog).  This method successfully adds a search, which can be run manually like any other, but it still cannot be found using Repository.GetElementsByQuery.

So, my questions are "Is GetElementsByQuery intended to be able to find and execute Model Search queries that are not built-in queries?"  If so, how does one do it?  If not, can this feature be added?

arose

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Can GetElementsByQuery run custom searches?
« Reply #4 on: April 15, 2008, 10:38:23 am »
Ah, I just found Repository.RunModelSearch :-) for displaying query results in the model search window.

It would still be helpfull to know how to have GetElementsByQuery work with custom queries.



alexander.erdei

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Can GetElementsByQuery run custom searches?
« Reply #5 on: June 10, 2016, 10:34:44 pm »
Quote from SparxSupport:
“…the GetElementsByQuery(), does work on Elements. It does not work on Diagrams.
We do not support a Get Diagrams equivalent.”
The EA example scripts do use “SQLQuery (string SQL)” for custom searches, then MSXML library for parsing the returned XML string;

OpenIT Solutions

  • EA User
  • **
  • Posts: 555
  • Karma: +9/-1
    • View Profile
Re: Can GetElementsByQuery run custom searches?
« Reply #6 on: June 15, 2016, 09:58:37 pm »
Hi,

If you want a collection of elements based upon an ad-hoc SQL query (as opposed to a saved EA query) use:

- GetElementSet (string IDList, long Options)

IDList will be your SQL, Options will be 2; see here for details:

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


Regards,

Jon.