Listing 1: u_ds_functions.get_delete()
/* Boolean get_delete( datastore the_ds, long the_row,
string the_column, ref string the_item )
This returns the value from the Delete! buffer
*/
Boolean lb_failed
// Call the "real" function, specifying the Delete! buffer
lb_failed = get_item_main( the_ds, the_row, the_column ,
true, Delete!, false, false, the_item )
return lb_failed
Listing 2: u_ds_functions.get_item_main()
/** private function Boolean get_item_main( datastore
the_ds, long the_row, string the_column,
Boolean the_null_is_ok_flag, dwbuffer the_buffer,
Boolean the_original_value, Boolean the_display_value,
ref string the_item )
Parameters:
datastore the_ds -- To get the_item from
long the_row -- For the GetItemX()
string the_column -- For the GetItemX()
Boolean the_null_is_ok_flag -- If FALSE,
then a NULL generates a failure
dwbuffer the_buffer -- Primary!, Filter!, or Delete!
Boolean the_original_value -- If TRUE,
return the original value
Boolean the_display_value -- If TRUE,
return the display value
ref string the_item --
This is what gets returned!
The_null_is_ok_flag is not yet applied.
Returns: Boolean, TRUE on failure, FALSE on success
Usage:
This function is called by the vanilla "get_xxx()"
functions, e.g. get_item()
and get_delete(). You do NOT want to call it
directly, esp. because we
reserve the right to change it. It's private anyway!
**/
Boolean lb_failed = true string ls_column_type
do // Once
// Get the lookup display?
if the_display_value then
// This works for all types...
a display value is always a string, kinda
the_item = describe( the_ds,
"evaluate( 'LookUpDisplay( " + the_column + " )',
" + string( the_row ) + " )" )
else
// What (data) type is the_column?
if get_column_type( the_ds, the_column,
ls_column_type ) then exit // Failed
// Get the data!
choose case ls_column_type
case "?", "!"
g.bug( "The column " + upper(
the_column ) + " is not valid." )
exit
case "date"
the_item = string
( the_ds.GetItemDate
( the_row, the_column, the_buffer,
the_original_value ), "YYYY-MM-DD" )
case "datetime"
the_item = string( the_ds.GetItemDateTime
( the_row, the_column, the_buffer, the_original_value )
, "YYYY-MM-DD HH:MM:SS" )
case "decimal"
the_item = string( the_ds.GetItemDecimal
( the_row, the_column, the_buffer,
the_original_value ) )
case "number"
the_item = string( the_ds.GetItemNumber
the_row, the_column, the_buffer,
the_original_value ) )
case "string"
the_item = the_ds.GetItemString
( the_row, the_column, the_buffer,
the_original_value )
case "time"
the_item = string( the_ds.GetItemTime
( the_row, the_column, the_buffer, the_original_value ) )
case else
g.bug( "Unexpected type: " + ls_column_type )
exit
end choose
end if
// It worked!
lb_failed = FALSE
loop until true // End of 'do once'
return lb_failed
Listing 3: f_create_overloaded_dw_and_dwc_objects()
/** Boolean f_create_overloaded_dw_and_dwc_objects( void )
This function creates dw_functions and dwc_functions from ds_functions.
Parameters: None
Returns: Boolean, TRUE on failure, FALSE on success
Usage:
Just call it:
f_create_overloaded_dw_and_dwc_objects()
**/
Boolean lb_failed = true string ls_source, ls_pbl,
ls_comment, ls_type
do // Once
// Where is the ds_functions object?
if f_get_library_object_from_stash
( "u_ds_functions", ls_pbl, ls_comment, ls_type )
then exit // Failed
// Export the ds_functions source
ls_source = LibraryExport( ls_pbl, "u_ds_functions",
ExportUserObject! )
if not f_is_string( ls_source ) then; g.bug
( "Failed to get the source" ); exit; end if
/// DataWINDOW
// Fix the source for U_DW_FUNCTIONS
ls_source = f_substr( ls_source, "ds_functions", "dw_func
tions" )
ls_source = f_substr( ls_source, "datastore", "datawindow" )
ls_source = f_substr( ls_source, "the_ds", "the_dw" )
ls_source = f_substr( ls_source, "from u_base_nuo", "from
ds_functions" )
// Fix the comment
ls_comment = "DO NOT MODIFY - U_DS_FUNCTIONS
transmogrified to apply to DATAWINDOWs (instead of dataSTORES) "
// Write it out for manual import
f_empty_out_file( "u_dw_functions.sru" )
f_write2file( "u_dw_functions.sru",
"$PBExportHeader$u_dw_functions.sru" )
f_write2file( "u_dw_functions.sru",
"$PBExportComments$" + ls_comment )
f_write2file( "u_dw_functions.sru", ls_source )
f_printf( "Source written to u_dw_functions.sru" )
/// DataWindowCHILD
// Fix the source for U_DWC_FUNCTIONS (the "C" is new)
ls_source = f_substr( ls_source, "dw_functions",
"dwc_functions" )
ls_source = f_substr( ls_source, "datawindow",
"datawindowchild" )
ls_source = f_substr( ls_source, "the_dw", "the_dwc" )
ls_source = f_substr( ls_source, "from ds_functions",
"from dw_functions" )
ls_source = f_substr( ls_source, ' on DataObject " +
upper( the_dwc.DataObject )', '"' )
ls_source = f_substr( ls_source, '+ " on DataObject "
+ upper( the_dwc.DataObject )', "" )
// Fix the comment
ls_comment = "DO NOT MODIFY - U_DS_FUNCTIONS
transmogrified to apply to datawindowCHILDs (instead of
dataSTORES or dataWINDOWS) "
// Write it out for manual import
f_empty_out_file( "u_dwc_functions.sru" )
f_write2file( "u_dwc_functions.sru",
"$PBExportHeader$u_dwc_functions.sru" )
f_write2file( "u_dwc_functions.sru",
"$PBExportComments$" + ls_comment )
f_write2file( "u_dwc_functions.sru",
ls_source )
f_printf( "Source written to u_dwc_functions.sru" )
// Notify user
f_msg_box( "Import Source Manually", &
"The files 'u_dw_functions.sru' and 'u_dwc_functions.sru' " + &
"have been written out and need to be imported." )
// It worked!
lb_failed = FALSE
loop until true // End of 'do once'
return lb_failed
Listing 4: DateTime()
/* DateTime datetime( string the_datetime_string )
This is a simple-minded function that assumes that the_
datetime_string contains
a space, with a date to the left of the space, and
a time to the right. If there
is NOT a space, then the string is treated as a date,
which is equivalent to
assuming that the time is 00:00:00.
Usage:
DateTime ldtm_datetime
string ls_date_string
// This conversion inserts the space
ls_date_string = string( today(), 'YYYY-MM-DD' )
+ " " + string( now() )
// This converts it back
ldtm_datetime = datetime( ls_date_string )
if date( ldtm_datetime ) = 1900-01-01 then return // Failed
The DateTime( string ) conversion is subject to short date problems.
To avoid them, specify
the short-date-proof YYYY-MM-DD format, as shown above.
*/
date ldt_date
long ll_pos
time ltm_time
// If there's a space, parse the piece to its left
ll_pos = pos( the_datetime_string, " " )
if ll_pos > 0 then
ldt_date = date( left( the_datetime_string, ll_pos - 1 ) )
ltm_time = time (mid( the_datetime_string, ll_pos + 1 ) )
else // Take the whole thing
ldt_date = date( the_datetime_string )
ltm_time = 00:00:00
end if
the_datetime = DateTime( ldt_date, ltm_time )
return the_datetime // Success