Exemplo n.º 1
0
        private bool CheckForOverload(PLSQLSpecPackage ss, string ProcName)
        {
            int count = 0;

            foreach (PLSQLSpecProc sp in ss.Procedures)
            {
                if (sp.ProcName.ToUpper() == ProcName.ToUpper())
                {
                    count++;
                }
            }
            return(count > 1);
        }
Exemplo n.º 2
0
        public void GenerateXML(PLSQLSpecPackage ss, bool dict_is_optional)
        {
            int  j;
            bool bIsFunction;

            if (ss == null)
            {
                return;
            }

            packageDef = new Package();

            packageDef.name = ss.PackageName;

            if (ss.Procedures != null)
            {
                {
                    string missingParameters = "";
                    // identify missing parameters from dictionary
                    foreach (PLSQLSpecProc sp in ss.Procedures)
                    {
                        foreach (PLSQLSpecParam p in sp.Params)
                        {
                            if (InDictionary(p.ParamName) == null)
                            {
                                missingParameters += "    <field name=\"" + p.ParamName + "\" />\r\n";
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(missingParameters))
                    {
                        Console.WriteLine("Warning parameters missing in dictionary\r\n" + missingParameters);
                    }
                }

                packageDef.procedures = new ProcedureType[ss.Procedures.Count];

                int i = 0;
                foreach (PLSQLSpecProc sp in ss.Procedures)
                {
                    bIsFunction = (sp.UnconnectedReturnType != "");

                    packageDef.procedures[i] = new ProcedureType();

                    packageDef.procedures[i].name       = sp.ProcName;
                    packageDef.procedures[i].overloaded = CheckForOverload(ss, sp.ProcName);

                    if (bIsFunction)
                    {
                        packageDef.procedures[i].type = ProcedureTypeType.Function;
                    }
                    else
                    {
                        packageDef.procedures[i].type = ProcedureTypeType.Procedure;
                    }

                    int ParamCount = sp.Params.Count;
                    if (bIsFunction)
                    {
                        ParamCount++; // return value is handled as an extra parameter
                    }
                    packageDef.procedures[i].parameters = new ParameterType[ParamCount];

                    j = 0;
                    foreach (PLSQLSpecParam p in sp.Params)
                    {
                        packageDef.procedures[i].parameters[j] = new ParameterType();

                        String newName = InDictionary(p.ParamName);
                        if (newName != null)
                        {
                            packageDef.procedures[i].parameters[j].name = newName;
                        }
                        else
                        {
                            if (dict_is_optional)
                            {
                                packageDef.procedures[i].parameters[j].name = p.ParamName;
                            }
                            else
                            {
                                Exception e = new Exception("Parameter not found in dictionary: " + p.ParamName);
                                throw (e);
                            }
                        }

                        packageDef.procedures[i].parameters[j].originTable  = p.TableName;
                        packageDef.procedures[i].parameters[j].originColumn = p.ColumnName;

                        if (p.DirIn && !p.DirOut)
                        {
                            packageDef.procedures[i].parameters[j].direction = ParameterTypeDirection.@In;
                        }
                        else if (!p.DirIn && p.DirOut)
                        {
                            packageDef.procedures[i].parameters[j].direction = ParameterTypeDirection.@Out;
                        }
                        else if (p.DirIn && p.DirOut)
                        {
                            packageDef.procedures[i].parameters[j].direction = ParameterTypeDirection.InOut;
                        }
                        else if (!p.DirIn && !p.DirOut)
                        {
                            packageDef.procedures[i].parameters[j].direction = ParameterTypeDirection.@In;
                        }

                        packageDef.procedures[i].parameters[j].dataType  = p.UnconnectedType;
                        packageDef.procedures[i].parameters[j].fieldType = ParameterTypeFieldType.Normal;

                        if (p.Mandatory)
                        {
                            packageDef.procedures[i].parameters[j].column           = new ColumnType();
                            packageDef.procedures[i].parameters[j].column.mandatory = true;
                        }

                        j++;
                    }

                    if (bIsFunction)
                    {
                        // the extra parameter
                        packageDef.procedures[i].parameters[j] = new ParameterType();

                        packageDef.procedures[i].parameters[j].name         = "";
                        packageDef.procedures[i].parameters[j].originTable  = "";
                        packageDef.procedures[i].parameters[j].originColumn = "";

                        packageDef.procedures[i].parameters[j].direction = ParameterTypeDirection.Result;
                        packageDef.procedures[i].parameters[j].dataType  = sp.UnconnectedReturnType;
                        packageDef.procedures[i].parameters[j].fieldType = ParameterTypeFieldType.Normal;
                    }

                    i++;
                }
            }
        }
Exemplo n.º 3
0
        // ----------------------------------------------------------------------------

        public PLSQLSpecParser(string spectext)
        {
            int             ixCurrent = 0;
            SourceTokenizer t         = new SourceTokenizer(spectext, " ();%.:=\r\n\t,/*");
            string          s;
            int             ixLast;
            string          DefaultValue = "";
            bool            bIsFunction  = false;

            bool WaitForPackageName    = false;
            bool WaitForProcedureName  = false;
            bool WaitForParamName      = false;
            bool WaitForMandatory      = false;
            bool WaitForParamType      = false;
            bool WaitForParamSeparator = false;
            bool WaitForReturnType     = false;
            bool WaitForDefaultValue   = false;

            PLSQLSpecProc  CurrentProc  = null;
            PLSQLSpecParam CurrentParam = null;

            while (!t.EOF(ixCurrent))
            {
                s      = "";
                ixLast = 0;

                if (t.EatSpace(ref ixCurrent))
                {
                    // eat space and countine in same lap!
                }

                if (t.IsComment(ixCurrent, "/" + "*", "*" + "/", ref s, ref ixLast))
                {
                    if (WaitForMandatory)
                    {
                        if (s.Trim().ToUpper() == "MANDATORY")
                        {
                            CurrentParam.Mandatory = true;
                            WaitForMandatory       = false;
                        }
                    }

                    // throw away comments
                    ixCurrent = ixLast;
                    //Console.WriteLine( "<comment><" + s + ">" );
                }

                else if (t.Peek(ixCurrent, 0).ToUpper() == "PACKAGE")
                {
                    WaitForPackageName = true;
                }

                else if (WaitForPackageName)
                {
                    //Console.WriteLine( "<package><" + t.Peek( ixCurrent, 0 ) + ">" );

                    Package = new PLSQLSpecPackage(t.Peek(ixCurrent, 0));

                    WaitForPackageName = false;
                }

                else if (t.Peek(ixCurrent, 0).ToUpper() == "PROCEDURE")
                {
                    WaitForProcedureName = true;
                    bIsFunction          = false;
                }

                else if (t.Peek(ixCurrent, 0).ToUpper() == "FUNCTION")
                {
                    WaitForProcedureName = true;
                    bIsFunction          = true;
                }

                else if (WaitForProcedureName)
                {
                    //Console.WriteLine( "  <procedure><" + t.Peek( ixCurrent, 0 ) + ">" );
                    string name = t.Peek(ixCurrent, 0);

                    // Ignore the function Get_Source_Version_Info. It's added by the deploy.
                    if (name != "Get_Source_Version_Info")
                    {
                        CurrentProc = new PLSQLSpecProc(name);
                        Package.Procedures.Add(CurrentProc);

                        WaitForParamName = true;
                    }
                    else
                    {
                        CurrentProc      = null;
                        WaitForParamName = false;
                    }

                    WaitForProcedureName = false;
                }

                // sample params
                // ,ALMID_O         out ALM.ALMID%type
                // ,CHK_AI_I            varchar2  := '1'  );
                // ,ALMID_I /* mandatory */ ALM.ALMID%type

                else if (WaitForParamName) // ALMID_O
                {
                    if (t.Peek(ixCurrent, 0) == "(")
                    {
                        // ignore start ( as it is expected
                    }
                    else
                    {
                        //Console.WriteLine( "    <param><" + t.Peek( ixCurrent, 0 ) + ">" );

                        CurrentParam = new PLSQLSpecParam(t.Peek(ixCurrent, 0));
                        CurrentProc.Params.Add(CurrentParam);

                        WaitForParamName = false;
                        WaitForParamType = true;
                        WaitForMandatory = true;
                    }
                }

                else if (WaitForParamType)
                {
                    if (t.Peek(ixCurrent, 0).ToUpper() == "IN") // in ALM.ALMID%type
                    {
                        //Console.WriteLine( "      <direction><IN>" );
                        CurrentParam.DirIn = true;
                    }
                    else if (t.Peek(ixCurrent, 0).ToUpper() == "OUT") // out ALM.ALMID%type
                    {
                        //Console.WriteLine( "      <direction><OUT>" );
                        CurrentParam.DirOut = true;
                    }
                    else
                    {
                        if ((t.Peek(ixCurrent, 1) == ".") &&
                            (t.Peek(ixCurrent, 3) == "%") &&
                            (t.Peek(ixCurrent, 4).ToUpper() == "TYPE")) // ALM.ALMID%type
                        {
                            // table.name%type
                            //Console.WriteLine( "      <table><" + t.Peek( ixCurrent, 0 ) + ">" );
                            //Console.WriteLine( "      <column><" + t.Peek( ixCurrent, 2 ) + ">" );

                            CurrentParam.TableName  = t.Peek(ixCurrent, 0);
                            CurrentParam.ColumnName = t.Peek(ixCurrent, 2);

                            ixCurrent += 4;
                        }

                        else // varchar2
                        {
                            //Console.WriteLine( "      <type><" + t.Peek( ixCurrent, 0 ).ToUpper() + ">" );

                            CurrentParam.UnconnectedType = t.Peek(ixCurrent, 0).ToUpper();
                        }

                        WaitForParamType      = false;
                        WaitForParamSeparator = true;
                        WaitForMandatory      = false;
                    }
                }

                else if (WaitForParamSeparator) // ","  ")"  ":= '1'"
                {
                    WaitForParamSeparator = false;

                    if (t.Peek(ixCurrent, 0) == ")")
                    {
                        WaitForReturnType = true;
                    }

                    else if (t.Peek(ixCurrent, 0) == ",")
                    {
                        WaitForParamName = true;
                    }

                    else if ((t.Peek(ixCurrent, 0) == ":") &&
                             (t.Peek(ixCurrent, 1) == "="))
                    {
                        WaitForDefaultValue = true;
                        ixCurrent          += 1;
                    }

                    else
                    {
                        Console.WriteLine("syntax error or unsupported format of spec");
                        if (CurrentProc != null)
                        {
                            Console.WriteLine("  parsing procedure/function " + CurrentProc.ProcName);
                        }
                        if (CurrentParam != null)
                        {
                            Console.WriteLine("  after param " + CurrentParam.ParamName);
                        }

                        Console.WriteLine(" near <" + t.Peek(ixCurrent, 0) + ">");
                        Package = null;
                    }
                }

                else if (WaitForDefaultValue) // '1' 1
                {
                    if (t.IsString(ixCurrent, "'", ref DefaultValue, ref ixLast))
                    {
                        ixCurrent = ixLast;
                    }
                    else
                    {
                        // Def.XXXXX
                        if (t.Peek(ixCurrent, 1) == ".")
                        {
                            DefaultValue = t.Peek(ixCurrent, 0) + t.Peek(ixCurrent, 1) + t.Peek(ixCurrent, 2);
                            ixCurrent   += 2;
                        }
                        else
                        {
                            DefaultValue = t.Peek(ixCurrent, 0);
                        }
                    }

                    //Console.WriteLine( "      <default><" + DefaultValue + ">" );

                    CurrentParam.DefaultValue = DefaultValue;

                    WaitForDefaultValue   = false;
                    WaitForParamSeparator = true; // redo that step to catch return value after default
                }

                else if (WaitForReturnType)
                {
                    if (bIsFunction)
                    {
                        if (t.Peek(ixCurrent, 0).ToUpper() == "RETURN")
                        {
                            // ignore
                        }

                        else
                        {
                            //Console.WriteLine( "    <return type><" + t.Peek( ixCurrent, 0 ).ToUpper() + ">" );

                            CurrentProc.UnconnectedReturnType = t.Peek(ixCurrent, 0).ToUpper();

                            WaitForReturnType = false;
                        }
                    }

                    else if (t.Peek(ixCurrent, 0) == ";")
                    {
                        WaitForReturnType = false;
                    }
                }

                ixCurrent++;
            }
        }