示例#1
0
        public mstring GetString()
        {
            int endIndex = Buffer.Count - 1;
            int strEnd   = -1;

            for (int i = CurrentGetPos; i <= endIndex; i = i + 2)
            {
                if (i + 1 > endIndex)
                {
                    throw new Exception("UTF-16 encoded string is missing some bytes.");
                }

                if (Buffer[i] == 0x0 && Buffer[i + 1] == 0x0)
                {
                    strEnd = i;
                    break;
                }
            }

            if (strEnd > -1)
            {
                mstring ms = mstring.Prepare(Buffer, CurrentGetPos, strEnd - CurrentGetPos);
                CurrentGetPos = strEnd + 2;
                return(ms);
            }
            else
            {
                throw new Exception("String end is not found.");
            }
        }
示例#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.");
                }
            }
        }
示例#3
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.");
                }
            }
        }
示例#4
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.");
                }
            }
        }
示例#5
0
        public static DbValue CONCAT(DbFunctionTools tools, DbFunctionArguments args)
        {
            string FunctionName = "CONCAT";

            args.EnsureCount(FunctionName, 2);

            DbType    arg0type;
            ByteSlice arg0 = args[0].Eval(out arg0type);

            if (Types.IsNullValue(arg0))
            {
                return(tools.AllocNullValue()); // Give a null, take a null.
            }
            if (arg0type.ID != DbTypeID.CHARS)
            {
                args.Expected(FunctionName, 0, "input CHAR(n), got " + arg0type.Name.ToUpper());
            }
            DbType    arg1type;
            ByteSlice arg1 = args[1].Eval(out arg1type);

            if (Types.IsNullValue(arg1))
            {
                return(tools.AllocNullValue()); // Give a null, take a null.
            }
            if (arg1type.ID != DbTypeID.CHARS)
            {
                args.Expected(FunctionName, 0, "input CHAR(n), got " + arg1type.Name.ToUpper());
            }

            mstring s0 = tools.GetString(arg0);
            mstring s1 = tools.GetString(arg1);

            s0 = s0.AppendM(s1);
            return(tools.AllocValue(s0));
        }
示例#6
0
        private mstring PutString(int index, string s)
        {
            mstring ms = mstring.Prepare(s);

            PutString(index, ms);
            return(ms);
        }
示例#7
0
        public static DbValue REVERSE(DbFunctionTools tools, DbFunctionArguments args)
        {
            string FunctionName = "REVERSE";

            args.EnsureCount(FunctionName, 1);

            DbType    arg0type;
            ByteSlice arg0 = args[0].Eval(out arg0type);

            if (Types.IsNullValue(arg0))
            {
                return(tools.AllocNullValue()); // Give a null, take a null.
            }
            if (arg0type.ID != DbTypeID.CHARS)
            {
                args.Expected(FunctionName, 0, "input CHAR(n), got " + arg0type.Name.ToUpper());
            }

            mstring x = tools.GetString(arg0);

            mstring r = mstring.Prepare();

            for (int i = x.Length - 1; i >= 0; i--)
            {
                r = r.AppendM(x.SubstringM(i, 1));
            }

            return(tools.AllocValue(r));
        }
示例#8
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.");
                }
            }
        }
示例#9
0
        public DbValue AllocValue(mstring x)
        {
            List <byte> buf = AllocBuffer(1 + x.Length * 2);

            buf.Add(0); // Nullable; IsNull=false
            x.ToByteSliceUTF16().AppendTo(buf);
            return(AllocValue(ByteSlice.Prepare(buf), DbTypeID.CHARS));
        }
示例#10
0
            ByteSlice Conv_String(ByteSlice value, int ResultSize, DbFunctionTools tools)
            {
                mstring x = tools.GetString(value);

                x = x.ToUpperM();
                DbValue v = tools.AllocValue(x, ResultSize);

                return(v.Eval());
            }
示例#11
0
        public mstring GetString(int length)
        {
            rs.GetBytes(dummy, 0, 1);
            byte[] buf = new byte[length * 2];
            rs.GetBytes(buf, 0, buf.Length);
            string  s  = System.Text.Encoding.Unicode.GetString(buf);
            mstring ms = mstring.Prepare(s);

            ms = ms.TrimM('\0');
            return(ms);
        }
示例#12
0
        public mstring GetString(ByteSlice input)
        {
#if DEBUG_FTGET
            if (Types.IsNullValue(input))
            {
                throw new Exception("DEBUG:  GetString: (Types.IsNullValue(input))");
            }
#endif
            mstring x = mstring.PrepareUTF16(ByteSlice.Prepare(input, 1, input.Length - 1));
            x = x.TrimM('\0');
            return(x);
        }
示例#13
0
        public DbValue AllocValue(mstring x, int RowSizeBytes)
        {
            List <byte> buf = AllocBuffer(RowSizeBytes);

            buf.Add(0); // Nullable; IsNull=false
            x.ToByteSliceUTF16().AppendTo(buf);
            for (int i = buf.Count; i < RowSizeBytes; i++)
            {
                buf.Add(0);
            }
            return(AllocValue(ByteSlice.Prepare(buf), DbTypeID.CHARS));
        }
示例#14
0
        public void PutString(mstring s, int length)
        {
            ByteSlice bs = s.ToByteSliceUTF16();
            rs.PutByte(0); //front byte
            int totalsize = length * 2;
            int min = bs.Length < totalsize ? bs.Length : totalsize;

            for (int i = 0; i < min; i++)
            {
                rs.PutByte(bs[i]);
            }
            for (int i = min; i < totalsize; i++)
            {
                rs.PutByte(0);
            }
        }
示例#15
0
        public static DbValue REPLACE(DbFunctionTools tools, DbFunctionArguments args)
        {
            string FunctionName = "REPLACE";

            args.EnsureCount(FunctionName, 3);

            DbType    arg0type;
            ByteSlice arg0 = args[0].Eval(out arg0type);

            if (Types.IsNullValue(arg0))
            {
                return(tools.AllocNullValue()); // Give a null, take a null.
            }
            if (arg0type.ID != DbTypeID.CHARS)
            {
                args.Expected(FunctionName, 0, "input CHAR(n), got " + arg0type.Name.ToUpper());
            }
            DbType    arg1type;
            ByteSlice arg1 = args[1].Eval(out arg1type);

            if (Types.IsNullValue(arg1))
            {
                return(tools.AllocNullValue()); // Give a null, take a null.
            }
            if (arg1type.ID != DbTypeID.CHARS)
            {
                args.Expected(FunctionName, 0, "input CHAR(n), got " + arg1type.Name.ToUpper());
            }
            DbType    arg2type;
            ByteSlice arg2 = args[2].Eval(out arg2type);

            if (Types.IsNullValue(arg2))
            {
                return(tools.AllocNullValue()); // Give a null, take a null.
            }
            if (arg2type.ID != DbTypeID.CHARS)
            {
                args.Expected(FunctionName, 0, "input CHAR(n), got " + arg2type.Name.ToUpper());
            }

            mstring sentence    = tools.GetString(arg0);
            mstring word        = tools.GetString(arg1);
            mstring replacement = tools.GetString(arg2);

            sentence = sentence.ReplaceM(ref word, ref replacement);
            return(tools.AllocValue(sentence));
        }
示例#16
0
        public void PutString(mstring s, int length)
        {
            ByteSlice bs = s.ToByteSliceUTF16();

            rs.PutByte(0); //front byte
            int totalsize = length * 2;
            int min       = bs.Length < totalsize ? bs.Length : totalsize;

            for (int i = 0; i < min; i++)
            {
                rs.PutByte(bs[i]);
            }
            for (int i = min; i < totalsize; i++)
            {
                rs.PutByte(0);
            }
        }
示例#17
0
        public static DbValue LEFT(DbFunctionTools tools, DbFunctionArguments args)
        {
            string FunctionName = "LEFT";

            args.EnsureCount(FunctionName, 2);

            DbType    arg0type;
            ByteSlice arg0 = args[0].Eval(out arg0type);

            if (Types.IsNullValue(arg0))
            {
                return(tools.AllocNullValue()); // Give a null, take a null.
            }
            if (arg0type.ID != DbTypeID.CHARS)
            {
                args.Expected(FunctionName, 0, "input CHAR(n), got " + arg0type.Name.ToUpper());
            }

            DbType    arg1type;
            ByteSlice arg1 = args[1].Eval(out arg1type);

            if (arg1type.ID != DbTypeID.INT)
            {
                args.Expected(FunctionName, 1, "count INT, got " + arg1type.Name.ToUpper());
            }

            mstring x         = tools.GetString(arg0);
            int     LeftCount = tools.GetInt(arg1);

            if (LeftCount >= x.Length)
            {
                // User requested the whole string.
                return(tools.AllocValue(arg0, arg0type));
            }
            else if (LeftCount < 0)
            {
                throw new ArgumentException(FunctionName + " count cannot be negative");
            }
            else
            {
                x = x.SubstringM(0, LeftCount);
                return(tools.AllocValue(x));
            }
        }
示例#18
0
        public void PutString(mstring s)
        {
            ContainsString = true;

            int endIndex = s.StartIndex + s.ByteCount - 1;

            for (int i = s.StartIndex; i <= endIndex; i++)
            {
                Buffer.Add(s.Buffer[i]);
            }

            Buffer.Add(0x0);
            Buffer.Add(0x0);

            if (StaticGlobals.ExecutionMode == ExecutionMode.DEBUG)
            {
                PutToDummy("[(mstring) " + s.ToString() + "]");
            }
        }
示例#19
0
        public static DbValue FORMAT(DbFunctionTools tools, DbFunctionArguments args)
        {
            string FunctionName = "FORMAT";

            args.EnsureCount(FunctionName, 2);

            DbType    arg0type;
            ByteSlice arg0 = args[0].Eval(out arg0type);
            DbType    arg1type;
            ByteSlice arg1 = args[1].Eval(out arg1type);

            if (Types.IsNullValue(arg0))
            {
                return(tools.AllocNullValue()); // Give a null, take a null.
            }
            if (arg0type.ID != DbTypeID.CHARS)
            {
                args.Expected(FunctionName, 0, "input CHAR(n), got " + arg0type.Name.ToUpper());
            }
            if (Types.IsNullValue(arg1))
            {
                return(tools.AllocNullValue()); // Give a null, take a null.
            }
            if (arg1type.ID != DbTypeID.DATETIME)
            {
                args.Expected(FunctionName, 0, "input DATETIME, got " + arg1type.Name.ToUpper());
            }

            string   formatstr = tools.GetString(arg0).ToString();
            DateTime dt        = tools.GetDateTime(arg1);

            mstring result = mstring.Prepare(dt.ToString(formatstr));

            while (result.Length < 80)
            {
                result.MAppend('\0');
            }
            return(tools.AllocValue(result));
        }
示例#20
0
        public static DbValue LEN(DbFunctionTools tools, DbFunctionArguments args)
        {
            string FunctionName = "LEN";

            args.EnsureCount(FunctionName, 1);

            DbType    arg0type;
            ByteSlice arg0 = args[0].Eval(out arg0type);

            if (Types.IsNullValue(arg0))
            {
                return(tools.AllocNullValue()); // Give a null, take a null.
            }
            if (arg0type.ID != DbTypeID.CHARS)
            {
                args.Expected(FunctionName, 0, "input CHAR(n), got " + arg0type.Name.ToUpper());
            }

            mstring x   = tools.GetString(arg0);
            int     len = x.Length;

            return(tools.AllocValue(len));
        }
示例#21
0
        public static DbValue SPACE(DbFunctionTools tools, DbFunctionArguments args)
        {
            string FunctionName = "SPACE";

            args.EnsureCount(FunctionName, 1);

            DbType    arg0type;
            ByteSlice arg0 = args[0].Eval(out arg0type);

            if (Types.IsNullValue(arg0))
            {
                return(tools.AllocNullValue()); // Give a null, take a null.
            }
            if (arg0type.ID != DbTypeID.INT)
            {
                args.Expected(FunctionName, 0, "input INT, got " + arg0type.Name.ToUpper());
                return(null);
            }

            int len = tools.GetInt(arg0);

            if (len < 1)
            {
                return(tools.AllocValue(mstring.Prepare("")));
            }
            else
            {
                mstring s = mstring.Prepare();

                for (int i = 0; i < len; i++)
                {
                    s = s.AppendM(" ");
                }

                return(tools.AllocValue(s));
            }
        }
示例#22
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.");
                    }
                }
            }
        }
示例#23
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.");
                }
            }
        }
示例#24
0
 public DbValue AllocValue(mstring x, int RowSizeBytes)
 {
     List<byte> buf = AllocBuffer(RowSizeBytes);
     buf.Add(0); // Nullable; IsNull=false
     x.ToByteSliceUTF16().AppendTo(buf);
     for (int i = buf.Count; i < RowSizeBytes; i++)
     {
         buf.Add(0);
     }
     return AllocValue(ByteSlice.Prepare(buf), DbTypeID.CHARS);
 }
示例#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.");
                }
            }
        }
示例#26
0
        public void PutString(mstring s)
        {          
            ContainsString = true;

            int endIndex = s.StartIndex + s.ByteCount - 1;

            for (int i = s.StartIndex; i <= endIndex; i++)
            {
                Buffer.Add(s.Buffer[i]);
            }

            Buffer.Add(0x0);
            Buffer.Add(0x0);

            if (StaticGlobals.ExecutionMode == ExecutionMode.DEBUG)
            {
                PutToDummy("[(mstring) " + s.ToString() + "]");
            }
        }
示例#27
0
 public static ByteSlice Prepare(mstring ms)
 {
     return ms.ToByteSlice();
 }
示例#28
0
 public DbValue AllocValue(mstring x)
 {
     List<byte> buf = AllocBuffer(1 + x.Length * 2);
     buf.Add(0); // Nullable; IsNull=false
     x.ToByteSliceUTF16().AppendTo(buf);
     return AllocValue(ByteSlice.Prepare(buf), DbTypeID.CHARS);
 }
示例#29
0
 private void PutString(int index, mstring s)
 {
     PutString(index, s.StartIndex, s.ByteCount);        
 }        
示例#30
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.");
                }
            }
        }
示例#31
0
        private static DbValue _PAD(string functionName, DbFunctionTools tools, DbFunctionArguments args, bool isLeft)
        {
            args.EnsureCount(functionName, 3);

            DbType    arg0type;
            ByteSlice arg0 = args[0].Eval(out arg0type);

            if (Types.IsNullValue(arg0))
            {
                return(tools.AllocNullValue()); // Give a null, take a null.
            }
            if (arg0type.ID != DbTypeID.CHARS)
            {
                args.Expected(functionName, 0, "input CHAR(n), got " + arg0type.Name.ToUpper());
            }
            DbType    arg1type;
            ByteSlice arg1 = args[1].Eval(out arg1type);

            if (Types.IsNullValue(arg1))
            {
                return(tools.AllocNullValue()); // Give a null, take a null.
            }
            if (arg1type.ID != DbTypeID.INT)
            {
                args.Expected(functionName, 0, "input INT, got " + arg1type.Name.ToUpper());
            }
            DbType    arg2type;
            ByteSlice arg2 = args[2].Eval(out arg2type);

            if (Types.IsNullValue(arg2))
            {
                return(tools.AllocNullValue()); // Give a null, take a null.
            }
            if (arg2type.ID != DbTypeID.CHARS)
            {
                args.Expected(functionName, 0, "input CHAR(n), got " + arg2type.Name.ToUpper());
            }

            mstring str      = tools.GetString(arg0);
            int     totallen = tools.GetInt(arg1);
            mstring padstr   = tools.GetString(arg2);

            if (str.Length > totallen)
            {
                str = str.SubstringM(0, totallen);
            }
            else if (str.Length < totallen)
            {
                int     delta  = totallen - str.Length;
                int     padlen = padstr.Length;
                mstring newstr = mstring.Prepare();

                for (int remain = delta; remain > 0;)
                {
                    newstr  = newstr.AppendM(padstr);
                    remain -= padlen;
                }

                //if we go over, truncate.
                if (newstr.Length > delta)
                {
                    newstr = newstr.SubstringM(0, delta);
                }

                if (isLeft)
                {
                    str = newstr.AppendM(str);
                }
                else
                {
                    str = str.AppendM(newstr);
                }
            }
            return(tools.AllocValue(str));
        }
示例#32
0
        public static DbValue CHARINDEX(DbFunctionTools tools, DbFunctionArguments args)
        {
            string FunctionName = "CHARINDEX";

            args.EnsureMinCount(FunctionName, 2);

            int       index = -1;
            DbType    arg0type;
            ByteSlice arg0 = args[0].Eval(out arg0type);
            DbType    arg1type;
            ByteSlice arg1 = args[1].Eval(out arg1type);

            if (Types.IsNullValue(arg0) || Types.IsNullValue(arg1))
            {
                return(tools.AllocValue(index));
            }

            if (arg0type.ID != DbTypeID.CHARS)
            {
                args.Expected(FunctionName, 0, "input CHAR(n), got " + arg0type.Name.ToUpper());
                return(null);
            }
            if (arg1type.ID != DbTypeID.CHARS)
            {
                args.Expected(FunctionName, 0, "input CHAR(n), got " + arg1type.Name.ToUpper());
                return(null);
            }

            int startIndex = 0;

            if (args.Length > 2)
            {
                DbType    arg2type;
                ByteSlice arg2 = args[2].Eval(out arg2type);
                if (arg2type.ID != DbTypeID.INT)
                {
                    args.Expected(FunctionName, 0, "input INT, got " + arg2type.Name.ToUpper());
                    return(null);
                }
                startIndex = tools.GetInt(arg2);
                if (startIndex < 0)
                {
                    startIndex = 0;
                }
            }

            mstring word     = tools.GetString(arg0);
            mstring sentence = tools.GetString(arg1);

            if (startIndex > sentence.Length - 1)
            {
                index = -1;
            }
            else if (startIndex == 0)
            {
                index = sentence.IndexOf(word);
            }
            else
            {
                mstring partsentence = sentence.SubstringM(startIndex);
                int     ix           = partsentence.IndexOf(word);
                if (ix == -1)
                {
                    index = -1;
                }
                else
                {
                    index = startIndex + ix;
                }
            }
            return(tools.AllocValue(index));
        }
示例#33
0
 public void Add(mstring key, recordset value)
 {
     Add(key.ToByteSlice(StaticGlobals.DSpace_KeyLength), value.ToByteSlice());
 }        
示例#34
0
 public void Add(mstring key, mstring value)
 {
     ByteSlice bKey = key.ToByteSlice(StaticGlobals.DSpace_KeyLength);
     ByteSlice bValue = value.ToByteSlice();
     Add(bKey, bValue);
 }
示例#35
0
        public void Add(recordset key, mstring value)
        {
            if (key.ContainsString)
            {
                throw new Exception("Key recordset cannot contain string.");
            }

            Add(key.ToByteSlice(StaticGlobals.DSpace_KeyLength), value.ToByteSlice());
        }
示例#36
0
        private static byte[] bitop(mstring[] values, int whatop)
        {
            byte[] buf = null;
            byte[] result = null;
            for (int i = 0; i < values.Length; i++)
            {
                if (i == 0)
                {
                    ByteSlice bs = values[i].ToByteSliceUTF16();
                    result = bs.ToBytes();
                    continue;
                }

                {
                    ByteSlice bs = values[i].ToByteSliceUTF16();
                    buf = bs.ToBytes();
                }
                bitop(result, buf, whatop);
            }
            return result;
        }
示例#37
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.");
                }
            }
        }
        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.");
                }
            }
        }
示例#39
0
 public static int PutString(mstring s)
 {
     Stack.PutBytes(Stack.Buffer, s.StartIndex, s.ByteCount);
     return s.ByteCount;
 }
示例#40
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));
                }
            }
        }
示例#41
0
        public static void DbAggregators_BIT_OR()
        {
            DbFunctionTools tools = new DbFunctionTools();
            Random rnd = new Random();
            const int rowcount = 20;

            //Double.
            {
                Console.WriteLine("Testing DbAggregators_BIT_OR(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_OR(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs = valOutput.Eval();
                double output = tools.GetDouble(bs);
                byte[] expected = bitop(values, 2);

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

            {
                Console.WriteLine("Testing DbAggregators_BIT_OR(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_OR(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs = valOutput.Eval();
                int output = tools.GetInt(bs);
                byte[] expected = bitop(values, 2);
                if (!compareBytes(expected, bs))
                {
                    throw new Exception("DbAggregators_BIT_OR(Int32) has failed.");
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_BIT_OR(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_OR(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs = valOutput.Eval();
                long output = tools.GetLong(bs);
                byte[] expected = bitop(values, 2);
                if (!compareBytes(expected, bs))
                {
                    throw new Exception("DbAggregators_BIT_OR(Int64) has failed.");
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }

            {
                Console.WriteLine("Testing DbAggregators_BIT_OR(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_OR(tools, new DbAggregatorArguments(fargs));
                ByteSlice bs = valOutput.Eval();
                mstring output = tools.GetString(bs);
                byte[] expected = bitop(values, 2);
                if (!compareBytes(expected, bs))
                {
                    throw new Exception("DbAggregators_BIT_OR(char(n)) has failed.");
                }
                else
                {
                    Console.WriteLine("Expected results received.");
                }
            }
        }
示例#42
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.");
                }
            }
        }
示例#43
0
 public static ByteSlice PreparePaddedMString(mstring x, int size)
 {
     return x.ToByteSlice(size);
 }