/////////////////////////////////////////////////////////////////////////////////////////
// Method : of_CountStar
// Author : PowerObject! (Shekar Reddy)
// Date : 12/26/2001
//////////////////////////////////////////////////////////////////////////////////////////
// Arg : dw
// Return : long
/////////////////////////////////////////////////////////////////////////////////////////
// Desc : Can be used for any dw to get the potential/pro-active rowcount QUICKLY!
// Usage : of_CountStar( ls_SQL )
// Ref : of_CountStar( dw )
//
/////////////////////////////////////////////////////////////////////////////////////////
// Modifications:
// Date Author Comments
// 4/27/3 PowerObject! Added n_cst_String.of_GlobalReplace() for removing ~" s
/////////////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////////////
// Get the row-count that is "going" to be retrieved
////////////////////////////////////////////////////
long ll_Count
n_cst_String lnv_String
/////////////////////////
//
IF IsNull( dw ) OR NOT IsValid( dw ) THEN
RETURN -1
ELSEIF Trim( dw.DataObject ) = "" THEN
RETURN -1
END IF
//
ls_SQL = Trim( String( This.Object.Datawindow.Table.Select ))
//
// Validate the SELECT-statement
IF IsNull( as_SQL ) OR as_SQL = "" THEN
RETURN -1
END IF
//
// Remove the ~" chars if SQLCA.dBParm was not set to "DelimitIdentifier='No'"
ls_SQL = lnv_String.of_GlobalReplace( ls_SQL, '~~"' , "" ) // They are actually ~" s
//
// Strip the SELECT clause
as_SQL = Mid( as_SQL, Pos( as_SQL, "FROM " ))
//
// Prepend the SELECT Count(*)
as_SQL = "SELECT COUNT(*) " + as_SQL
//
// Dynamic SQL
PREPARE SQLSA FROM :as_SQL USING SQLCA;
//
// Do some error-check here, if required...
IF SQLCA.SQLCode <> 0 THEN
RETURN -1
END IF
//
// Fetch the row-count for Progress-bar
DECLARE lc_Cursor DYNAMIC CURSOR FOR SQLSA;
OPEN DYNAMIC lc_Cursor;
// Do some error-check here if required...
//
FETCH lc_Cursor INTO :ll_Count;
// Do some error-check here if required...
//
CLOSE lc_Cursor; // Protected!
// Do some error-check here if required...
//
RETURN ( ll_Count )