Book a Demo

Please note : This help page is not for the latest version of Enterprise Architect. The latest help can be found here.

Prev Next

Create Search Definitions

If you want to define your own searches, you can do so using the SQL Editor, Query Builder or an Add-In, through the 'New Search' dialog. User-defined searches are stored in the user application data for the machine being used, and not in the project repository.

Access

Ribbon

Explore > Search > Model : New search icon.    or

Design > Element > Manage > Search Model : New search icon.

Keyboard Shortcuts

Crtl+F : New search icon.   or

Ctrl+Alt+A : New search icon.

Create a new search definition

Field/Button

Action

See also

Name

Type a name for the search.

Query Builder

Click on this radio button to create your search through the internal search editor.

SQL Editor

Click on this radio button to create your search by directly writing SQL statements.

(For advanced users.)

Add-In Search

Click on this radio button to define the search as a function of an Add-In.

Add-In Name and Method

(Available if you have selected the 'Add-In Search' radio button)

Type in:

  • The name of your Add-In
  • A period (full stop) and
  • The name of the method to be called whenever the search is run (for example, MyAddin.RunThisMethod); this search can be exported and distributed as a part of your Add-In
Add-In Search

OK

Click on this button to create the new search and close the dialog.

The search builder panel opens underneath the toolbar. For:

  • An Add-In search, no further action is required; click on the Edit search. icon to close the search builder panel
  • A Query Builder search, the panel defaults to the 'Query Builder' tab and you can start adding filters and constructing the search; see the Define and Modify Searches topic
  • An SQL search, the panel defaults to the 'Query Builder' tab and you can start to create the SQL statement for the search, as in Create SQL Search

The Search Builder also provides an 'SQL Scratch Pad' tab, which you can use to create and test SQL statements before copying them across to the 'Query Builder' tab.

SQL statements on the 'SQL Scratch Pad' are not attached to any search and are not the focus of any operations initiated from the 'Find in Project' toolbar.

Define & Modify Searches

Cancel

Click on this button to abort the search creation and close the dialog.

Create SQL Search

You can create SQL statements using the SQL Editor through the 'Query Builder' tab. The SQL editor is based on the common Code Editor, and provides an Intelli-sense autocompletion list populated from the Enterprise Architect repository structure.

To display the autocompletion list, position the cursor after a command and press Ctrl+Space.

A simple search might be to locate an object from a table, given a search term that the user enters in the 'Search Term' field; for example:

     SELECT * FROM t_object WHERE Name='<Search Term>'  (also see the <Search Term> row in the table))

In the WHERE statements you can use #xxx# macros as string replacers, so that the same search can be used by different people in different environments. These macros are all case-sensitive. They include:

Macro

Description

See also

#Author#

Takes the user name from the 'Author' field in the 'Preferences' dialog 'General' page, so the defined search can be performed on objects created by that user (this value can be manually re-set in the 'Preferences' dialog). This must be used within a string.

#Branch#

Gets the ID of each child Package under one or more parent Packages, working recursively down to the lowest level of sub-Package. For example:

     t_object.Package_ID in (#Branch#)

There are three permutations of this macro:

  • in #Branch# - gets the ID of each child Package of the parent Package selected by the user
  • in #Branch=<GUID># or #Branch=<ID># - gets the ID of each child Package of the parent Package specified by the GUID or ID
  • in #Branch=<ID>,<ID>,<ID># - gets the ID of each child Package under each parent Package specified by its ID

#Concat <value1>, <value2>, ...#

Provides a method of concatenating two or more SQL terms into one string, independent of the database type.

#Datepart <field>, <column>#

Provides a method of querying one part of the Date, independent of the database type. The value of <field> can be one of:

  • year
  • month
  • day
  • dayofyear
  • weekday
  • week
  • dayname

#CurrentElementGUID#

Gets the ea_guid for the currently-selected element. For example:

     t_object.ea_guid=#CurrentElementGUID#

#CurrentElementID#

Gets the Object_ID for the currently selected element. For example:

     t_object.Object_ID=#CurrentElementID#

#DB=<DBNAME>#

DBNAME can be one of:

  • SL3
  • FIREBIRD
  • JET
  • ACCESS2007
  • MYSQL
  • ORACLE
  • SQLSVR
  • ASA
  • POSTGRES

This only uses the section of code between two matching #DB=<DBNAME># macros if the current database type matches the specified DBNAME; it can be used where a section of the SQL might require special handling depending upon the current database type. For example:

     select *

     from t_object

     where

     #DB=Other#t_object.modifieddate >= now() - 'Search Term'#DB=Other#

     #DB=SQLSVR#t_object.modifieddate >= getdate() - 'Search Term'#DB=SQLSVR#

     #DB=ORACLE#t_object.ModifiedDate >= (SYSDATE - INTERVAL 'Search Term' DAY) #DB=ORACLE#

     #DB=POSTGRES#t_object.modifieddate >= CURRENT_DATE - 'Search Term'#DB=POSTGRES#

#Left <field>, <count>#

Returns the 'count' number of characters from the field, starting at the beginning of the string.

#Now#

Inserts the current date plus or minus a specified number of hours or days; the default is days (the date format is adjusted to suit the database in use) as in:

  • t_object.ModifiedDate >=#Now <Search Term>#

For example:

  • t_object.ModifiedDate >= #Now -4d#    d is days
  • t_object.ModifiedDate >= #Now -5h#    h is hours
  • t_object.ModifiedDate >= #Now +3#     defaults to days
  • t_object.ModifiedDate >= #Now#

#Package#

Gets the Package_ID for the currently-selected Package. For example:

     t_object.Package_ID=#Package#

#Right <field>, <count>#

Returns the last 'count' number of characters from the field.

<Search Term>

Gets the value on which to search, from the text entered in the 'Search Term' field in the Find in Project view (the third field from the left). It therefore functions when an active search is being run and values are being placed in that field. It must appear inside a string, and s required to be in quotes if the table.Field it is being compared with is of type string.

#Substring <field>, <start>#

Returns the remainder of the field beginning at the 'start' character (1-based)

#Substring <field>, <start>, <count>#

Returns the 'count' number of characters of the field starting at character 'start' (1-based).

#UserName#

Gets the name of the person logged into Version Control.; it must be used inside a string. This example is from the built in search 'My Checked Out Packages'.

     t_package.PackageFlags LIKE '#WC#VCCFG=#WC#CheckedOutTo=#UserName##WC#'

#WC#

Gets the appropriate wild card for the current database, so the search can be performed on models on different databases. It must be used inside a string. For example:

     t_object.Name LIKE '#WC#Test#WC#'

The GUID and Type

For all functions in which you use a custom SQL statement (including Document Reporting and Model Views) the statement must return the GUID and type of the object found so that the system can search for the selected item in the Browser window. The SELECT statement is case-sensitive and should be typed as shown:

  • SELECT ea_guid AS CLASSGUID, Object_Type AS CLASSTYPE, Name FROM t_object

You can extend the usability of your SQL searches using the aliases CLASSGUID and CLASSTYPE, so that you can display the 'Properties' dialog, Tagged Values and icon for elements, connectors, attributes or operations, as well as selecting them in the Browser window. Some simple examples for using these aliased fields are:

  • SELECT ea_guid AS CLASSGUID, Object_Type AS CLASSTYPE, Name FROM t_object
  • SELECT ea_guid AS CLASSGUID, 'Operation' AS CLASSTYPE, Name FROM t_operation
  • SELECT ea_guid AS CLASSGUID, 'Attribute' AS CLASSTYPE, Name FROM t_attribute

Queries for connectors and diagrams can both return types that match the default association to object types. For these tables, you should also return a CLASSTABLE field to allow them to be distinguished from the similar object type.

  • SELECT ea_guid AS CLASSGUID, Connector_Type AS CLASSTYPE, 't_connector' as CLASSTABLE, Name FROM t_connector
  • SELECT ea_guid AS CLASSGUID, Diagram_Type AS CLASSTYPE, 't_diagram' as CLASSTABLE, Name FROM t_diagram

You can enable your search users to drag and drop elements from the search results onto a diagram, by including one of these in your search SELECT statement:

  • (t_object.Object_ID and t_object.Object_Type) or
  • t_object. ea_guid AS CLASSGUID

When you have defined the SELECT statement, click on the Save button in the 'Query Builder' toolbar to save this search; the search is then available from the 'Search' drop-down list.

SQL Scratch Pad Toolbar buttons

The 'SQL Scratch Pad' tab provides a small number of facilities through its toolbar.

Icon

Description

Start test.

Click on this icon to test the search you have defined. The results display in the main panel of the 'Find in Project' view.

Click on this icon to save the current SQL search as a new search. A prompt displays for the new search name.

When you click on the OK button, the system switches to the 'Query Builder' tab, copies the SQL Statement to the tab, and puts the search name into the 'Search' field.

Click on this icon to clear the 'SQL Scratch Pad' of the current search definition.

Notes

  • When you create a custom SQL search on the 'Query Builder' tab, the only two icons that are available in the Toolbar are the Save icon and the Remove Filter icon Remove filter button.; the Remove Filter icon is effectively a Delete icon that removes the search content (the SQL statement)

Learn more