Chapter 2 Messages : Message Selectors

Message Selectors
A message selector is a string that lets a client program specify a set of messages, based on the values of message headers and properties. A selector matches a message if, after substituting header and property values from the message into the selector string, the string evaluates to true. Consumers can request that the server deliver only those messages that match a selector.
The syntax of selectors is based on a subset of the SQL92 conditional expression syntax.
Identifiers
Identifiers can refer to the values of message headers and properties, but not to the message body. Identifiers are case-sensitive.
Basic Syntax
An identifier is a sequence of letters and digits, of any length, that begins with a letter. As in Java, the set of letters includes _ (underscore) and $ (dollar).
Illegal
Certain names are exceptions, which cannot be used as identifiers. In particular, NULL, TRUE, FALSE, NOT, AND, OR, BETWEEN, LIKE, IN, IS, and ESCAPE are defined to have special meaning in message selector syntax.
Value
Identifiers refer either to message header names or property names. The type of an identifier in a message selector corresponds to the type of the header or property value. If an identifier refers to a header or property that does not exist in a message, its value is NULL.
Literals
String Literal
A string literal is enclosed in single quotes. To represent a single quote within a literal, use two single quotes; for example, 'literal''s'. String literals use the Unicode character encoding. String literals are case sensitive.
Exact Numeric Literal
An exact numeric literal is a numeric value without a decimal point, such as 57, -957, and +62; numbers in the range of long are supported.
Approximate Numeric Literal
An approximate numeric literal is a numeric value with a decimal point (such as 7., -95.7, and +6.2), or a numeric value in scientific notation (such as 7E3 and -57.9E2); numbers in the range of double are supported. Approximate literals use the floating-point literal syntax of the Java programming language.
Boolean Literal
The boolean literals are TRUE and FALSE (case insensitive).
Internal computations of expression values use a 3-value boolean logic similar to SQL. However, the final value of an expression is always either TRUE or FALSE—never UNKNOWN.
Expressions
Selectors as Expressions
Every selector is a conditional expression. A selector that evaluates to true matches the message; a selector that evaluates to false or unknown does not match.
Arithmetic Expression
Arithmetic expressions are composed of numeric literals, identifiers (that evaluate to numeric literals), arithmetic operations, and smaller arithmetic expressions.
Conditional Expression
Conditional expressions are composed of comparison operations, logical operations, and smaller conditional expressions.
Order of Evaluation
Order of evaluation is left-to-right, within precedence levels. Parentheses override this order.
Operators
Case Insensitivity
Operator names are case-insensitive.
Logical Operators
Logical operators in precedence order: NOT, AND, OR.
Comparison Operators
Comparison operators: =, >, >=, <, <=, <> (not equal).
These operators can compare only values of comparable types. (Exact numeric values and approximate numerical values are comparable types.) Attempting to compare incomparable types yields false. If either value in a comparison evaluates to NULL, then the result is unknown (in SQL 3-valued logic).
Comparison of string values is restricted to = and <>. Two strings are equal if and only if they contain the same sequence of characters.
Comparison of boolean values is restricted to = and <>.
Arithmetic Operators
Arithmetic operators in precedence order:
+, - (unary)
*, / (multiplication and division)
+, - (addition and subtraction)
Arithmetic operations obey numeric promotion rules of the Java programming language.
Between Operator
arithmetic-expr1 [NOT] BETWEEN arithmetic-expr2 AND arithmetic-expr3
The BETWEEN comparison operator includes its endpoints. For example:
age BETWEEN 5 AND 9   is equivalent to   age >= 5 AND age <= 9
age NOT BETWEEN 5 AND 9   is equivalent to   age < 5 OR age > 9
String
Set Membership
identifier [NOT] IN (string-literal1, string-literal2, ...)
The identifier must evaluate to either a string or NULL. If it is NULL, then the value of this expression is unknown.
Pattern Matching
identifier [NOT] LIKE pattern-value [ESCAPE escape-character]
The identifier must evaluate to a string.
The pattern-value is a string literal, in which some characters bear special meaning:
_ (underscore) can match any single character.
% (percent) can match any sequence of zero or more characters.
escape-character preceding either of the special characters changes them into ordinary characters (which match only themselves).
Null Header or Property
identifier IS NULL
This comparison operator tests whether a message header is null, or a message property is absent.
identifier IS NOT NULL
This comparison operator tests whether a message header or message property is non-null.
White Space
White space is any of the characters space, horizontal tab, form feed, or line terminator—or any contiguous run of characters in this set.