combit List & Label 24 - .NET Online Web Help
TranslateFilterSyntax Method


combit.ListLabel24.DataProviders Namespace > IAdvancedFiltering Interface : TranslateFilterSyntax Method

Describes the currently given arguments.

Name to be translated. If part is e.g. LlExpressionPart.Text, this object contains an index and can be set to a string to use as parameter name instead. The value of the parameter is then passed to the ApplyAdvancedFilter Method later.

If parameter part equals LlExpressionPart.RelationEqual, the name might be "@ARG:MULTIVALUE". In this case, the right hand side arguments[1] contains a comma separated list of values to compare to arguments[0].

If the parameter part is LlExpressionPart.Function, the parameter can also be an empty string. In this case, you return the translation for a compound expression (see example below).

Number of arguments that are not null.

The parts of a formula which should be translated.

This method is called whenever a part of a filter expression should be translated.
Syntax
'Declaration
 
Function TranslateFilterSyntax( _
   ByVal part As LlExpressionPart, _
   ByRef name As Object, _
   ByVal argumentCount As Integer, _
   ByVal arguments() As Object _
) As Object

Parameters

part

Describes the currently given arguments.

name

Name to be translated. If part is e.g. LlExpressionPart.Text, this object contains an index and can be set to a string to use as parameter name instead. The value of the parameter is then passed to the ApplyAdvancedFilter Method later.

If parameter part equals LlExpressionPart.RelationEqual, the name might be "@ARG:MULTIVALUE". In this case, the right hand side arguments[1] contains a comma separated list of values to compare to arguments[0].

If the parameter part is LlExpressionPart.Function, the parameter can also be an empty string. In this case, you return the translation for a compound expression (see example below).

argumentCount

Number of arguments that are not null.

arguments

The parts of a formula which should be translated.

Return Value

The translated expression or null if no translation is possible.

Example

This snippet is part of the implementation in the DbCommandSetDataProvider and shows how to work with parameter names:

public object TranslateFilterSyntax(LlExpressionPart part, ref object name, int argumentCount, object[] arguments)
{
    switch (part)
    {
        case LlExpressionPart.Text:
            {
                if (arguments[0] != null)
                {
                    name = String.Format(_commandSet.ParameterFormatMap[_dbCommand.Connection.GetType()], String.Format("LLAdvancedFilterKeyVal{0}", (int)name));
                    return arguments[0];
                }
                else
                {
                    return "NULL";
                }
            }
        default:
            return null;
    }
}
 

This snippet is the implementation of this method for the AdoDataProvider:

public object TranslateFilterSyntax(LlExpressionPart part, ref object name, int argumentCount, object[] arguments)
{
    switch (part)
    {
        case LlExpressionPart.Unknown:
            {
                return null;
            }
        case LlExpressionPart.Boolean:
            {
                if (arguments[0] != null)
                {
                    return ((bool)arguments[0] ? "true" : "false");
                }
                else
                {
                    return "null";
                }
            }
        case LlExpressionPart.Text:
            {
                if (arguments[0] != null)
                {
                    return String.Format("'{0}'", arguments[0]);
                }
                else
                {
                    return "null";
                }
            }
        case LlExpressionPart.Number:
            {
                if (arguments[0] != null)
                {
                    return arguments[0].ToString();
                }
                else
                {
                    return "null";
                }
            }
        case LlExpressionPart.Date:
            {
                if (arguments[0] != null)
                {
                    return String.Format("#{0}#", ((DateTime)arguments[0]).ToString(CultureInfo.InvariantCulture));
                }
                else
                {
                    return "null";
                }
            }
        case LlExpressionPart.UnaryOperatorSign:
            {
                return (String.Format("(-({0}))", arguments[0]));
            }
        case LlExpressionPart.UnaryOperatorNegation:
            {
                return (String.Format("(NOT ({0}))", arguments[0]));
            }
        case LlExpressionPart.BinaryOperatorAdd:
            {
                return (String.Format("({0}+{1})", arguments[0], arguments[1]));
            }
        case LlExpressionPart.BinaryOperatorSubstract:
            {
                return (String.Format("({0}-{1})", arguments[0], arguments[1]));
            }
        case LlExpressionPart.BinaryOperatorMultiply:
            {
                return (String.Format("({0}*{1})", arguments[0], arguments[1]));
            }
        case LlExpressionPart.BinaryOperatorDivide:
            {
                return (String.Format("({0}/{1})", arguments[0], arguments[1]));
            }
        case LlExpressionPart.BinaryOperatorModulo:
            {
                return (String.Format("({0}%{1})", arguments[0], arguments[1]));
            }
        case LlExpressionPart.RelationXor:
            {
                return (String.Format("(({0} AND NOT {1}) OR (NOT {0} AND {1}))", arguments[0], arguments[1]));
            }
        case LlExpressionPart.RelationOr:
            {
                return (String.Format("({0} OR {1})", arguments[0], arguments[1]));
            }
        case LlExpressionPart.RelationAnd:
            {
                return (String.Format("({0} AND {1})", arguments[0], arguments[1]));
            }
        case LlExpressionPart.RelationEqual:
            {
                if (!name.ToString().Equals("@ARG:MULTIVALUE", StringComparison.InvariantCultureIgnoreCase))
                {
                    return (String.Format("({0} = {1})", arguments[0], arguments[1]));
                }
                else
                {
                    return (String.Format("({0} IN ({1}))", arguments[0], arguments[1]));
                }
            }
        case LlExpressionPart.RelationNotEqual:
            {
                if (!name.ToString().Equals("@ARG:MULTIVALUE", StringComparison.InvariantCultureIgnoreCase))
                {
                    return (String.Format("({0} <> {1})", arguments[0], arguments[1]));
                }
                else
                {
                    return (String.Format("(NOT {0} IN ({1}))", arguments[0], arguments[1]));
                }
            }
        case LlExpressionPart.RelationLarger:
            {
                return (String.Format("({0} > {1})", arguments[0], arguments[1]));
            }
        case LlExpressionPart.RelationLargerEqual:
            {
                return (String.Format("({0} >= {1})", arguments[0], arguments[1]));
            }
        case LlExpressionPart.RelationSmaller:
            {
                return (String.Format("({0} < {1})", arguments[0], arguments[1]));
            }
        case LlExpressionPart.RelationSmallerEqual:
            {
                return (String.Format("({0} <= {1})", arguments[0], arguments[1]));
            }
        case LlExpressionPart.Function:
            {
                switch (name.ToString().ToUpper())
                {
                    case "":
                        return (String.Format("({0})", arguments[0]));
                    case "ISNULL":
                        return (String.Format("(ISNULL({0}))", arguments[0]));
                    case "STARTSWITH":
                        return (String.Format("({0} LIKE '{1}%')", arguments[0], EscapeArgumentForRowFilter(arguments[1].ToString())));
                    case "ENDSWITH":
                        return (String.Format("({0} LIKE '%{1}')", arguments[0], EscapeArgumentForRowFilter(arguments[1].ToString())));
                    case "CONTAINS":
                        return (String.Format("({0} LIKE '{1}')", arguments[0], EscapeArgumentForRowFilter(arguments[1].ToString())));
                    case "MID$":
                        {
                            long arg1 = Convert.ToInt64(arguments[1]);
                            if (arg1 < 0)
                            {
                                return null;
                            }
                            if (argumentCount == 3)
                                return (String.Format("(SUBSTRING({0},{1},{2}))", arguments[0], arg1 + 1, arguments[2]));
                            else
                                return String.Empty;
                        }
                    case "LEFT$":
                        return (String.Format("(SUBSTRING({0},1,{1}))", arguments[0], arguments[1]));
                    case "LEN":
                        return (String.Format("(LEN({0}))", arguments[0]));
                    case "EMPTY":
                        if (argumentCount == 1)
                            return (String.Format("(LEN({0})=0)", arguments[0]));
                        else
                            return (String.Format("(LEN(TRIM({0}))=0)", arguments[0]));
                    case "ATRIM$":
                        return (String.Format("(TRIM({0}))", arguments[0]));
                    case "COND":
                        return (String.Format("(IIF({0},{1},{2}))", arguments[0], arguments[1], arguments[2]));
                    case "DATEINRANGE":
                        return (String.Format("(({0} >= {1}) AND ({0} <= {2}))", arguments[0], arguments[1], arguments[2]));
                    case "NUMINRANGE":
                        return (String.Format("(({0} >= {1}) AND ({0} <= {2}))", arguments[0], arguments[1], arguments[2]));
                }
                return null;
            }
        case LlExpressionPart.Field:
            {
                if (arguments[0] == null || !arguments[0].ToString().StartsWith(TableName + "."))
                {
                    return null;
                }
                return String.Format("[{0}]", arguments[0].ToString().Substring(TableName.Length + 1));
            }
        default:
            return null;
     
    }
}

 

Requirements

Platforms: Windows Vista - Windows 10 Version 1809, Windows Server 2008 - 2016

See Also

Reference

IAdvancedFiltering Interface
IAdvancedFiltering Members