コード例 #1
0
        private void UpdateProcedures()
        {
            foreach (Procedure procedure in Project.Database.Procedures)
            {
                ProcedureSelectStatement selectStatement = null;
                foreach (Parameter enumParameter in procedure.Parameters)
                {
                    // Find the original parameter
                    MethodParameter methodParameter = enumParameter.MethodParameter;
                    if (methodParameter == null)
                    {
                        continue;
                    }

                    MethodParameter originalMethodParameter = methodParameter.GetData(NamespaceUri + ":parameter", (MethodParameter)null);
                    if (originalMethodParameter == null)
                    {
                        continue;
                    }

                    Parameter valueParameter = procedure.Parameters.FirstOrDefault(_ => _.MethodParameter == originalMethodParameter);
                    if (valueParameter == null || valueParameter.Column == null)
                    {
                        continue;
                    }

                    if (selectStatement == null)
                    {
                        // Get the select statement of the procedure
                        // The procedure should contains only one Select statement
                        selectStatement = procedure.Body.Statements.OfType <ProcedureSelectStatement>().FirstOrDefault();
                        if (selectStatement == null)
                        {
                            return;
                        }
                    }

                    ProcedureExpressionStatement whereStatement = null;
                    foreach (EnumerationValue enumValue in FilterFunctionsEnumeration.Values)
                    {
                        FilterFunctions op = GetFilterFunction(enumValue);
                        if (!IsSupported(op, procedure, valueParameter))
                        {
                            continue;
                        }

                        ProcedureExpressionStatement testEnumValueStatement = CreateEnumerationEqualsStatement(selectStatement, enumParameter, enumValue);
                        ProcedureExpressionStatement testValueStatement     = CreateParameterTestStatement(selectStatement, valueParameter, op);
                        if (testValueStatement == null)
                        {
                            continue;
                        }

                        ProcedureExpressionStatement paramWhereStatement = new ProcedureExpressionStatement(
                            selectStatement,
                            ProcedureOperationType.And,
                            testEnumValueStatement,
                            testValueStatement);

                        if (whereStatement == null)
                        {
                            whereStatement = paramWhereStatement;
                        }
                        else
                        {
                            whereStatement = new ProcedureExpressionStatement(selectStatement, ProcedureOperationType.Or, whereStatement, paramWhereStatement);
                        }
                    }

                    // Declare the statement as a search expression
                    // Search expression is used by SEARCH method to identify dynamic parts of the body
                    if (whereStatement != null)
                    {
                        whereStatement.Visit <ProcedureStatement>(statement =>
                        {
                            ProcedureExpressionStatement s = statement as ProcedureExpressionStatement;
                            if (s != null)
                            {
                                procedure.MarkSearchExpression(s, valueParameter);
                                if (!s.IsLiteral)
                                {
                                    s.SearchExpressionParameter = valueParameter;
                                }
                            }
                        });

                        selectStatement.AddExpressionToWhere(whereStatement, ProcedureOperationType.And);
                    }
                }
            }
        }