query_language

Selects objects by their metadata

Applicability

Product

Command type

ClearCase®

general information

Platform

UNIX

Linux

Windows

Synopsis

Query primitives:
query-function (arg-list)

attribute-type-name  comparison-operator  value

Compound queries:
query && query

query || query ! query ( query )

Description

The query language is used to formulate queries on VOBs. It includes logical operators similar to those in the C programming language. A query searches one or more VOBs and returns the names of objects, such as versions, branches, and elements. A query may return a single object, many objects, or no objects at all.

A query primitive evaluates to TRUE or FALSE. A TRUE value selects an object, such as an element, branch, or version; a FALSE value excludes it.

A query must be enclosed in quotes if it includes spaces. You may also need to enclose a query in quotes to prevent shell-level interpretation of characters such as ( (open parenthesis). Quoting parentheses in config specs is not required.

Queries in version selectors

You can use a query in a version selector in these contexts:

  • Command-line options in the following cleartool commands:

    describe, merge, mkattr, mkbranch, mklabel, rmattr, rmlabel, rmver

  • Configuration rules; see the config_spec reference page
  • Version-extended pathnames in ClearCase commands; see the pathnames_ccase reference page

A query in a version selector must be enclosed in braces ( {} ).

When a query is applied to a single branch, ClearCase selects the most recent version on that branch that satisfies the query. For example:

cmd-context  describe -ver '/main/{attype(QAed)}' util.c

Using a query without a branch pathname causes an element's entire version tree to be searched. If the query returns a single version, the version-selection operation succeeds; the operation fails if the query returns no version (not found) or returns more than one version (ambiguous). For example:

cmd-context  describe -ver "{attype(QAed)}" util.c
cleartool: Error: Ambiguous query: "{attype(QAed)}"

Queries in the find and findmerge commands

You can also use queries in the find and findmerge commands. In this context, the query can be enclosed in braces ({...}). The query returns the names of all matching objects. For example:

  • UNIX and Linux:

    cleartool find util.c -ver attype(QAed) -print
    util.c@@/main/1
    util.c@@/main/3

  • Windows (notice the quotes):

    cleartool find util.c -ver "attype(QAed)" -print
    util.c@@\main\1
    util.c@@\main\3

Query primitives

The query language includes these primitives:

attribute-type-name  comparison-operator  value

comparison-operator is one of the following:

==     !=    <    <=    >    >=

Examples:

BugNum==4053
BugNum>=4000
Status!="tested"

This primitive is TRUE if the object itself has an attribute of that type and the value comparison is true. To test whether an object or its subobjects has a particular attribute (for example, an element or its branches and versions), use the attr_sub primitive.

Note: If no attribute named BugNum has been attached to an object, then !BugNum==671 is TRUE, but BugNum!=671 is FALSE. The second query would be true if an attribute of type BugNum existed, but had a different value.
attr_sub (attribute-type-name, comparison-operator, value)

With elements

TRUE if the element or any of its branches or versions has an attribute of type attribute-type-name that satisfies the specified comparison with value.

With branches

TRUE if the branch or any of its versions has an attribute of type attribute-type-name that satisfies the specified comparison with value.

With versions

TRUE if the version itself has an attribute of type attribute-type-name that satisfies the specified comparison with value.

attype (attribute-type-name)

With elements

TRUE if the element itself has an attribute of type attribute-type-name.

With branches

TRUE if the branch itself has an attribute of type attribute-type-name.

With versions

TRUE if the version itself has an attribute of type attribute-type-name.

attype_sub (attribute-type-name)

With elements

TRUE if the element or any of its branches or versions has an attribute of type attribute-type-name.

With branches

TRUE if the branch or any of its versions has an attribute of type attribute-type-name.

With versions

TRUE if the version itself has an attribute of type attribute-type-name.

brtype (branch-type-name)

With elements

TRUE if the element has a branch named branch-type-name.

With branches

TRUE if the branch is named branch-type-name.

With versions

TRUE if the version is on a branch named branch-type-name.

created_by (login-name)
In all cases, TRUE if the object was created by the user login-name (as shown by the describe command).
created_since (date-time)
In all cases, TRUE if the object was created since date-time. The date-time argument can be input in ISO 8601 format or in any of the following formats:

date.time | date | time |now where:

date

:=

day-of-week | long-date

time

:=

h[h]:m[m][:s[s]] [UTC [ [ + | - ]h[h][:m[m] ] ] ]

day-of-week

:=

today |yesterday |Sunday | ... |Saturday |Sun | ... |Sat

long-date

:=

d[d]month[[yy]yy]

month

:=

January |... |December |Jan |... |Dec

Specify the time in 24-hour format, relative to the local time zone. If you omit the time, the default value is 00:00:00. If you omit the date, the default is today. If you omit the century, year, or a specific date, the most recent one is used. Specify UTC if you want to resolve the time to the same moment in time regardless of time zone. Use the plus (+) or minus (-) operator to specify a positive or negative offset to the UTC time. If you specify UTC without hour or minute offsets, Greenwich Mean Time (GMT) is used. (Dates before January 1, 1970 Universal Coordinated Time (UTC) are invalid.)

Regardless of input format, date and time values are output in ISO 8601 format.

eltype (element-type-name)
In all cases, TRUE if the element to which the object belongs is of type element-type-name.
hltype (hlink-type-name), hltype (hlink-type-name, ->), hltype (hlink-type-name ,<-)
In all cases, TRUE if the object is either end of a hyperlink (first form) named hlink-type-name, or is the from-end of a hyperlink (second form), or is the to-end of a hyperlink (third form)
lbtype (label-type-name)
In all cases, TRUE if the object itself is labeled label-type-name. (Because elements and branches cannot have labels, this primitive can be true only for versions.)
lbtype_sub (label-type-name)

With elements

TRUE if the element has a version that is labeled label-type-name.

With branches

TRUE if the branch has a version that is labeled label-type-name.

With versions

TRUE if the version itself is labeled label-type-name.

merge (from-location , to-location)
In all cases, TRUE if the element to which the object belongs has a merge hyperlink (default name: Merge) connecting the from-location and to-location. You can specify either or both locations with a branch pathname or a version selector. Specifying a branch produces TRUE if the merge hyperlink involves any version on that branch. The branch pathname must be complete (for example, /main/rel2_bugfix, not rel2_bugfix).
pool (pool-name)
In all cases, TRUE if the element to which the object belongs has a source pool or cleartext pool named pool-name.
trtype (trigger-type-name)
In all cases, TRUE if the element to which the object belongs has an attached or inherited trigger named trigger-type-name.
version (version-selector)

With elements

TRUE if the element has a version with the specified version-selector.

With branches

TRUE if the branch has a version with the specified version-selector.

With versions

TRUE if the version itself has the specified version-selector.

Note that in this context, version-selector cannot itself contain a query. For example, version(REL1) is valid, but version(lbtype(REL1)) is not.

Compound queries

Primitives can be combined into expressions with logical operators. An expression can take any of these forms, where query is a primitive or another expression:

  • Logical OR: query||query
  • Logical AND: query&&query
  • Logical NOT: !query
  • Grouping to override precedence: (query)

Operator precedence

The precedence and associativity of the operators for attribute comparisons and formation of logical expressions are the same as in the C programming language:

  • Highest precedence: ! (right associative)
  • Lower precedence: < <= > >= (left associative)
  • Lower precedence: == != (left associative)
  • Lower precedence: && (left associative)
  • Lowest precedence: || (left associative)

Examples

The UNIX system and Linux examples in this section are written for use in csh. If you use another shell, you might need to use different quoting and escaping conventions.

The Windows examples that include wildcards or quoting are written for use in cleartool interactive mode. If you use cleartool single-command mode, you might need to change the wildcards and quoting to make your command interpreter process the command appropriately.

In cleartool single-command mode, cmd-context represents the UNIX system and Linux shells or Windows command interpreter prompt, followed by the cleartool command. In cleartool interactive mode, cmd-context represents the interactive cleartool prompt.

  • On a UNIX or Linux system, display all versions of test.c for which the attribute QAed has the value Yes.

    cat ‘cleartool describe –s –ver /main'{QAed=="Yes"}' test.c‘

  • Attach the label REL6 to the version of test.c that is already labeled REL5.

    UNIX and Linux:

    cleartool mklabel -ver '{lbtype(REL5)}' REL6 test.c
    Created label "REL6" on "test.c" version "/main/4".

    Windows:

    Z:\vob2\src> cleartool mklabel -ver "{lbtype(REL5)}" REL6 test.c

    Created label "REL6" on "test.c" version "\main\4".

  • Attach an attribute to the latest version of test.c created since yesterday at 1 P.M. by user asd. Note the use of backslashes (\) to escape quote characters (") required to specify a string argument to mkattr.

    UNIX and Linux:

    mkattr -ver '{created_since(yesterday.13:00)&&created_by(asd)}' \
    QAed \"No\" test.c

    Created attribute "QAed" on "test.c@@/main/5".

    Windows:

    cleartool> mkattr -ver "{created_since(yesterday.13:00)&&created_by(asd)}" 
    QAed \"No\" test.c
    Created attribute "QAed" on "test.c@@\main\5".
  • List each branch named rel2_bugfix that occurs in an element to which a trigger named mail_all has been attached.

    UNIX and Linux:

    cleartool find . -branch 'brtype(rel2_bugfix)&&trtype(mail_all)' \
    -print ./util.c@@/main/rel2_bugfix

    Windows:

    Z:\vob2\src> cleartool find . ^
    -branch "brtype(rel2_bugfix)&&trtype(mail_all)" ^
    -print .\util.c@@\main\rel2_bugfix