Welcome!

PowerBuilder Authors: Chris Pollach, Yeshim Deniz, Jayaram Krishnaswamy, Kevin Benedict, Avi Rosenthal

Related Topics: PowerBuilder

PowerBuilder: Article

DataWindow.NET Pet Shop

It's easy and productive

for (int i = 1; i <= rows; i++)
{
ProductInfo product = new ProductInfo(
     productDataStore.GetItemString ( i, "productid" ),
     productDataStore.GetItemString ( i, "name" ),
     null);
productsByCategory.Add(product);
}
return productsByCategory;

Note that null values in the result set create a special situation, both in the original DAL and in the DataWindow.NET-based DAL. Neither the original DALs GetString method nor the DataWindow.NET GetItemString methods handle nulls. So if a column can be null, you need to test the value first and then access the value only if it's not null. In the original DAL, the nullable addr2 field for the Account class is handled as follows:

string addr2;
if (rdr.IsDBNull(4)){
addr2 = "";
}else{
     addr2 = rdr.GetString(4);
}

Similarly, the DataWindow.NET-based DAL handles it as follows:

string addr2 ;
if ( accountDataStore.IsItemNull( 1, "addr2" ) ) {
     addr2 = "" ;
}else{
     addr2 = accountDataStore.GetItemString ( 1, "addr2" );
}

Note that the DataWindow and DataStore classes in DataWindow.NET do have a GetItemSQLString method that will handle null values. It returns a SQLString rather than a String and you would use the ToString method of the returned object to convert it back to the String data type that the Account class uses. Also note that it's not only the GetItemString method that doesn't handle nulls; that issue is common to all of the GetItem<datatypes> methods. And the corresponding SQL<datatype> classes (which are native to the .NET Framework) all have methods that can be used to convert the SQL<datatype> to the native data type (e.g., the GetItemSQLDataTime has a SQLDateTime, and the SQLDateTime class has a DateTime method to convert the result back to a regular DateTime).

Similar to SELECTS, in the original DAL the values being used for INSERT and UPDATE statements are also assigned by position. For example, in the Order class there is actually a separate method whose main purpose is to create an array of parameter objects to use for the INSERT statement (see Listing 2).

Those parameters are then set based on the order class attributes (see Listing 3). Then the same technique is used to assign the parameters for each of the line items (see Listing 4).

With the DataWindow.NET-based DAL, we create a DataWindow object for each of the tables we're planning to update, create DataStores for each of them, and assign the connection to them (see Listing 5).

There is actually one more DataWindow than tables here. The d_ordernum DataWindow is used to retrieve the order ID number from the database. In the case of Oracle, this is done by selecting the nextval off of a sequence; whereas for ASA we'll accomplish the same thing by selecting the @@identity global variable after the order is inserted.

To create an order, we insert a new row in the order DataStore and assign the values to the columns directly from the Order class attributes, and then issue an UpdateData on the DataStore (see Listing 6). A similar approach is used to create the line items for the order (see Listing 7).

More Stories By Bruce Armstrong

Bruce Armstrong is a development lead with Integrated Data Services (www.get-integrated.com). A charter member of TeamSybase, he has been using PowerBuilder since version 1.0.B. He was a contributing author to SYS-CON's PowerBuilder 4.0 Secrets of the Masters and the editor of SAMs' PowerBuilder 9: Advanced Client/Server Development.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Tanveer 08/29/05 11:12:27 PM EDT

Excellent article.
I have a question from where i can download source code for this article.
i dont see any link to download @http://pbdj.sys-con.com