msgconsume  Chapter 6: Common Topics in Real Time Messaging

Chapter 5: Real Time Data Functions

msgpropvalue

Description

Extracts a specified property from a <msgheader> or <msgproperties> document. There are five msgpropvalue functions: msgproplist, msgpropcount, msgpropname, msgpropvalue, and msgproptype.

Syntax

 msgproplist_call::=
      msgproplist([ msg_doc] [returns varchar | text]))
 msgpropcount_call ::=
      msgpropcount([msg_doc])
 msgpropname_call ::=
     msgpropname(integer[ ,msg_doc]), )
 msgpropvalue_call::=
     msgpropvalue(prop_name [ , msg_doc]  )
 msgproptype_call::=
     msgproptype(prop_name [ , msg_doc]  )
 msg_doc ::= basic_character_expression
 prop_name::= basic_character_expression

Parameters

msgproplist

Returns a string in the format of an option_string with all of the property attributes of msg_doc.

msgpropcount

Returns the number of properties, or attributes, in msg_doc.

msgpropname

Returns the name of msg_doc’s Ith property, where I is the value of the integer parameter. The result is a null value if the value of the integer parameter is less than one or greater than the number of properties in msg_doc.

msgpropvalue

Returns the value for the msg_doc property whose name equals prop_name. The result is the property value converted to varchar, and is null if msg_doc does not have a property whose name is equal to prop_name.

msgproptype

Returns the message provider’s property type for the msg_doc property whose name equals prop_name. The result is null if msg_doc does not have a property whose name is equal to prop_name.

msg_doc

The <msgheader> or <msgproperties> XML document. A basic_character_expression. If msg_doc is not specified, the current value of @@msgprpoperties is used.

prop_name

The property name from which you want to extract a value or type. A basic_character_expression.

Examples

Example 1

The following examples assume that a call from msgrecv returns a message whose single property is named trade_name and whose value is “Acme Maintenance” (“Quick & Safe”). The value of the @@msgproperties global variable is then:

<?xml version=’1.0’ encoding=’UTF-8’ standalone=’yes’ ?>
     <msgproperties trade_name=’Acme Maintenance (&quot;Quick &amp;
     Safe&quot;)’></msgproperties>

The ampersand and the quotation marks surrounding the phrase Quick & Safe are replaced with the XML entities &quot; and &amp;,as required by XML convention.

Example 2

To retrieve the message property “trade name”:

select msgpropvalue(@@msgproperties, ’trade_name’)
---------------
(’Quick & Safe’)Acme Maintenance 

This is the original string that is stored in an Transact-SQL variable or column.

Example 3

To retrieve the list of properties belonging to a message, use one of the following examples:

select msgproplist()
select msgproplist(@@msgproperties)

Example 4

The following query to msgpropvalue returns null because the message retrieved does not have a property named “discount”:

select msgpropvalue(’discount’, @@msgproperties)

Example 5

To retrieve the number of properties from the last message retrieved:

select msgpropcount(@@msgproperties)

Example 6

To retrieve the 8th property from the last message retrieved:

select msgpropname(8, @@msgproperties)

Example 7

This query returns null, because the 9th property does not exist:

select msgpropname(9, @@msgproperties)

Example 8

To retrieve the value of the 8th property:

select msgpropvalue (msgpropname(8, @@msgproperties))

Usage





Copyright © 2004. Sybase Inc. All rights reserved. Chapter 6: Common Topics in Real Time Messaging

View this book as PDF