コード例 #1
0
        public void BuildCommandForSqlQueryWithStoredProcedureWithParameters()
        {
            var command = new OleDbCommand();

            var sqlQuery = new SqlQuery(
                "CALL GetTableContents @identifier, @Cust_Name",
                100, "hello");

            var dbDriver = new MySqlDbDriver();
            dbDriver.BuildCommand(command, sqlQuery);

            // The command text should only contain the stored procedure name.
            Assert.Equal("GetTableContents", command.CommandText);
            Assert.Equal(CommandType.StoredProcedure, command.CommandType);
            Assert.Equal(2, command.Parameters.Count);

            var parameter1 = (IDataParameter)command.Parameters[0];
            Assert.Equal(DbType.Int32, parameter1.DbType);
            Assert.Equal(ParameterDirection.Input, parameter1.Direction);
            Assert.Equal("@identifier", parameter1.ParameterName);
            Assert.Equal(sqlQuery.Arguments[0].Value, parameter1.Value);

            var parameter2 = (IDataParameter)command.Parameters[1];
            Assert.Equal(DbType.String, parameter2.DbType);
            Assert.Equal(ParameterDirection.Input, parameter2.Direction);
            Assert.Equal("@Cust_Name", parameter2.ParameterName);
            Assert.Equal(sqlQuery.Arguments[1].Value, parameter2.Value);
        }
コード例 #2
0
        public void BuildCommandForSqlQueryWithSqlTextWhichUsesSameParameterTwice()
        {
            var command = new OleDbCommand();

            var sqlQuery = new SqlQuery(
                "SELECT * FROM `Table` WHERE `Table`.`Id` = @p0 AND `Table`.`Value1` = @p1 OR @p1 IS NULL",
                100, "hello");

            var dbDriver = new MySqlDbDriver();
            dbDriver.BuildCommand(command, sqlQuery);

            Assert.Equal(sqlQuery.CommandText, command.CommandText);
            Assert.Equal(CommandType.Text, command.CommandType);
            Assert.Equal(2, command.Parameters.Count);

            var parameter1 = (IDataParameter)command.Parameters[0];
            Assert.Equal(DbType.Int32, parameter1.DbType);
            Assert.Equal(ParameterDirection.Input, parameter1.Direction);
            Assert.Equal("@p0", parameter1.ParameterName);
            Assert.Equal(sqlQuery.Arguments[0].Value, parameter1.Value);

            var parameter2 = (IDataParameter)command.Parameters[1];
            Assert.Equal(DbType.String, parameter2.DbType);
            Assert.Equal(ParameterDirection.Input, parameter2.Direction);
            Assert.Equal("@p1", parameter2.ParameterName);
            Assert.Equal(sqlQuery.Arguments[1].Value, parameter2.Value);
        }
コード例 #3
0
        public void BuildCommandForSqlQueryWithStoredProcedureWithoutParameters()
        {
            var command = new OleDbCommand();

            var sqlQuery = new SqlQuery("CALL GetTableContents");

            var dbDriver = new MySqlDbDriver();
            dbDriver.BuildCommand(command, sqlQuery);

            // The command text should only contain the stored procedure name.
            Assert.Equal("GetTableContents", command.CommandText);
            Assert.Equal(CommandType.StoredProcedure, command.CommandType);
            Assert.Equal(0, command.Parameters.Count);
        }