示例#1
0
        // returns true if this parameter belongs to the specified node
        internal bool BelongsTo(FuncOrProc node)
        {
            if (node == null)
            {
                return(false);
            }

            return(SCHEMA == node.SCHEMA && OBJECT_NAME == node.OBJECT_NAME);
        }
示例#2
0
        // process parameter names (OPTIMIZED)
        private void ProcessParamNames()
        {
            // order nodes by name
            var orderedNodes = _nodes
                               .Where(a => ((IColumn)a).OBJECT_TYPE >= 3)
                               .OrderBy(a => ((IColumn)a).SCHEMA)
                               .ThenBy(a => ((IColumn)a).OBJECT_NAME)
                               .ToList();

            // declarations
            var        nodeix      = -1;                     // current node index
            var        paramSet    = new HashSet <string>(); // columns hash set (to check duplicates)
            FuncOrProc node        = null;                   // current node
            int        renameIndex = 1;                      // rename index (inside the node)
            string     clrName     = null;                   // param CLR name

            // loop through ordered columns (the same order as of the nodes)
            // WE ASSUME THAT THE COLUMN NODE ORDER IS THE SAME AS THE NODE ORDER ITSELF
            // Important! Inside the node the columns are ordered by ORDINAL_POSITION
            foreach (var param in DbInfo.Table4
                     .OrderBy(a => a.SCHEMA)
                     .ThenBy(a => a.OBJECT_NAME)
                     .ThenBy(c => c.ORDINAL_POSITION))
            {
                // ordinal position = 0 => always move to the next node
                if (param.ORDINAL_POSITION == 0)
                {
                    ++nodeix;                                       // mode to the next table
                    node = (FuncOrProc)orderedNodes[nodeix];        // with no check (should exists) !!
                    paramSet.Clear();                               // prepare empty param set
                }
                // ordinal position = 0 => move to the next node if the current node does not have a ZERO param
                else if (param.ORDINAL_POSITION == 1)
                {
                    //if (node == null || !(node.SCHEMA == param.SCHEMA && node.OBJECT_NAME == param.OBJECT_NAME))
                    if (node == null || !param.BelongsTo(node))
                    {
                        // clear param set if this is the first param
                        if (!param.BelongsTo(node))
                        {
                            paramSet.Clear();
                        }

                        ++nodeix;                                   // mode to the next table
                        node = (FuncOrProc)orderedNodes[nodeix];    // with no check (should exists) !!
                    }
                }

                // ----------------------------------------------------------------------------------
                // IMPORTANT VALIDITY CHECK
                // Exclude objects that does not fulfill the following rules:
                //   - First parameter should have the ordinal position 0 or 1.
                // Reason why this can happen is that either the SQL Server does not return
                // correct data (not likely) or the user permissions causes that certain parameters
                // are excluded because the user does not have the access permission to certain
                // underlying user defined types (likely to happen).
                // ----------------------------------------------------------------------------------
                if (nodeix >= 0 && !param.BelongsTo(node))
                //!(param.SCHEMA == node.SCHEMA && param.OBJECT_NAME == node.OBJECT_NAME))
                {
                    ((IColumn)node).SetNotCompliant();
                    ++nodeix;   // if node && param's node do not match => move to next node
                    continue;
                }

                // skip NONE params
                if ((ParameterMode)param.PARAMETER_MODE == ParameterMode.None)
                {
                    continue;
                }

                // get param CLR name (for non-OUT params)
                if ((ParameterMode)param.PARAMETER_MODE != ParameterMode.Out)
                {
                    // remove @
                    clrName = Regex.Replace(param.PARAMETER_NAME, "^@", "");
                    clrName = Api.GetClrName(clrName);
                    clrName = ClrName.GetArgName(clrName);

                    if (!ClrName.CheckParamName(clrName, ((IName)node).Name))
                    {
                        clrName = ClrName.Rename(clrName, 1);
                    }

                    // prepare schema_node name
                    //var schema_node = param.SCHEMA + "_" + param.OBJECT_NAME;

                    // ensure that the param name is unique (inside the node)
                    renameIndex = 1; // reset rename index
                    //while (!paramSet.Add(schema_node + "_" + clrName))
                    while (!paramSet.Add(clrName))
                    {
                        clrName = ClrName.Rename(clrName, renameIndex++);
                    }

                    // append columns to table
                    ((IName)param).Name = clrName;
                }

                // add param
                node.Parameters.Add(param);
            }
        }