Azure 服务总线的 SQLRuleAction 语法参考SQLRuleAction syntax reference for Azure Service Bus

SqlRuleAction 是 SqlRuleAction 类的实例,代表以基于 SQL 语言的语法编写的一组操作,该语法针对 BrokeredMessage 执行。A SqlRuleAction is an instance of the SqlRuleAction class, and represents set of actions written in SQL-language based syntax that is performed against a BrokeredMessage.

本文列出了有关 SQL 规则操作语法的详细信息。This article lists details about the SQL rule action grammar.

<statements> ::=
    <statement> [, ...n]  

<statement> ::=
    <action> [;]
    Remarks
    -------
    Semicolon is optional.  

<action> ::=
    SET <property> = <expression>
    REMOVE <property>  
<expression> ::=
    <constant>
    | <function>
    | <property>
    | <expression> { + | - | * | / | % } <expression>
    | { + | - } <expression>
    | ( <expression> )
<property> := 
    [<scope> .] <property_name>

参数Arguments

  • <scope> 是一个可选字符串,指示 <property_name> 的范围。<scope> is an optional string indicating the scope of the <property_name>. 有效值为 sysuserValid values are sys or user. sys 值指示系统范围,其中 <property_name>BrokeredMessage 类的公共属性名称。The sys value indicates system scope where <property_name> is a public property name of the BrokeredMessage Class. user 指示用户范围,其中 <property_name>BrokeredMessage 类字典的项。user indicates user scope where <property_name> is a key of the BrokeredMessage Class dictionary. user 范围是默认范围(如果 <scope> 未指定)。user scope is the default scope if <scope> is not specified.

备注Remarks

尝试访问不存在的系统属性属于错误,而尝试访问不存在的用户属性不属于错误。An attempt to access a non-existent system property is an error, while an attempt to access a non-existent user property is not an error. 不存在的用户属性在内部是作为未知值计算的。Instead, a non-existent user property is internally evaluated as an unknown value. 在运算符求值过程中,未知值的处理方式很特殊。An unknown value is treated specially during operator evaluation.

property_nameproperty_name

<property_name> ::=  
     <identifier>  
     | <delimited_identifier>  

<identifier> ::=  
     <regular_identifier> | <quoted_identifier> | <delimited_identifier>  

参数Arguments

<regular_identifier> 是一个字符串,由以下正则表达式表示:<regular_identifier> is a string represented by the following regular expression:

[[:IsLetter:]][_[:IsLetter:][:IsDigit:]]*  

这是指任何以字母开头且后跟一个或多个下划线/字母/数字的字符串。This means any string that starts with a letter and is followed by one or more underscore/letter/digit.

[:IsLetter:] 是指其类别为 Unicode 字母的任何 Unicode 字符。[:IsLetter:] means any Unicode character that is categorized as a Unicode letter. System.Char.IsLetter(c) 返回 true(如果 c 为 Unicode 字母)。System.Char.IsLetter(c) returns true if c is a Unicode letter.

[:IsDigit:] 是指其类别为十进制数字的任何 Unicode 字符。[:IsDigit:] means any Unicode character that is categorized as a decimal digit. System.Char.IsDigit(c) 返回 true(如果 c 为 Unicode 数字)。System.Char.IsDigit(c) returns true if c is a Unicode digit.

<regular_identifier> 不能为保留关键字。A <regular_identifier> cannot be a reserved keyword.

<delimited_identifier> 是用左/右方括号 ([]) 括起来的任何字符串。<delimited_identifier> is any string that is enclosed with left/right square brackets ([]). 右方括号采用两个右方括号的形式。A right square bracket is represented as two right square brackets. 下面是 <delimited_identifier> 的示例:The following are examples of <delimited_identifier>:

[Property With Space]  
[HR-EmployeeID]  

<quoted_identifier> 是用双引号括起来的任何字符串。<quoted_identifier> is any string that is enclosed with double quotation marks. 在标识符中,双引号采用两个双引号的形式。A double quotation mark in identifier is represented as two double quotation marks. 建议不要使用带引号的标识符,因为很容易与字符串常量混淆。It is not recommended to use quoted identifiers because it can easily be confused with a string constant. 可能情况下使用分隔的标识符。Use a delimited identifier if possible. 下面是 <quoted_identifier> 的示例:The following is an example of <quoted_identifier>:

"Contoso & Northwind"  

patternpattern

<pattern> ::=  
      <expression>  

备注Remarks

<pattern> 必须是以字符串形式求值的表达式,<pattern> must be an expression that is evaluated as a string. 用作 LIKE 运算符的模式,It is used as a pattern for the LIKE operator. 并可能包含下列通配符:It can contain the following wildcard characters:

  • %:包含零个或多个字符的任意字符串。%: Any string of zero or more characters.

  • _:任何单个字符。_: Any single character.

escape_charescape_char

<escape_char> ::=  
      <expression>  

备注Remarks

<escape_char> 必须是以长度为 1 的字符串形式求值的表达式,<escape_char> must be an expression that is evaluated as a string of length 1. 作为转义符用于 LIKE 运算符。It is used as an escape character for the LIKE operator.

例如,property LIKE 'ABC\%' ESCAPE '\'ABC% 匹配,而不是与开头为 ABC 的字符串配置。For example, property LIKE 'ABC\%' ESCAPE '\' matches ABC% rather than a string that starts with ABC.

常量constant

<constant> ::=  
      <integer_constant> | <decimal_constant> | <approximate_number_constant> | <boolean_constant> | NULL  

参数Arguments

  • <integer_constant> 是一个数字字符串,不使用引号,且不包含小数点。<integer_constant> is a string of numbers that are not enclosed in quotation marks and do not contain decimal points. 这些值以 System.Int64 形式存储在内部,并具有相同的范围。The values are stored as System.Int64 internally, and follow the same range.

    下面是长常量的示例:The following are examples of long constants:

    1894  
    2  
    
  • <decimal_constant> 是一个数字字符串,不使用引号,但包含小数点。<decimal_constant> is a string of numbers that are not enclosed in quotation marks, and contain a decimal point. 这些值以 System.Double 形式存储在内部,并具有相同的范围/精度。The values are stored as System.Double internally, and follow the same range/precision.

    在未来版本中,此数字可能以其他数据类型存储,目的是支持确切的数字语义,因此不应依赖于 <decimal_constant> 的基础数据类型为 System.Double 这一事实。In a future version, this number might be stored in a different data type to support exact number semantics, so you should not rely on the fact the underlying data type is System.Double for <decimal_constant>.

    下面是十进制常量的示例:The following are examples of decimal constants:

    1894.1204  
    2.0  
    
  • <approximate_number_constant> 是以科学记数法表示的数字。<approximate_number_constant> is a number written in scientific notation. 这些值以 System.Double 形式存储在内部,并具有相同的范围/精度。The values are stored as System.Double internally, and follow the same range/precision. 下面是近似数常量的示例:The following are examples of approximate number constants:

    101.5E5  
    0.5E-2  
    

boolean_constantboolean_constant

<boolean_constant> :=  
      TRUE | FALSE  

备注Remarks

布尔常量以关键字 TRUEFALSE 表示。Boolean constants are represented by the keywords TRUE or FALSE. 这些值以 System.Boolean 形式存储。The values are stored as System.Boolean.

string_constantstring_constant

<string_constant>  

备注Remarks

字符串常量使用单引号,包括任何有效的 Unicode 字符。String constants are enclosed in single quotation marks and include any valid Unicode characters. 嵌入字符串常量中的单引号采用两个单引号的形式。A single quotation mark embedded in a string constant is represented as two single quotation marks.

函数function

<function> :=  
      newid() |  
      property(name) | p(name)  

备注Remarks

newid() 函数返回 System.Guid.NewGuid() 方法生成的 System.GuidThe newid() function returns a System.Guid generated by the System.Guid.NewGuid() method.

property(name) 函数返回 name 所引用的属性的值。The property(name) function returns the value of the property referenced by name. name 值可以是任何返回字符串值的有效表达式。The name value can be any valid expression that returns a string value.

注意事项Considerations

  • SET 用于创建新属性或更新现有属性的值。SET is used to create a new property or update the value of an existing property.
  • REMOVE 用于删除属性。REMOVE is used to remove a property.
  • 当表达式类型和现有的属性类型不同时,SET 会尽可能执行隐式转换。SET performs implicit conversion if possible when the expression type and the existing property type are different.
  • 如果引用了不存在的系统属性,操作会失败。Action fails if non-existent system properties were referenced.
  • 如果引用了不存在的用户属性,操作不会失败。Action does not fail if non-existent user properties were referenced.
  • 不存在的用户属性在内部的求值为“未知”,其遵循的语义与 SQLFilter 相同(在对运算符求值时)。A non-existent user property is evaluated as "Unknown" internally, following the same semantics as SQLFilter when evaluating operators.

后续步骤Next steps