Wednesday, October 20, 2010

Powerbuilder Pipeline

Another feature in Powerbuilder programming is Pipeline.
According to manual help of Powerbuilder, a Pipeline system object is used to manage a data pipeline during execution.

You use a Pipeline object by defining a standard class user object inherited from the built-in Pipeline object in the User Object painter. You can then access the Pipeline events by writing scripts that contain code for the events.


Now I will show you how to execute pipeline by writing the script.

The scenario of this case is you want to pipeline a table from one database to another database. So, first you need at least 2 transaction objects, which mean we must declare first in the top of the script. Since we have a default database connection SQLCA, we only have declare another new transaction object called SQLCAtarget, which represent for the target database connection. Remember, in this case, SQLCA will be the source of database connection

1:  transaction SQLCAtarget // declare this variable as INSTANT variable  
2:    
3:  SQLCA.DBMS = 'your source dbms name'  
4:  SQLCA.Database = 'your source database name'  
5:  SQLCA.LogId = 'your source database login id'  
6:  SQLCA.LogPass = 'your source database password'  
7:  SQLCA.ServerName = 'your source database server'  
8:    
9:  CONNECT USING SQLCA;  
10:    
11:    
12:  SQLCAtarget = CREATE transaction  
13:  SQLCAtarget.DBMS = 'your target dbms name'  
14:  SQLCAtarget.Database = 'your target database login id'  
15:  SQLCAtarget.LogPass = 'your target database password'  
16:  SQLCAtarget.ServerName = 'your target database server'  
17:  SQLCAtarget.LogId = 'your target database login id'  
18:    
19:  CONNECT USING SQLCAtarget;  


Next step, you need to build pipeline object by clicking Pipeline painter in main toolbar. Remember, use MAIN TOOLBAR, if you want to pipeline the data to ANOTHER DATABASE.
Setup your source database and the target database profile, chooce the table(s), column(s) and criteria(s), then save as pl_mypipeline.



Choose source and target of Pipeline

Set the table, column and criteria of your pipeline


save your pipeline


Create a window, then put 1 datawindow object and 1 button object. You don't need to put dataobject for the datawindow, just keep it blank. And put the script below at clicked event in button object.

1:  integer iReturn  
2:  pipeline myPipeline  
3:  myPipeline = CREATE pipeline  
4:    
5:  myPipeline.DataObject = "pl_mypipeline"  
6:  iReturn = myPipeline.Start(SQLCA, SQLCAtarget, dw_1)  
7:    
8:  // always disconnect your database connection  
9:  DISCONNECT USING SQLCA;  
10: DISCONNECT USING SQLCAtarget;  


iReturn should be has 0 (zero) value if the pipeline run smoothly.

No comments:

Post a Comment