Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


PBDJ Cover Story — A DataWindow Based on Oracle Stored Procedures with a Result Set
In DataWindow.NET 2.0, Sybase added support for access to Oracle

In DataWindow.NET 2.0, Sybase added support for access to Oracle through the Oracle managed data provider (ODP.NET). A managed data provider provides better performance and more support than a non-managed driver for database-specific functions, though not as much as the Oracle native driver.

On the other hand, the managed data provider can still utilize ADO features of the .NET Framework (including connection caching), which native drivers cannot. In addition, Oracle recently added support to ODP.NET for returning REF CURSORS from Oracle stored procedures. That opens up the possibility of using Oracle stored procedures as the data source for a DataWindow.NET DataWindowObject.

Unfortunately, the ADO.NET driver provided with DataWindow.NET currently doesn't support that functionality. Therefore, our demonstration to implement such functionality will still use the native drivers. At some point, when the ADO.NET driver supports this functionality, the techniques shown in this article should still be applicable.

Bruce Armstrong provided an excellent description of using the DataWindow with Oracle stored procedures in his article "Using Oracle Stored Procedures in Your DataWindows" (PBDJ, Vol. 10, issue 2). It has a detailed explanation of the REF CURSOR concept, which is the key to the solution. The main ideas of that article are still the same for both DataWindows in PowerBuilder and DataWindow.NET. Therefore, we won't discuss the theory, but instead focus on a practical example.

Oracle Stored Procedure Example
A standard Oracle installation has a special SCOTT scheme for demonstration and learning purposes. If you don't have it, the script for this scheme installation could be found in <ORACLE_DB>\RDBMS\ADMIN\scott.sql. In our example, we want to create a stored procedure that returns a list of employees for a given department.

REF CURSOR ORACLE TYPE
For our procedure we need a special Oracle type called a REF CURSOR. We can create this type in any package. An example of such a package is provided in Listing 1.

We need only one ref cursor because we can use the same ref cursor for all procedures; that's why we use an unconstrained ref cursor. At the end of Listing 1, we granted access to our package (and our ref cursor) to every database user.

STORED PROCEDURE
The Oracle stored procedure with the result set can contain any number of input parameters, but the last one should be declared as an IN OUT ref cursor. In Listing 2, we can see the procedure SCOTT.EMP_BY_DEPT. This procedure has two arguments. The first argument (P_DEPTNO) is a department number and it's declared as IN INTEGER. The second argument (P_RESULTSET) is declared as IN OUT SCOTT.MYCURSOR.CURTYPE. This is the type we created in Listing 1.

We can populate the cursor many different ways, but the simplest one is OPEN cursor FOR SELECT.

Sybase DataWindow.NET 2.0 Example
Let's create a simple WinForms application using our procedure. For this purpose, we can create a new project using the Windows Application template. Add a combo-box for the Department selection and a DataWindowControl to show the list of employees from the chosen department.

Sybase DataWindow.NET has two classes for a database connection: AdoTransaction and Transaction. The AdoTransaction class is used for managed and unmanaged ADO.NET providers. However, since it currently doesn't handle REF CURSOR from the stored procedure, we will be using the Transaction class only.

DataWindow
In the Sybase DataWindow Designer, we should connect to Oracle using either O10 Oracle 10g or O90 Oracle 9i interface. Then we can create a new DataWindow d_emp_by_dept based on our stored procedure and put it into demo.pbl library.

REFERENCES
Next we add the references shown in Table 1 to our project.

INSTANCE VARIABLES
Next, put instance variables to the Form1 class declaration.

public partial class Form1 : Form
{
    private string m_ConnectionString = null; // Connection string
    private DataSet m_DeptDS = new DataSet(); // Dataset for Departments
    private Transaction m_Trans = new Transaction();// Sybase transaction object

CONNECTION SETTINGS
It's not a good idea to place the hard-coded connection strings into code, but we do so to simplify our example.

private void Form1_Load(object sender, EventArgs e)
{
    // Connection string
    this.m_ConnectionString = "Data Source=;User ID=SCOTT;Password=TIGER;";

    // Connection parameters
    this.m_Trans.DbParameter = "ConnectString=\'" + this.m_ConnectionString + "\'";
    this.m_Trans.Dbms = DbmsType.Oracle10g;
    this.m_Trans.UserId = "SCOTT";
    this.m_Trans.Password = "TIGER";
    this.m_Trans.ServerName = ""; // put TNS-service name here

LIST OF DEPARTMENTS
We want to allow the user to select a Department from the list and use the Department Number as a first argument to our procedure. For this purpose we can use either standard WinForms Combobox or a DataWindow with a single column and a DropDownDataWindow (dddw) presentation style.

The second solution is better, because it's simpler and allows you to avoid the hard coding of Oracle classes, which in turn provides an opportunity to create a program that supports different database vendors. However, this is not as obvious to .NET developers as it is to PowerBuilder ones, so we will populate Combo-box with the example in Listing 3.

SHOW LIST OF EMPLOYEES FOR THE CHOSEN DEPARTMENT
To get the data we need to connect to the database, retrieve data and disconnect at the end. The script to do this is shown in Listing 4.

RESULT
We can see the result of our application in Figure 1.

Conclusion
It is possible to create a stored procedure-based DataWindow for Oracle as easily as it is for other database vendors. Using Sybase DataWindow.NET 2.0, you can make it transparent for developers and hide Oracle-specific details from the client side, so the same application can be used to access several different DBMS from different vendors.

References

About Mikhail Klygin
Mikhail Klygin is a senior developer and has been using PowerBuilder since version 5.0.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

In DataWindow.NET 2.0, Sybase added support for access to Oracle through the Oracle managed data provider (ODP.NET). A managed data provider provides better performance and more support than a non-managed driver for database-specific functions, though not as much as the Oracle native driver.


Your Feedback
PBDJ News Desk wrote: In DataWindow.NET 2.0, Sybase added support for access to Oracle through the Oracle managed data provider (ODP.NET). A managed data provider provides better performance and more support than a non-managed driver for database-specific functions, though not as much as the Oracle native driver.
Enterprise Open Source Magazine Latest Stories . . .
With Cloud Expo 2012 New York (10th Cloud Expo) just four months away, what better time to start introducing you in greater detail to the distinguished individuals in our incredible Speaker Faculty for the technical and strategy sessions at the conference... We have technical and st...
AMD said late Tuesday that its chief sales officer Emilio Ghilardi had left the company and that CEO and president Rory Read is going to do his job while a replacement is sought. AMD didn’t say why Ghilardi left but it’s assumed Read wants his own people. Read is relatively new to th...
During the lifespan of M3 (Monitis Monitor Manager) there has always been something lacking – timers. M3 execution procedure was outlined in this previous article. The execution mentioned in the latter was a one-time-execution, whereas server monitoring requires periodic invocati...
Red Hat is putting its bought-in Gluster scale-out NAS storage technology, acquired in October, on the Amazon cloud. It’s styled Red Hat Virtual Storage Appliance for Amazon Web Services and other clouds are supposed to follow in short order.
A new episode of the screencast series is now available at the OpenNebula YouTube Channel. This screencast demonstrates the new easily-customizable self-service portal for cloud consumers. Its aim is to offer a simplified access to shared infrastructure for non-IT end users. The scree...
C12G Labs has just announced an update release of OpenNebulaPro, the enterprise edition of the OpenNebula Toolkit. OpenNebula 3.2, released two weeks ago, brings important benefits to cloud providers with a new easily-customizable self-service portal for cloud consumers, and builders w...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON Featured Whitepapers
ADS BY GOOGLE