예제 #1
0
        public void ArgsDiffParams()
        {
            SQLFunctionTemplate ft;
            IList args = new ArrayList();

            // No Args; 2 params
            ft = new SQLFunctionTemplate(NHibernateUtil.String, "func(?1,?2)");
            Assert.AreEqual("func(,)", ft.Render(args, factoryImpl).ToString());

            // Args<params
            args.Clear();
            ft = new SQLFunctionTemplate(NHibernateUtil.String, "func(?1,?2)");
            args.Add(1);
            Assert.AreEqual("func(1,)", ft.Render(args, factoryImpl).ToString());

            // Args>params
            args.Clear();
            ft = new SQLFunctionTemplate(NHibernateUtil.String, "func(?1,?3)");
            args.Add(1);
            args.Add(2);
            args.Add(3);
            Assert.AreEqual("func(1,3)", ft.Render(args, factoryImpl).ToString());

            // Args in different position
            args.Clear();
            ft = new SQLFunctionTemplate(NHibernateUtil.String, "func(?2, ?1, ?3)");
            args.Add(1);
            args.Add(2);
            args.Add(3);
            Assert.AreEqual("func(2, 1, 3)", ft.Render(args, factoryImpl).ToString());
        }
예제 #2
0
        public MsSql2012GeometryDialect()
        {
            IType type = NHibernateUtil.GuessType(typeof(Guid));
            SQLFunctionTemplate template = new SQLFunctionTemplate(type, "NEWID()");

            RegisterFunction("guid", template);
        }
예제 #3
0
        public static ISQLFunction RegisterFunction <T>(this ISessionFactory factory, String name, String sql)
        {
            IType        type     = NHibernateUtil.GuessType(typeof(T));
            ISQLFunction function = new SQLFunctionTemplate(type, sql);

            RegisterFunction(factory, name, function);
            return(function);
        }
    private static ISQLFunction GetDateDiffFunction(string datepart)
    {
        ISQLFunction sqlFunction;

        if (!DateDiffFunctionCache.TryGetValue(datepart, out sqlFunction))
        {
            string functionTemplate = string.Format(DateDiffFormat, datepart);
            sqlFunction = new SQLFunctionTemplate(NHibernateUtil.Int32, functionTemplate);

            DateDiffFunctionCache[datepart] = sqlFunction;
        }
        return(sqlFunction);
    }
예제 #5
0
        private static ISQLFunction GetGetDateFunction()
        {
            ISQLFunction sqlFunction;

            if (!DateDiffFunctionCache.TryGetValue("getdate", out sqlFunction))
            {
                string functionTemplate = "getdate()";
                sqlFunction = new SQLFunctionTemplate(NHibernateUtil.DateTime, functionTemplate);
                DateDiffFunctionCache["getdate"] = sqlFunction;
            }

            return(sqlFunction);
        }
예제 #6
0
        //[Test] not required
        public void NoStringArguments()
        {
            SQLFunctionTemplate ft;
            IList args = new ArrayList();

            ft = new SQLFunctionTemplate(NHibernateUtil.String, "?1 ?2 ?3");
            args.Add(DateTime.Today);
            args.Add(125.6D);
            args.Add(0910.123456m);
            string expected = string.Format("{0} {1} {2}",
                                            DateTime.Today.ToString(DateTimeFormatInfo.InvariantInfo),
                                            (125.6D).ToString(NumberFormatInfo.InvariantInfo),
                                            (0910.123456m).ToString(NumberFormatInfo.InvariantInfo));

            Assert.AreEqual(expected, ft.Render(args, factoryImpl).ToString());
        }
예제 #7
0
        public void RepetedParams()
        {
            SQLFunctionTemplate ft;
            IList args = new ArrayList();

            ft =
                new SQLFunctionTemplate(NHibernateUtil.String,
                                        "replace( replace( rtrim( replace( replace( ?1, ' ', '${space}$' ), ?2, ' ' ) ), ' ', ?2 ), '${space}$', ' ' )");
            args.Add("'param1  '");
            args.Add("'param2 ab '");
            Assert.AreEqual(
                "replace( replace( rtrim( replace( replace( 'param1  ', ' ', '${space}$' ), 'param2 ab ', ' ' ) ), ' ', 'param2 ab ' ), '${space}$', ' ' )",
                ft.Render(args, factoryImpl).ToString());

            args.Clear();
            ft = new SQLFunctionTemplate(NHibernateUtil.String, "?1 ?3 ?2 ?3 ?1");
            args.Add(1);
            args.Add(2);
            args.Add(3);
            Assert.AreEqual("1 3 2 3 1", ft.Render(args, factoryImpl).ToString());
        }
예제 #8
0
        public void Simple()
        {
            SQLFunctionTemplate ft = new SQLFunctionTemplate(NHibernateUtil.String, "ltrim( ?1 )");

            Assert.IsTrue(ft.HasArguments);
            IList args = new ArrayList();

            args.Add("'abcd   <'");
            Assert.AreEqual("ltrim( 'abcd   <' )", ft.Render(args, factoryImpl).ToString());

            ft = new SQLFunctionTemplate(NHibernateUtil.String, "ltrim( Az?ab )");
            Assert.IsFalse(ft.HasArguments);
            Assert.AreEqual("ltrim( Az?ab )", ft.Render(args, factoryImpl).ToString());

            ft = new SQLFunctionTemplate(NHibernateUtil.String, "function( ?1 )? 5:6");
            Assert.IsTrue(ft.HasArguments);
            Assert.AreEqual("function( 'abcd   <' )? 5:6", ft.Render(args, factoryImpl).ToString());

            ft = new SQLFunctionTemplate(NHibernateUtil.String, "????????1?");
            Assert.IsTrue(ft.HasArguments);
            Assert.AreEqual("???????'abcd   <'?", ft.Render(args, factoryImpl).ToString());
        }