Step 5: code your application to use the user object
What you have done so far
In the previous steps, you defined the GIVE_RAISE remote
stored procedure as an external function for the u_trans_database standard
class user object. You then specified u_trans_database as
the default global variable type for SQLCA.
These steps give your PowerBuilder application access to the properties
and functions encapsulated in the user object.
What you do now
You now need to write code that uses the user object to perform
the necessary processing.
In your application script, you can use PowerScript dot notation
to call the stored procedure functions you defined for the user
object, just as you do when using SQLCA for
all other PowerBuilder objects. The dot notation syntax is:
1 |
<span>object.function</span> ( <span>arguments</span> ) |
For example, you can call the GIVE_RAISE stored
procedure with code similar to the following:
1 |
SQLCA.give_raise(salary) |
To code your application to use the user object:
-
Open the object or control for which you
want to write a script. -
Select the event for which you want to write the
script.For instructions on using the Script view,
see the PowerBuilder Users Guide. -
Write code that uses the user object to do the
necessary processing for your application.Here is a simple code example that connects to an Oracle database,
calls the GIVE_RAISE stored procedure
to calculate the raise, displays a message box with the new salary,
and disconnects from the database:1// Set Transaction object connection properties.1SQLCA.DBMS="OR7"1SQLCA.LogID="scott"1SQLCA.LogPass="xxyyzz"1SQLCA.ServerName="@t:oracle:testdb"1SQLCA.DBParm="sqlcache=24,pbdbms=1"11// Connect to the Oracle database.1CONNECT USING SQLCA ;11// Check for errors.1IF SQLCA.sqlcode <> 0 THEN1      MessageBox ("Connect Error",SQLCA.SQLErrText)1      return1END IF11// Set 20,000 as the current salary.1DOUBLE val = 200001DOUBLE rv11// Call the GIVE_RAISE stored procedure to1// calculate the raise.1// Use dot notation to call the stored procedure1<span>rv = SQLCA.give_raise(val)</span>11// Display a message box with the new salary.1MessageBox("The new salary is",string(rv))11// Disconnect from the Oracle database.1DISCONNECT USING SQLCA; -
Compile the script to save your changes.
An actual script would include error checking after the CONNECT statement, DISCONNECT statement,
and call to the GIVE_RAISE procedure.
For details, see “Error handling after
a SQL statement”.