INFORMIX
Visionary User's Guide
Chapter 3: Creating Data Sources
Home Contents Index Master Index New Book

Creating Data Sources

This section introduces data sources, as follows:

What Are Data Sources?

Data sources represent the returned values from an SQL query. Visionary provides two query wizards and a query diagram editor that enable you to compose and modify queries.

The Simple Query and Advanced Query wizards provide step-by-step procedures for creating simple queries from single tables or complex queries that join multiple tables and contain query parameters. The Query Editor allows you to diagram an SQL query using query blocks that represent SQL data and operations. In addition, you can use the Query Editor to type or copy and paste SQL text to create queries. You can use any of these tools to create a data source.

The first step in creating a scene is to create a data source. After you have created a data source, the next step is to choose a layout. A layout determines how a data source is displayed within a scene and conveys information about the relationships between data points.

For more information on layouts, see "Displaying Data in a Scene".

Tools

The following table lists the Visionary Studio tools you can use to create and modify data sources.
Tool Description Use when...

Simple Query wizard

Guides you through the steps to create an SQL query from a single table and, optionally, to specify aggregates and functional expressions.

Creating an SQL query from a single table.

Advanced Query wizard

Guides you through the steps to create an SQL query from multiple tables in the database and, optionally, to specify filtering criteria, query parameters, aggregates, and functional expressions.

Creating a complex SQL query.

Query Editor

Provides a design window with the following views:

Query Diagram. Provides a design window in which you can modify and compose an SQL query graphically. This option requires some familiarity with SQL.

SQL Text. Provides a text window in which you can view, modify, and compose SQL queries. This option offers the most flexibility but requires fluency in SQL.

Data Sheet. Provides a window in which you can view returned data from an SQL query.

Modifying, viewing, testing, and composing SQL queries.

Query Design panel in the World Manager

Contains a palette of query blocks you can use to create and modify SQL queries.

Modifying an SQL query.

Database Contents panel in the World Manager

Contains a tree view of the tables and views, functions, data types, aggregates, and procedures in the active database.

Viewing database contents to compose and modifying queries.

Using the Query Wizards

Visionary Studio provides Simple Query and Advanced Query wizards that enable you to compose queries with a minimal knowledge of SQL. You can launch the query wizards in one of the following ways:

Basic Steps

Follow these steps to create a data source using the query wizards:

    1. Insert a data source.

    2. Launch the query wizard.

    3. Select a single table or view and columns that contain the data you want to present.

    4. Define functional expressions, define aggregates, add multiple tables, and add parameters for your data source. You can only add multiple tables and parameters using the Advanced Query wizard.

    5. Define query output.

    6. Execute and view the query results in the data sheet.

Examples

The following examples demonstrate how to create data sources using the Simple Query and Advanced Query wizards. The example using the Advanced Query wizard begins on page 3-14.

Simple Query Wizard

Use the Simple Query wizard to query a single table in the database.

The number of steps in the Simple Query wizard depends on whether or not you want to define functional expressions or aggregate functions in your query. The following example shows the general format of a query generated by the Simple Query wizard:

To create a data source using the Simple Query wizard

    1. Choose Insert DataSource to display the New Data Source dialog box

    Figure 3-1
    New Data Source Dialog Box

    .

    2. Select Simple Query Wizard and click OK to launch the wizard.

    3. Select a table or view and the columns of data you want to display.

    Figure 3-2
    Selecting a Table and Columns

    4. If you want to define a functional expression for your query, double-click (Expression) in the Available fields list box to display the Expression Editor dialog box.

    Figure 3-3
    Expression Editor Dialog Box


    Function button

    5. Click the Function button in the Expression toolbar to display the Choose Function dialog box.

    6. Select the function type, name, and version, and then click OK to return to the Expression Editor. A General function returns a calculated column; a Filter function returns a True or False value based on restriction criteria.

    Figure 3-4
    Choosing a Function


    Column button

    7. Highlight the function argument and click the Column button on the Expression toolbar to display the Choose Column dialog box.

    Figure 3-5
    Selecting the Function Argument

    8. Select a column from the Column name list box and click OK to return to the Expression Editor.

    Figure 3-6
    Choosing a Column


Cancel and Apply buttons

    9. Click OK in the Expression Editor to return to the query wizard.

    10. Click Next to display the Summarize Records page of the query wizard.

    11. Select the column you want to summarize and the aggregate function; then click Add. For example, to return the total shipping charges, you would select the orders.ship_charge column and the Sum() function.

    Figure 3-9
    Defining an Aggregate in a Query

    12. Click Next to display the Output page of the query wizard.

    13. To order the output of your query, type the query name and field names, specify output order and sort keys, and then click Finish.

    Figure 3-10
    Naming Your
    Query and
    Ordering Output

    14. Click Yes in the Visionary Studio prompt to execute and view your query results.

    Figure 3-11
    Viewing Query Results in
    the Data Sheet

The new data source appears in the Data Sources panel in the World Manager with the name Orders.

Advanced Query Wizard

Use the Advanced Query wizard to query multiple tables in the database. The number of steps in the Advanced Query wizard depends on the complexity of the query you create.

The following example shows the general format of a query generated by the Advanced Query wizard:

To create a data source using the Advanced Query wizard

    1. Choose Insert DataSource to display the New Data Source dialog box

    Figure 3-12
    New Data Source Dialog Box

    .

    2. Select Advanced Query Wizard and click OK to launch the wizard.

    3. Select a single table or view and columns of data you want to display.

    Figure 3-13
    Selecting a Table and Columns

    4. To define functional expressions in your query, double-click (Expression) or click Edit to display the Expression Editor. For detailed instructions on defining expressions using the Expression Editor, see the Simple Query wizard example on page 3-9.

    5. Optionally, click Yes, there is more information and Next to query additional tables in the database.

    Figure 3-14
    Querying Additional Tables

    6. Select the additional table and columns and click Next. The tables must be related in some way; for example, by a matching column name or a calculated expression:

    Figure 3-15
    Selecting an Additional Table and Columns


    Column button

    7. To define the relationship between the two tables, click the Fields from <tablename> cell and the Column button in the Expression Editor toolbar to display the Choose Column dialog box.

    Figure 3-16
    Choosing a Column

    8. Select a column and click OK to return to the query wizard.

    9. Click the Apply button in the Expression toolbar to display the column name in the Related fields <tablename> cell.

    Figure 3-17
    Defining Column Relationships


    Function button

    10. Click the Operator cell and the Function button in the Expression toolbar to display the Choose Boolean Function dialog box.

    Figure 3-18
    Choosing a Boolean Operator

    11. Select an operator and click OK to return to the query wizard.


    Apply button

    12. Click the Apply button in the Expression toolbar to display the operator in the Operator cell.

    Figure 3-19
    Defining a Boolean Operator


    Column button

    13. To select the field that relates to the field in the first table, click the Related field cell and the Column button in the Expression toolbar to display the Choose Column dialog box.

    Figure 3-20
    Choosing a Related Field Column

    14. Select a column and click OK to return to the query wizard.


    Apply button

    15. Click the Apply button in the Expression toolbar to apply the relationship you have defined.

    Figure 3-21
    Defining a Related Column

    16. Click Next to display the Additional Tables page of the query wizard. If you want to add more tables to your query, repeat the steps on pages 3-17 through 3-21.

    17. If you do not want to include additional tables, click No, there is no more information to be added and click Next.

    Figure 3-22
    Additional Tables Page

    18. If you want to filter your query results, click Yes, filter the rows based on additional criteria and click Next to specify how you want to filter data. You can specify expressions based on defined parameters, functions, or user-defined expressions

    Figure 3-23
    Filter Rows Page

    19. Type an expression in the Expression text box to specify the search criteria for the rows in the table. For example, to return only those items where the total price is greater than or equal to $250, you would type items.total_price >= 250 in the Expression text box. In addition, when you define constants in an expression they must be enclosed in single quotation marks, for example, customer_name = 'Informix'.

    Figure 3-24
    Defining Search Criteria

Tip: You can also select a column using the Choose Column dialog box. Click the Column button to display the Choose Column dialog box. Select a column from the list box and click OK to return to the query wizard. Type the remainder of the expression in the Expression text box.

    20. To define a query parameter, click Define Parameter to display the Query Parameter dialog box. A query parameter is a value assigned to a variable.

    21. Define the parameter and click Set and OK to return to the query wizard. For detailed instructions on defining query parameters using the Query Parameter dialog box, see "Inserting Query Parameters"

    Figure 3-25
    Defining a Query Parameter

    .

    22. Type the filter criteria in the Expression text box. You combine filter constraints using the logical operators AND and OR.

    Figure 3-26
    Combining Search Constraints

    23. If you want to define aggregate functions for your query, click Summarize the records and click Next. An aggregate is a function that summarizes information about the groups of rows in a table. If you do not want to summarize the query results, click Return individual records. For detailed instructions on defining aggregate functions, see the Simple Query wizard example on page 3-11.

    Figure 3-27
    Returning Individual Records

    24. To order the output of your query, type the query name and field names, specify output order and sort keys, and then click Finish.

    Figure 3-28
    Naming Your Query and Ordering Output

    25. Click Yes in the Visionary Studio prompt to execute and view the query results.

    Figure 3-29
    Viewing Results in the Data Sheet

The new data source appears on the Data Sources panel in the World Manager.

Using the Query Editor

Visionary also provides a Query Editor in which you can create, modify, and view SQL queries. The Query Editor has the following views:

What Is a Query Diagram?

A query diagram is a block diagram that is the visual representation of an SQL query. Using the Query Diagram view, you can create and modify SQL queries.

A query diagram consists of the following elements:

Figure 3-30
Query Editor

There are two types of query blocks: data and operation. The following sections first describe these two types, and then describe ports and connections.

Data Blocks

Data blocks represent the data you want to query. Data blocks include the following types:

Operation Blocks

Operation blocks represent the SQL operations you can perform on the data. Operation blocks include the following types:

Each block in a query diagram is assigned a name: for example, i n.<identifier> where n is a sequentially assigned integer. You can track your SQL errors using the block name in the Output window, as follows:

Ports and Connections

Ports and connections form the links between the data and operation blocks in a query diagram.

Row and column connections have properties; single-value connections do not have properties.

Query blocks and connections are color-coded. Blue indicates a valid connection; red indicates an invalid connection. The following rules apply to valid connections:

Basic Steps

Follow these steps to create a data source using the Query Diagram view:

    1. Insert a data source and select Query Diagram.

    2. Insert query blocks.

    3. Select a table or view for your query.

    4. Define query properties such as filters, parameters, and constants, as desired.

    5. Define the column output.

    6. Execute and view the query results in the data sheet.

Example

The following example demonstrates how to create a query diagram that contains a constant. For example, if you wanted to display address information for the customers from the city of Sunnyvale, you would define a constant for column city as equal to the name Sunnyvale. The following is an example of the SQL statement for this query:

To create data sources using the Query Diagram view

    1. Choose Insert Data Source to display the New Data Source dialog box.

    2. Select Query Diagram View from the list box and click OK.

    3. Double-click the Table, Constant, Filter, and Output blocks to place them in the Query Diagram view.

    4. Click the Input and Output ports to connect the query blocks.

    Figure 3-31
    Connecting Query Blocks

    5. Right-click the Table block and select Properties to display the Table dialog box.

    6. Select a table or view from the Table name list box and click OK.

    Figure 3-32
    Selecting a Table or View

    7. Right-click the Constant block and select Properties to display the Constant dialog box.

    8. Define the constant value. Text values must be enclosed in single quotation marks, for example 'Sunnyvale'. If necessary, click Cast value as type and select the data type value from the list box. The data type is used to cast the value of the parameter in the SQL query before it is submitted to the database. Click OK to return to the Query Editor.

    Figure 3-33
    Defining a Constant

    9. Right-click the Filter block and select Properties to display the Filter dialog box.

    Figure 3-34
    Defining Filter Criteria

    10. To define a single argument, click Standard operator and select a filter expression from the Filter Expression box; then click OK. You can define two argument functional expressions by selecting the Two argument function option.You can also change the column placement and define a NOT clause by checking the Place column on the right and Negate comparison check boxes, respectively.

    Figure 3-35
    Defining Filter Properties

    11. Right-click the Output block and select Properties to display the Output dialog box.

    12. Select columns from the Available fields list and click OK.

    Figure 3-36
    Defining and Ordering Output

    13. Click SQL Text to view the generated SQL expression. If the query is not correctly defined, a query does not appear. The Output window displays execution and error messages.

    Figure 3-37
    SQL Text View

    14. Click Data Sheet to view the results of your query. Execution and error messages appear in the Output window.

    Figure 3-38
    Data Sheet
    View




Visionary User's Guide, version 1.0
Copyright © 1998, Informix Software, Inc. All rights reserved.