예제 #1
0
        // TODO
        #endregion

        #region SetItemVariable
        // TODO
        #endregion

        #region SetColumnAssignmentEquals
        // TODO
        #endregion

        #region SetColumnAssignmentOperator
        // TODO
        #endregion

        #region SetVariableColumnAssignment
        // TODO
        #endregion

        #region SetVariableAssignment
        // TODO
        #endregion

        #region WithCommonTable
        // TODO
        #endregion

        #region OperatorQueryExpression
        // TODO
        #endregion

        #region QuerySpecification
        public virtual bool Action(QuerySpecification child)
        {
            if (child.SelectClause != null)
            {
                Scan(child.SelectClause);
            }
            if (child.FromClause != null)
            {
                _HTML += " FROM ";
                for (int i = 0; i < child.FromClause.Count; i++)
                {
                    if (i > 0)
                    {
                        _HTML += " ";
                    }
                    Scan(child.FromClause[i]);
                }
            }
            if (child.WhereClause != null)
            {
                _HTML += " WHERE ";
                Scan(child.WhereClause);
            }
            if (child.GroupByClause != null)
            {
                _HTML += " GROUP BY ";
                for (int i = 0; i < child.GroupByClause.Count; i++)
                {
                    if (i > 0)
                    {
                        _HTML += ",";
                    }
                    Scan(child.GroupByClause[i]);
                }
            }
            if (child.HavingClause != null)
            {
                _HTML += " HAVING ";
                Scan(child.HavingClause);
            }
            if (child.OrderByClause != null)
            {
                Stringifier str = new Stringifier();
                str.AddSpace();
                str.Add("ORDER BY");
                str.AddSpace();
                foreach (OrderByItem item in child.OrderByClause)
                {
                    str.Add(item);
                    if (item != child.OrderByClause.Last())
                    {
                        str.Add(",");
                        str.AddSpace();
                    }
                }
                _HTML += str.Statement;
            }
            return(false);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="translated"></param>
        /// <param name="writer"></param>
        /// <param name="varTokenizer"></param>
        void PrintOutput(Statement translated, TextWriter writer, Tokenizer tokenizer)
        {
            if (translated == null)
            {
                return;
            }

            String output = string.Empty;

            if (Config.Formatter)
            {
                Formatter formatter = new Formatter();
                formatter.Add(translated);
                output = formatter.Statement;
            }
            else
            {
                Stringifier stringifier = new Stringifier();
                stringifier.Add(translated);
                output = stringifier.Statement;
            }

            writer.Write(tokenizer.detokenizeInputStatements(output));
        }
예제 #3
0
        void TranslateStatements(IList <Statement> statements)
        {
            string outputFile = Config.OutputFile;
            Dictionary <string, string> msgs = new Dictionary <string, string>();
            int errStatement = 0;

            msgs[Note.CASEFIXER]     = ResStr.MSG_CORRECTED_IDENTIFIERS;
            msgs[Note.ERR_CASEFIXER] = ResStr.MSG_COLUMNS_NOT_FOUND;
            msgs[Note.STRINGIFIER]   = ResStr.MSG_SUMINFO_UNSUPPORTED_FEATURES;
            msgs[Note.ERR_MODIFIER]  = ResStr.MSG_ERRORS_LIMITATIONS;

            if (outputFile != "")
            {
                using (StreamWriter writer = CreateOutputFile(outputFile))
                {
                    CharacterCaseFixer fixer = new CharacterCaseFixer(Config.DBServer, Config.DBSchema, Config.DBUser, Config.DBPasswd);
                    NotesScanner       ns    = new NotesScanner(writer);

                    ns.SetFilter(Config.CommentsFilter);
                    ns.WriteNotesToWritter(false);

                    bool displayWarning = true;
                    int  idx            = 1;


                    Console.WriteLine(ResStr.MSG_TRANSLATING_QUERY, idx++, statements.Count);
                    Modifier       md = new Modifier();
                    BlockStatement RootStatement;
                    if (Config.CreateProcedure && !(statements[1] is CreateProcedureStatement))
                    {
                        CreateProcedureStatement procedure = new CreateProcedureStatement(new DbObject(new Identifier(IdentifierType.Plain, md.ProcPool.GetNewProcedureName())), -1,
                                                                                          new List <ProcedureParameter> {
                        }, null, false, statements as List <Statement>);
                        procedure.Declarations = new BlockStatement();
                        RootStatement          = new BlockStatement(procedure);
                    }
                    else
                    {
                        RootStatement = new BlockStatement(statements);
                    }
                    md.Scan(RootStatement);

                    ns.ClearSummaryInfo();
                    ns.SetFilter(Config.CommentsFilter);

                    Statement translated = md.Statement;

                    if (translated != null)
                    {
                        if (translated is BlockStatement)
                        {
                            foreach (Statement st in ((BlockStatement)translated).Statements)
                            {
                                fixer.ClearIdentifiersTables();
                                fixer.Scan(st);

                                if (Config.UseCaseFixer && (translated is SqlStartStatement) == false)
                                {
                                    string res = fixer.CorrectIdentifiers();
                                    if (!string.IsNullOrEmpty(res) && displayWarning)
                                    {
                                        Console.WriteLine(ResStr.MSG_UNABLE_TO_VERIFY_IDENTFIERS);
                                        Console.WriteLine(ResStr.MSG_TECHNICAL_INFO + " " + res);
                                        displayWarning = false;
                                    }
                                }
                            }
                        }
                        else
                        {
                            fixer.ClearIdentifiersTables();
                            fixer.Scan(translated);

                            if (Config.UseCaseFixer && (translated is SqlStartStatement) == false)
                            {
                                string res = fixer.CorrectIdentifiers();
                                if (!string.IsNullOrEmpty(res) && displayWarning)
                                {
                                    Console.WriteLine(ResStr.MSG_UNABLE_TO_VERIFY_IDENTFIERS);
                                    Console.WriteLine(ResStr.MSG_TECHNICAL_INFO + " " + res);
                                    displayWarning = false;
                                }
                            }
                        }

                        if (Config.Formatter)
                        {
                            Formatter formatter = new Formatter();
                            formatter.Add(translated);
                            writer.Write(formatter.Statement);
                        }
                        else
                        {
                            Stringifier stringifier = new Stringifier();
                            stringifier.Add(translated);
                            writer.Write(stringifier.Statement);
                        }

                        ns.Scan(translated);
                    }

                    ns.SetFilter(Config.InfoFilter);
                    ns.DisplaySummaryInfo(Console.Out, msgs);

                    if (ns.NotesCount(Note.STRINGIFIER) > 0 || ns.NotesCount(Note.ERR_MODIFIER) > 0 || ns.NotesCount(Note.ERR_CASEFIXER) > 0)
                    {
                        ++errStatement;
                    }
                }

                DbUtil.ReleaseSingleton();

                Console.WriteLine("=================================================================");
                Console.WriteLine(ResStr.MSG_NUM_OF_OK_QUERIES, statements.Count - errStatement);
                Console.WriteLine(ResStr.MSG_NUM_OF_NOK_QUERIES, errStatement);
                Console.WriteLine(ResStr.MSG_NUM_OF_QUERIES, statements.Count);
            }
        }