예제 #1
0
        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();
            }
        }
예제 #2
0
        public void TestGetString(TestCaseResult result)
        {
            InsertRowText();

            VirtuosoCommand cmd = connection.CreateCommand();

            cmd.CommandText = "select data from xmlt";

            VirtuosoDataReader rdr = cmd.ExecuteReader();

            rdr.Read();
            String x = rdr.GetString(0);

            FailIfXmlNotEqual(result, x, TheXml);
        }
예제 #3
0
        public void TestGetValue(TestCaseResult result)
        {
            InsertRowText();

            VirtuosoCommand cmd = connection.CreateCommand();

            cmd.CommandText = "select data from xmlt";

            VirtuosoDataReader rdr = cmd.ExecuteReader();

            rdr.Read();
            object obj = rdr.GetValue(0);

            result.FailIfNotEqual(typeof(SqlXml).Name, obj.GetType().Name);
            SqlXml x = (SqlXml)obj;

            FailIfXmlNotEqual(result, x.ToString(), TheXml);
        }
예제 #4
0
        public void TestGetSqlXmlReader(TestCaseResult result)
        {
            InsertRowText();

            VirtuosoCommand cmd = connection.CreateCommand();

            cmd.CommandText = "select data from xmlt";

            VirtuosoDataReader rdr = cmd.ExecuteReader();

            rdr.Read();
            SqlXml x = rdr.GetSqlXml(0);

            XmlDocument doc = new XmlDocument();

            doc.Load(x.CreateReader());

            FailIfXmlNotEqual(result, doc.OuterXml, TheXml);
        }
예제 #5
0
        public void TestInsertSqlXml(TestCaseResult result)
        {
            VirtuosoCommand insert = connection.CreateCommand();

            insert.CommandText = "insert into xmlt (id, data) values (1, ?)";
            insert.Parameters.Add(new VirtuosoParameter(":0", new SqlXml(TheXml)));
            insert.ExecuteNonQuery();
            insert.Dispose();

            VirtuosoCommand cmd = connection.CreateCommand();

            cmd.CommandText = "select data from xmlt";

            VirtuosoDataReader rdr = cmd.ExecuteReader();

            rdr.Read();
            SqlXml x = rdr.GetSqlXml(0);

            FailIfXmlNotEqual(result, x.ToString(), TheXml);
        }
예제 #6
0
        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();
            }
        }
예제 #7
0
        public static void DeriveParameters(VirtuosoCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            if (command.CommandType != CommandType.StoredProcedure)
            {
                throw new InvalidOperationException("DeriveParameters supports only stored procedures.");
            }

            VirtuosoConnection connection = (VirtuosoConnection)command.Connection;

            if (connection == null)
            {
                throw new InvalidOperationException("The Connection property is not set.");
            }
            if (connection.State == ConnectionState.Closed)
            {
                throw new InvalidOperationException("The connection is closed.");
            }

            IInnerCommand      innerCommand = null;
            VirtuosoDataReader reader       = null;

            try
            {
                innerCommand = connection.innerConnection.CreateInnerCommand(null);
                innerCommand.GetProcedureColumns(command.CommandText);
                reader = new VirtuosoDataReader(connection, innerCommand, null, CommandBehavior.Default, false);

                command.Parameters.Clear();
                while (reader.Read())
                {
                    CLI.InOutType iotype = (CLI.InOutType)reader.GetInt16(reader.GetOrdinal("COLUMN_TYPE"));

                    ParameterDirection direction;
                    switch (iotype)
                    {
                    case CLI.InOutType.SQL_PARAM_INPUT:
                        direction = ParameterDirection.Input;
                        break;

                    case CLI.InOutType.SQL_PARAM_OUTPUT:
                        direction = ParameterDirection.Output;
                        break;

                    case CLI.InOutType.SQL_PARAM_INPUT_OUTPUT:
                        direction = ParameterDirection.InputOutput;
                        break;

                    case CLI.InOutType.SQL_PARAM_RETURN_VALUE:
                        direction = ParameterDirection.ReturnValue;
                        break;

                    default:
#if MONO
                        direction = ParameterDirection.Input;
#endif
                        continue;
                    }

                    string name = reader.GetString(reader.GetOrdinal("COLUMN_NAME"));
                    if (name == "" && iotype == CLI.InOutType.SQL_PARAM_RETURN_VALUE)
                    {
                        name = "ReturnValue";
                    }

                    CLI.SqlType sqlType = (CLI.SqlType)reader.GetInt16(reader.GetOrdinal("DATA_TYPE"));
                    DataType    type    = DataTypeInfo.MapSqlType(sqlType);
                    if (type == null)
                    {
                        throw new SystemException("Unknown data type");
                    }

                    int sizeOrdinal = reader.GetOrdinal("COLUMN_SIZE");
                    if (sizeOrdinal < 0)
                    {
                        sizeOrdinal = reader.GetOrdinal("PRECISION");
                    }
                    int size = reader.IsDBNull(sizeOrdinal) ? 0 : reader.GetInt32(sizeOrdinal);

                    int scaleOrdinal = reader.GetOrdinal("DECIMAL_DIGITS");
                    if (scaleOrdinal < 0)
                    {
                        scaleOrdinal = reader.GetOrdinal("SCALE");
                    }
                    short scale = reader.IsDBNull(scaleOrdinal) ? (short)0 : reader.GetInt16(scaleOrdinal);

                    int          nullableOrdinal = reader.GetOrdinal("NULLABLE");
                    CLI.Nullable nullable        = (CLI.Nullable)reader.GetInt16(nullableOrdinal);
                    bool         isNullable      = (nullable != CLI.Nullable.SQL_NO_NULLS);

                    VirtuosoParameter parameter = (VirtuosoParameter)command.CreateParameter();
                    parameter.ParameterName = name;
                    parameter.Direction     = direction;
                    parameter.VirtDbType    = type.vdbType;
                    parameter.Size          = type.GetFieldSize(size);
                    parameter.Precision     = type.GetPrecision(size);
                    parameter.Scale         = (byte)scale;
                    parameter.IsNullable    = isNullable;
                    command.Parameters.Add(parameter);
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                if (innerCommand != null)
                {
                    innerCommand.Dispose();
                }
            }
        }
예제 #8
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;
                        }
                    }
                }
            }
        }