private void AddMiscFunctions() { Register(config => config.Named("iif") .WithBooleanParameter("condition") .WithDynamicParameter("ifTrue") .WithDynamicParameter("ifFalse") .WhenExecute(context => SystemFunctions.Iif(context)) .ReturnsType(IifReturnType)); Register(config => config.Named("i_frule_convert") .WithDynamicParameter("rule") .WhenExecute(context => Simple(context, args => SystemFunctions.FRuleConvert(args[0]))) .ReturnsType(context => { var argType = ReturnType(context.Arguments[0], context); return(argType is StringType ? (SqlType)PrimitiveTypes.Numeric() : (SqlType)PrimitiveTypes.String()); })); }
private void MiscFunctions() { Register(config => config.Named("iif") .WithBooleanParameter("condition") .WithDynamicParameter("ifTrue") .WithDynamicParameter("ifFalse") .WhenExecute(context => Simple(context, args => { Field result = Field.Null(); var condition = args[0]; if (condition.Type is BooleanType) { if (condition.Equals(Field.BooleanTrue)) { result = args[1]; } else if (condition.Equals(Field.BooleanFalse)) { result = args[2]; } } return(result); })) .ReturnsType(IifReturnType)); Register(config => config.Named("i_frule_convert") .WithDynamicParameter("rule") .WhenExecute(context => Simple(context, args => SystemFunctions.FRuleConvert(args[0]))) .ReturnsType(context => { var argType = ReturnType(context.Arguments[0].Value, context); return(argType is StringType ? PrimitiveTypes.Numeric() : (SqlType)PrimitiveTypes.String()); })); Register(config => config.Named("i_privilege_string") .WithNumericParameter("privBit") .WhenExecute(context => Simple(context, args => SystemFunctions.PrivilegeString(args[0]))) .ReturnsString()); // VERSION Register(config => config .Named("version") .WhenExecute(context => context.Result(Field.String(context.Request.Query.Session.Database().Version.ToString(3)))) .ReturnsString()); // COALESCE Register(config => config.Named("coalesce") .WhenExecute(context => Simple(context, args => { var argc = args.Length; for (int i = 0; i < argc; i++) { var arg = args[i]; if (!Field.IsNullField(arg)) { return(arg); } } return(Field.Null()); })) .ReturnsType(context => { var argc = context.Arguments.Length; for (int i = 0; i < argc; i++) { var returnType = context.Arguments[i].Value.ReturnType(context.Request, context.VariableResolver); if (!(returnType is NullType)) { return(returnType); } } return(PrimitiveTypes.Null()); })); // object instantiation Register(config => config.Named("new_object") .WithStringParameter("typeName") .WithUnoundedParameter("args", Function.DynamicType) .WhenExecute(context => { var typeName = context.EvaluatedArguments[0]; var argc = context.ArgumentCount; var args = new Field[argc - 1]; if (argc > 1) { Array.Copy(context.EvaluatedArguments, 1, args, 0, args.Length); } var obj = SystemFunctions.NewObject(context.Request, typeName, args); return(context.Result(obj)); }).ReturnsType(context => { var typeName = context.EvaluatedArguments[0].Value.ToString(); return(context.Request.Access().ResolveUserType(typeName)); })); }