public void MultipleResultSets(TestCaseResult result)
        {
            DropProcedure();
            ExecuteNonQuery(
                "create procedure bar ()\n" +
                "{\n" +
                "  declare i int;\n" +
                "  declare c char;\n" +
                "  result_names (i);\n" +
                "  result (1);\n" +
                "  result (2);\n" +
                "  end_result ();\n" +
                "  result_names (c);\n" +
                "  result ('a');\n" +
                "  result ('b');\n" +
                "  return 0;\n" +
                "}\n"
                );

            VirtuosoCommand command = connection.CreateCommand();

            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "bar";

            VirtuosoDataReader reader = null;

            try
            {
                reader = command.ExecuteReader();
                result.FailIfNotEqual(1, reader.FieldCount);
                result.FailIfNotEqual("i", reader.GetName(0).ToLower());
                result.FailIfNotEqual(typeof(int), reader.GetFieldType(0));
                result.FailIfNotEqual(true, reader.Read());
                result.FailIfNotEqual(1, reader["i"]);
                result.FailIfNotEqual(true, reader.Read());
                result.FailIfNotEqual(2, reader["i"]);
                result.FailIfNotEqual(false, reader.Read());
                result.FailIfNotEqual(true, reader.NextResult());
                result.FailIfNotEqual(1, reader.FieldCount);
                result.FailIfNotEqual("c", reader.GetName(0).ToLower());
                result.FailIfNotEqual(typeof(string), reader.GetFieldType(0));
                result.FailIfNotEqual(true, reader.Read());
                result.FailIfNotEqual("a", reader["c"]);
                result.FailIfNotEqual(true, reader.Read());
                result.FailIfNotEqual("b", reader["c"]);
                result.FailIfNotEqual(false, reader.NextResult());
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                command.Dispose();
            }
        }
        public void ResultSetAndOutputParameters(TestCaseResult result)
        {
            DropProcedure();
            DropProcedure();
            ExecuteNonQuery(
                "create procedure bar (out x integer)\n" +
                "{\n" +
                "  declare i int;\n" +
                "  result_names (i);\n" +
                "  result (1);\n" +
                "  result (2);\n" +
                "  x := 3;\n" +
                "  return 4;\n" +
                "}\n"
                );

            VirtuosoCommand command = connection.CreateCommand();

            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "bar";

            VirtuosoParameter returnValue = command.CreateParameter();

            returnValue.ParameterName = "ReturnValue";
            returnValue.Direction     = ParameterDirection.ReturnValue;
            returnValue.VirtDbType    = VirtDbType.Integer;
            command.Parameters.Add(returnValue);

            VirtuosoParameter x = command.CreateParameter();

            x.ParameterName = "x";
            x.Direction     = ParameterDirection.Output;
            x.VirtDbType    = VirtDbType.Integer;
            command.Parameters.Add(x);

            VirtuosoDataReader reader = null;
            bool closed = false;

            try
            {
                reader = command.ExecuteReader();
                result.FailIfNotEqual(1, reader.FieldCount);
                result.FailIfNotEqual("i", reader.GetName(0).ToLower());
                result.FailIfNotEqual(typeof(int), reader.GetFieldType(0));
                result.FailIfNotEqual(true, reader.Read());
                result.FailIfNotEqual(1, reader["i"]);
                result.FailIfNotEqual(true, reader.Read());
                result.FailIfNotEqual(2, reader["i"]);
                result.FailIfNotEqual(false, reader.Read());

                reader.Close();
                closed = true;

                result.FailIfNotEqual("Out Parameter", 3, x.Value);
                result.FailIfNotEqual("Return Value", 4, returnValue.Value);
            }
            finally
            {
                if (reader != null && !closed)
                {
                    reader.Close();
                }
                command.Dispose();
            }
        }
示例#3
0
        private void CheckGetData(TestCaseResult result,
                                  VirtuosoDataReader dr, int column, Selector selector, Sequence sequence)
        {
            string name        = dr.GetName(column);
            int    tableColumn = checkTable.Columns.IndexOf(name);

            for (int row = 0; dr.Read(); row++)
            {
                //if (dr.IsDBNull (column))
                if (row == 0)
                {
                    continue;
                }

                long length;
                if (selector == Selector.GetBytes)
                {
                    length = dr.GetBytes(column, 0, null, 0, 0);
                }
                else                 //if (selector == Selector.GetChars)
                {
                    length = dr.GetChars(column, 0, null, 0, 0);
                }

                //Console.WriteLine ("row: {0}", row);
                //Console.WriteLine ("length: {0}", length);

                CompareSize(result, row, tableColumn, selector, length, 0);

                long   offset = 0;
                byte[] bytes  = new byte[BufferSize];
                char[] chars  = new char[BufferSize];
                int    count  = 0;
                while (offset < length)
                {
                    //Console.WriteLine ("offset: {0}", offset);

                    long nextLength;
                    if (selector == Selector.GetBytes)
                    {
                        for (int i = 0; i < bytes.Length; i++)
                        {
                            bytes[i] = 0;
                        }
                        nextLength = dr.GetBytes(column, offset, bytes, 0, bytes.Length);
                    }
                    else                     //if (selector == Selector.GetChars)
                    {
                        for (int i = 0; i < chars.Length; i++)
                        {
                            chars[i] = (char)0;
                        }
                        nextLength = dr.GetChars(column, offset, chars, 0, chars.Length);
                    }

                    result.FailIfEqual(this, 0, nextLength);
                    if (offset + nextLength < length)
                    {
                        result.FailIfNotEqual(this, (long)BufferSize, nextLength);
                    }
                    else
                    {
                        result.FailIfNotEqual(this, (long)(length - offset), nextLength);
                    }

                    if (selector == Selector.GetBytes)
                    {
                        CompareData(result, row, tableColumn, bytes, nextLength, offset);
                    }
                    else                     //if (selector == Selector.GetChars)
                    {
                        CompareData(result, row, tableColumn, chars, nextLength, offset);
                    }

                    if (sequence == Sequence.GetAll)
                    {
                        offset += nextLength;
                    }
                    else if (sequence == Sequence.GetHalf)
                    {
                        offset += 2 * nextLength;
                    }
                    else                     //if (sequence == Sequence.GetTwice)
                    {
                        count++;
                        if (count == 2)
                        {
                            count   = 0;
                            offset += 2 * nextLength;
                        }
                    }
                }
            }
        }