Thursday, 20 April 2017

Display Datawindow Column Names

Use the following code to Get the all column names on the Datawindow.

string ls_colname, ls_colvariable
int li, li_count

li_count = integer(dw_st1.describe('DataWindow.Column.Count'))

FOR li = 1 TO li_count
  ls_colvariable = '#'+string(li)+'.name'
  ls_colname = dw_st1.describe(ls_colvariable)
  Messagebox ('Column Names', + ls_colname)
NEXT


Disable the Triggers Temporarly In Sybase


On SQL Query editor write and execute the following code to Disable the Trigger

SET TEMPORARY OPTION FIRE_TRIGGERS = OFF;

Now do all your INSERT/UPDATE/DELETE HERE that will not fire tiggers




After your work is completed execute the following code to Enable the triggrers.

SET TEMPORARY OPTION FIRE_TRIGGERS = ON;


Search for a Text in Sybase and SQL Server Database

SQL Server Code:

select
S.name as [Schema],
o.name as [Object] ,
o.type_desc as [Object_Type],
C.text as [Object_Definition]
from sys.all_objects O inner join sys.schemas S on O.schema_id = S.schema_id
inner join sys.syscomments C on O.object_id = C.id
where S.schema_id not in (3,4) -- avoid searching in sys and INFORMATION_SCHEMA schemas
and C.text like '%%'
order by [Schema]


Sybase Code:

Select distinct sysobjects.name
, case
 when sysobjects.type = 'TR' then 'TRIGGER'
 when sysobjects.type = 'P' then 'PROCEDURE'
 when sysobjects.type = 'V' then 'VIEW'
 else 'UNKNOWN' end type
from sysobjects inner join syscomments
on sysobjects.id = syscomments.id
where syscomments.text like '%tbl_books%'


Datawindow Blinking Color Text

You will need to set the timer inteval of the datawindow to something, You can find the timer by double clicking on any blank part of the datawindow.

Next place a text field on the datawindow and In the visible section place this code:

if( mod( Integer( Mid( String( Now() ), 7, 2 ) ),2 ) =1,0,1)

Also possible to change colours by using color attribute:

if( mod( Integer( Mid( String( Now() ), 7, 2 ) ),2 ) =1,0,255)


Create Visual Objects Dynamically in PowerBuilder

Yes, We can create and open that Visual User Objects in PowerBuilder at run time. in the following example we are going to see how to create a Picture control at runtime and assigning the image for that Picture Control also.

Code:

 picture p_2 // declare the picture variable 
 p_2 = create picture // create the picture object 
  
 p_2.x = 100 // x position of the object 
 p_2.y = 100 // y position of the object 
 p_2.height = 350 // height value of the object 
 p_2.width = 450 // with value of the object 
 p_2.picturename = "D:\raj\profile.jpg" // name of the picture inc full path 

parent.openuserobject( p_2, "p_2", 100, 100) // ok, let's create the object


PowerBuilder 10.5 AnimateWindow Code.

Decalre the External Function:
Function boolean AnimateWindow( &
   long lhWnd, long lTm, long lFlags ) library 'user32'

The first parameter is the handle to your window,
the second is the time taken for the animation (larger values take longer),
the last parameter is the animation type.

To call the function add the following code to the open event of your about window:

// Animate the window from left to right
Constant Long AW_HOR_POSITIVE = 1
// Animate the window from right to left
Constant Long AW_HOR_NEGATIVE = 2
// Animate the window from top to bottom
Constant Long AW_VER_POSITIVE = 4
// Animate the window from bottom to
Constant Long AW_VER_NEGATIVE = 8
// Makes the window appear to collapse inward
Constant Long AW_CENTER = 16
// Hides the window
Constant Long AW_HIDE = 65536
// Activates the window
Constant Long AW_ACTIVATE = 131072
// Uses slide animation
Constant Long AW_SLIDE = 262144
// Uses a fade effect
Constant Long AW_BLEND = 524288

AnimateWindow( Handle( this ), 500, AW_VER_NEGATIVE )

How do I get the output parameters back from the server if my stored procedure is also returning a resultset?

There are a couple of different ways to get the RESULTSET and OUTPUT parameter from a stored procedure.

Code Sample 1: DECLARE, EXECUTE and FETCH ResultSet and Output parameters:

The first is to declare, execute and fetch the resultset and then when the sqlcode = 100 get out of loop and fetch the procedure a second time.  The code would look like this:

//declare local variable
LONG l_parm1
LONG l_out_parm

STRING s_message

CONNECT USING SQLCA;

//Initialize the input parameter - this could be hard coded.
l_parm1 = 35

DECLARE testproc PROCEDURE FOR dbo.testproc @Parm1 = :l_parm1, @OutParm = :l_out_parm OUTPUT USING SQLCA;

EXECUTE testproc;
//First, fetch the RESULTSET
do while sqlca.sqlcode = 0
FETCH testproc INTO :s_message;
if sqlca.sqlcode = 0 then
MessageBox( "s_message", s_message)
end if

loop
//Now fetch the OUTPUT PARM
FETCH testproc INTO :l_out_parm;
MessageBox( "l_out_parm", String(l_out_parm))
CLOSE testproc;
DISCONNECT USING SQLCA;

The second way this can be accomplished is by using the RPC method.  This is discussed in the "Application Techniques" manual.

Code sample 2: Dynamic SQL Format 4 declaring a stored procedure

The sample in our help file illustrates ways to use format 4 using a declared cursor.  This script uses Format 4 embedded SQL statements and a declared stored procedure. This example assumes you know that there will be only one output descriptor and that it will be an integer. You can expand this example to support any number of output descriptors and any data type by wrapping the CHOOSE CASE statement in a loop and expanding the CASE statements.

string ls_procname, ls_sql, ls_Temp
int li_job_id, li_Ctr, li_Temp
int li_rtn

li_job_id = dw_emp.getitemNumber(1, "job_id")
setNull(li_job_id)

ls_procname = 'pr_405237'
ls_sql = 'execute ' + ls_procname + ' @job_id=' + '?'

PREPARE SQLSA FROM :ls_sql using sqlca;
DESCRIBE SQLSA INTO SQLDA ;

DECLARE my_procudure DYNAMIC PROCEDURE FOR SQLSA ;
li_rtn = SQLDA.SetDynamicParm(1, li_job_id)
sle_1.Text = String(li_rtn)
EXECUTE DYNAMIC my_procudure USING DESCRIPTOR SQLDA ;
FETCH my_procudure USING DESCRIPTOR SQLDA ;
If Sqlca.Sqlcode <> 0 then
    Messagebox("Error ", String(Sqlca.Sqlcode) + sqlca.sqlerrtext)
 else
       for li_Ctr = 1 to sqlda.NumOutputs
          CHOOSE CASE SQLDA.OutParmType[li_Ctr]
            CASE TypeString!
              ls_Temp = GetDynamicString(SQLDA, li_Ctr)
            CASE TypeInteger!
              li_Temp = GetDynamicNumber(SQLDA, li_Ctr)
          END CHOOSE
       next
  end if

CLOSE my_procedure ;

----------------------------------------------------------------------
Et Voila
Pushparaj