Performing some final housekeeping
When your application has finished processing pipelines, you
need to make sure it takes care of a few cleanup chores. These chores
basically involve releasing the resources you obtained at the beginning
to support pipeline execution.
Garbage collection You should avoid using the DESTROY statement to clean up resources
unless you are sure that the objects you are destroying are not
used elsewhere. PowerBuilder’s garbage collection mechanism
automatically removes unreferenced objects.
For more information, see “Garbage collection”.
To clean up when you’ve finished using
pipelines:
-
Destroy the instance that you created of
your supporting user object.To do this, code the DESTROY statement in an appropriate script
and specify the name of the variable that contains that user-object
instance. -
Disconnect from the pipeline’s source
and destination databases.To do this, code two DISCONNECT statements in an appropriate
script. In one, specify the name of the variable that contains your
source transaction-object instance. In the other, specify the name
of the variable that contains your destination transaction-object
instance.Then test the result of each DISCONNECT statement.
-
Destroy your source transaction-object instance
and your destination transaction-object instance.To do this, code two DESTROY statements in an appropriate
script. In one, specify the name of the variable that contains your
source transaction-object instance. In the other, specify the name
of the variable that contains your destination transaction-object
instance.
For more information on coding the DESTROY
and DISCONNECT statements, see the PowerScript Reference
.
Example
The following code in the Close event of the w_sales_extract
window takes care of these cleanup chores.
Destroying the user-object instance At the beginning of the Close event script, code the following
statement to destroy the instance of the user object u_sales_pipe_logistics
(which is stored in the iuo_pipe_logistics variable):
1 |
DESTROY iuo_pipe_logistics |
Disconnecting from the source database Next, code these statements to disconnect from the source
database, test the result of the disconnection, and destroy the
source transaction-object instance (which is stored in the itrans_source
variable):
1 |
DISCONNECT USING itrans_source; |
1 |
1 |
// Check result of DISCONNECT statement. |
1 |
IF itrans_source.SQLCode = -1 THEN |
1 |
Beep (1) |
1 |
MessageBox("Database Connection Error", & |
1 |
"Problem when disconnecting from the source " & |
1 |
+ "database. Please call technical support. " & |
1 |
+ "~n~r~n~rDetails follow: " + & |
1 |
String(itrans_source.SQLDBCode) + " " + & |
1 |
itrans_source.SQLErrText, Exclamation!) |
1 |
END IF |
1 |
1 |
DESTROY itrans_source |
Disconnecting from the destination database Finally, code these statements to disconnect from the destination
database, test the result of the disconnection, and destroy their
destination transaction-object instance (which is stored in the
itrans_destination variable):
1 |
DISCONNECT USING itrans_destination; |
1 |
1 |
// Check result of DISCONNECT statement. |
1 |
IF itrans_destination.SQLCode = -1 THEN |
1 |
Beep (1) |
1 |
MessageBox("Database Connection Error", & |
1 |
"Problem when disconnecting from " + & |
1 |
"the destination (Sales) database. " + & |
1 |
"Please call technical support." + & |
1 |
"~n~r~n~rDetails follow: " + & |
1 |
String(itrans_destination.SQLDBCode) + " " + & |
1 |
itrans_destination.SQLErrText, Exclamation!) |
1 |
END IF |
1 |
1 |
DESTROY itrans_destination |
A collection of techniques you can use to implement program
access features in the applications you develop with PowerBuilder.
Includes using DDE in an application, using OLE in an application,
building a mail-enabled application, and adding other processing
extensions.