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

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 Edit | Search Model:

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 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 Create 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+Spacebar.

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, such as:

     SELECT * FROM t_object WHERE NAME='<Search Term>'

In the WHERE statements you can also 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

#WC#

Gets the appropriate wild card for the current database, so the search can be performed on models on different databases. For example:

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

#Author#

Takes the user name from the 'Author' field in the 'Options' 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 'Options' dialog).

#DB=<DBNAME>#

<DBNAME> can be one of:

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

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:

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

#UserName#

Gets the name of the person logged into version control. This example is from the built in search 'My Checked Out Packages'.

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

#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#
  • t_object.ModifiedDate >= #Now#

#Package#

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

     t_object.Package_ID = #Package#

#Branch#

Gets the IDs of the child Packages of the currently-selected Package, working recursively down to the lowest level of sub-Package. For example:

  • t_object.Package_ID IN (#Branch#)

#CurrentElementID#

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

  • t_object.Object_ID=#CurrentElementID#

#CurentElementGUID#

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

  • t_object.ea_guid LIKE #CurrentElementGUID#

The GUID and Type

For all functions in which you use a custom SQL statement (such as Document Reporting or 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 Project Browser.

  • 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 Project Browser.  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

For connectors you must also include the alias CLASSTABLE, for example:

  • SELECT ea_guid AS CLASSGUID, Connector_Type AS CLASSTYPE, "t_connector" as CLASSTABLE, Name FROM t_connector

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

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 icon; the Remove Filter icon is effectively a Delete icon that removes the search content (the SQL statement)

Learn more