Using SQL Function Blocks in XQuery Mapper

When you create a call to a SQL update function using XQuery Mapper, a SQL function block representing the function appears on the Mapper canvas. For example, consider the SQL block created for a ddtek:sql-update function call on the Products table:

The first port on the left is colored because it already has a value - it is the table used to create the SQL update block; "myServer:pubs.dbo.authors", for example. The other two ports are column name/value pairs. They are empty because they do not contain values when the function call is first created. You provide these values by mapping, or, in the case of update functions, by explicitly providing a value for the port by double-clicking it.

To map column name/value pairs, you first expand the SQL function block by double-clicking it. When you double-click a SQL function block, it expands to show the table name and each of the columns that make up the table:

Each column has an associated port. You use these ports to map nodes from XML data sources in the Add Source Document pane. Always perform mapping operations using the ports on the expanded SQL function block when you are building your XQuery using the XQuery Mapper.

For a summary of SQL function blocks, see SQL Function Blocks.

About the Output Port

All function blocks in Stylus Studio have an output port on the right side. In most cases, output from a function is mapped to either another function (a conditional expression, for example) or to a node on the target document.

Unlike most other XQuery source-target mappings, SQL functions do not generate any output - any changes specified by the XQuery are performed directly on the database. However, a link from the SQL function block's output port to the Set Target Document pane is required in order to commit the XQuery mapping to Stylus Studio. This link is completed automatically for you by Stylus Studio when you create SQL insert and update functions using drag and drop. If you create these functions using the short-cut menu (right-click the Mapper canvas and select Function Block > DataDirect XQuery...), you must create this link manually. The same is true for delete functions, which cannot be created using drag-and-drop.

Further, nothing is displayed in the Output window when you preview the XQuery - any changes resulting from the XQuery are reflected directly in the database.

For general information on mapping, see Building an XQuery Using the Mapper.

 
Free Stylus Studio XML Training:
W3C Member