FunctionCall() public static method

public static FunctionCall ( ObjectName functionName ) : SqlFunctionCallExpression
functionName ObjectName
return SqlFunctionCallExpression
Ejemplo n.º 1
0
            public override SqlFunctionCallExpression Deserialize(BinaryReader reader)
            {
                var functionName = ObjectName.Deserialize(reader);
                var args         = ReadExpressions(reader);

                return(SqlExpression.FunctionCall(functionName, args));
            }
Ejemplo n.º 2
0
        public static void FormatWithNoArguments()
        {
            var expression = SqlExpression.FunctionCall(ObjectName.Parse("SYS.func1"));

            var sql      = expression.ToString();
            var expected = "SYS.func1()";

            Assert.AreEqual(expected, sql);
        }
        public void FormatToString()
        {
            var exp = SqlExpression.Cast(SqlExpression.FunctionCall("test", new SqlExpression[] {
                SqlExpression.Constant(56)
            }), PrimitiveTypes.VarChar(45));

            var expected = "CAST(test(56) AS VARCHAR(45))";

            Assert.AreEqual(expected, exp.ToString());
        }
Ejemplo n.º 4
0
        public static void FormatToString()
        {
            var trueExp   = SqlExpression.FunctionCall("testResult");
            var falseExp  = SqlExpression.Constant(false);
            var testExp   = SqlExpression.Equal(SqlExpression.VariableReference("a"), SqlExpression.Constant(22));
            var condition = SqlExpression.Conditional(testExp, trueExp, falseExp);

            var expected = "CASE WHEN :a = 22 THEN testResult() ELSE FALSE";

            Assert.AreEqual(expected, condition.ToString());
        }
Ejemplo n.º 5
0
        public static void FormatWithNamedArguments()
        {
            var expression = SqlExpression.FunctionCall(ObjectName.Parse("SYS.func1"), new InvokeArgument[] {
                new InvokeArgument("a", SqlExpression.Constant(1)),
            });

            var sql      = expression.ToString();
            var expected = "SYS.func1(a => 1)";

            Assert.AreEqual(expected, sql);
        }
Ejemplo n.º 6
0
        public static void FormatWithAnonArguments()
        {
            var expression = SqlExpression.FunctionCall(ObjectName.Parse("SYS.func1"), new SqlExpression[] {
                SqlExpression.Constant("order1"),
                SqlExpression.Constant(2)
            });

            var sql      = expression.ToString();
            var expected = "SYS.func1('order1', 2)";

            Assert.AreEqual(expected, sql);
        }
Ejemplo n.º 7
0
        private void CreateTestTable()
        {
            var tableInfo = new TableInfo(ObjectName.Parse("APP.test_table"));
            var idColumn  = tableInfo.AddColumn("id", PrimitiveTypes.Integer());

            idColumn.DefaultExpression = SqlExpression.FunctionCall("UNIQUEKEY",
                                                                    new SqlExpression[] { SqlExpression.Reference(tableInfo.TableName) });
            tableInfo.AddColumn("first_name", PrimitiveTypes.String());
            tableInfo.AddColumn("last_name", PrimitiveTypes.String());
            tableInfo.AddColumn("birth_date", PrimitiveTypes.DateTime());
            tableInfo.AddColumn("active", PrimitiveTypes.Boolean());

            Query.CreateTable(tableInfo);
            Query.AddPrimaryKey(tableInfo.TableName, "id", "PK_TEST_TABLE");
        }
        private void CreateTestTable(IQuery query)
        {
            var tableName = ObjectName.Parse("APP.test_table");

            query.Access().CreateTable(table => table
                                       .Named(tableName)
                                       .WithColumn(column => column
                                                   .Named("id")
                                                   .HavingType(PrimitiveTypes.Integer())
                                                   .WithDefault(SqlExpression.FunctionCall("UNIQUEKEY",
                                                                                           new SqlExpression[] { SqlExpression.Constant(tableName.FullName) })))
                                       .WithColumn("first_name", PrimitiveTypes.String())
                                       .WithColumn("last_name", PrimitiveTypes.String())
                                       .WithColumn("birth_date", PrimitiveTypes.DateTime())
                                       .WithColumn("active", PrimitiveTypes.Boolean()));

            query.Access().AddPrimaryKey(tableName, "id", "PK_TEST_TABLE");
        }
        public void StringToDate()
        {
            var toDate = SqlExpression.FunctionCall("TODATE", new[] { SqlExpression.Constant(Field.String("2016-01-20")) });

            var returnType = toDate.ReturnType(null, null);

            Assert.IsInstanceOf <DateType>(returnType);

            var evaluated = toDate.Evaluate();

            Assert.IsNotNull(evaluated);
            Assert.IsInstanceOf <SqlConstantExpression>(evaluated);

            var constExpr = (SqlConstantExpression)evaluated;

            Assert.IsNotNull(constExpr.Value);
            Assert.IsInstanceOf <DateType>(constExpr.Value.Type);

            var date = (SqlDateTime)constExpr.Value.Value;

            Assert.AreEqual(2016, date.Year);
            Assert.AreEqual(1, date.Month);
            Assert.AreEqual(20, date.Day);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Visits the expression that calls the function defined.
        /// </summary>
        /// <param name="expression">The <see cref="SqlFunctionCallExpression"/> to visit.</param>
        /// <returns></returns>
        public virtual SqlExpression VisitFunctionCall(SqlFunctionCallExpression expression)
        {
            var ags = VisitExpressionList(expression.Arguments);

            return(SqlExpression.FunctionCall(expression.FunctioName, ags));
        }