Defining DataWindow Objects

About this chapter

The applications you build are centered around your organization's data. This chapter describes how to define DataWindow objects to display and manipulate the data.

About DataWindow objects

A DataWindow object is an object you use to retrieve, present, and manipulate data from a relational database or other data source (such as an Excel worksheet or Web service).

DataWindow objects have knowledge about the data they are retrieving. You can specify display formats, presentation styles, and other data properties so that users can make the most meaningful use of the data.

DataWindow object examples

You can display the data in the format that best presents the data to your users.

Edit styles

If a column can take only a small number of values, you can have the data appear as radio buttons in a DataWindow object so that users know what their choices are.


Display formats

If a column displays phone numbers, salaries, or dates, you can specify the format appropriate to the data.


Validation rules

If a column can take numbers only in a specific range, you can specify a simple validation rule for the data, without writing any code, to make sure users enter valid data.

Enhancing DataWindow objects

If you want to enhance the presentation and manipulation of data in a DataWindow object, you can include computed fields, pictures, and graphs that are tied directly to the data retrieved by the object.

How to use DataWindow objects

Before you can use a DataWindow object, you need to build the object. To do that you can go to the DataWindow painter, which lets you create and edit DataWindow objects. It also lets you make PSR (Powersoft report) files, which you might also want to use in applications. A PSR file contains a report definition—essentially a nonupdatable DataWindow object—as well as the data contained in that report when the PSR file was created.

This section describes the overall process for creating and using DataWindow objects. You can use DataWindow objects in client/server, Web-based, and multitier applications. For more information about using DataWindow objects in different kinds of applications and writing code that interacts with DataWindow objects, see the section called “Using DataWindow Objects” in DataWindow Programmers Guide.

To use DataWindow objects in an application

  1. Create the DataWindow object using one of the DataWindow wizards on the DataWindow tab page of the New dialog box.

    The wizard helps you define the data source, presentation style, and other basic properties of the object, and the DataWindow object displays in the DataWindow painter. In this painter, you define additional properties for the DataWindow object, such as display formats, validation rules, and sorting and filtering criteria.

  2. For more information about creating a DataWindow object, see Building a DataWindow object.

  3. Place a DataWindow control in a window or user object.

    It is through this control that your application communicates with the DataWindow object you created in the DataWindow painter.

  4. Associate the DataWindow control with the DataWindow object.

  5. Write scripts in the Window painter to manipulate the DataWindow control and its contents.

    For example, you use the PowerScript Retrieve method to retrieve data into the DataWindow control.

    You can write scripts for the DataWindow control to deal with error handling, sharing data between DataWindow controls, and so on.

Reports versus DataWindow objects

Reports and DataWindow objects are the same objects. You can open and modify both in the DataWindow painter. However, a report is not updatable and can only be used to present data. For information about how you can specify whether users can update the data in a DataWindow object, see Controlling Updates in DataWindow objects.

Choosing a presentation style

The presentation style you select for a DataWindow object determines the format PowerBuilder uses to display the DataWindow object in the Design view. You can use the format as displayed or modify it to meet your needs.

When you create a DataWindow object, you can choose from the presentation styles listed in the following table.

Using this DataWindow wizard

You create a new DataWindow object

Composite

That includes other DataWindow objects

Crosstab

With summary data in a spreadsheet-like grid

Freeform

With the data columns going down the page and labels next to each column

Graph

With data displayed in a graph

Grid

With data in row and column format with grid lines separating rows and columns

Group

With data in rows that are divided into groups

Label

That presents data as labels

N-Up

With two or more rows of data next to each other

OLE 2.0

That is a single OLE object

RichText

That combines input fields that represent database columns with formatted text

Tabular

With data columns going across the page and headers above each column

TreeView

With data grouped in rows in a TreeView; the TreeView displays the data hierarchically in a way that allows you to expand and collapse it


Using the Tabular style

The Tabular presentation style presents data with the data columns going across the page and headers above each column. As many rows from the database will display at one time as can fit in the DataWindow object. You can reorganize the default layout any way you want by moving columns and text:


Using the Freeform style

The Freeform presentation style presents data with the data columns going down the page and labels next to each column. You can reorganize the default layout any way you want by moving columns and text. The Freeform style is often used for data entry forms.


Using the Grid style

The Grid presentation style shows data in row-and-column format with grid lines separating rows and columns. With other styles, you can move text, values, and other objects around freely in designing the report. With the grid style, the grid lines create a rigid structure of cells.

An advantage of the Grid style is that users can reorder and resize columns at runtime.

Original Grid report

This grid report shows employee information. Several of the columns have a large amount of extra white space:


Grid report with modified column widths

This grid report was created from the original one by decreasing the width of some columns:


Using the Label style

The Label presentation style shows data as labels. With this style you can create mailing labels, business cards, name tags, index cards, diskette labels, file folder labels, and many other types of labels.

Mailing labels


Business cards

Name tags

Specifying label properties

If you choose the Label style, you are asked to specify the properties for the label after specifying the data source. You can choose from a list of predefined label types or enter your own specifications manually.

Where label definitions come from

PowerBuilder gets the information about the predefined label formats from a preferences file called pblab.ini.

Using the N-Up style

The N-Up style presents two or more rows of data next to each other. It is similar to the Label style in that you can have information from several rows in the database across the page. However, the information is not meant to be printed on labels. The N-Up presentation style is useful if you have periodic data; you can set it up so that each period repeats in a row.

After you select a data source, you are asked how many rows to display across the page.

For each column in the data source, PowerBuilder defines n columns in the DataWindow object (column_1 to column_n), where n is the number of rows you specified.

Table example

For a table of daily stock prices, you can define the DataWindow object as five across, so each row in the DataWindow object displays five days' prices (Monday through Friday). Suppose you have a table with two columns, day and price, that record the closing stock price each day for three weeks.

In the following n-up DataWindow object, 5 was selected as the number of rows to display across the page, so each line in the DataWindow object shows five days' stock prices. A computed field was added to get the average closing price in the week:


About computed fields in n-up DataWindow objects

You use subscripts, such as price[0], to refer to particular rows in the detail band in n-up DataWindow objects.

For more information, see Enhancing DataWindow Objects.

Here is the DataWindow object in the Preview view:


Another way to get multiple-column DataWindow objects

In an n-up DataWindow object, the data is displayed across and then down. If you want your data to go down the page and then across in multiple columns, as in a phone list, you should create a standard tabular DataWindow object, then specify newspaper columns.

For more information on newspaper columns, see Enhancing DataWindow Objects.

Using the Group style

The Group presentation style provides an easy way to create grouped DataWindow objects, where the rows are divided into groups, each of which can have statistics calculated for it. Using this style generates a tabular DataWindow object that has grouping properties defined.

This Group style report groups by department and lists employees and salaries. It also includes a subtotal and a grand total for the salary column:


For more about the Group presentation style, see Filtering, Sorting, and Grouping Rows.

Using the Composite style

The Composite presentation style allows you to combine multiple DataWindow objects in the same object. It is particularly handy if you want to print more than one DataWindow object on a page.

This composite report consists of three nested tabular reports. One of the tabular reports includes a graph:


For more about the Composite presentation style, see Using Nested Reports.

Using the Graph and Crosstab styles

In addition to the (preceding) text-based presentation styles, PowerBuilder provides two styles that allow you to display information graphically: Graph and Crosstab.

There is a graph report in the composite report in Using the Composite style. This crosstab report counts the number of employees that fit into each cell. For example, there are three employees in department 100 who make between $30,000 and $39,999:


For more information about these two presentation styles, see Working with Graphs, and Working with Crosstabs.

Using the OLE 2.0 style

The OLE presentation style lets you link or embed an OLE object in a DataWindow object.

For information about the OLE 2.0 presentation style, see Using OLE in a DataWindow Object.

Using the RichText style

The RichText presentation style lets you combine input fields that represent database columns with formatted text.

For more information about the RichText presentation style, see Working with Rich Text.

Using the TreeView style

The TreeView presentation style provides an easy way to create DataWindow objects that display hierarchical data in a TreeView, where the rows are divided into groups that can be expanded and collapsed. Icons (+ or –) show whether the state of a group in the TreeView is expanded or collapsed, and lines connect parents and their children.

This TreeView style report groups by manager ID and state and lists employee information and salaries:


For more about the TreeView presentation style, see Working with TreeViews.

Building a DataWindow object

You use a wizard to build a new DataWindow object. To create a DataWindow object or use the DataWindow painter, you must be connected to the database whose data you will be accessing. When you open the DataWindow painter or select a data source in the wizard, PowerBuilder connects you to the DBMS and database you used last. If you need to connect to a different database, do so before working with a DataWindow object.

Column limit

There is a limit of 1000 on the number of columns in a DataWindow object.

For information about changing your database connection, see Working with Database Connections in Connecting to Your Database.

To create a new DataWindow object:

  1. Select File>New from the menu bar and select the DataWindow tab.

    If there is more than one target in the workspace, select the target where you want the DataWindow to be created from the drop-down list at the bottom of the dialog box.

  2. Choose a presentation style for the DataWindow object.

    The presentation style determines how the data is displayed. See Choosing a presentation style. When you choose the presentation style, the appropriate DataWindow object wizard starts.

    If you want data to be retrieved in the Preview view when the DataWindow object opens, select the Retrieve on Preview check box.

  3. Define the data source.

    See Selecting a data source.

  4. Choose options for the DataWindow object and click Next.

    See Choosing DataWindow object-wide options.

  5. Review your specifications and click Finish.

    The DataWindow object displays in the Design view.

  6. Save the DataWindow object in a library.

Selecting a data source

The data source you choose determines how you select the data that will be used in the DataWindow object.

About the term data source

The term data source used here refers to how you use the DataWindow painter to specify the data to retrieve into the DataWindow object. Data source can also refer to where the data comes from, such as a SQL Anywhere data source (meaning a database file) or an XML data source (meaning an XML file). Connecting to Your Database uses the term data source in this second sense.

If the data is in the database

If the data for the DataWindow object will be retrieved from a database, choose one of the data sources from the following table.

Data source

Use when

Quick Select

The data is from a single table (or from tables that are related through foreign keys) and you need only to choose columns, selection criteria, and sorting.

SQL Select

You want more control over the SQL SELECT statement generated for the data source or your data is from tables that are not connected through a key. For example, you need to specify grouping, computed columns, or retrieval arguments within the SQL SELECT statement.

Query

The data has been defined as a query.

Stored Procedure

The data is defined in a stored procedure.


If the data is not in a database

Web Service data source. Select the Web Service data source if you want to populate the DataWindow object with data you obtain from a Web service.

For more information, see Using a Web service data source.

External data source. Select the External data source if:

  • The DataWindow object will be populated programmatically.

  • Data will be imported from a DDE application.

  • Data will be imported from an external file, such as an XML, comma-separated values (CSV), tab-separated text (TXT), or dBASE (DBF) file.

You can also use an ODBC driver to access data from a file.

For more information, see the section called “Using the ODBC Interface” in Connecting to Your Database.

After you choose a data source in the various DataWindow wizards, you specify the data. The data source you choose determines what displays in the wizards and how you define the data.

Why use a DataWindow if the data is not from a DBMS

Even when the data is not coming from the database, there are many times when you want to take advantage of the intelligence of a DataWindow object:

  • Data Validation

    You have full access to validation rules for data

  • Display Formats

    You can use any existing display formats to present the data, or create your own

  • Edit Styles

    You can use any existing edit styles, such as radio buttons and edit masks, to present the data, or create your own

Using Quick Select

The easiest way to define a data source is using Quick Select.

To define the data using Quick Select:

  1. Click Quick Select in the Choose Data Source dialog box in the wizard and click Next.

  2. Select the table that you will use in the DataWindow object.

    For more information, see Selecting a table.

  3. Select the columns to be retrieved from the database.

    For more information, see Selecting columns.

  4. (Optional) Sort the rows before you retrieve data.

    For more information, see Specifying sorting criteria.

  5. (Optional) Select what data to retrieve.

    For more information, see Specifying selection criteria.

  6. Click the OK button in the Quick Select dialog box.

    You return to the wizard to complete the definition of the DataWindow object.

Quick Select limitations

When you choose Quick Select as your data source, you cannot:

  • Specify grouping before rows are retrieved

  • Include computed columns

  • Specify retrieval arguments for the SELECT statement that are supplied at runtime.

To use these options when you create a DataWindow object, choose SQL Select as your data source. If you decide later that you want to use retrieval arguments, you can define them by modifying the data source. For more information, see Enhancing DataWindow Objects.

Selecting a table

When you choose Quick Select, the Quick Select dialog box displays. The Tables box lists tables and views in the current database.

Displaying table comments

To display a comment about a table, position the pointer on the table and click the right mouse button or select the table.

Which tables and views display?

The DBMS determines what tables and views display. For some DBMSs, all tables and views display, whether or not you have authorization. If you select a table or view you are not authorized to access, the DBMS issues a message.

For ODBC databases, the tables and views that display depend on the driver for the data source. SQL Anywhere does not restrict the display, so all tables and views display, whether or not you have authorization.

Tables with key relationships

When you select a table, the table's column names display in the Columns box, and any tables having a key relationship with the selected table display in the Tables box. These tables are indented and marked with an arrow to show their relationship to the selected table. You can select any of these related tables if you want to include columns from them in the DataWindow object.


Meaning of the up and down arrows

An arrow displays next to a table to indicate its relationship to the selected table. The arrow always points in the many direction of the relationship—toward the selected table (up) if the selected table contains a foreign key in the relationship and away from the selected table (down) if the selected table contains a primary key in the relationship:


In this preceding illustration, the selected table is sales_order. The Up arrows indicate that a foreign key in the sales_order table is mapped to the primary key in the customer and fin_code tables. The Down arrow indicates that the sales_order_items table contains a foreign key mapped to the primary key in the sales_order table.

How columns from additional tables display

The column names of selected tables display in the Columns box. If you select more than one table, the column names are identified as:

tablename.columnname

For example, department.dept_name and employee.emp_id display when the Employee table and the Department table are selected.

To return to the original table list

Click the table you first selected at the top of the table list.

Selecting columns

You can select columns from the primary table and from its related tables. Select the table whose columns you want to use in the Tables box, and add columns from the Columns box:

  • To add a column, select it in the Columns box.

  • To add all the columns that display in the Columns box, click Add All.

  • To remove a column, deselect it in the Columns box.

  • To view comments that describe a table or column, position the pointer on a table or column name, and press and hold the right mouse button.

As you select columns, they display in the grid at the bottom of the dialog box in the order in which you select them. If you want the columns to display in a different order in the DataWindow object, select a column name you want to move in the grid and drag it to the new location.

Specifying sorting criteria

In the grid at the bottom of the Quick Select dialog box, you can specify if you want the retrieved rows to be sorted. As you specify sorting criteria, PowerBuilder builds an ORDER BY clause for the SELECT statement.

To sort retrieved rows on a column

  1. Click in the Sort row for the column you want to sort on.

    PowerBuilder displays a drop-down list:


  2. Select the sorting order for the rows: Ascending or Descending.

Multilevel sorts

You can specify as many columns for sorting as you want. PowerBuilder processes the sorting criteria left to right in the grid: the first column with Ascending or Descending specified becomes the highest level sorting column, the next column with Ascending or Descending specified becomes the next level sorting column, and so on.

If you want to do a multilevel sort that does not match the column order in the grid, drag the columns to the correct order and then specify the columns for sorting.

Specifying selection criteria

You can enter selection criteria in the grid to specify which rows to retrieve. For example, instead of retrieving data about all employees, you might want to limit the data to employees in Sales and Marketing, or to employees in Sales who make more than $80,000.

As you specify selection criteria, PowerBuilder builds a WHERE clause for the SELECT statement.

To specify selection criteria

  1. Click the Criteria row below the first column for which you want to select the data to retrieve.

  2. Enter an expression, or if the column has an edit style, select or enter a value.

  3. If the column is too narrow for the criterion, drag the grid line to enlarge the column. This enlargement does not affect the column size in a DataWindow object.

  4. Enter additional expressions until you have specified the data you want to retrieve.

    About edit styles

    If a column has an edit style associated with it in the extended attribute system tables (that is, the association was made in the Database painter), if possible, the edit style is used in the grid. Drop-down list boxes are used for columns with code tables and columns using the CheckBox and RadioButton edit styles.

SQL operators supported in Quick Select

You can use these SQL relational operators in the retrieval criteria:

Operator

Meaning

=

Is equal to (default operator)

>

Is greater than

<

Is less than

< >

Is not equal to

> =

Is greater than or equal to

< =

Is less than or equal to

LIKE

Matches this pattern

NOT LIKE

Does not match this pattern

IN

Is in this set of values

NOT IN

Is not in this set of values


Because = is the default operator, you can enter the value 100 instead of = 100, or the value New Hampshire instead of = New Hampshire.

Comparison operators

You can use the LIKE, NOT LIKE, IN, and NOT IN operators to compare expressions.

  • Use LIKE to search for strings that match a predetermined pattern. Use NOT LIKE to find strings that do not match a predetermined pattern. When you use LIKE or NOT LIKE, you can use wildcards:

    The percent sign (%), like the wildcard asterisk (*) used in many applications, matches multiple characters. For example, Good% matches all names that begin with Good.

    The underscore character (_) matches a single character. For example, Good _ _ _ matches all seven-letter names that begin with Good.

  • Use IN to compare and include a value that is in a set of values. Use NOT IN to compare and include values that are not in a set of values. For example, the following clause selects all employees in department 100, 200, or 500:

    SELECT * from employee
    WHERE dept_id IN (100, 200, 500)
  • Using NOT IN in this clause would exclude employees in those departments.

Connection operators

You can use the OR and AND logical operators to connect expressions.

PowerBuilder makes some assumptions based on how you specify selection criteria. When you specify:

  • Criteria for more than one column on one line

    PowerBuilder assumes a logical AND between the criteria. A row from the database is retrieved if all criteria in the line are met.

  • Two or more lines of selection criteria

    PowerBuilder assumes a logical OR. A row from the database is retrieved if the criterion in any of the lines is met.

To override these defaults, begin an expression with the AND or OR operator:

Operator

Meaning

OR

The row is selected if one expression OR another expression is true

AND

The row is selected if one expression AND another expression are true


This technique is particularly handy when you want to retrieve a range of values in a column. See example 6 below.

SQL expression examples

The first six examples in this section all refer to a grid that contains three columns from the employee table: emp_id, dept_id, and salary.

Example 1

The expression <50000 in the Criteria row in the salary column in the grid retrieves information for employees whose salaries are less than $50,000.


The SELECT statement that PowerBuilder creates is:

SELECT employee.emp_id, 
   employee.dept_id, 
   employee.salary
FROM employee
WHERE employee.salary < '50000'

Example 2

The expression 100 in the Criteria row in the DeptId column in the grid retrieves information for employees who belong to department 100.


The SELECT statement that PowerBuilder creates is:

SELECT employee.emp_id, 
   employee.dept_id, 
   employee.salary
FROM employee
WHERE employee.dept_id ='100'

Example 3

The expression >300 in the Criteria row in the EmpId column and the expression <50000 in the Criteria row in the Salary column in the grid retrieve information for any employee whose employee ID is greater than 300 and whose salary is less than $50,000.


The SELECT statement that PowerBuilder creates is:

SELECT employee.emp_id, 
   employee.dept_id, 
   employee.salary
FROM employee
WHERE (employee.emp_id >'300') AND
   employee.salary <'50000'

Example 4

The expressions 100 in the Criteria row and >300 in the Or row for the DeptId column, together with the expression <50000 in the Criteria row in the Salary column, retrieve information for employees who belong to:

  • Department 100 and have a salary less than $50,000

    or

  • A department whose ID is greater than 300, no matter what their salaries


The SELECT statement that PowerBuilder creates is:

SELECT employee.emp_id, 
   employee.dept_id, 
   employee.salary
FROM employee
WHERE (employee.dept_id = '100') AND 
   (emplyee.salary < '50000')OR 
   (employee.dept_id > '300')

Example 5

The expression IN(100,200) in the Criteria row in the DeptId column in the grid retrieves information for employees who are in department 100 or 200.


The SELECT statement that PowerBuilder creates is:

SELECT employee.emp_id, 
   employee.dept_id, 
   employee.salary
FROM employee
WHERE employee.dept_id IN ('100,200')

Example 6

This example shows the use of the word AND in the Or criteria row. In the Criteria row, >=500 is in the EmpId column and >=30000 is in the Salary column. In the Or row, AND <=1000 is in the EmpId column and AND <=50000 is in the Salary column. These criteria retrieve information for employees who have an employee ID from 500 to 1000 and a salary from $30,000 to $50,000.


The SELECT statement that PowerBuilder creates is:

SELECT employee.emp_id, 
   employee.dept_id, 
   employee.salary
FROM employee
WHERE (((employee.emp_id >='500') AND
   (employee.salary >='30000') AND
   (employee.emp_id <='1000') AND
   (employee.salary <='50000')))

Example 7

In a grid with three columns: emp_last_name, emp_first_name, and salary, the expressions LIKE C% in the Criteria row and LIKE G% in the Or row in the emp_last_name column retrieve information for employees who have last names that begin with C or G.


The SELECT statement that PowerBuilder creates is:

SELECT employee.emp_last_name, 
   employee.emp_first_name, 
   employee.salary
FROM employee
WHERE (((employee.emp_last_name LIKE 'C%'))OR
   ((employee.emp_last_name LIKE 'G%')))

Providing SQL functionality to users

You can allow your users to specify selection criteria in a DataWindow object using these techniques at runtime:

Using SQL Select

In specifying data for a DataWindow object, you have more options for specifying complex SQL statements when you use SQL Select as the data source. When you choose SQL Select, you go to the SQL Select painter, where you can paint a SELECT statement that includes the following:

  • More than one table

  • Selection criteria (WHERE clause)

  • Sorting criteria (ORDER BY clause)

  • Grouping criteria (GROUP BY and HAVING clauses)

  • Computed columns

  • One or more arguments to be supplied at runtime

Saving your work as a query

While in the SQL Select painter, you can save the current SELECT statement as a query by selecting File>Save As from the menu bar. Doing so allows you to easily use this data specification again in other DataWindows.

For more information about queries, see Defining queries.

To define the data using SQL Select:

  1. Click SQL Select in the Choose Data Source dialog box in the wizard and click Next.

    The Select Tables dialog box displays.

  2. Select the tables and/or views that you will use in the DataWindow object.

    For more information, see Selecting tables and views.

  3. Select the columns to be retrieved from the database.

    For more information, see Selecting columns.

  4. Join the tables if you have selected more than one.

    For more information, see Joining tables.

  5. Select retrieval arguments if appropriate.

    For more information, see Using retrieval arguments.

  6. Limit the retrieved rows with WHERE, ORDER BY, GROUP BY, and HAVING criteria, if appropriate.

    For more information, see Specifying selection, sorting, and grouping criteria.

  7. If you want to eliminate duplicate rows, select Distinct from the Design menu. This adds the DISTINCT keyword to the SELECT statement.

  8. Click the Return button on the PainterBar.

    You return to the wizard to complete the definition of the DataWindow object.

  9. Click OK.

Selecting tables and views

After you have chosen SQL Select, the Select Tables dialog box displays in front of the Table Layout view of the SQL Select painter.What tables and views display in the dialog box depends on the DBMS. For some DBMSs, all tables and views display, whether or not you have authorization. Then, if you select a table or view you are not authorized to access, the DBMS issues a message.

For ODBC databases, the tables and views that display depend on the driver for the data source. SQL Anywhere does not restrict the display, so all tables and views display, whether or not you have authorization.

To select the tables and views

  • Do one of the following:

    • Click the name of each table or view you want to open.

      Each table you select is highlighted. (To deselect a table, click it again.) Click the Open button to close the Select Tables dialog box.

    • Double-click the name of each table or view you want to open.

      Each object opens immediately behind the Select Tables dialog box. Click the Cancel button to close the Select Tables dialog box.

    Representations of the selected tables and views display. You can move or size each table to fit the space as needed.

    Below the Table Layout view, several tabbed views also display by default. You use the views (for example, Compute, Having, Group) to specify the SQL SELECT statement in more detail. You can turn the views on and off from the View menu on the menu bar.


Specifying what is displayed

You can display the label and datatype of each column in the tables (the label information comes from the extended attribute system tables). If you need more space, you can choose to hide this information.

To hide or display comments, datatypes, and labels

  1. Position the pointer on any unused area of the Table Layout view and select Show from the pop-up menu.

    A cascading menu displays.

  2. Select or clear Datatypes, Labels, or Comments as needed.

Colors in the SQL Select painter

The colors used by the SQL Select painter to display the Table Layout view background and table information are specified in the Database painter. You can also set colors for the text and background components in the table header and detail areas.

For more information about specifying colors in the Database painter, see Modifying database preferences.

Adding and removing tables and views

You can add tables and views to your Table Layout view at any time.

To do this

Do this

Add tables or views

Click the Tables button in the PainterBar and select tables or views to add

Remove a table or view

Display its pop-up menu and select Close

Remove all tables and views

Select Design>Undo All from the menu bar


You can also remove individual tables and views from the Table Layout view, or clear them all at once and begin selecting a new set of tables.

How PowerBuilder joins tables

If you select more than one table in the SQL Select painter, PowerBuilder joins columns based on their key relationship.

For information about joins, see Joining tables.

Selecting columns

You can click each column you want to include from the table representations in the Table Layout view. PowerBuilder highlights selected columns and places them in the Selection List at the top of the SQL Select painter.

To reorder the selected columns

  • Drag a column in the Selection List with the mouse. Release the mouse button when the column is in the proper position in the list.


To select all columns from a table

  • Move the pointer to the table name and select Select All from the pop-up menu.

To include computed columns

  1. Click the Compute tab to make the Compute view available (or select View>Compute if the Compute view is not currently displayed).

    Each row in the Compute view is a place for entering an expression that defines a computed column.

  2. Enter one of the following:

    • An expression for the computed column. For example: salary/12

    • A function supported by your DBMS. For example, the following is a SQL Anywhere function:

      substr("employee"."emp_fname",1,2)

    You can display the pop-up menu for any row in the Compute view. Using the pop-up menu, you can select and paste the following into the expression:

    • Names of columns in the tables used in the DataWindow or pipeline

    • Any retrieval arguments you have specified

    • Functions supported by the DBMS

    About these functions

    The functions listed here are provided by your DBMS. They are not PowerBuilder functions. This is so because you are now defining a SELECT statement that will be sent to your DBMS for processing.

  3. Press the Tab key to get to the next row to define another computed column, or click another tab to make additional specifications.

    PowerBuilder adds the computed columns to the list of columns you have selected.

About computed columns and computed fields

Computed columns you define in the SQL Select painter are added to the SQL statement and used by the DBMS to retrieve the data. The expression you define here follows your DBMS's rules.

You can also choose to define computed fields, which are created and processed dynamically by PowerBuilder after the data has been retrieved from the DBMS. There are advantages to doing this. For example, work is offloaded from the database server, and the computed fields update dynamically as data changes in the DataWindow object. (If you have many rows, however, this updating can result in slower performance.) For more information, see Enhancing DataWindow Objects.

Displaying the underlying SQL statement

As you specify the data for the DataWindow object in the SQL Select painter, PowerBuilder generates a SQL SELECT statement. It is this SQL statement that will be sent to the DBMS when you retrieve data into the DataWindow object. You can look at the SQL as it is being generated while you continue defining the data for the DataWindow object.

To display the SQL statement

  • Click the Syntax tab to make the Syntax view available, or select View>Syntax if the Syntax view is not currently displayed.

    You may need to use the scroll bar to see all parts of the SQL SELECT statement. This statement is updated each time you make a change.

Editing the SELECT statement syntactically

Instead of modifying the data source graphically, you can directly edit the SELECT statement in the SQL Select painter.

Converting from syntax to graphics

If the SQL statement contains unions or the BETWEEN operator, it may not be possible to convert the syntax back to graphics mode. In general, once you convert the SQL statement to syntax, you should maintain it in syntax mode.

To edit the SELECT statement

  1. Select Design > Convert to Syntax from the menu bar.

    PowerBuilder displays the SELECT statement in a text window.

  2. Edit the SELECT statement.

  3. Do one of the following:

    • Select Design > Convert to Graphics from the menu bar to return to the SQL Select painter.

    • Click the Return button to return to the wizard if you are building a new DataWindow object, or to the DataWindow painter if you are modifying an existing DataWindow object.

Joining tables

If the DataWindow object will contain data from more than one table, you should join the tables on their common columns. If you have selected more than one table, PowerBuilder joins columns according to whether they have a key relationship:

  • Columns with a primary/foreign key relationship are joined automatically.

  • Columns with no key relationship are joined, if possible, based on common column names and types.

PowerBuilder links joined tables in the SQL Select painter Table Layout view. PowerBuilder joins can differ depending on the order in which you select the tables, and sometimes the PowerBuilder best-guess join is incorrect, so you may need to delete a join and manually define a join.

To delete a join

  1. Click the join operator connecting the tables.

    The Join dialog box displays.

  2. Click Delete.

To join tables

  1. Click the Join button in the PainterBar.

  2. Click the columns on which you want to join the tables.

    To create a join other than an equality join, click the join operator in the Table Layout view.

    The Join dialog box displays:


  3. Select the join operator you want and click OK.

    If your DBMS supports outer joins, outer join options also display in the Join dialog box.

Using ANSI outer joins

All PowerBuilder database interfaces provide support for ANSI SQL-92 outer join SQL syntax generation. PowerBuilder supports both left and right outer joins in graphics mode in the SQL Select painter, and full outer and inner joins in syntax mode. Depending on your database interface, you might need to set the OJSyntax DBParm to enable ANSI outer joins. For more information, see the section called “OJSyntax” in Connection Reference.

The syntax for ANSI outer joins is generated according to the following BNF (Backus Naur form):

OUTER-join ::= 
table-reference {LEFT | RIGHT} OUTER JOIN table-reference ON search-condition 
table-reference ::= 
table_view_name [correlation_name] | OUTER-join

Order of evaluation and nesting

In ANSI SQL-92, when nesting joins, the result of the first outer join (determined by order of ON conditions) is the operand of the outer join that follows it. In PowerBuilder, an outer join is considered to be nested if the table-reference on the left of the JOIN has been used before within the same outer join nested sequence.

The order of evaluation for ANSI syntax nested outer joins is determined by the order of the ON search conditions. This means that you must create the outer joins in the intended evaluation order and add nested outer joins to the end of the existing sequence, so that the second table-reference in the outer join BNF above will always be a table_view_name.

Nesting example

For example, if you create a left outer join between a column in Table1 and a column in Table2, then join the column in Table2 to a column in Table3, the product of the outer join between Table1 and Table2 is the operand for the outer join with Table3.

For standard database connections, the default generated syntax encloses the outer joins in escape notation {oj ...} that is parsed by the driver and replaced with DBMS-specific grammar:

SELECT Table1.col1, Table2.col1, Table3.col1
FROM {oj {oj Table1 LEFT OUTER JOIN Table2 ON Table1.col1 = Table2.col1}
LEFT OUTER JOIN Table3 ON Table2.col1 = Table3.col1} 

Table references

Table references are considered equal when the table names are equal and there is either no alias (correlation name) or the same alias for both. Reusing the operand on the right is not allowed, because ANSI does not allow referencing the table_view_name twice in the same statement without an alias.

Determining left and right outer joins

When you create a join condition, the table you select first in the painter is the left operand of the outer join. The table that you select second is the right operand. The condition you select from the Joins dialog box determines whether the join is a left or right outer join.

For example, suppose you select the dept_id column in the employee table, then select the dept_id column in the department table, then choose the following condition:

employee.dept_id = department.dept_id and rows from department that have no employee

The syntax generated is:

SELECT employee.dept_id, department.dept_id
FROM {oj "employee" RIGHT OUTER JOIN "department" ON "employee"."dept_id" = "department"."dept_id"}

If you select the condition, rows from employee that have no department, you create a left outer join instead.

Equivalent statements

The syntax generated when you select table A then table B and create a left outer join is equivalent to the syntax generated when you select table B then table A and create a right outer join.

For more about outer joins, see your DBMS documentation.

Using retrieval arguments

If you know which rows will be retrieved into the DataWindow object at runtime—that is, if you can fully specify the SELECT statement without having to provide a variable—you do not need to specify retrieval arguments.

Adding retrieval arguments

If you decide later that you need arguments, you can return to the SQL Select painter to define the arguments.

Defining retrieval arguments in the DataWindow painter

You can select View>Column Specifications from the menu bar. In the Column Specification view, a column of check boxes next to the columns in the data source lets you identify the columns users should be prompted for. This, like the Retrieval Arguments prompt, calls the Retrieve method.

See Enhancing DataWindow Objects.

If you want the user to be prompted to identify which rows to retrieve, you can define retrieval arguments when defining the SQL SELECT statement. For example, consider these situations:

  • Retrieving the row in the Employee table for an employee ID entered into a text box. You must pass that information to the SELECT statement as an argument at runtime.

  • Retrieving all rows from a table for a department selected from a drop-down list. The department is passed as an argument at runtime.

Using retrieval arguments at runtime

If a DataWindow object has retrieval arguments, call the Retrieve method of the DataWindow control to retrieve data at runtime and pass the arguments in the method.

To define retrieval arguments

  1. In the SQL Select painter, select Design > Retrieval Arguments from the menu bar.

  2. Enter a name and select a datatype for each argument.

    You can enter any valid SQL identifier for the argument name. The position number identifies the argument position in the Retrieve method you code in a script that retrieves to retrieve data into the DataWindow object.

  3. Click Add to define additional arguments as needed and click OK when done.

    Specifying an array as a retrieval argument

    You can specify an array of values as your retrieval argument. Choose the type of array from the Type drop-down list in the Specify Retrieval Arguments dialog box. You specify an array if you want to use the IN operator in your WHERE clause to retrieve rows that match one of a set of values. For example:

    SELECT * from employee WHERE dept_id IN (100, 200, 500)

    retrieves all employees in department 100, 200, or 500. If you want your user to specify the list of departments to retrieve, you define the retrieval argument as a number array (such as 100, 200, 500).

    In the code that does the retrieval, you declare an array and reference it in the Retrieve method., as in:

    int x[3]
    // Now populate the array with values
    // such as x[1] = sle_dept.Text, and so on,
    // then retrieve the data, as follows.
    dw_1.Retrieve(x)
    Integer x[]= new Integer[3];
    x[0]=new Integer(100);
    x[1]=new Integer(200);
    x[2]=new Integer(500);
    dw1.retrieve(x);

    PowerBuilder passes the appropriate comma-delimited list to the method (such as 100, 200, 500 if x[1] = 100, x[2] = 200, and x[3] = 500 if x[0] = 100, x[1] = 200, and x[2] = 500).

    When building the SELECT statement, you reference the retrieval arguments in the WHERE or HAVING clause, as described in the next section.

Specifying selection, sorting, and grouping criteria

In the SELECT statement associated with a DataWindow object, you can add selection, sorting, and grouping criteria that are added to the SQL statement and processed by the DBMS as part of the retrieval.

To do this

Use this clause

Limit the data that is retrieved from the database

WHERE

Sort the retrieved data before it is brought into the DataWindow object

ORDER BY

Group the retrieved data before it is brought into the DataWindow object

GROUP BY

Limit the groups specified in the GROUP BY clause

HAVING


Dynamically selecting, sorting, and grouping data

Selection, sorting, and grouping criteria that you define in the SQL Select painter are added to the SQL statement and processed by the DBMS as part of the retrieval. You can also define selection, sorting, and grouping criteria that are created and processed dynamically by PowerBuilder after data has been retrieved from the DBMS.

For more information, see Filtering, Sorting, and Grouping Rows.

Referencing retrieval arguments

If you have defined retrieval arguments, you reference them in the WHERE or HAVING clause. In SQL statements, variables (called host variables) are always prefaced with a colon to distinguish them from column names.

For example, if the DataWindow object is retrieving all rows from the Department table where the dept_id matches a value provided by the user at runtime, your WHERE clause will look something like this:

WHERE dept_id = :Entered_id

where Entered_id was defined previously as an argument in the Specify Retrieval Arguments dialog box.

Referencing arrays

Use the IN operator and reference the retrieval argument in the WHERE or HAVING clause.

For example, if you reference an array defined as deptarray, the expression in the WHERE view might look like this:

"employee.de pt_id" IN (:deptarray)

You need to supply the parentheses yourself.

Defining WHERE criteria

You can limit the rows that are retrieved into the DataWindow object by specifying selection criteria that correspond to the WHERE clause in the SELECT statement.

For example, if you are retrieving information about employees, you can limit the employees to those in Sales and Marketing, or to those in Sales and Marketing who make more than $50,000.

To define WHERE criteria

  1. Click the Where tab to make the Where view available (or select View>Where if the Where view is not currently displayed).

    Each row in the Where view is a place for entering an expression that limits the retrieval of rows.

  2. Click in the first row under Column to display columns in a drop-down list, or select Columns from the pop-up menu.

  3. Select the column you want to use in the left-hand side of the expression.

    The equality (=) operator displays in the Operator column.

    Using a function or retrieval argument in the expression

    To use a function, select Functions from the pop-up menu and click a listed function. These are the functions provided by the DBMS.

    To use a retrieval argument, select Arguments from the pop-up menu. You must have defined a retrieval argument already.

  4. (Optional) Change the default equality operator.

  5. Enter the operator you want, or click to display a list of operators and select an operator.

  6. Under Value, specify the right-hand side of the expression. You can:

    • Type a value.

    • Paste a column, function, or retrieval argument (if there is one) by selecting Columns, Functions, or Arguments from the pop-up menu.

    • Paste a value from the database by selecting Value from the pop-up menu, then selecting a value from the list of values retrieved from the database. (It may take some time to display values if the column has many values in the database.)

    • Define a nested SELECT statement by selecting Select from the pop-up menu. In the Nested Select dialog box, you can define a nested SELECT statement. Click Return when you have finished.

  7. Continue to define additional WHERE expressions as needed.

    For each additional expression, select a logical operator (AND or OR) to connect the multiple boolean expressions into one expression that PowerBuilder evaluates as true or false to limit the rows that are retrieved.

  8. Define sorting (Sort view), grouping (Group view), and limiting (Having view) criteria as appropriate.

  9. Click the Return button to return to the DataWindow painter.

Defining ORDER BY criteria

You can sort the rows that are retrieved into the DataWindow object by specifying columns that correspond to the ORDER BY clause in the SELECT statement.

For example, if you are retrieving information about employees, you can sort on department, and then within each department, you can sort on employee ID.

To define ORDER BY criteria

  1. Click the Sort tab to make the Sort view available (or select View>Sort if the Sort view is not currently displayed).

    The columns you selected display in the order of selection. You might need to scroll to see your selections.

  2. Drag the first column you want to sort on to the right side of the Sort view.

    This specifies the column for the first level of sorting. By default, the column is sorted in ascending order. To specify descending order, clear the Ascending check box.

  3. Continue to specify additional columns for sorting in ascending or descending order as needed.

    You can change the sorting order by dragging the selected column names up or down. With the following sorting specification, rows will be sorted first by department ID, then by employee ID:


  4. Define limiting (Where view), grouping (Group view), and limiting groups (Having view) criteria as appropriate.

  5. Click the SQL Select button to return to the DataWindow painter.

Defining GROUP BY criteria

You can group the retrieved rows by specifying groups that correspond to the GROUP BY clause in the SELECT statement. This grouping happens before the data is retrieved into the DataWindow object. Each group is retrieved as one row into the DataWindow object.

For example, if in the SELECT statement you group data from the Employee table by department ID, you will get one row back from the database for every department represented in the Employee table. You can also specify computed columns, such as total and average salary, for the grouped data. This is the corresponding SELECT statement:

SELECT dept_id, sum(salary), avg(salary)
FROM employee
GROUP BY dept_id

If you specify this with the Employee table in the PB Demo DB, you get five rows back, one for each department.


For more about GROUP BY, see your DBMS documentation.

To define GROUP BY criteria

  1. Click the Group tab to make the Group view available (or select View>Group if the Group view is not currently displayed).

    The columns in the tables you selected display in the left side of the Group view. You might need to scroll to see your selections.

  2. Drag the first column you want to group onto the right side of the Group view.

    This specifies the column for grouping. Columns are grouped in the order in which they are displayed in the right side of the Group view.

  3. Continue to specify additional columns for grouping within the first grouping column as needed.

    To change the grouping order, drag the column names in the right side to the positions you want.

  4. Define sorting (Sort view), limiting (Where view), and limiting groups (Having view) criteria as appropriate.

  5. Click the Return button to return to the DataWindow painter.

Defining HAVING criteria

If you have defined groups, you can define HAVING criteria to restrict the retrieved groups. For example, if you group employees by department, you can restrict the retrieved groups to departments whose employees have an average salary of less than $50,000. This corresponds to:

SELECT dept_id, sum(salary), avg(salary)
FROM employee
GROUP BY dept_id
HAVING avg(salary) < 50000

If you specify this with the Employee table in the PB Demo DB, you will get three rows back, because there are three departments that have average salaries less than $50,000.


To define HAVING criteria

  • Click the Having tab to make the Having view available (or select View>Having if the Having view is not currently displayed).

    Each row in the Having view is a place for entering an expression that limits which groups are retrieved. For information on how to define criteria in the Having view, see the procedure in Defining WHERE criteria.

Using Query

When you choose Query as the data source, you select a predefined SQL SELECT statement (a query) as specifying the data for your DataWindow object.

To define the data using Query:

  1. While using any of the DataWindow wizards, click Query in the Choose Data Source dialog box, and click Next.

    The Select Query dialog box displays.

  2. Type the name of a query or use the Browse button to find the query, then click Next.

  3. Finish interacting with the DataWindow object wizard as needed for the presentation style you are using.

    To learn how to create queries, see Defining queries.

Using External

If the data for the DataWindow object does not come from a database (either through a native SAP database interface or through a standard database interface), specify External as the data source. You then specify the data columns and their types so PowerBuilder can build the appropriate DataWindow object to hold the data. These columns make up the result set. PowerBuilder places the columns you specified in the result set in the DataWindow object.

To define the data using External:

  1. Click External in the Choose Data Source dialog box in the wizard and click Next.

    The Define Result Set dialog box displays for you to specify the first column in the result set.

  2. Enter the name and type of the column.

    Available datatypes are listed in the drop-down list. The number datatype is equivalent to the PowerBuilder double datatype.

  3. Click Add to enter the name and type of any additional columns you want in the result set.

  4. Click Next when you have added all the columns you want.

What you do next

In code, you need to tell PowerBuilder how to get data into the DataWindow object in your application. Typically, you import data at runtime using a method (such as ImportFile or ImportString) or do some data manipulation and use the SetItem method to populate the DataWindow.

For more about these methods, see DataWindow Reference.

You can also import data values from an external file into the DataWindow object or report.

To import the data values from an external file:

  1. Make sure the Preview view of the DataWindow object is selected.

  2. Select Rows > Import from the menu bar.

    The Select Import File dialog box displays.

  3. Select the type of files to list from the List Files of Type drop-down list (an XML, CSV, TXT, or DBF file).

  4. Enter the name of the import file and click OK.

    Alternatively, you can select the name from the file list. Use the Drives drop-down list and the Directories box as needed to display the list of files that includes the one you want.

Using Stored Procedure

A stored procedure is a set of precompiled and preoptimized SQL statements that performs some database operation. Stored procedures reside where the database resides, and you can access them as needed.

Defining data using a stored procedure

You can specify a stored procedure as the data source for a DataWindow object if your DBMS supports stored procedures.

For information on support for stored procedures, see your database documentation.

If the Stored Procedure icon is not displayed

The icon for the Stored Procedure data source displays in the Choose Data Source dialog box in the DataWindow object wizards only if the database to which you are connected supports stored procedures.

To define the data using Stored Procedure:

  1. Select Stored Procedure in the Choose Data Source dialog box in the wizard and click Next.

    The Select Stored Procedure dialog box displays a list of the stored procedures in the current database.

  2. Select a stored procedure from the list.

    To list system procedures, select the System Procedure check box.

    The syntax of the selected stored procedure displays below the list of stored procedures.

  3. Specify how you want the result set description built:

    • To build the result set description automatically, clear the Manual Result Set check box and click Next.

      PowerBuilder executes the stored procedure and builds the result set description for you.

    • To define the result set description manually, select the Manual Result Set check box and click Next.

      In the Define Stored Procedure Result Set dialog box:

      • Enter the name and type of the first column in the result set.

      • To add additional columns, click Add.

    Your preference is saved

    PowerBuilder records your preference for building result set descriptions for stored procedure DataWindow objects in the variable Stored_Procedure_Build in the PowerBuilder initialization file. If this variable is set to 1, PowerBuilder will automatically build the result set; if the variable is set to 0, you are prompted to define the result set description.

  4. Continue in the DataWindow wizard as needed for the presentation style you are using.

    When you have finished interacting with the wizard, you go to the DataWindow painter with the columns specified in the result set placed in the DataWindow object.

    For information about defining retrieval arguments for DataWindow objects, see Enhancing DataWindow Objects.

    For information about using a stored procedure to update the database, see Using stored procedures to update the database.

Editing a result set description

After you create a result set that uses a stored procedure, you can edit the result set description from the DataWindow painter.

To edit the result set description:

  1. Select Design>Data Source from the menu bar.

    This displays the Column Specification view if it is not already displayed.

  2. Select Stored Procedure from the Column Specification view's pop-up menu.

    The Modify Stored Procedure dialog box displays.

  3. Edit the Execute statement, select another stored procedure, or add arguments.

    The syntax is:

    execute sp_procname;num arg1 = :arg1, arg2 = :arg2..., argn =:argn

    where sp_procname is the name of the stored procedure, num is the stored procedure group suffix, and arg1, arg2, and argn are the stored procedure's arguments.

    The group suffix is an optional integer used in some DBMSs to group procedures of the same name so that they can be dropped together with a single DROP PROCEDURE statement. For other DBMSs the number is ignored.

  4. When you have defined the entire result set, click OK.

    You return to the DataWindow painter with the columns specified in the result set placed in the DataWindow object.

    For information about defining retrieval arguments for DataWindow objects, see Enhancing DataWindow Objects.

Using a Web service data source (Obsolete)

Presentation style requirement

You can use a Web service as the data source for a DataWindow having any of the following DataWindow presentation styles:

Composite

Graph

Label

TreeView

Crosstab

Grid

N-Up

 

Freeform

Group

Tabular

 

Support for a Web service data source is not available for RichText and OLE presentation styles.

Using the DataWindow wizard

After you select a supported DataWindow presentation style from the DataWindow tab of the New dialog box, you select a data source for the DataWindow.

When you select Web Service as the data source and click Next, the DataWindow wizard opens a page that prompts you to select a WSDL file. The file you select should be in a publicly accessible location for all members of the development team. You can enter the URL to a WSDL, ASMX, or XML file, or you can browse a mapped drive for these types of files.

The Choose WSDL File page of the DataWindow wizard also lets you name the assembly file that the wizard will create. The assembly file serves as an interface between the DataWindow and the Web service. If you do not name the assembly file, the wizard will select a name for you based on the name of the WSDL file entry.

The next step to access a Web service data source is to select a service described in the WSDL, and then one of its public methods. You must then select a parameter for the DataWindow to use as the result set for the method.

A DataWindow typically obtains its data from an array of structures. Because a Web service method can pass an array of structures in one of its arguments rather than in a return value, the wizard prompts you to select one of the method's arguments or its return value as the designated result set for the method. If you want data for a single row and column only, you can select a parameter that has a simple datatype. You can also select a parameter that is an array of simple datatypes rather than an array of structures.

You complete the wizard as you would when using any other type of data source for your DataWindow. After you complete the wizard, the DataWindow displays in the DataWindow painter. However, there is no equivalent to the SQL painter for a DataWindow with a Web service data source. For this type of DataWindow, you cannot select Design>Data Source from the DataWindow painter menu to change selected columns or modify the DataWindow syntax.

Runtime requirements on a deployment computer

To run the Web service DataWindow application from a deployment computer, the assembly file that you generate with the wizard must be copied along with the application executable and required PowerBuilder runtime DLLs for Web service applications. For information on the required DLLs and the Runtime Packager tool that you can use to deploy them, see the section called “Deploying Applications and Components” in Application Techniques.

For information on rebuilding an assembly generated by the DataWindow wizard, see Regenerating an assembly.

Datatype mappings

The following table lists .NET datatypes and the DataWindow datatypes to which they map when you use a .NET Web service as a data source. Arrays are also supported for these datatypes except for System.Byte.

.NET datatype

DataWindow datatype

System.Boolean

long (Handled as a boolean at runtime.)

System.Byte

ulong

System.DateTime

datetime (Minimum and maximum dates for .NET can be outside the range of dates supported by PowerBuilder. PowerBuilder does not support dates prior to the year 1000 or after the year 3000.)

System.Decimal

decimal

System.Double

number

System.Int16

long

System.Int32

long

System.Int64

decimal

System.SByte

long

System.Single

real

System.String

string

System.UInt16

ulong

System.UInt32

ulong

System.UInt64

decimal


The DataWindow can also use a Web service data source that has structures for parameters, as long as the structures are composed of the simple datatypes that can be mapped to DataWindow datatypes. An array of structures can be mapped to n rows with x columns where n is the size of the array and x is the number of members in the structure. Nested structures are not supported.

Using parameters by reference

For a Web service that you create from a PowerBuilder nonvisual object, a result set must be passed by reference, but it cannot be passed in a method return value. You must use a method argument to pass the result set and then select that argument in any DataWindow object that uses the method as its data source.

A parameter passed by reference is a bidirectional [IN,OUT] parameter by definition. The Web Service DataWindow wizard lets you select a Web service method [OUT] or [IN,OUT] parameter, instead of the method return value, to pass a result set to a DataWindow object. However, the parameter you select cannot be used for both a return value and a retrieval argument by the same DataWindow object.

Database-related functions and events

In the Web Service DataWindow, some database or transaction-related functions and events are not supported and meaningless because the Web Service DataWindow has no direct relation to the database. The following functions cannot be used with the Web Service DataWindow: GetSQLPreview, GetSQLSelect, SetSQLPreview, SetSQLSelect, SetTrans, and SetTransObject.

The DBError event is also not supported for the Web Service DataWindow. Instead, you can use the WSError error event to handle errors during retrieve, insert, or update operations.

Using the WSConnection object

Some Web services support or require a user ID and password, and other session-related properties like firewall settings. The WSConnection object can provide this information for your DataWindow connections.

You use an instance of the WSConnection object to connect to a Web service by calling the SetWSObject method.

The following code instantiates a WSConnection object with user-related and authentication information, then sets the object as the connection object for a Web service data source:

int ii_return
wsconnection ws_1
ws_1 = create wsconnection
ws_1.username = "johndoe"
ws_1.password = "mypassword"
ws_1.endpoint = "myendpoint"
ws_1.authenticationmode = "basic"
ws_1.usewindowsintegratedauthentication = true
ii_return = dw_1.setwsobject (ws_1)

For more information about setting properties for a Web service connection, see the section called “WSConnection object (Obsolete)” in Objects and Controls and the section called “SetWSObject (Obsolete)” in DataWindow Reference.

For more information about updating the database with a Web service DataWindow, see Using a Web service to update the database.

Using the OData Service (Obsolete)

Creating a DataWindow Using an OData Service

Select the OData Service data source in the DataWindow wizard:

  1. Select File > New from the menu bar and select DataWindow.

    If there is more than one target, select the target where you want the DataWindow to be created from the drop-down list.

  2. Choose the presentation style for the DataWindow object and click Next.

  3. Select the OData Service datasource and click Next.

  4. Select the OData profile and click Next.

    In the SQL painter:

    • You can select one table.

    • The Sort, Group, and Having tabs are not available.

    • The Results tab is obsolete, because it is used by PowerBuilder .NET.

    • In the Where tab you can specify some selection criteria using the WHERE clause for the SELECT statement.

  5. When you complete the query, click OK.

  6. Review your specifications and click Finish.

At runtime, the DataWindow or DataStore can manipulate OData service data, which includes retrieving, updating, inserting, and deleting the data.

Setting the Connection Information for the OData Service

As with other databases, use the SQLCA Transaction object (or user-defined transaction object) to retrieve and display data from the OData service in a DataWindow or DataStore.

Set the appropriate values for the transaction object.

Connect to the OData service.

Set the transaction object for the DataWindow or DataStore.

Retrieve and update the data.

When the processes are complete, disconnect from the OData service.

The code looks something like this:

SQLCA.DBMS = "ODT"
SQLCA.DBParm = "ConnectString='URI=http://esx2-appserver/TestDataService/Employee.svc'"
//connect to the service
connect using SQLCA;
dw_1.SetTransObject(SQLCA)
dw_1.Retrieve()
...
//disconnect from the service
disconnect using SQLCA;

For more information on using the global Transaction object, see the section called “Using Transaction Objects” in Application Techniques.

Choosing DataWindow object-wide options

You can set the default options, such as colors and borders, that PowerBuilder uses in creating the initial draft of a DataWindow object.

DataWindow generation options are for styles that use a layout made up of bands, which include Freeform, Grid, Label, N-Up, Tabular, Group, TreeView, and Crosstab. PowerBuilder maintains a separate set of options for each of these styles.

When you first create any of these style DataWindow objects, you can choose options in the wizard and save your choices as the future defaults for the style.

To specify default colors and borders for a style:

  1. Select Design>Options from the menu bar.

    The DataWindow Options dialog box displays.

  2. Select the Generation tab page if it is not on top.

  3. Select the presentation style you want from the Presentation Style drop-down list.

    The values for properties shown on the page are for the currently selected presentation style.

  4. Change one or more of the following properties:

    Property

    Meaning for the DataWindow object

    Background color

    The default color for the background.

    Text border and color

    The default border and color used for labels and headings.

    Column border and color

    The default border and color used for data values.

    Wrap Height (Freeform only)

    The height of the detail band.

    When the value is None, the number of columns selected determines the height of the detail band. The columns display in a single vertical line.

    When the value is set to a number, the detail band height is set to the number specified and columns wrap within the detail band.


  5. Click OK.

About color selections

If you select Window Background, Application Workspace, Button Face, or Window Text from the Color drop-down list, the DataWindow object uses the colors specified in the Windows Control Panel on the computer on which the DataWindow object is running.

Your choices are saved

PowerBuilder saves your generation option choices as the defaults to use when creating a DataWindow object with the same presentation style.

Generating and saving a DataWindow object

When you have finished interacting with the wizard, PowerBuilder generates the DataWindow object and opens the DataWindow painter.

When generating the DataWindow object, PowerBuilder might use information from a set of tables called the extended attribute system tables. If this information is available, PowerBuilder uses it.

About the extended attribute system tables and DataWindow objects

The extended attribute system tables are a set of tables maintained by the Database painter. They contain information about database tables and columns. Extended attribute information extends database definitions by recording information that is relevant to using database data in screens and reports.

For example, labels and headings you defined for columns in the Database painter are used in the generated DataWindow object. Similarly, if you associated an edit style with a column in the Database painter, that edit style is automatically used for the column in the DataWindow object.

When generating a DataWindow object, PowerBuilder uses the following information from the extended attribute system tables:

For

PowerBuilder uses

Tables

Fonts specified for labels, headings, and data

Columns

Text specified for labels and headingsDisplay formatsValidation rulesEdit styles


If there is no extended attribute information for the database tables and columns you are using, you can set the text for headings and labels, the fonts, and the display formats in the DataWindow painter. The difference is that you have to do this individually for every DataWindow object that you create using the data.

If you want to change something that came from the extended attribute system tables, you can change it in the DataWindow painter. The changes you make in the DataWindow painter apply only to the DataWindow object you are working on.

The advantage of using the extended attribute system tables is that it saves time and ensures consistency. You only have to specify the information once, in the database. Since PowerBuilder uses the information whenever anyone creates a new DataWindow object with the data, it is more likely that the appearance and labels of data items will be consistent.

For more information about the extended attribute system tables, see Managing the Database, and Appendix A, The Extended Attribute System Tables.

Saving the DataWindow object

When you have created a DataWindow object, you should save it. The first time you save it you give it a name. As you work, you should save your DataWindow object frequently so that you do not lose changes.

To save the DataWindow object

  1. Select File > Save from the menu bar.

    If you have previously saved the DataWindow object, PowerBuilder saves the new version in the same library and returns you to the DataWindow painter.

    If you have not previously saved the DataWindow object, PowerBuilder displays the Save DataWindow dialog box.

  2. (Optional) Enter comments in the Comments box to describe the DataWindow object.

  3. Enter a name for the DataWindow object in the DataWindows box.

  4. Specify the library in which the DataWindow object is to be saved and click OK.

Naming the DataWindow object

The DataWindow object name can be any valid PowerBuilder identifier up to 255 contiguous characters.A common convention is to prefix the name of the DataWindow object with d_.

For information about PowerBuilder identifiers, see the section called “Identifier names” in PowerScript Reference.

Modifying an existing DataWindow object

To modify an existing DataWindow object

  1. Select File>Open from the menu bar.

    The Open dialog box displays.

  2. Select the object type and the library.

    PowerBuilder lists the DataWindow objects in the current library.

  3. Select the object you want.

    PowerBuilder opens the DataWindow painter and displays the DataWindow object. You can also open a DataWindow object by double-clicking it in the System Tree, or, if it has been placed in a window or visual user object, selecting Modify DataWindow from the control's pop-up menu.

    To learn how you can modify an existing DataWindow object, see Enhancing DataWindow Objects.

Defining queries

A query is a SQL SELECT statement created in the Query painter and saved with a name so that it can be used repeatedly as the data source for a DataWindow object.

Queries save time, because you specify all the data requirements just once. For example, you can specify the columns, which rows to retrieve, and the sorting order in a query. Whenever you want to create a DataWindow object using that data, simply specify the query as the data source.

To define a query:

  1. Select File>New from the menu bar.

  2. In the New dialog box, select the Database tab.

  3. Select the Query icon and click OK.

  4. Select tables in the Select Tables dialog box and click Open.

    You can select columns, define sorting and grouping criteria, define computed columns, and so on, exactly as you do when creating a DataWindow object using the SQL Select data source.

    For more about defining the SELECT statement, see Using SQL Select.

Previewing the query

While creating a query, you can preview it to make sure it is retrieving the correct rows and columns.

To preview a query

  1. Select Design > Preview from the menu bar.

    PowerBuilder retrieves the rows satisfying the currently defined query in a grid-style DataWindow object.

  2. Manipulate the retrieved data as you do in the Database painter in the Output view.

    You can sort and filter the data, but you cannot insert or delete a row or apply changes to the database. For more about manipulating data, see Managing the Database.

  3. When you have finished previewing the query, click the Close button in the PainterBar to return to the Query painter.

Saving the query

To save a query

  1. Select File > Save Query from the menu bar.

    If you have previously saved the query, PowerBuilder saves the new version in the same library and returns you to the Query painter. If you have not previously saved the query, PowerBuilder displays the Save Query dialog box.

  2. Enter a name for the query in the Queries box (see Naming the query).

  3. (Optional) Enter comments to describe the query.

    These comments display in the Library painter. It is a good idea to use comments to remind yourself and others of the purpose of the query.

  4. Specify the library in which to save the query, and click OK.

Naming the query

The query name can be any valid PowerBuilder identifier up to 255 characters. When you name queries, use a unique name to identify each one. A common convention is to use a two-part name: a standard prefix that identifies the object as a query (such as q_) and a unique suffix.For example, you might name a query that displays employee data q_emp_data. For information about PowerBuilder identifiers, see the section called “Identifier names” in PowerScript Reference.

Modifying a query

To modify a query

  1. Select File>Open from the menu bar.

  2. Select the Queries object type and then the query you want to modify, and click OK.

  3. Modify the query as needed.

What's next

After you have generated your DataWindow object, you will probably want to preview it to see how it looks. After that, you might want to enhance the DataWindow object in the DataWindow painter before using it. PowerBuilder provides many ways for you to make a DataWindow object easier to use and more informative for users. See the next section Enhancing DataWindow Objects.