Esempio n. 1
0
        public static void DbFunctions_ADD_MONTHS()
        {
            DbFunctionTools tools = new DbFunctionTools();

            //String,Int32.
            {
                Console.WriteLine("Testing DbFunctions.ADD_MONTHS...");

                List <DbValue> args   = new List <DbValue>();
                DateTime       dt     = DateTime.Now;
                int            months = 9;
                args.Add(tools.AllocValue(dt));
                args.Add(tools.AllocValue(months));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ADD_MONTHS(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                DateTime  output    = tools.GetDateTime(bs);

                DateTime expected = dt.AddMonths(months);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ADD_MONTHS has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 2
0
        public static void DbFunctions_RIGHT()
        {
            DbFunctionTools tools = new DbFunctionTools();

            //String,Int32.
            {
                Console.WriteLine("Testing DbFunctions.RIGHT(String,Int32)...");

                mstring        input = Utils.GenString(100);
                List <DbValue> args  = new List <DbValue>();
                args.Add(tools.AllocValue(input));
                args.Add(tools.AllocValue(5));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.RIGHT(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                mstring   output    = tools.GetString(bs);

                string str      = input.ToString();
                string expected = str.Substring(str.Length - 5, 5);

                if (expected != output.ToString())
                {
                    throw new Exception("DbFunctions.RIGHT(String,Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 3
0
        public static void DbFunctions_CONCAT()
        {
            DbFunctionTools tools = new DbFunctionTools();

            //String,Int32.
            {
                Console.WriteLine("Testing DbFunctions.CONCAT(String,String)...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("hello ")));
                args.Add(tools.AllocValue(mstring.Prepare("world")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.CONCAT(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                mstring   output    = tools.GetString(bs);

                mstring expected = mstring.Prepare("hello world");

                if (expected != output)
                {
                    throw new Exception("DbFunctions.CONCAT(String,String) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 4
0
        public static void DbFunctions_SUBSTRING()
        {
            DbFunctionTools tools = new DbFunctionTools();

            //String,Int32.
            {
                Console.WriteLine("Testing DbFunctions.SUBSTRING(String, int, int)...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("HELLO WORLD")));
                int si  = 6;
                int len = 5;
                args.Add(tools.AllocValue(si));
                args.Add(tools.AllocValue(len));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.SUBSTRING(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                mstring   output    = tools.GetString(bs);

                mstring expected = mstring.Prepare("WORLD");

                if (expected != output)
                {
                    throw new Exception("DbFunctions.SUBSTRING(String, int, int) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 5
0
        public static void DbFunctions_PATINDEX()
        {
            DbFunctionTools tools = new DbFunctionTools();

            //String,Int32.
            {
                Console.WriteLine("Testing DbFunctions.PATINDEX(String, string)...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("%ap_pl[e]%")));
                args.Add(tools.AllocValue(mstring.Prepare("red is ap5ple, my favourite.")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.PATINDEX(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 7;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.PATINDEX(String) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 6
0
        public static void DbFunctions_CHARINDEX()
        {
            DbFunctionTools tools = new DbFunctionTools();

            //String,Int32.
            {
                Console.WriteLine("Testing DbFunctions.CHARINDEX(char(n), char(n)...");

                mstring        word     = mstring.Prepare("apple");
                mstring        sentence = mstring.Prepare("Red is apple");
                List <DbValue> args     = new List <DbValue>();
                args.Add(tools.AllocValue(word));
                args.Add(tools.AllocValue(sentence));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.CHARINDEX(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 7;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.CHARINDEX(char(n), char(n) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.CHARINDEX(char(n), char(n), Int32...");

                mstring        word       = mstring.Prepare("apple");
                mstring        sentence   = mstring.Prepare("Red is apple, or more apples.");
                int            startIndex = 8;
                List <DbValue> args       = new List <DbValue>();
                args.Add(tools.AllocValue(word));
                args.Add(tools.AllocValue(sentence));
                args.Add(tools.AllocValue(startIndex));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.CHARINDEX(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 22;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.CHARINDEX(char(n), char(n), Int32 has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 7
0
        public static void DbFunctions_NVL()
        {
            DbFunctionTools tools = new DbFunctionTools();

            {
                Console.WriteLine("Testing DbFunctions.NVL(DateTime)...");

                List <DbValue> args = new List <DbValue>();
                DateTime       dt   = DateTime.Parse("12/1/2000 10:00:00 AM");
                args.Add(tools.AllocValue(dt));
                args.Add(tools.AllocValue(DateTime.Parse("12/12/2000 10:00:00 AM")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.NVL(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                DateTime  output    = tools.GetDateTime(bs);

                DateTime expected = DateTime.Parse("12/1/2000 10:00:00 AM");

                if (expected != output)
                {
                    throw new Exception("DbFunctions.NVL(DateTime) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.NVL(DateTime)...");

                List <DbValue> args = new List <DbValue>();

                byte[] buf = new byte[9];
                buf[0] = 1; //is null
                args.Add(tools.AllocValue(ByteSlice.Prepare(buf), DbType.Prepare("DateTime", 9)));
                args.Add(tools.AllocValue(DateTime.Parse("1/1/2009 10:00:00 AM")));
                DbFunctionArguments fargs     = new DbFunctionArguments(args);
                DbValue             valOutput = DbFunctions.NVL(tools, fargs);
                ByteSlice           bs        = valOutput.Eval();
                DateTime            output    = tools.GetDateTime(bs);

                DateTime expected = DateTime.Parse("1/1/2009 10:00:00 AM");

                if (expected != output)
                {
                    throw new Exception("DbFunctions.NVL(DateTime) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 8
0
        public static void DbFunctions_INSTR()
        {
            DbFunctionTools tools = new DbFunctionTools();

            {
                Console.WriteLine("Testing DbFunctions.SUBSTR(String,String)...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("apple is red")));
                args.Add(tools.AllocValue(mstring.Prepare("red")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.INSTR(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 9;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.SUBSTR(String,String) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.SUBSTR(String,String, Int32)...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("apple is red")));
                args.Add(tools.AllocValue(mstring.Prepare("red")));
                int startindex = 2;
                args.Add(tools.AllocValue(startindex));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.INSTR(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 9;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.SUBSTR(String,String, Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 9
0
        public static void DbFunctions_RAND()
        {
            DbFunctionTools tools = new DbFunctionTools();
            Random          rnd   = new Random();


            {
                Console.WriteLine("Testing DbFunctions.RAND(Int32)...");

                int input = rnd.Next(Int32.MinValue, Int32.MaxValue);

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(input));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.RAND(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                Console.WriteLine("Expected results received: {0}", output);
            }

            {
                Console.WriteLine("Testing DbFunctions.RAND()...");

                List <DbValue>      args  = new List <DbValue>();
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.RAND(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                Console.WriteLine("Expected results received: {0}", output);
            }
        }
Esempio n. 10
0
        public static void DbFunctions_LAST_DAY()
        {
            DbFunctionTools tools = new DbFunctionTools();

            //String,Int32.
            {
                Console.WriteLine("Testing DbFunctions.LAST_DAY...");

                List <DbValue> args = new List <DbValue>();
                DateTime       dt   = DateTime.Parse("12/1/2000 10:00:00 AM");
                args.Add(tools.AllocValue(dt));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.LAST_DAY(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                DateTime  output    = tools.GetDateTime(bs);

                DateTime expected = DateTime.Parse("12/31/2000 10:00:00 AM");

                if (expected != output)
                {
                    throw new Exception("DbFunctions.LAST_DAY has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 11
0
        public static void DbFunctions_ROUND()
        {
            DbFunctionTools tools = new DbFunctionTools();
            Random          rnd   = new Random();

            //Double.
            {
                Console.WriteLine("Testing DbFunctions.ROUND(Double, Int32)...");

                double input = rnd.NextDouble();

                if (input < 0.5)
                {
                    input = input * -1d;
                }

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(input));
                args.Add(tools.AllocValue(3));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ROUND(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = Math.Round(input, 3);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ROUND(Double, Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 12
0
        public static void DbAggregators_VAR_SAMP()
        {
            DbFunctionTools tools    = new DbFunctionTools();
            Random          rnd      = new Random();
            const int       rowcount = 20;

            double[] values = new double[rowcount];

            //Double.
            {
                Console.WriteLine("Testing DbAggregators_VAR_SAMP(Double)...");

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                for (int i = 0; i < fargs.Length; i++)
                {
                    double input = rnd.NextDouble();
                    if (input < 0.5)
                    {
                        input = input * -1d;
                    }
                    values[i] = input;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.VAR_SAMP(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);
                double    expected  = var(values, true);
                if (expected != output)
                {
                    throw new Exception("DbAggregators_VAR_SAMP(Double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_VAR_SAMP(Int32)...");

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                for (int i = 0; i < fargs.Length; i++)
                {
                    int input = rnd.Next(Int32.MinValue, Int32.MaxValue);
                    values[i] = (double)input;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.VAR_SAMP(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);
                double    expected  = var(values, true);
                if (expected != output)
                {
                    throw new Exception("DbAggregators_VAR_SAMP(Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_VAR_SAMP(Int64)...");

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                for (int i = 0; i < fargs.Length; i++)
                {
                    long input = DateTime.Now.Ticks;
                    if (input % 2 == 0)
                    {
                        input = input * -1;
                    }
                    values[i] = (double)input;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.VAR_SAMP(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);
                double    expected  = var(values, true);
                if (expected != output)
                {
                    throw new Exception("DbAggregators_VAR_SAMP(Int64) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 13
0
        public static void DbFunctions_ABS()
        {
            DbFunctionTools tools = new DbFunctionTools();
            Random          rnd   = new Random();

            //Int32.
            {
                Console.WriteLine("Testing DbFunctions.ABS(Int32)...");

                int            input    = rnd.Next(Int32.MinValue, Int32.MaxValue);
                DbValue        valInput = tools.AllocValue(input);
                List <DbValue> args     = new List <DbValue>();
                args.Add(valInput);
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ABS(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = Math.Abs(input);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ABS(Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            //Int64.
            {
                Console.WriteLine("Testing DbFunctions.ABS(Int64)...");

                long input = DateTime.Now.Ticks - 1;
                if (input % 2 == 0)
                {
                    input = input * -1L;
                }

                DbValue        valInput = tools.AllocValue(input);
                List <DbValue> args     = new List <DbValue>();
                args.Add(valInput);
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ABS(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                byte[]    buf       = bs.ToBytes();
                long      output    = Entry.ToInt64(Entry.BytesToULong(buf, 1));

                long expected = Math.Abs(input);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ABS(Int64) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            //Double.
            {
                Console.WriteLine("Testing DbFunctions.ABS(Double)...");

                double input = rnd.NextDouble();

                if (input < 0.5)
                {
                    input = input * -1d;
                }

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(input));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ABS(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                byte[]    buf       = bs.ToBytes();
                double    output    = Entry.BytesToDouble(buf, 1);

                double expected = Math.Abs(input);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ABS(Double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 14
0
        public static void DbFunctions_ISNOTNULL()
        {
            DbFunctionTools tools = new DbFunctionTools();
            Random          rnd   = new Random();

            {
                Console.WriteLine("Testing DbFunctions.ISNOTNULL(char(n))...");

                {
                    mstring s1 = Utils.GenString(rnd.Next(1, 200));

                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(s1));
                    DbFunctionArguments fargs = new DbFunctionArguments(args);

                    DbValue   valOutput = DbFunctions.ISNOTNULL(tools, fargs);
                    ByteSlice bs        = valOutput.Eval();
                    bool      output    = tools.GetInt(bs) != 0;

                    bool expected = !false;

                    if (expected != output)
                    {
                        throw new Exception("DbFunctions.ISNOTNULL(char(n)='" + s1.ToString() + "') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                    }
                    else
                    {
                        Console.WriteLine("Expected results received.");
                    }
                }

                {
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(ByteSlice.Prepare(new byte[] { 1 }), DbTypeID.CHARS));
                    DbFunctionArguments fargs = new DbFunctionArguments(args);

                    DbValue   valOutput = DbFunctions.ISNOTNULL(tools, fargs);
                    ByteSlice bs        = valOutput.Eval();
                    bool      output    = tools.GetInt(bs) != 0;

                    bool expected = !true;

                    if (expected != output)
                    {
                        throw new Exception("DbFunctions.ISNOTNULL(char(n)=NULL) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                    }
                    else
                    {
                        Console.WriteLine("Expected results received.");
                    }
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.ISNOTNULL(Int32)...");

                {
                    int x = rnd.Next(Int32.MinValue, Int32.MaxValue);

                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(x));
                    DbFunctionArguments fargs = new DbFunctionArguments(args);

                    DbValue   valOutput = DbFunctions.ISNOTNULL(tools, fargs);
                    ByteSlice bs        = valOutput.Eval();
                    bool      output    = tools.GetInt(bs) != 0;

                    bool expected = !false;

                    if (expected != output)
                    {
                        throw new Exception("DbFunctions.ISNOTNULL(Int32=" + x.ToString() + ") has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                    }
                    else
                    {
                        Console.WriteLine("Expected results received.");
                    }
                }

                {
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(ByteSlice.Prepare(new byte[] { 1 }), DbTypeID.INT));
                    DbFunctionArguments fargs = new DbFunctionArguments(args);

                    DbValue   valOutput = DbFunctions.ISNOTNULL(tools, fargs);
                    ByteSlice bs        = valOutput.Eval();
                    bool      output    = tools.GetInt(bs) != 0;

                    bool expected = !true;

                    if (expected != output)
                    {
                        throw new Exception("DbFunctions.ISNOTNULL(Int32=NULL) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                    }
                    else
                    {
                        Console.WriteLine("Expected results received.");
                    }
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.ISNOTNULL(Double)...");

                {
                    double x = rnd.NextDouble();

                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(x));
                    DbFunctionArguments fargs = new DbFunctionArguments(args);

                    DbValue   valOutput = DbFunctions.ISNOTNULL(tools, fargs);
                    ByteSlice bs        = valOutput.Eval();
                    bool      output    = tools.GetInt(bs) != 0;

                    bool expected = !false;

                    if (expected != output)
                    {
                        throw new Exception("DbFunctions.ISNOTNULL(Double=" + x.ToString() + ") has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                    }
                    else
                    {
                        Console.WriteLine("Expected results received.");
                    }
                }

                {
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(ByteSlice.Prepare(new byte[] { 1 }), DbTypeID.DOUBLE));
                    DbFunctionArguments fargs = new DbFunctionArguments(args);

                    DbValue   valOutput = DbFunctions.ISNOTNULL(tools, fargs);
                    ByteSlice bs        = valOutput.Eval();
                    bool      output    = tools.GetInt(bs) != 0;

                    bool expected = !true;

                    if (expected != output)
                    {
                        throw new Exception("DbFunctions.ISNOTNULL(Double=NULL) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                    }
                    else
                    {
                        Console.WriteLine("Expected results received.");
                    }
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.ISNOTNULL(Long)...");

                {
                    long x = DateTime.Now.Ticks;

                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(x));
                    DbFunctionArguments fargs = new DbFunctionArguments(args);

                    DbValue   valOutput = DbFunctions.ISNOTNULL(tools, fargs);
                    ByteSlice bs        = valOutput.Eval();
                    bool      output    = tools.GetInt(bs) != 0;

                    bool expected = !false;

                    if (expected != output)
                    {
                        throw new Exception("DbFunctions.ISNOTNULL(Long=" + x.ToString() + ") has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                    }
                    else
                    {
                        Console.WriteLine("Expected results received.");
                    }
                }

                {
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(ByteSlice.Prepare(new byte[] { 1 }), DbTypeID.LONG));
                    DbFunctionArguments fargs = new DbFunctionArguments(args);

                    DbValue   valOutput = DbFunctions.ISNOTNULL(tools, fargs);
                    ByteSlice bs        = valOutput.Eval();
                    bool      output    = tools.GetInt(bs) != 0;

                    bool expected = !true;

                    if (expected != output)
                    {
                        throw new Exception("DbFunctions.ISNOTNULL(Long=NULL) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                    }
                    else
                    {
                        Console.WriteLine("Expected results received.");
                    }
                }
            }
        }
Esempio n. 15
0
        public static void DbFunctions_NULLIF()
        {
            DbFunctionTools tools = new DbFunctionTools();

            {
                Console.WriteLine("Testing DbFunctions.NULLIF(DateTime, DateTime)...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(DateTime.Parse("12/1/2000 10:00:00 AM")));
                args.Add(tools.AllocValue(DateTime.Parse("12/1/2000 10:00:00 AM")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.NULLIF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                bool      output    = Types.IsNullValue(bs);
                bool      expected  = true;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.NULLIF(DateTime, DateTime) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.NULLIF(DateTime, DateTime)...");

                List <DbValue> args = new List <DbValue>();
                DateTime       dt   = DateTime.Parse("12/1/2000 10:00:00 AM");
                args.Add(tools.AllocValue(dt));
                args.Add(tools.AllocValue(DateTime.Parse("12/2/2000 10:00:00 AM")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.NULLIF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                DateTime  output    = tools.GetDateTime(bs);
                DateTime  expected  = dt;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.NULLIF(DateTime, DateTime) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.NULLIF(Int32, Int32)...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(10));
                args.Add(tools.AllocValue(10));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.NULLIF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                bool      output    = Types.IsNullValue(bs);
                bool      expected  = true;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.NULLIF(Int32, Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.NULLIF(Int32, Int32)...");

                List <DbValue> args = new List <DbValue>();
                int            x    = 10;
                args.Add(tools.AllocValue(x));
                args.Add(tools.AllocValue(11));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.NULLIF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);
                int       expected  = x;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.NULLIF(Int32, Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.NULLIF(Int32, long)...");

                List <DbValue> args = new List <DbValue>();
                int            x    = 10;
                long           y    = 10;
                args.Add(tools.AllocValue(x));
                args.Add(tools.AllocValue(y));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.NULLIF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                bool      output    = Types.IsNullValue(bs);
                bool      expected  = true;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.NULLIF(Int32, long) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.NULLIF(Int32, long)...");

                List <DbValue> args = new List <DbValue>();
                int            x    = 10;
                long           y    = 11;
                args.Add(tools.AllocValue(x));
                args.Add(tools.AllocValue(y));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.NULLIF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);
                int       expected  = x;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.NULLIF(Int32, long) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 16
0
        public static void DbFunctions_ARITHMETIC()
        {
            DbFunctionTools tools = new DbFunctionTools();
            Random          rnd   = new Random();

            //Int32.
            {
                Console.WriteLine("Testing DbFunctions.ADD(Int32, Int32)...");

                int            input1 = rnd.Next(Int32.MinValue, Int32.MaxValue);
                int            input2 = rnd.Next(Int32.MinValue, Int32.MaxValue);
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ADD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = input1 + input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ADD(Int32, Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
            {
                Console.WriteLine("Testing DbFunctions.SUB(Int32, Int32)...");

                int            input1 = rnd.Next(Int32.MinValue, Int32.MaxValue);
                int            input2 = rnd.Next(Int32.MinValue, Int32.MaxValue);
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.SUB(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = input1 - input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.SUB(Int32, Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
            {
                Console.WriteLine("Testing DbFunctions.MUL(Int32, Int32)...");

                int            input1 = rnd.Next(Int32.MinValue, Int32.MaxValue);
                int            input2 = rnd.Next(Int32.MinValue, Int32.MaxValue);
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MUL(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = input1 * input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MUL(Int32, Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
            {
                Console.WriteLine("Testing DbFunctions.DIV(Int32, Int32)...");

                int            input1 = rnd.Next(Int32.MinValue, Int32.MaxValue);
                int            input2 = rnd.Next(Int32.MinValue, Int32.MaxValue);
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DIV(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = input1 / input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DIV(Int32, Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            // Int32, Int64
            {
                Console.WriteLine("Testing DbFunctions.ADD(Int32, Int64)...");

                int            input1 = rnd.Next(Int32.MinValue, Int32.MaxValue);
                long           input2 = (long)rnd.Next(Int32.MinValue, Int32.MaxValue) * rnd.Next();
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ADD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);

                long expected = input1 + input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ADD(Int32, Int64) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            //Int64.
            {
                Console.WriteLine("Testing DbFunctions.ADD(Int64, Int64)...");

                long           input1 = (long)rnd.Next(Int32.MinValue, Int32.MaxValue) * rnd.Next();
                long           input2 = (long)rnd.Next(Int32.MinValue, Int32.MaxValue) * rnd.Next();
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ADD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);

                long expected = input1 + input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ADD(Int64, Int64) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
            {
                Console.WriteLine("Testing DbFunctions.SUB(Int64, Int64)...");

                long           input1 = (long)rnd.Next(Int32.MinValue, Int32.MaxValue) * rnd.Next();
                long           input2 = (long)rnd.Next(Int32.MinValue, Int32.MaxValue) * rnd.Next();
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.SUB(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);

                long expected = input1 - input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.SUB(Int64, Int64) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
            {
                Console.WriteLine("Testing DbFunctions.MUL(Int64, Int64)...");

                long           input1 = (long)rnd.Next(Int32.MinValue, Int32.MaxValue) * rnd.Next();
                long           input2 = (long)rnd.Next(Int32.MinValue, Int32.MaxValue) * rnd.Next();
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MUL(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);

                long expected = input1 * input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MUL(Int64, Int64) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
            {
                Console.WriteLine("Testing DbFunctions.DIV(Int64, Int64)...");

                long           input1 = (long)rnd.Next(Int32.MinValue, Int32.MaxValue) * rnd.Next();
                long           input2 = (long)rnd.Next(Int32.MinValue, Int32.MaxValue) * rnd.Next();
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DIV(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);

                long expected = input1 / input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DIV(Int64, Int64) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            // Int64, Int32
            {
                Console.WriteLine("Testing DbFunctions.SUB(Int64, Int32)...");

                long           input1 = (long)rnd.Next(Int32.MinValue, Int32.MaxValue) * rnd.Next();
                int            input2 = rnd.Next(Int32.MinValue, Int32.MaxValue);
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.SUB(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);

                long expected = input1 - input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.SUB(Int64, Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            //double.
            {
                Console.WriteLine("Testing DbFunctions.ADD(double, double)...");

                double         input1 = rnd.NextDouble() * rnd.Next(int.MinValue, int.MaxValue);
                double         input2 = rnd.NextDouble() * rnd.Next(int.MinValue, int.MaxValue);
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ADD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = input1 + input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ADD(double, double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
            {
                Console.WriteLine("Testing DbFunctions.SUB(double, double)...");

                double         input1 = rnd.NextDouble() * rnd.Next(int.MinValue, int.MaxValue);
                double         input2 = rnd.NextDouble() * rnd.Next(int.MinValue, int.MaxValue);
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.SUB(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = input1 - input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.SUB(double, double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
            {
                Console.WriteLine("Testing DbFunctions.MUL(double, double)...");

                double         input1 = rnd.NextDouble() * rnd.Next(int.MinValue, int.MaxValue);
                double         input2 = rnd.NextDouble() * rnd.Next(int.MinValue, int.MaxValue);
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MUL(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = input1 * input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MUL(double, double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
            {
                Console.WriteLine("Testing DbFunctions.DIV(double, double)...");

                double         input1 = rnd.NextDouble() * rnd.Next(int.MinValue, int.MaxValue);
                double         input2 = rnd.NextDouble() * rnd.Next(int.MinValue, int.MaxValue);
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DIV(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = input1 / input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DIV(double, double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            // double, Int32
            {
                Console.WriteLine("Testing DbFunctions.MUL(double, Int32)...");

                double         input1 = rnd.NextDouble() * rnd.Next(int.MinValue, int.MaxValue);
                int            input2 = rnd.Next(int.MinValue, int.MaxValue);
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MUL(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = input1 * input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MUL(double, Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            // Int64, double
            {
                Console.WriteLine("Testing DbFunctions.DIV(Int64, double)...");

                long           input1 = rnd.Next(int.MinValue, int.MaxValue) * rnd.Next();
                double         input2 = rnd.NextDouble() * rnd.Next(int.MinValue, int.MaxValue);
                List <DbValue> args   = new List <DbValue>();
                args.Add(tools.AllocValue(input1));
                args.Add(tools.AllocValue(input2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DIV(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = input1 / input2;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DIV(Int64, double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 17
0
        public static void DbFunctions_FORMAT()
        {
            DbFunctionTools tools = new DbFunctionTools();

            {
                Console.WriteLine("Testing DbFunctions.FORMAT('MM')...");

                List <DbValue> args      = new List <DbValue>();
                mstring        formatstr = mstring.Prepare("MM");
                args.Add(tools.AllocValue(formatstr));
                DateTime dt = new DateTime(2000, 9, 14, 12, 0, 0);
                args.Add(tools.AllocValue(dt));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.FORMAT(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                mstring   output    = tools.GetString(bs);
                mstring   expected  = mstring.Prepare(dt.ToString(formatstr.ToString()));

                if (expected != output)
                {
                    throw new Exception("DbFunctions.FORMAT('MM') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.FORMAT('dd')...");

                List <DbValue> args      = new List <DbValue>();
                mstring        formatstr = mstring.Prepare("dd");
                args.Add(tools.AllocValue(formatstr));
                DateTime dt = new DateTime(2000, 9, 14, 12, 0, 0);
                args.Add(tools.AllocValue(dt));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.FORMAT(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                mstring   output    = tools.GetString(bs);
                mstring   expected  = mstring.Prepare(dt.ToString(formatstr.ToString()));

                if (expected != output)
                {
                    throw new Exception("DbFunctions.FORMAT('dd') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.FORMAT('t')...");

                List <DbValue> args      = new List <DbValue>();
                mstring        formatstr = mstring.Prepare("t");
                args.Add(tools.AllocValue(formatstr));
                DateTime dt = new DateTime(2000, 9, 14, 12, 0, 0);
                args.Add(tools.AllocValue(dt));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.FORMAT(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                mstring   output    = tools.GetString(bs);
                mstring   expected  = mstring.Prepare(dt.ToString(formatstr.ToString()));

                if (expected != output)
                {
                    throw new Exception("DbFunctions.FORMAT('t') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 18
0
        public static void DbFunctions_MONTHS_BETWEEN()
        {
            DbFunctionTools tools = new DbFunctionTools();

            {
                Console.WriteLine("Testing DbFunctions.MONTHS_BETWEEN...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(DateTime.Parse("1/31/2000 10:00:00 AM")));
                args.Add(tools.AllocValue(DateTime.Parse("1/3/2000 10:00:00 AM")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MONTHS_BETWEEN(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = (double)(31 - 3) / (double)31;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MONTHS_BETWEEN has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.MONTHS_BETWEEN...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(DateTime.Parse("1/31/2000 10:00:00 AM")));
                args.Add(tools.AllocValue(DateTime.Parse("4/30/1999 10:00:00 AM")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MONTHS_BETWEEN(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = 9;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MONTHS_BETWEEN has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.MONTHS_BETWEEN...");

                List <DbValue> args = new List <DbValue>();
                DateTime       d0   = DateTime.Parse("1/31/2000 10:00:00 AM");
                DateTime       d1   = DateTime.Parse("4/1/1999 10:00:00 AM");
                args.Add(tools.AllocValue(d0));
                args.Add(tools.AllocValue(d1));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MONTHS_BETWEEN(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                TimeSpan sp       = d0 - d1;
                double   expected = sp.TotalDays / 31d;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MONTHS_BETWEEN has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 19
0
        public static void DbFunctions_ISLIKE()
        {
            DbFunctionTools tools = new DbFunctionTools();

            {
                Console.WriteLine("Testing positive DbFunctions.ISLIKE(String,'%xxx')...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("red apple")));
                args.Add(tools.AllocValue(mstring.Prepare("%apple")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ISLIKE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 1;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ISLIKE(String,'%xxx') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing case-insensitive positive DbFunctions.ISLIKE(String,'%xxx')...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("red apple")));
                args.Add(tools.AllocValue(mstring.Prepare("%Apple")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ISLIKE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 1;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ISLIKE(String,'%xxx') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing negative DbFunctions.ISLIKE(String,'%xxx')...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("red aple")));
                args.Add(tools.AllocValue(mstring.Prepare("%apple")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ISLIKE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 0;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ISLIKE(String,'%xxx') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing positive DbFunctions.ISLIKE(String,'xx_x')...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("apple")));
                args.Add(tools.AllocValue(mstring.Prepare("app_e")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ISLIKE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 1;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ISLIKE(String,'xx_x') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing negative DbFunctions.ISLIKE(String,'xx_x')...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("applle")));
                args.Add(tools.AllocValue(mstring.Prepare("app_e")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ISLIKE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 0;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ISLIKE(String,'xx_x') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing positive DbFunctions.ISLIKE(String,'xx[a-d]xx')...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("comater")));
                args.Add(tools.AllocValue(mstring.Prepare("com[a-d]ter")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ISLIKE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 1;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ISLIKE(String,'xx[a-d]xx') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing negative DbFunctions.ISLIKE(String,'xx[a-d]xx')...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("comxter")));
                args.Add(tools.AllocValue(mstring.Prepare("com[a-d]ter")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ISLIKE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 0;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ISLIKE(String,'xx[a-d]xx') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing positive DbFunctions.ISLIKE(String,'xx[^a-d]xx')...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("comxter")));
                args.Add(tools.AllocValue(mstring.Prepare("com[^a-d]ter")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ISLIKE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 1;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ISLIKE(String,'xx[a-d]xx') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing negative DbFunctions.ISLIKE(String,'xx[^a-d]xx')...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("comater")));
                args.Add(tools.AllocValue(mstring.Prepare("com[^a-d]ter")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ISLIKE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 0;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ISLIKE(String,'xx[a-d]xx') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            //Using Wildcard Characters As Literals
            {
                Console.WriteLine("Testing positive DbFunctions.ISLIKE(String,'x[%]')...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("5%")));
                args.Add(tools.AllocValue(mstring.Prepare("5[%]")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ISLIKE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 1;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ISLIKE(String,'x[%]') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing negative DbFunctions.ISLIKE(String,'x[%]')...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("54")));
                args.Add(tools.AllocValue(mstring.Prepare("5[%]")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ISLIKE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 0;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ISLIKE(String,'x[%]') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing positive DbFunctions.ISLIKE(String,'[_]n')...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("_n")));
                args.Add(tools.AllocValue(mstring.Prepare("[_]n")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ISLIKE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 1;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ISLIKE(String,'x[%]') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing negative DbFunctions.ISLIKE(String,'[_]n')...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("n")));
                args.Add(tools.AllocValue(mstring.Prepare("[_]n")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ISLIKE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 0;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ISLIKE(String,'[_]n') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing positive DbFunctions.ISLIKE(String,'[-acdf]')...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("-")));
                args.Add(tools.AllocValue(mstring.Prepare("[-acdf]")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ISLIKE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 1;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ISLIKE(String,'[-acdf]') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing negative DbFunctions.ISLIKE(String,'[-acdf]')...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("b")));
                args.Add(tools.AllocValue(mstring.Prepare("[-acdf]")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ISLIKE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 0;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ISLIKE(String,'[-acdf]') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing positive DbFunctions.ISLIKE(String,'[ [ ]')...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("[")));
                args.Add(tools.AllocValue(mstring.Prepare("[ [ ]")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ISLIKE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 1;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ISLIKE(String,'[ [ ]') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing negative DbFunctions.ISLIKE(String,'[ [ ]')...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("p")));
                args.Add(tools.AllocValue(mstring.Prepare("[ [ ]")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ISLIKE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 0;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ISLIKE(String,'[ [ ]') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing negative DbFunctions.ISLIKE(String,'[*]')...");

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(mstring.Prepare("*")));
                args.Add(tools.AllocValue(mstring.Prepare("[*]")));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.ISLIKE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = 1;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.ISLIKE(String,'[*]') has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 20
0
        public static void DbFunctions_DATEPART()
        {
            DbFunctionTools tools = new DbFunctionTools();

            DateTime input = new DateTime(1999, 3, 14, 13, 1, 33);

            DbValue        valInput = tools.AllocValue(input);
            List <DbValue> args     = new List <DbValue>();

            args.Add(valInput);
            DbFunctionArguments fargs = new DbFunctionArguments(args);

            {
                Console.WriteLine("Testing DbFunctions.DATEPART_YEAR...");

                DbValue   valOutput = DbFunctions.DATEPART_YEAR(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = input.Year;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEPART_YEAR has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEPART_MONTH...");

                DbValue   valOutput = DbFunctions.DATEPART_MONTH(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = input.Month;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEPART_MONTH has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEPART_DAY...");

                DbValue   valOutput = DbFunctions.DATEPART_DAY(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = input.Day;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEPART_DAY has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEPART_HOUR...");

                DbValue   valOutput = DbFunctions.DATEPART_HOUR(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = input.Hour;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEPART_HOUR has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEPART_MINUTE...");

                DbValue   valOutput = DbFunctions.DATEPART_MINUTE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = input.Minute;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEPART_MINUTE has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEPART_SECOND...");

                DbValue   valOutput = DbFunctions.DATEPART_SECOND(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = input.Second;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEPART_SECOND has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 21
0
        public static void DbFunctions_DATEADD()
        {
            DbFunctionTools tools = new DbFunctionTools();

            {
                Console.WriteLine("Testing DbFunctions.DATEADD(year)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("year");
                args.Add(tools.AllocValue(datepart));
                int number = -10;
                args.Add(tools.AllocValue(number));
                DateTime dt = new DateTime(2000, 9, 14, 12, 0, 0);
                args.Add(tools.AllocValue(dt));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEADD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                DateTime  output    = tools.GetDateTime(bs);
                DateTime  expected  = dt.AddYears(number);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEADD(year) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEADD(quarter)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("qq");
                args.Add(tools.AllocValue(datepart));
                int number = 5;
                args.Add(tools.AllocValue(number));
                DateTime dt = new DateTime(2000, 9, 14, 12, 0, 0);
                args.Add(tools.AllocValue(dt));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEADD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                DateTime  output    = tools.GetDateTime(bs);
                DateTime  expected  = dt.AddMonths(number * 3);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEADD(quarter) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEADD(month)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("m");
                args.Add(tools.AllocValue(datepart));
                int number = 10;
                args.Add(tools.AllocValue(number));
                DateTime dt = new DateTime(2000, 9, 14, 12, 0, 0);
                args.Add(tools.AllocValue(dt));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEADD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                DateTime  output    = tools.GetDateTime(bs);
                DateTime  expected  = dt.AddMonths(number);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEADD(month) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEADD(day)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("day");
                args.Add(tools.AllocValue(datepart));
                int number = -9;
                args.Add(tools.AllocValue(number));
                DateTime dt = new DateTime(2000, 9, 14, 12, 0, 0);
                args.Add(tools.AllocValue(dt));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEADD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                DateTime  output    = tools.GetDateTime(bs);
                DateTime  expected  = dt.AddDays(number);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEADD(day) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEADD(week)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("wk");
                args.Add(tools.AllocValue(datepart));
                int number = 22;
                args.Add(tools.AllocValue(number));
                DateTime dt = new DateTime(2000, 9, 14, 12, 0, 0);
                args.Add(tools.AllocValue(dt));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEADD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                DateTime  output    = tools.GetDateTime(bs);
                DateTime  expected  = dt.AddDays(number * 7);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEADD(week) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEADD(hour)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("hour");
                args.Add(tools.AllocValue(datepart));
                int number = -99;
                args.Add(tools.AllocValue(number));
                DateTime dt = new DateTime(2000, 9, 14, 12, 0, 0);
                args.Add(tools.AllocValue(dt));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEADD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                DateTime  output    = tools.GetDateTime(bs);
                DateTime  expected  = dt.AddHours(number);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEADD(hour) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEADD(minute)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("mi");
                args.Add(tools.AllocValue(datepart));
                int number = 80;
                args.Add(tools.AllocValue(number));
                DateTime dt = new DateTime(2000, 9, 14, 12, 0, 0);
                args.Add(tools.AllocValue(dt));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEADD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                DateTime  output    = tools.GetDateTime(bs);
                DateTime  expected  = dt.AddMinutes(number);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEADD(minute) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEADD(second)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("s");
                args.Add(tools.AllocValue(datepart));
                int number = 900;
                args.Add(tools.AllocValue(number));
                DateTime dt = new DateTime(2000, 9, 14, 12, 0, 0);
                args.Add(tools.AllocValue(dt));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEADD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                DateTime  output    = tools.GetDateTime(bs);
                DateTime  expected  = dt.AddSeconds(number);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEADD(second) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEADD(millisecond)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("millisecond");
                args.Add(tools.AllocValue(datepart));
                int number = 900;
                args.Add(tools.AllocValue(number));
                DateTime dt = new DateTime(2000, 9, 14, 12, 0, 0);
                args.Add(tools.AllocValue(dt));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEADD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                DateTime  output    = tools.GetDateTime(bs);
                DateTime  expected  = dt.AddMilliseconds(number);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEADD(millisecond) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 22
0
        public static void DbFunctions_COMPARE()
        {
            DbFunctionTools tools = new DbFunctionTools();
            Random          rnd   = new Random();

            const int NUM_RUNS_EACH = 4;

            for (int it = 0; it < NUM_RUNS_EACH; it++)
            {
                Console.WriteLine("Testing DbFunctions.COMPARE(char(n), char(n)) ({0} of {1})...", it + 1, NUM_RUNS_EACH);

                mstring x = Utils.GenString(rnd.Next(1, 200));
                mstring y = Utils.GenString(rnd.Next(1, 200));
                if (1 == it)
                {
                    y = x;
                }

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(x));
                args.Add(tools.AllocValue(y));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.COMPARE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = string.Compare(x.ToString(), y.ToString(), StringComparison.OrdinalIgnoreCase);

                if (!_SameCompareRank(expected, output))
                {
                    if (0 == expected || 0 == output)
                    {
                        throw new Exception("DbFunctions.COMPARE(char(n), char(n)) has failed.  Expected result: " + _CompareRankToString(expected) + ", but received: " + _CompareRankToString(output));
                    }
                    Console.WriteLine("Warning: C# StringComparison.OrdinalIgnoreCase and DbFunctions.COMPARE do not agree on string ordering: C# says " + _CompareRankToString(expected) + " but I say " + _CompareRankToString(output) + " for:\r\n\t'{0}'\r\n\t'{1}'", x.ToString(), y.ToString());
                    System.Threading.Thread.Sleep(1000 * 3);
                }
                else
                {
                    Console.WriteLine("Expected results received: {0}", _CompareRankToString(expected));
                }
            }

            for (int it = 0; it < NUM_RUNS_EACH; it++)
            {
                Console.WriteLine("Testing DbFunctions.COMPARE(Int32, Int32) ({0} of {1})...", it + 1, NUM_RUNS_EACH);

                int x = rnd.Next(Int32.MinValue, Int32.MaxValue);
                int y = rnd.Next(Int32.MinValue, Int32.MaxValue);
                if (1 == it)
                {
                    y = x;
                }

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(x));
                args.Add(tools.AllocValue(y));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.COMPARE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = x.CompareTo(y);

                if (!_SameCompareRank(expected, output))
                {
                    throw new Exception("DbFunctions.COMPARE(Int32, Int32) has failed.  Expected result: " + _CompareRankToString(expected) + ", but received: " + _CompareRankToString(output));
                }
                else
                {
                    Console.WriteLine("Expected results received: {0}", _CompareRankToString(expected));
                }
            }

            for (int it = 0; it < NUM_RUNS_EACH; it++)
            {
                Console.WriteLine("Testing DbFunctions.COMPARE(Double, Double) ({0} of {1})...", it + 1, NUM_RUNS_EACH);

                double x = rnd.NextDouble();
                double y = rnd.NextDouble();
                if (1 == it)
                {
                    y = x;
                }

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(x));
                args.Add(tools.AllocValue(y));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.COMPARE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = x.CompareTo(y);

                if (!_SameCompareRank(expected, output))
                {
                    throw new Exception("DbFunctions.COMPARE(Double, Double) has failed.  Expected result: " + _CompareRankToString(expected) + ", but received: " + _CompareRankToString(output));
                }
                else
                {
                    Console.WriteLine("Expected results received: {0}", _CompareRankToString(expected));
                }
            }

            for (int it = 0; it < NUM_RUNS_EACH; it++)
            {
                Console.WriteLine("Testing DbFunctions.COMPARE(Long, Long) ({0} of {1})...", it + 1, NUM_RUNS_EACH);

                long x = unchecked ((long)rnd.Next() * (long)rnd.Next());
                long y = unchecked ((long)rnd.Next() * (long)rnd.Next());
                if (1 == it)
                {
                    y = x;
                }

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(x));
                args.Add(tools.AllocValue(y));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.COMPARE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = x.CompareTo(y);

                if (!_SameCompareRank(expected, output))
                {
                    throw new Exception("DbFunctions.COMPARE(Long, Long) has failed.  Expected result: " + _CompareRankToString(expected) + ", but received: " + _CompareRankToString(output));
                }
                else
                {
                    Console.WriteLine("Expected results received: {0}", _CompareRankToString(expected));
                }
            }

            for (int it = 0; it < NUM_RUNS_EACH; it++)
            {
                Console.WriteLine("Testing DbFunctions.COMPARE(Double, Int32) ({0} of {1})...", it + 1, NUM_RUNS_EACH);

                double x = rnd.NextDouble();
                int    y = rnd.Next();
                if (1 == it)
                {
                    //y = x;
                    x = y;
                }

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(x));
                args.Add(tools.AllocValue(y));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.COMPARE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = x.CompareTo((double)y);

                if (!_SameCompareRank(expected, output))
                {
                    throw new Exception("DbFunctions.COMPARE(Double, Int32) has failed.  Expected result: " + _CompareRankToString(expected) + ", but received: " + _CompareRankToString(output));
                }
                else
                {
                    Console.WriteLine("Expected results received: {0}", _CompareRankToString(expected));
                }
            }

            for (int it = 0; it < NUM_RUNS_EACH; it++)
            {
                Console.WriteLine("Testing DbFunctions.COMPARE(Double, Long) ({0} of {1})...", it + 1, NUM_RUNS_EACH);

                double x = rnd.NextDouble();
                long   y = unchecked ((long)rnd.Next() * (long)rnd.Next());
                if (1 == it)
                {
                    //y = x;
                    x = y;
                }

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(x));
                args.Add(tools.AllocValue(y));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.COMPARE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = x.CompareTo((double)y);

                if (!_SameCompareRank(expected, output))
                {
                    throw new Exception("DbFunctions.COMPARE(Double, Long) has failed.  Expected result: " + _CompareRankToString(expected) + ", but received: " + _CompareRankToString(output));
                }
                else
                {
                    Console.WriteLine("Expected results received: {0}", _CompareRankToString(expected));
                }
            }

            for (int it = 0; it < NUM_RUNS_EACH; it++)
            {
                Console.WriteLine("Testing DbFunctions.COMPARE(DateTime, DateTime) ({0} of {1})...", it + 1, NUM_RUNS_EACH);

                DateTime x = DateTime.Now;
                DateTime y = x.AddDays(rnd.Next(-365, 365));
                if (1 == it)
                {
                    y = x;
                }

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(x));
                args.Add(tools.AllocValue(y));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.COMPARE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = x.CompareTo(y);

                if (!_SameCompareRank(expected, output))
                {
                    throw new Exception("DbFunctions.COMPARE(DateTime, DateTime) has failed.  Expected result: " + _CompareRankToString(expected) + ", but received: " + _CompareRankToString(output));
                }
                else
                {
                    Console.WriteLine("Expected results received: {0}", _CompareRankToString(expected));
                }
            }

            for (int it = 0; it < NUM_RUNS_EACH; it++)
            {
                Console.WriteLine("Testing DbFunctions.COMPARE(DateTime, Char(n)) ({0} of {1})...", it + 1, NUM_RUNS_EACH);

                DateTime x  = DateTime.Now;
                DateTime dt = x.AddDays(rnd.Next(-365, 365));
                mstring  y  = mstring.Prepare(dt.ToString());

                if (1 == it)
                {
                    y = mstring.Prepare(x.ToString());
                }

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(x));
                args.Add(tools.AllocValue(y));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.COMPARE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = x.CompareTo(DateTime.Parse(y.ToString()));

                if (!_SameCompareRank(expected, output))
                {
                    throw new Exception("DbFunctions.COMPARE(DateTime, Char(n)) has failed.  Expected result: " + _CompareRankToString(expected) + ", but received: " + _CompareRankToString(output));
                }
                else
                {
                    Console.WriteLine("Expected results received: {0}", _CompareRankToString(expected));
                }
            }

            for (int it = 0; it < NUM_RUNS_EACH; it++)
            {
                Console.WriteLine("Testing DbFunctions.COMPARE(Char(n), DateTime) ({0} of {1})...", it + 1, NUM_RUNS_EACH);

                DateTime y  = DateTime.Now;
                DateTime dt = y.AddDays(rnd.Next(-365, 365));
                mstring  x  = mstring.Prepare(dt.ToString());

                if (1 == it)
                {
                    x = mstring.Prepare(y.ToString());
                }

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(x));
                args.Add(tools.AllocValue(y));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.COMPARE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = DateTime.Parse(x.ToString()).CompareTo(y);

                if (!_SameCompareRank(expected, output))
                {
                    throw new Exception("DbFunctions.COMPARE(Char(n), DateTime) has failed.  Expected result: " + _CompareRankToString(expected) + ", but received: " + _CompareRankToString(output));
                }
                else
                {
                    Console.WriteLine("Expected results received: {0}", _CompareRankToString(expected));
                }
            }
        }
Esempio n. 23
0
        public static void DbAggregators_CHOOSERND()
        {
            DbFunctionTools tools    = new DbFunctionTools();
            Random          rnd      = new Random();
            const int       rowcount = 20;

            //Double.
            {
                Console.WriteLine("Testing DbAggregators_CHOOSERND(Double)...");

                DbFunctionArguments[]    fargs = new DbFunctionArguments[rowcount];
                Dictionary <double, int> dict  = new Dictionary <double, int>();

                for (int i = 0; i < fargs.Length; i++)
                {
                    double input = rnd.NextDouble();
                    if (input < 0.5)
                    {
                        input = input * -1d;
                    }
                    dict[input] = 1;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.CHOOSERND(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                if (!dict.ContainsKey(output))
                {
                    throw new Exception("DbAggregators_CHOOSERND(Double) has failed.  Value not found: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_CHOOSERND(Int32)...");

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                Dictionary <int, int> dict  = new Dictionary <int, int>();

                for (int i = 0; i < fargs.Length; i++)
                {
                    int input = rnd.Next(Int32.MinValue, Int32.MaxValue);
                    dict[input] = 1;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.CHOOSERND(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                if (!dict.ContainsKey(output))
                {
                    throw new Exception("DbAggregators_CHOOSERND(Int32) has failed.  Value not found: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_CHOOSERND(Int64)...");

                DbFunctionArguments[]  fargs = new DbFunctionArguments[rowcount];
                Dictionary <long, int> dict  = new Dictionary <long, int>();

                for (int i = 0; i < fargs.Length; i++)
                {
                    long input = DateTime.Now.Ticks;
                    if (input % 2 == 0)
                    {
                        input = input * -1;
                    }
                    dict[input] = 1;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.CHOOSERND(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);

                if (!dict.ContainsKey(output))
                {
                    throw new Exception("DbAggregators_CHOOSERND(Int64) has failed.  Value not found: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_CHOOSERND(char(n))...");

                DbFunctionArguments[]    fargs = new DbFunctionArguments[rowcount];
                Dictionary <string, int> dict  = new Dictionary <string, int>();

                for (int i = 0; i < fargs.Length; i++)
                {
                    int     strlen = rnd.Next(1, 100);
                    mstring input  = Utils.GenString(strlen);
                    dict[input.ToString()] = 1;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.CHOOSERND(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                mstring   output    = tools.GetString(bs);

                if (!dict.ContainsKey(output.ToString()))
                {
                    throw new Exception("DbAggregators_CHOOSERND(char(n)) has failed.  Value not found: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 24
0
        public static void DbFunctions_DATEDIFF()
        {
            DbFunctionTools tools = new DbFunctionTools();

            {
                Console.WriteLine("Testing DbFunctions.DATEDIFF(year)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("year");
                args.Add(tools.AllocValue(datepart));
                DateTime startdate = new DateTime(2010, 12, 2, 10, 0, 0);
                args.Add(tools.AllocValue(startdate));
                DateTime enddate = new DateTime(2000, 9, 14, 12, 0, 0);
                args.Add(tools.AllocValue(enddate));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEDIFF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);
                double    expected  = -10;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEDIFF(year) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEDIFF(quarter)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("qq");
                args.Add(tools.AllocValue(datepart));
                DateTime startdate = new DateTime(2000, 7, 1, 10, 0, 0);
                args.Add(tools.AllocValue(startdate));
                DateTime enddate = new DateTime(2002, 8, 30, 12, 0, 0);
                args.Add(tools.AllocValue(enddate));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEDIFF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);
                double    expected  = 8;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEDIFF(quarter) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEDIFF(month)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("month");
                args.Add(tools.AllocValue(datepart));
                DateTime startdate = new DateTime(2000, 7, 1, 10, 0, 0);
                args.Add(tools.AllocValue(startdate));
                DateTime enddate = new DateTime(2002, 8, 15, 12, 0, 0);
                args.Add(tools.AllocValue(enddate));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEDIFF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);
                double    expected  = 25;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEDIFF(month) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEDIFF(day)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("d");
                args.Add(tools.AllocValue(datepart));
                DateTime startdate = new DateTime(2000, 7, 1, 10, 0, 0);
                args.Add(tools.AllocValue(startdate));
                DateTime enddate = new DateTime(2002, 8, 20, 12, 0, 0);
                args.Add(tools.AllocValue(enddate));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEDIFF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = 0;
                {
                    DateTime xstartdate = new DateTime(2000, 7, 1);
                    DateTime xenddate   = new DateTime(2002, 8, 20);
                    TimeSpan sp         = xenddate - xstartdate;
                    expected = sp.TotalDays;
                }

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEDIFF(day) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEDIFF(week)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("week");
                args.Add(tools.AllocValue(datepart));
                DateTime startdate = new DateTime(2000, 7, 1, 10, 0, 0);
                args.Add(tools.AllocValue(startdate));
                DateTime enddate = new DateTime(2002, 8, 20, 12, 0, 0);
                args.Add(tools.AllocValue(enddate));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEDIFF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = 0;
                {
                    DateTime xstartdate = new DateTime(2000, 7, 1);
                    DateTime xenddate   = new DateTime(2002, 8, 20);
                    TimeSpan sp         = xenddate - xstartdate;
                    expected = (int)sp.TotalDays / 7;
                }

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEDIFF(week) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEDIFF(hour)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("hh");
                args.Add(tools.AllocValue(datepart));
                DateTime startdate = new DateTime(2000, 7, 1, 10, 30, 1);
                args.Add(tools.AllocValue(startdate));
                DateTime enddate = new DateTime(2002, 8, 20, 12, 20, 3);
                args.Add(tools.AllocValue(enddate));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEDIFF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = 0;
                {
                    DateTime xstartdate = new DateTime(2000, 7, 1, 10, 0, 0);
                    DateTime xenddate   = new DateTime(2002, 8, 20, 12, 0, 0);
                    TimeSpan sp         = xenddate - xstartdate;
                    expected = sp.TotalHours;
                }

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEDIFF(hour) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEDIFF(minute)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("minute");
                args.Add(tools.AllocValue(datepart));
                DateTime startdate = new DateTime(2000, 7, 1, 10, 30, 1);
                args.Add(tools.AllocValue(startdate));
                DateTime enddate = new DateTime(2002, 8, 20, 12, 20, 3);
                args.Add(tools.AllocValue(enddate));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEDIFF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = 0;
                {
                    DateTime xstartdate = new DateTime(2000, 7, 1, 10, 30, 0);
                    DateTime xenddate   = new DateTime(2002, 8, 20, 12, 20, 0);
                    TimeSpan sp         = xenddate - xstartdate;
                    expected = sp.TotalMinutes;
                }

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEDIFF(minute) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEDIFF(second)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("ss");
                args.Add(tools.AllocValue(datepart));
                DateTime startdate = new DateTime(2000, 7, 1, 10, 30, 1);
                args.Add(tools.AllocValue(startdate));
                DateTime enddate = new DateTime(2002, 8, 20, 12, 20, 3);
                args.Add(tools.AllocValue(enddate));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEDIFF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = 0;
                {
                    DateTime xstartdate = new DateTime(2000, 7, 1, 10, 30, 1);
                    DateTime xenddate   = new DateTime(2002, 8, 20, 12, 20, 3);
                    TimeSpan sp         = xenddate - xstartdate;
                    expected = sp.TotalSeconds;
                }

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEDIFF(second) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.DATEDIFF(millisecond)...");

                List <DbValue> args     = new List <DbValue>();
                mstring        datepart = mstring.Prepare("ms");
                args.Add(tools.AllocValue(datepart));
                DateTime startdate = new DateTime(2000, 7, 1, 10, 30, 1, 2);
                args.Add(tools.AllocValue(startdate));
                DateTime enddate = new DateTime(2002, 8, 20, 12, 20, 3, 5);
                args.Add(tools.AllocValue(enddate));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.DATEDIFF(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double   expected = 0;
                TimeSpan sp       = enddate - startdate;
                expected = sp.TotalMilliseconds;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.DATEDIFF(millisecond) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 25
0
        public static void DbAggregators_BIT_AND()
        {
            DbFunctionTools tools    = new DbFunctionTools();
            Random          rnd      = new Random();
            const int       rowcount = 20;

            //Double.
            {
                Console.WriteLine("Testing DbAggregators_BIT_AND(Double)...");

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                double[] values             = new double[rowcount];

                for (int i = 0; i < fargs.Length; i++)
                {
                    double input = rnd.NextDouble();
                    if (input < 0.5)
                    {
                        input = input * -1d;
                    }
                    values[i] = input;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.BIT_AND(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);
                byte[]    expected  = bitop(values, 1);

                if (!compareBytes(expected, bs))
                {
                    throw new Exception("DbAggregators_BIT_AND(Double) has failed.");
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_BIT_AND(Int32)...");

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                int[] values = new int[rowcount];

                for (int i = 0; i < fargs.Length; i++)
                {
                    int input = rnd.Next(Int32.MinValue, Int32.MaxValue);
                    values[i] = input;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.BIT_AND(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);
                byte[]    expected  = bitop(values, 1);
                if (!compareBytes(expected, bs))
                {
                    throw new Exception("DbAggregators_BIT_AND(Int32) has failed.");
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_BIT_AND(Int64)...");

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                long[] values = new long[rowcount];

                for (int i = 0; i < fargs.Length; i++)
                {
                    long input = DateTime.Now.Ticks;
                    if (input % 2 == 0)
                    {
                        input = input * -1;
                    }
                    values[i] = input;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.BIT_AND(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);
                byte[]    expected  = bitop(values, 1);
                if (!compareBytes(expected, bs))
                {
                    throw new Exception("DbAggregators_BIT_AND(Int64) has failed.");
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_BIT_AND(char(n))...");

                DbFunctionArguments[] fargs  = new DbFunctionArguments[rowcount];
                mstring[]             values = new mstring[rowcount];

                for (int i = 0; i < fargs.Length; i++)
                {
                    int     strlen = 30;
                    mstring input  = Utils.GenString(strlen);
                    values[i] = input;
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.BIT_AND(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                mstring   output    = tools.GetString(bs);
                byte[]    expected  = bitop(values, 1);
                if (!compareBytes(expected, bs))
                {
                    throw new Exception("DbAggregators_BIT_AND(char(n)) has failed.");
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 26
0
        public static void DbFunctions_MOD()
        {
            DbFunctionTools tools = new DbFunctionTools();
            Random          rnd   = new Random();

            //Double.
            {
                Console.WriteLine("Testing DbFunctions.MOD(Double, Double)...");

                double input0 = rnd.NextDouble();
                double input1 = rnd.NextDouble();

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(input0));
                args.Add(tools.AllocValue(input1));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MOD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = input0 % input1;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MOD(Double, Double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.MOD(Int32, Int32)...");

                int input0 = rnd.Next();
                int input1 = rnd.Next();

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(input0));
                args.Add(tools.AllocValue(input1));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MOD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = input0 % input1;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MOD(Int32, Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.MOD(Long, Long)...");

                long input0 = DateTime.Now.Ticks;
                long input1 = DateTime.Now.Ticks;

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(input0));
                args.Add(tools.AllocValue(input1));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MOD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);

                long expected = input0 % input1;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MOD(Long, Long) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.MOD(Int32, Double)...");

                int    input0 = rnd.Next();
                double input1 = rnd.NextDouble();

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(input0));
                args.Add(tools.AllocValue(input1));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MOD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = (double)input0 % input1;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MOD(Int32, Double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.MOD(Int32, Long)...");

                int  input0 = rnd.Next();
                long input1 = DateTime.Now.Ticks;

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(input0));
                args.Add(tools.AllocValue(input1));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.MOD(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);

                long expected = (long)input0 % input1;

                if (expected != output)
                {
                    throw new Exception("DbFunctions.MOD(Int32, Long) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 27
0
        public static void DbAggregators_LAST()
        {
            DbFunctionTools tools    = new DbFunctionTools();
            Random          rnd      = new Random();
            const int       rowcount = 20;

            //Double.
            {
                Console.WriteLine("Testing DbAggregators_LAST(Double)...");

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                double expected             = 0;

                for (int i = 0; i < fargs.Length; i++)
                {
                    double input = rnd.NextDouble();
                    if (input < 0.5)
                    {
                        input = input * -1d;
                    }
                    if (i == fargs.Length - 1)
                    {
                        expected = input;
                    }

                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.LAST(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                if (expected != output)
                {
                    throw new Exception("DbAggregators_LAST(Double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_LAST(Int32)...");

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                int expected = Int32.MaxValue;

                for (int i = 0; i < fargs.Length; i++)
                {
                    int input = rnd.Next(Int32.MinValue, Int32.MaxValue);
                    if (i == fargs.Length - 1)
                    {
                        expected = input;
                    }
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.LAST(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                if (expected != output)
                {
                    throw new Exception("DbAggregators_LAST(Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_LAST(Int64)...");

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                long expected = Int64.MaxValue;

                for (int i = 0; i < fargs.Length; i++)
                {
                    long input = DateTime.Now.Ticks;
                    if (input % 2 == 0)
                    {
                        input = input * -1;
                    }
                    if (i == fargs.Length - 1)
                    {
                        expected = input;
                    }
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.LAST(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                long      output    = tools.GetLong(bs);

                if (expected != output)
                {
                    throw new Exception("DbAggregators_LAST(Int64) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_LAST(char(n))...");

                DbFunctionArguments[] fargs = new DbFunctionArguments[rowcount];
                string expected             = null;

                for (int i = 0; i < fargs.Length; i++)
                {
                    int     strlen = rnd.Next(1, 100);
                    mstring input  = Utils.GenString(strlen);
                    if (i == fargs.Length - 1)
                    {
                        expected = input.ToString();
                    }
                    List <DbValue> args = new List <DbValue>();
                    args.Add(tools.AllocValue(input));
                    fargs[i] = new DbFunctionArguments(args);
                }
                DbValue   valOutput = DbAggregators.LAST(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs        = valOutput.Eval();
                mstring   output    = tools.GetString(bs);

                if (expected != output.ToString())
                {
                    throw new Exception("DbAggregators_LAST(char(n)) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 28
0
        public static void DbFunctions_CAST()
        {
            DbFunctionTools tools = new DbFunctionTools();

            DateTime dt = DateTime.Now;

            DbValue[] conv = new DbValue[]
            {
                tools.AllocValue((int)-372), tools.AllocValue((int)-372),
                tools.AllocValue((int)-372), tools.AllocValue((long)-372),
                tools.AllocValue((int)-372), tools.AllocValue((double)-372),
                //tools.AllocValue((int)dt.Ticks), tools.AllocValue(new DateTime((int)dt.Ticks)),
                tools.AllocValue((int)-372), tools.AllocValue(mstring.Prepare("-372")),
                tools.AllocValue((int)-372), tools.AllocValue(mstring.Prepare("-372"), 51),

                tools.AllocValue((long)-372), tools.AllocValue((int)-372),
                tools.AllocValue((long)-372), tools.AllocValue((long)-372),
                tools.AllocValue((long)-372), tools.AllocValue((double)-372),
                tools.AllocValue((long)dt.Ticks), tools.AllocValue(new DateTime((long)dt.Ticks)),
                tools.AllocValue((long)-372), tools.AllocValue(mstring.Prepare("-372")),
                tools.AllocValue((long)-372), tools.AllocValue(mstring.Prepare("-372"), 51),

                tools.AllocValue((double)-372), tools.AllocValue((int)-372),
                tools.AllocValue((double)-372), tools.AllocValue((long)-372),
                tools.AllocValue((double)-372), tools.AllocValue((double)-372),
                tools.AllocValue((double)dt.Ticks), tools.AllocValue(new DateTime((long)(double)dt.Ticks)),
                tools.AllocValue((double)-372), tools.AllocValue(mstring.Prepare("-372")),
                tools.AllocValue((double)-372), tools.AllocValue(mstring.Prepare("-372"), 51),
                // Extra double ones:
                tools.AllocValue((double)101.1), tools.AllocValue((int)101),
                tools.AllocValue((double)101.1), tools.AllocValue((long)101),
                tools.AllocValue((double)101.1), tools.AllocValue(mstring.Prepare((double)101.1)),
                tools.AllocValue((double)(22.0 / 7.0)), tools.AllocValue(mstring.Prepare((double)(22.0 / 7.0))),

                tools.AllocValue(dt), tools.AllocValue((int)dt.Ticks),
                tools.AllocValue(dt), tools.AllocValue((long)dt.Ticks),
                tools.AllocValue(dt), tools.AllocValue((double)dt.Ticks),
                tools.AllocValue(dt), tools.AllocValue(dt),
                tools.AllocValue(dt), tools.AllocValue(mstring.Prepare(dt.ToString())),
                tools.AllocValue(dt), tools.AllocValue(mstring.Prepare(dt.ToString()), 51),

                tools.AllocValue(mstring.Prepare("-372")), tools.AllocValue((int)-372),
                tools.AllocValue(mstring.Prepare("-372")), tools.AllocValue((long)-372),
                tools.AllocValue(mstring.Prepare("-372")), tools.AllocValue((double)-372),
                tools.AllocValue(mstring.Prepare(dt.ToString())), tools.AllocValue(dt),
                tools.AllocValue(mstring.Prepare("-372")), tools.AllocValue(mstring.Prepare("-372")),
                tools.AllocValue(mstring.Prepare("-372")), tools.AllocValue(mstring.Prepare("-372"), 51),
                // Extra string ones:
                tools.AllocValue(mstring.Prepare("-372"), 51), tools.AllocValue(mstring.Prepare("-372"), 101),
                tools.AllocValue(mstring.Prepare("-372"), 101), tools.AllocValue(mstring.Prepare("-372"), 51),

                null
            };


            for (int ic = 0; ic + 2 <= conv.Length; ic += 2)
            {
                DbValue   a = conv[ic + 0];
                DbType    atype;
                ByteSlice abytes = a.Eval(out atype);

                DbValue   b = conv[ic + 1];
                DbType    btype;
                ByteSlice bbytes = b.Eval(out btype);

                Console.WriteLine("Testing DbFunctions.CAST({0} AS {1})...", atype.Name, btype.Name);

                List <DbValue> args = new List <DbValue>();
                args.Add(a);
                args.Add(tools.AllocValue(mstring.Prepare("AS " + btype.Name)));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   r = DbFunctions.CAST(tools, fargs);
                DbType    rtype;
                ByteSlice rbytes = r.Eval(out rtype);

                if (rtype.ID != btype.ID)
                {
                    throw new Exception(string.Format("DbFunctions.CAST({0} AS {1}) resulted in type {2}: result has unexpected ID of {3}",
                                                      atype.Name, btype.Name, btype.Name, rtype.ID));
                }
                if (rtype.Size != btype.Size)
                {
                    throw new Exception(string.Format("DbFunctions.CAST({0} AS {1}) resulted in type {2}: result has unexpected size of {3}",
                                                      atype.Name, btype.Name, btype.Name, rtype.Size));
                }
                if (rtype.ID == DbTypeID.DATETIME)
                {
                    if (tools.GetDateTime(rbytes).ToString() != tools.GetDateTime(bbytes).ToString())
                    {
                        throw new Exception(string.Format("DbFunctions.CAST({0} AS {1}) resulted in type {2}: result has unexpected value",
                                                          atype.Name, btype.Name, btype.Name));
                    }
                }
                else
                {
                    for (int ix = 0; ix < rtype.Size; ix++)
                    {
                        if (rbytes[ix] != bbytes[ix])
                        {
                            throw new Exception(string.Format("DbFunctions.CAST({0} AS {1}) resulted in type {2}: result has unexpected value",
                                                              atype.Name, btype.Name, btype.Name));
                        }
                    }
                }
            }
        }
Esempio n. 29
0
        public static void DbFunctions_SQUARE()
        {
            DbFunctionTools tools = new DbFunctionTools();
            Random          rnd   = new Random();

            //Double.
            {
                Console.WriteLine("Testing DbFunctions.SQUARE(Double)...");

                double input = rnd.NextDouble();

                if (input < 0.5)
                {
                    input = input * -1d;
                }

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(input));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.SQUARE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = Math.Pow((double)input, 2);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.SQUARE(Double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.SQUARE(Int32)...");

                int input = rnd.Next(Int32.MinValue, Int32.MaxValue);

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(input));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.SQUARE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = Math.Pow((double)input, 2);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.SQUARE(Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.SQUARE(Long)...");

                long input = DateTime.Now.Ticks;

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(input));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.SQUARE(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                double    output    = tools.GetDouble(bs);

                double expected = Math.Pow((double)input, 2);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.SQUARE(Long) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
Esempio n. 30
0
        public static void DbFunctions_GREATEREQUAL()
        {
            DbFunctionTools tools = new DbFunctionTools();
            Random          rnd   = new Random();

            {
                Console.WriteLine("Testing DbFunctions.GREATEREQUAL(char(n), char(n))...");

                mstring s1 = Utils.GenString(rnd.Next(1, 200));
                mstring s2 = Utils.GenString(rnd.Next(1, 200));

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(s1));
                args.Add(tools.AllocValue(s2));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.GREATEREQUAL(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = (s1.ToString().CompareTo(s2.ToString()) >= 0 ? 1 : 0);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.GREATEREQUAL(char(n), char(n)) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.GREATEREQUAL(Int32, Int32)...");

                int x = rnd.Next(Int32.MinValue, Int32.MaxValue);
                int y = rnd.Next(Int32.MinValue, Int32.MaxValue);

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(x));
                args.Add(tools.AllocValue(y));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.GREATEREQUAL(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = (x >= y ? 1 : 0);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.GREATEREQUAL(Int32, Int32) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.GREATEREQUAL(Double, Double)...");

                double x = rnd.NextDouble();
                double y = rnd.NextDouble();

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(x));
                args.Add(tools.AllocValue(y));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.GREATEREQUAL(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = (x >= y ? 1 : 0);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.GREATEREQUAL(Double, Double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.GREATEREQUAL(Long, Long)...");

                long x = DateTime.Now.Ticks;
                long y = DateTime.Now.Ticks;

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(x));
                args.Add(tools.AllocValue(y));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.GREATEREQUAL(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = (x >= y ? 1 : 0);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.GREATEREQUAL(Long, Long) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.GREATEREQUAL(Int32, Double)...");

                int    x = rnd.Next(Int32.MinValue, Int32.MaxValue);
                double y = rnd.NextDouble();

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(x));
                args.Add(tools.AllocValue(y));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.GREATEREQUAL(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = (x >= y ? 1 : 0);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.GREATEREQUAL(Int32, Double) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbFunctions.GREATEREQUAL(Int32, Long)...");

                int  x = rnd.Next(Int32.MinValue, Int32.MaxValue);
                long y = DateTime.Now.Ticks;

                List <DbValue> args = new List <DbValue>();
                args.Add(tools.AllocValue(x));
                args.Add(tools.AllocValue(y));
                DbFunctionArguments fargs = new DbFunctionArguments(args);

                DbValue   valOutput = DbFunctions.GREATEREQUAL(tools, fargs);
                ByteSlice bs        = valOutput.Eval();
                int       output    = tools.GetInt(bs);

                int expected = (x >= y ? 1 : 0);

                if (expected != output)
                {
                    throw new Exception("DbFunctions.GREATEREQUAL(Int32, Long) has failed.  Expected result: " + expected.ToString() + ", but received: " + output.ToString());
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }