Пример #1
0
        public override void Translate(IATranslator translator, ASTNodeList newNodes, ASTNodeList subNodes, IASTNodeFactory nodeFactory)
        {
            Translator  = translator;
            NodeFactory = nodeFactory;

            AddFunction(newNodes, "to_number", CreateFunctionParameterNodeWithSubNodes(subNodes[1]));
        }
Пример #2
0
        private void CreateView(ICommands cmd, IAParser parser, IATranslator translator, IViewDefinition view)
        {
            ASTNodeList   aNodes         = null;
            StringBuilder createViewStmt = new StringBuilder("create view ");

            createViewStmt.Append(view.ViewName);

            if (view.DbType == DbTypeName.Any || parser.ExpandEmptyStrings)
            {
                aNodes = parser.CreateNodeList(view.SelectStatement);
            }

            if (view.DbType == DbTypeName.Any)
            {
                if (!ColumnListContainStar(aNodes))
                {
                    createViewStmt.Append(CreateColumnList(aNodes));
                }

                aNodes = translator.Translate(aNodes);
            }

            createViewStmt.Append(" as ");

            if (aNodes != null)
            {
                createViewStmt.Append(aNodes);
            }
            else
            {
                createViewStmt.Append(view.SelectStatement);
            }

            cmd.ExecuteNonQuery(createViewStmt.ToString());
        }
Пример #3
0
        public override void Translate(IATranslator translator, ASTNodeList newNodes, ASTNodeList subNodes, IASTNodeFactory nodeFactory)
        {
            Translator  = translator;
            NodeFactory = nodeFactory;

            AddFunction(newNodes, "getdate", new List <IASTNode>());
        }
Пример #4
0
        public override void Translate(IATranslator translator, ASTNodeList newNodes, ASTNodeList subNodes, IASTNodeFactory nodeFactory)
        {
            // TO_int('123') => CONVERT(int, '123')
            Translator  = translator;
            NodeFactory = nodeFactory;

            AddFunction(newNodes, "convert", CreateFunctionParameterNode("int"), CreateFunctionParameterNodeWithSubNodes(subNodes[1]));
        }
Пример #5
0
        public override void Translate(IATranslator translator, ASTNodeList newNodes, ASTNodeList subNodes, IASTNodeFactory nodeFactory)
        {
            // TO_COUNTER('9') => convert(bigint, '0') )
            Translator  = translator;
            NodeFactory = nodeFactory;

            AddFunction(newNodes, "convert", CreateFunctionParameterNode("bigint"), CreateFunctionParameterNodeWithSubNodes(subNodes[1]));
        }
Пример #6
0
        public override void Translate(IATranslator translator, ASTNodeList newNodes, ASTNodeList subNodes, IASTNodeFactory nodeFactory)
        {
            // TO_CHAR(123) => CONVERT(nvarchar, 123)
            Translator  = translator;
            NodeFactory = nodeFactory;

            AddFunction(newNodes, "convert", CreateFunctionParameterNode("nvarchar"), CreateFunctionParameterNodeWithSubNodes(subNodes[1]));
        }
Пример #7
0
        public override void Translate(IATranslator translator, ASTNodeList newNodes, ASTNodeList subNodes, IASTNodeFactory nodeFactory)
        {
            // GUID2STR(guid_col) => lower(guid_col)

            Translator  = translator;
            NodeFactory = nodeFactory;

            AddFunction(newNodes, "lower", CreateFunctionParameterNodeWithSubNodes(subNodes[1]));
        }
Пример #8
0
        public override void Translate(IATranslator translator, ASTNodeList newNodes, ASTNodeList subNodes, IASTNodeFactory nodeFactory)
        {
            // MOD(3, 5) => (3) % (5)
            Translator  = translator;
            NodeFactory = nodeFactory;

            WrapParameterInParentheses(newNodes, subNodes[1]);
            newNodes.Add(nodeFactory.CreateNode("%"));
            WrapParameterInParentheses(newNodes, subNodes[3]);
        }
Пример #9
0
        private void TestDoFunctions(string input, string expected)
        {
            IASTNodeFactory nodeFactory = new ASTNodeFactory();
            IAParser        parser      = AParserFactory.CreateInstance(nodeFactory);
            ASTNodeList     aNodes      = parser.CreateNodeList(input);
            IATranslator    translator  = ATranslatorFactory.CreateInstance(DbTypeName.SqlServer, nodeFactory);
            ASTNodeList     msNodes     = translator.Translate(aNodes);

            string result = msNodes.ToString();

            result.Should().BeEquivalentTo(expected);
        }
Пример #10
0
        public override void Translate(IATranslator translator, ASTNodeList newNodes, ASTNodeList subNodes, IASTNodeFactory nodeFactory)
        {
            IASTNode newNode = nodeFactory.CreateNode(ASTStartParenthesesNode.KeyWord, false);

            newNode.SubNodes.Add(nodeFactory.CreateFunctionParameterNode());
            newNode.SubNodes.Add(nodeFactory.CreateNode("+"));
            newNode.SubNodes.Add(nodeFactory.CreateFunctionParameterNode());
            newNode.SubNodes.Add(nodeFactory.CreateNode(ASTEndParenthesesNode.KeyWord));

            newNodes.Add(newNode);
            translator.TranslateSubNodes(newNode.SubNodes[0].SubNodes, subNodes[1]);
            translator.TranslateSubNodes(newNode.SubNodes[2].SubNodes, subNodes[3]);
        }
Пример #11
0
        public override void Translate(IATranslator translator, ASTNodeList newNodes, ASTNodeList subNodes, IASTNodeFactory nodeFactory)
        {
            // Translated to to_date('19000101 00:00:00', 'yyyymmdd hh24:mi:ss')
            Translator  = translator;
            NodeFactory = nodeFactory;

            List <IASTNode> functionParameters = new List <IASTNode>
            {
                nodeFactory.CreateNode("'19000101 00:00:00'", false),
                nodeFactory.CreateNode("'yyyymmdd hh24:mi:ss'", false)
            };

            AddFunction(newNodes, "to_date", functionParameters);
        }
Пример #12
0
        public override void Translate(IATranslator translator, ASTNodeList newNodes, ASTNodeList subNodes, IASTNodeFactory nodeFactory)
        {
            // MONTHADD(3, today) => add_months(today, 3)
            Translator  = translator;
            NodeFactory = nodeFactory;

            List <IASTNode> functionParameters = new List <IASTNode>
            {
                CreateFunctionParameterNodeWithSubNodes(subNodes[3]),
                CreateFunctionParameterNodeWithSubNodes(subNodes[1])
            };

            AddFunction(newNodes, "add_months", functionParameters);
        }
Пример #13
0
        public override void Translate(IATranslator translator, ASTNodeList newNodes, ASTNodeList subNodes, IASTNodeFactory nodeFactory)
        {
            // IFNULL(somecol, 0) => nvl(somecol, 0)
            Translator  = translator;
            NodeFactory = nodeFactory;

            List <IASTNode> functionParameters = new List <IASTNode>
            {
                CreateFunctionParameterNodeWithSubNodes(subNodes[1]),
                CreateFunctionParameterNodeWithSubNodes(subNodes[3])
            };

            AddFunction(newNodes, "nvl", functionParameters);
        }
Пример #14
0
        public override void Translate(IATranslator translator, ASTNodeList newNodes, ASTNodeList subNodes, IASTNodeFactory nodeFactory)
        {
            // Translated to convert(datetime, '19000101 00:00:00:000', 9)
            Translator  = translator;
            NodeFactory = nodeFactory;

            List <IASTNode> functionParameters = new List <IASTNode>
            {
                nodeFactory.CreateNode("datetime", false),
                nodeFactory.CreateNode("'19000101 00:00:00:000'", false),
                nodeFactory.CreateNode("9", false)
            };

            AddFunction(newNodes, "convert", functionParameters);
        }
Пример #15
0
        public override void Translate(IATranslator translator, ASTNodeList newNodes, ASTNodeList subNodes, IASTNodeFactory nodeFactory)
        {
            // MOD(3, 5) translated to: mod(floor(3), floor(5))
            Translator  = translator;
            NodeFactory = nodeFactory;

            IASTNode newParam1 = NodeFactory.CreateFunctionParameterNode();

            AddFunction(newParam1.SubNodes, "floor", CreateFunctionParameterNodeWithSubNodes(subNodes[1]));
            IASTNode newParam2 = NodeFactory.CreateFunctionParameterNode();

            AddFunction(newParam2.SubNodes, "floor", CreateFunctionParameterNodeWithSubNodes(subNodes[3]));

            AddFunction(newNodes, "mod", newParam1, newParam2);
        }
Пример #16
0
        public override void Translate(IATranslator translator, ASTNodeList newNodes, ASTNodeList subNodes, IASTNodeFactory nodeFactory)
        {
            // TO_FLOAT('123') => convert(dec(28,8) , '123')
            Translator  = translator;
            NodeFactory = nodeFactory;

            IASTNode newNode = NodeFactory.CreateNode("convert", false);

            newNode.SubNodes.Add(NodeFactory.CreateNode(ASTStartParenthesesNode.KeyWord, false));
            newNode.SubNodes.Add(NodeFactory.CreateFunctionParameterNode());
            newNode.SubNodes.Add(NodeFactory.CreateNode(ASTCommaNode.KeyWord));
            newNode.SubNodes.Add(CreateFunctionParameterNodeWithSubNodes(subNodes[1]));
            newNode.SubNodes.Add(NodeFactory.CreateNode(ASTEndParenthesesNode.KeyWord));

            AddFunction(newNode.SubNodes[1].SubNodes, "dec", CreateFunctionParameterNode("28"), CreateFunctionParameterNode("8"));
            newNodes.Add(newNode);
        }
Пример #17
0
        public override void Translate(IATranslator translator, ASTNodeList newNodes, ASTNodeList subNodes, IASTNodeFactory nodeFactory)
        {
            // The guid2str function is pretty ugly in Oracle. A call like guid2str(guid_col) becomes:
            //     lower(substr(guid_col,1,8) || '-' || substr(guid_col,9,4) || '-' || substr(guid_col,13,4) || '-' || substr(guid_col,17,4) || '-' || substr(guid_col,21,12))
            Translator  = translator;
            NodeFactory = nodeFactory;

            IASTNode newNode = NodeFactory.CreateNode("lower", false);

            newNode.SubNodes.Add(NodeFactory.CreateNode(ASTStartParenthesesNode.KeyWord, false));
            newNode.SubNodes.Add(NodeFactory.CreateFunctionParameterNode());
            newNode.SubNodes.Add(NodeFactory.CreateNode(ASTEndParenthesesNode.KeyWord));

            CreateNodesForGuidParts(newNode.SubNodes[1].SubNodes, subNodes[1]);

            newNodes.Add(newNode);
        }
Пример #18
0
        public void DoViews(out int totalViews, out int failedViews, IALogger tmpLogger = null)
        {
            IALogger logger = tmpLogger ?? new TestLogger();

            totalViews  = 0;
            failedViews = 0;

            List <IViewDefinition> viewDefinitions = new List <IViewDefinition>();

            viewDefinitions.AddRange(GetViewsFromAagView());
            viewDefinitions.AddRange(GetViewsFromAsysViewThatAreNotInAagView());

            ICommands       cmd         = _dbContext.PowerPlant.CreateCommands();
            IDbSchema       schema      = _dbContext.PowerPlant.CreateDbSchema();
            IASTNodeFactory nodeFactory = new ASTNodeFactory();
            IAParser        parser      = AParserFactory.CreateInstance(nodeFactory);

            if (_dbContext.DbType == DbTypeName.Oracle)
            {
                parser.ExpandEmptyStrings = true;
            }
            IATranslator translator = ATranslatorFactory.CreateInstance(_dbContext.DbType, nodeFactory);

            foreach (var view in viewDefinitions)
            {
                if (view.DbType != DbTypeName.Any && view.DbType != _dbContext.DbType)
                {
                    continue;
                }

                totalViews++;
                try
                {
                    schema.DropView(view.ViewName);
                    CreateView(cmd, parser, translator, view);
                    logger.Write(string.Format("View '{0}' created", view.ViewName));
                }
                catch (Exception ex)
                {
                    logger.Write(string.Format("ERROR: Can't create view '{0}'", view.ViewName));
                    logger.Write(ex.Message);
                    failedViews++;
                }
            }
        }
Пример #19
0
        public override void Translate(IATranslator translator, ASTNodeList newNodes, ASTNodeList subNodes, IASTNodeFactory nodeFactory)
        {
            // TO_FLOAT('123') => cast(decode('123', ' ', 0.00, '123') as number(30,8) )
            Translator  = translator;
            NodeFactory = nodeFactory;

            IASTNode newNode = NodeFactory.CreateNode("cast", false);

            newNode.SubNodes.Add(NodeFactory.CreateNode(ASTStartParenthesesNode.KeyWord, false));
            newNode.SubNodes.Add(NodeFactory.CreateFunctionParameterNode());
            newNode.SubNodes.Add(NodeFactory.CreateNode(ASTEndParenthesesNode.KeyWord));

            IASTNode parameter = CreateFunctionParameterNodeWithSubNodes(subNodes[1]);

            AddDecodeFunction(newNode.SubNodes[1].SubNodes, parameter);

            newNodes.Add(newNode);
        }
Пример #20
0
        public override void Translate(IATranslator translator, ASTNodeList newNodes, ASTNodeList subNodes, IASTNodeFactory nodeFactory)
        {
            // MONTHADD(3, today) => dateadd(mm, 3, today)
            Translator  = translator;
            NodeFactory = nodeFactory;

            IASTNode mmParameter = NodeFactory.CreateFunctionParameterNode();

            mmParameter.SubNodes.Add(NodeFactory.CreateNode("mm", false));

            List <IASTNode> functionParameters = new List <IASTNode>
            {
                mmParameter,
                CreateFunctionParameterNodeWithSubNodes(subNodes[1]),
                CreateFunctionParameterNodeWithSubNodes(subNodes[3])
            };

            AddFunction(newNodes, "dateadd", functionParameters);
        }
Пример #21
0
        public override void Translate(IATranslator translator, ASTNodeList newNodes, ASTNodeList subNodes, IASTNodeFactory nodeFactory)
        {
            // DAYADD(3, day_col) => dateadd(dd, 3, day_col)
            Translator  = translator;
            NodeFactory = nodeFactory;

            IASTNode unitParameter = NodeFactory.CreateFunctionParameterNode();

            unitParameter.SubNodes.Add(NodeFactory.CreateNode("dd", false));

            List <IASTNode> functionParameters = new List <IASTNode>
            {
                unitParameter,
                CreateFunctionParameterNodeWithSubNodes(subNodes[1]),
                CreateFunctionParameterNodeWithSubNodes(subNodes[3])
            };

            AddFunction(newNodes, "dateadd", functionParameters);
        }
Пример #22
0
 public override void Translate(IATranslator translator, ASTNodeList newNodes, ASTNodeList subNodes, IASTNodeFactory nodeFactory)
 {
     newNodes.Add(nodeFactory.CreateNode("sysdate"));
 }
Пример #23
0
 public abstract void Translate(IATranslator translator, ASTNodeList newNodes, ASTNodeList subNodes, IASTNodeFactory nodeFactory);