Back

Tip 47. Dynamic Datawindow Function

This tip was send in by Jan Hink as a solution to one of the disadvantages of Using Datastores Instead of Cursors.

The function allows you to use a datastore without have a datawindow object. It makes use of the SQLFromSyntax function.

//---------------------------------------------------------------------------
//  Function Name : f_dynamic_ds
//     Parameters : ads_datastore
//			transaction atrans
//			string as_sqlsyntax
//			ref string as_error
//        Purpose : Dynamic Datastore function.
//        Returns : Success (-1/0) or Row count
//           Sets : None
//---------------------------------------------------------------------------

string	ls_dw_syntax, ls_presentation
long		ll_row_count

IF NOT IsValid(ads_datastore) OR as_sqlsyntax = "" THEN
	RETURN 0
END IF

ls_presentation = "style(type=Grid Horizontal_spread=10 Detail_top_margin=0 detail_bottom_margin=0 ) "
ls_presentation += "column(border=0 font.face='Arial' font.height=-8) " 
ls_presentation += "text(border=2 font.face='Arial' font.height=-9 font.weight=700 alignment=2)"

ls_dw_syntax = SyntaxFromSQL(atrans, as_sqlsyntax, ls_presentation, as_error)

IF as_error <> "" THEN
	atrans.sqlerrtext = as_sqlsyntax + "~r~n" + as_error
	RETURN -1
END IF

if ads_datastore.Create(ls_dw_syntax, as_error) < 0 THEN
	atrans.sqlerrtext = as_sqlsyntax + "~r~n" + as_error
	RETURN -1
END IF

ads_datastore.SetTransObject(atrans)
ll_row_count = ads_datastore.retrieve()

RETURN ll_row_count
See Also Use Datastores Instead of Cursors.
and A Datastore that Destroys Itself. which now includes object version of this function.

Added before 01 Jan 2000

Back