Ejemplo n.º 1
0
        public void Function_Name_Only()
        {
            IFunction func = (IFunction)sql.Val(() => SqlExp.Function("NOW"));

            QueryResult result = engine.Compile(func);

            Assert.Equal("NOW()", result.Sql);
            Assert.Equal(new Dictionary <string, object>(), result.Parameters);
        }
        public void Function()
        {
            Person person = new Person();

            Exception ex = Assert.Throws <InvalidOperationException>(() =>
                                                                     SqlExp.Function("CONCAT", person.Name, person.SurName));

            Assert.Equal("Only for expressions.", ex.Message);
        }
        public void Cast_Invalid()
        {
            engine.AddFunction(FunctionName.Cast, FunctionHelper.Cast);

            IFunction func = (IFunction)sql.Val(() => SqlExp.Function("CAST"));

            Exception ex = Assert.Throws <CompileException>(() => engine.Compile(func));

            Assert.Equal("Invalid function \"CAST\", wrong number of parameters.", ex.Message);
        }
        public void Not_Supported()
        {
            engine.AddFunction("LASTINSERTID", FunctionHelper.NotSupported);

            IFunction func = (IFunction)sql.Val(() => SqlExp.Function("LASTINSERTID"));

            Exception ex = Assert.Throws <ClauseNotSupportedException>(() => engine.Compile(func));

            Assert.Equal("Function \"LASTINSERTID\" is not supported in this engine.", ex.Message);
        }
Ejemplo n.º 5
0
        public void Function()
        {
            Person    person = null;
            IFunction func   = (IFunction)sql.Val(() => SqlExp.Function("CONCAT", person.Name, person.SurName));

            QueryResult result = engine.Compile(func);

            Assert.Equal("CONCAT(\"person\".\"Name\", \"person\".\"SurName\")", result.Sql);
            Assert.Equal(new Dictionary <string, object>(), result.Parameters);
        }
        public void TrimTrailing_Invalid()
        {
            engine.AddFunction(FunctionName.RTrim, FunctionHelper.TrimTrailing);

            Person    person = null;
            IFunction func   = (IFunction)sql.Val(() => SqlExp.Function("RTRIM", person.Name, ",", ","));

            Exception ex = Assert.Throws <CompileException>(() => engine.Compile(func));

            Assert.Equal("Invalid function \"RTRIM\", wrong number of parameters.", ex.Message);
        }
        public void NameOnly_Invalid()
        {
            engine.AddFunction("SYSDATE", FunctionHelper.NameOnly);

            Person    person = null;
            IFunction func   = (IFunction)sql.Val(() => SqlExp.Function("SYSDATE", person.Name));

            Exception ex = Assert.Throws <CompileException>(() => engine.Compile(func));

            Assert.Equal("Invalid function \"SYSDATE\", wrong number of parameters.", ex.Message);
        }
        public void NameOnly()
        {
            engine.AddFunction("SYSDATE", FunctionHelper.NameOnly);

            IFunction func = (IFunction)sql.Val(() => SqlExp.Function("SYSDATE"));

            QueryResult result = engine.Compile(func);

            Assert.Equal("SYSDATE", result.Sql);
            Assert.Equal(new Dictionary <string, object>(), result.Parameters);
        }
Ejemplo n.º 9
0
        public void Translation()
        {
            engine.AddFunction("CUSTOM", "TRANSLATED");

            Person    person = null;
            IFunction func   = (IFunction)sql.Val(() => SqlExp.Function("CUSTOM", person.Name, ", ", person.SurName));

            QueryResult result = engine.Compile(func);

            Assert.Equal("TRANSLATED(\"person\".\"Name\", @p0, \"person\".\"SurName\")", result.Sql);
            Assert.Equal(new Dictionary <string, object>
            {
                ["@p0"] = ", "
            }, result.Parameters);
        }
Ejemplo n.º 10
0
        public void Delegate_Translation_Empty()
        {
            engine.AddFunction("CAST", null, (queryBuilder, engine, name, fn) =>
            {
                queryBuilder.Write(name + "(");
                queryBuilder.WriteValue(fn.Args[0]);
                queryBuilder.Write(" AS ");
                queryBuilder.WriteValue(fn.Args[1]);
                queryBuilder.Write(")");
            });

            Person    person = null;
            IFunction func   = (IFunction)sql.Val(() => SqlExp.Function("CAST", person.Salary, sql.Type("VARCHAR")));

            QueryResult result = engine.Compile(func);

            Assert.Equal("CAST(\"person\".\"Salary\" AS VARCHAR)", result.Sql);
            Assert.Equal(new Dictionary <string, object>(), result.Parameters);
        }
Ejemplo n.º 11
0
        public void Only_Registered()
        {
            engine.Options.FunctionsOnlyRegistered = true;

            Person    person = null;
            IFunction func   = (IFunction)sql.Val(() => SqlExp.Function("CONCAT", person.Name, ", ", person.SurName));

            Exception ex = Assert.Throws <InvalidConfigurationException>(() => engine.Compile(func));

            Assert.Equal("Function \"CONCAT\" is not registered.", ex.Message);

            engine.AddFunction("CONCAT");
            QueryResult result = engine.Compile(func);

            Assert.Equal("CONCAT(\"person\".\"Name\", @p0, \"person\".\"SurName\")", result.Sql);
            Assert.Equal(new Dictionary <string, object>
            {
                ["@p0"] = ", "
            }, result.Parameters);
        }
        public void Function_Name_Only()
        {
            Exception ex = Assert.Throws <InvalidOperationException>(() => SqlExp.Function("NOW"));

            Assert.Equal("Only for expressions.", ex.Message);
        }