コード例 #1
0
        /// <summary>
        /// Creates a new BoundStatement object and bind its variables to the provided
        /// values.
        /// <para>
        /// Specify the parameter values by the position of the markers in the query or by name,
        /// using a single instance of an anonymous type, with property names as parameter names.
        /// </para>
        /// <para>
        /// Note that while no more <c>values</c> than bound variables can be provided, it is allowed to
        /// provide less <c>values</c> that there is variables.
        /// </para>
        /// </summary>
        /// <param name="values"> the values to bind to the variables of the newly
        ///  created BoundStatement. </param>
        /// <returns>the newly created <c>BoundStatement</c> with its variables
        ///  bound to <c>values</c>. </returns>
        public BoundStatement Bind(params object[] values)
        {
            var bs = new BoundStatement(this)
            {
                ProtocolVersion = _protocolVersion
            };

            bs.SetRoutingKey(_routingKey);
            if (values == null)
            {
                return(bs);
            }
            var valuesByPosition   = values;
            var useNamedParameters = values.Length == 1 && Utils.IsAnonymousType(values[0]);

            if (useNamedParameters)
            {
                //Using named parameters
                //Reorder the params according the position in the query
                valuesByPosition = Utils.GetValues(Metadata.Columns.Select(c => c.Name), values[0]).ToArray();
            }
            bs.SetValues(valuesByPosition);
            bs.CalculateRoutingKey(useNamedParameters, RoutingIndexes, _routingNames, valuesByPosition, values);
            return(bs);
        }
コード例 #2
0
        /// <summary>
        /// <para>
        /// Creates a new <see cref="BoundStatement"/> instance with the provided parameter values.
        /// </para>
        /// <para>
        /// You can specify the parameter values by the position of the markers in the query, or by name
        /// using a single instance of an anonymous type, with property names as parameter names.
        /// </para>
        /// <para>
        /// Note that while no more <c>values</c> than bound variables can be provided, it is allowed to
        /// provide less <c>values</c> that there is variables.
        /// </para>
        /// <para>
        /// You can provide a comma-separated variable number of arguments to the <c>Bind()</c> method. When providing
        /// an array, the reference might be used by the driver making it not safe to modify its content.
        /// </para>
        /// </summary>
        /// <param name="values">The values to bind to the variables of the newly created BoundStatement.</param>
        /// <returns>The newly created <see cref="BoundStatement"/> with the query parameters set.</returns>
        /// <example>
        /// Binding different parameters:
        /// <code>
        /// PreparedStatement ps = session.Prepare("INSERT INTO table (id, name) VALUES (?, ?)");
        /// BoundStatement statement = ps.Bind(Guid.NewGuid(), "Franz Ferdinand");
        /// session.Execute(statement);
        /// </code>
        /// </example>
        public virtual BoundStatement Bind(params object[] values)
        {
            var bs = new BoundStatement(this);

            bs.SetRoutingKey(_routingKey);
            if (values == null)
            {
                return(bs);
            }
            var valuesByPosition   = values;
            var useNamedParameters = values.Length == 1 && Utils.IsAnonymousType(values[0]);

            if (useNamedParameters)
            {
                //Using named parameters
                //Reorder the params according the position in the query
                valuesByPosition = Utils.GetValues(_variablesRowsMetadata.Columns.Select(c => c.Name), values[0]).ToArray();
            }

            var serializer = _serializerManager.GetCurrentSerializer();

            bs.SetValues(valuesByPosition, serializer);
            bs.CalculateRoutingKey(serializer, useNamedParameters, RoutingIndexes, _routingNames, valuesByPosition, values);
            return(bs);
        }
コード例 #3
0
 /// <summary>
 /// Creates a new BoundStatement object and bind its variables to the provided
 /// values.
 /// <para>
 /// Specify the parameter values by the position of the markers in the query or by name, 
 /// using a single instance of an anonymous type, with property names as parameter names.
 /// </para>
 /// <para>
 /// Note that while no more <c>values</c> than bound variables can be provided, it is allowed to
 /// provide less <c>values</c> that there is variables.
 /// </para>
 /// </summary>
 /// <param name="values"> the values to bind to the variables of the newly
 ///  created BoundStatement. </param>
 /// <returns>the newly created <c>BoundStatement</c> with its variables
 ///  bound to <c>values</c>. </returns>
 public virtual BoundStatement Bind(params object[] values)
 {
     var bs = new BoundStatement(this, _serializer);
     bs.SetRoutingKey(_routingKey);
     if (values == null)
     {
         return bs;
     }
     var valuesByPosition = values;
     var useNamedParameters = values.Length == 1 && Utils.IsAnonymousType(values[0]);
     if (useNamedParameters)
     {
         //Using named parameters
         //Reorder the params according the position in the query
         valuesByPosition = Utils.GetValues(Metadata.Columns.Select(c => c.Name), values[0]).ToArray();
     }
     bs.SetValues(valuesByPosition);
     bs.CalculateRoutingKey(useNamedParameters, RoutingIndexes, _routingNames, valuesByPosition, values);
     return bs;
 }