SalCompileAndEvaluate
SalCompileAndEvaluate uses the interpreter built in the PPJ Framework. Which is the same one used to evaluate bind/into variables in embedded SQL statements.
The preferred parser (default) supports C# syntax. However, it is possible to plug in a custom parser and support any syntax, including SAL.
See Custom Parsers for more information on how to plug in your own parser.
Syntax
By default, the PPJ Framework supports the C# language. If the expressions being evaluated by SalCompileAndEvaluate() are simple function calls or variables access, the execution of the expression shouldn't impose any problem.
However, if the expression being evaluated contains operators that are incompatible with C# you will get a syntax error. See the following table to see the most common operators that need to be replaced.
String Concatenation
||
+
Logical And
AND
&&
Logical Or
OR
||
Equality Comparison
=
==
There is an important difference when using SalCompileAndEvaluate: by default inline assignments are disabled to avoid assigning values to a variable when the intention of the expression was to compare the value for equality.
For example, in Team Developer the expression "If nValue = 10" means that the value of nValue should be compared to 10 and the result of the comparison is the result of the expression. However, in C# the single "=" operator is an assignment operator, so the expression above means that 10 should be assigned to nValue and then returned as the result of the expression.
For this reason, when executing expression with the "=" operator but not preceded by a Set keyword, SalCompileAndEvaluate() returns an error for the illegal assignment. The expression should be changed to "If nValue == 10" using the "==" equality operator.
You can enable inline assignments by setting a static property on the ScriptEngine type:
PPJ.Runtime.Script.ScriptEngine.AllowInlineAssignments = true;
Full Script
In Team Developer it was possible to only execute one statement at a time. Using the script engine in the PPJ Framework you can now execute entire scripts using the full C# language.
To run a script you need to enclose the script in a block, as shown in the example below:
Scope
SalCompileAndEvaluate() uses the same scope resolution rules used by the Sql module in the PPJ Framework. Basically, local variables are never accessible. All globals, instance and static members are always visible. Local variables can be used in scripts only if they have been extracted into the SqlLocals inner class.
Last updated