From the documentation available in the programming editor (right-click menu, select "List Browser", starting typing the name of the command you are interested in.):
@XResultSetRunProgram(rs as int, global_program as string, program as string, test_only as int) as string
This command runs an SBasic program, specified as a string argument, on every record in a result set. It returns as a string any content written using Write or WriteLn.
The programming is sent to the engine to be executed. Because it runs on the engine, the programming must use field names instead of element names. No commands that reference the user interface, forms, or reports are legal in the supplied program. For security, the File I/O commands, Shell commands and Process commands are disabled by default. These can be optionally allowed using the SERVER CODE FILE I/O and SERVER CODE SHELL INI file entries, but you should consider carefully before doing so.
NOTE: Because this method of working with a group of records works directly on the engine, it is much faster than a normal mass update, but it also is able to provide less feedback. You should always test this command using a backup of your data to make sure that is doing what you intend.
Arguments: rs - Handle to a result set
global_program - Programming that you would type into the GLOBAL CODE area
program - Programming to run on each record in the result set
test_only - Flag indicating whether to actually run the program. 0 runs the program. 1 tests whether the program compiles without running it.
As the program compiles on the engine, the syntax error interface available in the Programming Editor is not available, however, @Error will be set if the program fails to compile. To test your program, set test_only to 1 and check @Error.
For easier assembly of the program to be run into a string, you can write it using single quotes or another unlikely "placeholder" character where double quotes would normally appear. You can then use @Replace to replace the placeholder with double quotes. The example below sets Company to "No company name provided" on any record where Company is blank.
#include "sbasic_include.sbas"
var key as int var pgm as string var str as string
// Use single quotes to for strings internal to the program string pgm = "XCompany = 'No company name provided'"
// and replace them with double quotes pgm = @Replace(pgm, "'", @Chr(34))
key = @XResultSetSearch(@FN, "Customers", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Company==") if(key > -1) { str = @XResultSetRunProgram(key, "", pgm, 0) If @Error { WriteLn("Program failed to compile.") } XResultSetClose(key) }
|