A QUICK TOUR OF POWERBUILDER
ENVIRONMENT
Assignment 2 - IFS 320 - Database Management Systems
Author: Dr. Vijay Raghavan
Objective:
CREATE A SIMPLE POWER BUILDER APPLICATION
PowerBuilder development
environment consists of many painters that can be accessed from a
toolbar. In this exercise, we will use some of these painters to
create different PB objects. Many of these toolbar buttons can
launch a particular painter which you can use to create or modify
a PB object. Thus, the application painter can create an
application object, window painter a window object and so on. As
you start each painter, you will see a painter bar in addition to
the main toolbar. These painterbars contain many painterbar
buttons that can be used to do things that are particular to this
painter.
Step 1: Create a library
Launch PB, go to the library
painter and create a .PBL (pronounced 'pebble') in your drive A.
Name the .PBL - myfirst. myfirst.pbl is simply a
DOS file that can hold many PowerBuilder objects.
Step 2: Create an application object
Create a new application named basic
using the application painter. When PB starts, it always connects
to the last used application. Start the application painter and
choose "NEW" from the FILE menu. 'SELECT NEW
APPLICATION LIBRARY" dialog displays. Choose myfirst.pbl as
the file name. Here you are specifying that your new application
object be saved in myfirst.pbl. SAVE APPLICATION AS dialog
displays, name your new application as basic. From the
EDIT,LIBRARY LIST menu item ensure that the application search
path is specified as myfrst.pbl.
GO TO TOP
Step 3: Create a Window
Create a window called w_first
using the window painter. Ensure you save this in myfirst.pbl.
Now, you myfirst.pbl has two objects: an application object, and
a window object. Objects and controls have events associated with
them. You can write powerscript programming language to write
scripts in various events. Place a command button called CLOSE
(When you type in the name, type &Close - this will make
Alt-C the shortcut key at run time) in this window and write the
script:
close (parent) |
in the clicked event of this
command button. The parent of this command button is the window
that contains it. Hence, this script simply means that you want
the window closed when you click on the CLOSE command button.
Step 4: Add a script to the application open event
Now, you can go to the
application open event and specify
Open (w_first) |
Step 5: Run the application
Run the application using the running man icon, and observe its behavior.
CONNECT TO A DATABASE AND
PERFORM A SIMPLE RETRIEVAL
The power of PB lies in its
ability to access relational databases. PowerBuilder provides a
special control, called datawindow control to perform this task.
The datawindow control is a container for datawindow object which
actually provides the link to databases. We first create a
datawindow object, then attach the datawindow object to a
datawindow control that is contained in a window.
Step 6: Create a datawindow
object
Using the datawindow painter,
you wil now create a new datawindow object. After you launch the
datawindow painter, you will asked to specify a datasource
and a presentation style. Select the datasource to
be SQL SELECT and the presentation style to be tabular.
Select a table from the SELECT TABLES dialog, click on the
columns that you want to view from this table (you can see the
SQL statements generated by clicking on the Syntax tab on the tab
folder at the bottom.) Go to the design mode and click on
"preview" painter bar button and ensure that the data
is properly retrieved. Save the datawindow as d_first. If you go
to your library painter, you will see that your application now
has three objects: basic, an application object; w_first,
a window object, and d_first, a datawindow object.
Step 7: Attach datawindow object to datawindow control
Open your window object by
double clicking on your library entry, and place a datawindow
control on this window. Although this appears in its default size
when you initially place it, you can grab the cornor or the sides
of the control to resize it within the window. Double click on
the datawindow control, Select DataWindow dialog appears.
Attach d_first to this datawindow control. After you attach, the
column headings of your datawindow object should be clearly
visible within the control. If not, you can again resize the
control appropriately (you would not see any data in the control
until you write few lines of code (referred to powerscripts by
PB,) and run the application.
Step 8: Add script in the application open event to connect to database
Type in the following code in
your application open event - before opening w_first:
SetPointer
(HourGlass!) sqlca.DBMS = ProfileString("example.ini","sqlca","dbms","") sqlca.database = ProfileString("example.ini","sqlca","database","") sqlca.userid = ProfileString("example.ini","sqlca","userid","") sqlca.dbpass = ProfileString("example.ini","sqlca","dbpass","") sqlca.logid = ProfileString("example.ini","sqlca","logid","") sqlca.logpass = ProfileString("example.ini","sqlca","logpass","") sqlca.servername = ProfileString("example.ini","sqlca","servername","") sqlca.dbparm = ProfileString("example.ini","sqlca","dbparm","") connect; if sqlca.sqlcode <> 0 then MessageBox ("Sorry! Cannot Connect to Database", sqlca.sqlerrtext) halt close return end if |
Step 9: Add script in the window open event to retrieve data
In the open event of w_first type in the script
dw_1.settransobject(SQLCA)
dw_1.retrieve() |
and run the application.
Please send your comments to: Raghavan
© Dr. Vijay V. Raghavan
BACK TO Table of contents
BACK TO DATABASE Main Page