AppContextRegisterEmbeddedFunction Method (String, String, String) |
Registers an embedded function for use in SQL statments. The function name should
not include
the leading lowercase 'fn' associated with embedded functions.
See EmbeddedParser for more information on embedded functions.
Embedded functions are automatically resolved for both DefaultValues on Field objects
and Filters on Mapper objects.
Normally, you register an extension to run at startup and register custom functions in the
ExtensionEvents.ApplicationAfterLoad event.
Namespace:
NetQuarry
Assembly:
EAP.Core (in EAP.Core.dll) Version: 2.0.0.0 (4.6.8.0)
Syntaxpublic void RegisterEmbeddedFunction(
string functionName,
string replacementValue,
string description
)
Public Sub RegisterEmbeddedFunction (
functionName As String,
replacementValue As String,
description As String
)
Parameters
- functionName
- Type: SystemString
The name of the function. The name should not include the leading 'fn.' - replacementValue
- Type: SystemString
The replacement value. - description
- Type: SystemString
The description of the function.
Implements
IAppContextRegisterEmbeddedFunction(String, String, String)
ExamplesThe following example extension event handler registers several functions loaded based on the user ID set during authentication.
public override void AfterLoad(IAppContext sender, EAPEventArgs e)
{
string dealerID = iLuxCars.Common.EmailHelper.GetUserDealerID(sender);
IDatabase db = sender.Databases["DealerTrac"];
if (db != null)
{
using (IDataReader dr = db.OpenDataReader("SELECT dealer_id, dealership_id, dealership_nm FROM dealer_user_dealership_view WHERE user_id = !fnUserID$()"))
{
if (dr.Read())
{
db.RegisterEmbeddedFunction("DealerID", dr.GetValue(0).ToString());
db.RegisterEmbeddedFunction("DealershipID", dr.GetValue(1).ToString());
db.RegisterEmbeddedFunction("DealershipName", dr.GetValue(2).ToString());
}
dr.Close();
}
}
You can then use these functions as a
Field.DefaultValue" by adding '!fn' to the beginning of the function
name. For example:
!fnDealerID(). To use an embedded function in a SQL filter you can specify that the result
be quoted for use in an ANSI SQL statement by appending a '$' sign to the name of the function:
dealer_id = !fnDealerID$().
See Also