Chapter 6 Exchanging data with databases supporting XML


Generating SQL/XML queries

SQL/XML is an XML extension of the Structured Query Language. With SQL/XML, you retrieve relational data using extended SQL syntax, and produce a result using XML. SQL/XML is made of five main functions:

An XML model allows you to generate SQL/XML queries for global elements, whatever the targeted XML language (XSD, DTD or XDR). You need first to map an XML model to a PDM, then to attach the SQL/XML extended model definition to the mapped XML model.

The best way to map an XML model to a PDM is to use the XML Builder Wizard from a PDM. The generated XML model is automatically mapped to the PDM and linked with the SQL/XML extended model definition. If need be, you can still modify the mapping through the Mapping tab of elements and complex types property sheets.

For more information on the XML Builder Wizard, see Generating an XML model via the XML Builder Wizard, in chapter Generating from a PDM, in the PDM User's Guide .

Generated SQL/XML queries cannot be parameterized.

WARNING! 

Caution
The following procedure assumes you have an XML model open in the workspace and mapped to a PDM.

Steps To generate SQL/XML queries:

  1. < If the SQL/XML extended model definition is already attached to the XML model, go to step 6 > Select Model→Extended Model Definitions.

    The List of Extended Model Definitions is displayed.
  2. Click the Import an Extended Model Definition button.

    The Extended Model Definition Selection dialog box is displayed.
  3. In the General Purpose tab, select SQL/XML.
  4. Click OK.

    SQL/XML is displayed in the List of Extended Model Definitions.
  5. Click OK.

    The SQL/XML extended model definition is displayed in the Browser tree view, attached to the model.
  6. < optional > Double-click a global element in the diagram to display its property sheet.
  7. In the Preview tab, click the SQL/XML.Query tab to display the SQL/XML query.


    The Preview tab is in read-only mode, you cannot modify the script.
  8. Click OK.
  9. Select Tools→Extended Generation.

    The Generation dialog box is displayed with SQL/XML selected in the Targets tab.
  10. Click the Select a Path button beside the Directory box to select a path for the SQL/XML queries.
  11. In the Selection tab, select the global elements for which you want to generate a SQL/XML query. (Only one global element in the example)
  12. Click OK.

    The Result dialog box is displayed with a path for each SQL/XML query. (Only one in the example)
  13. Select the path of a SQL/XML query and click Edit.

    The SQL/XML query is displayed in the Editor window. (Extract)
  14. Repeat step 13 to edit another SQL/XML query.

    or

    Click Close in the Result dialog box.

Once generated, SQL/XML queries are processed by SQL interpreters in databases supporting XML.

 


Copyright (C) 2007. Sybase Inc. All rights reserved.