Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
 internal override void SetValues(object[] values)
 {
     if (values != null && values.Length == 1 && Utils.IsAnonymousType(values[0]))
     {
         var keyValues = Utils.GetValues(values[0]);
         SetParameterNames(keyValues.Keys);
         values = keyValues.Values.ToArray();
     }
     base.SetValues(values);
 }
Ejemplo n.º 4
0
 internal override void SetValues(object[] values)
 {
     if (values != null && values.Length == 1 && Utils.IsAnonymousType(values[0]))
     {
         var keyValues = Utils.GetValues(values[0]);
         //Force named values to lowercase as identifiers are lowercased in Cassandra
         QueryValueNames = keyValues.Keys.Select(k => k.ToLowerInvariant()).ToList();
         values          = keyValues.Values.ToArray();
     }
     base.SetValues(values);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Sets the parameter values for the query.
 /// <para>
 /// The same amount of values must be provided as parameter markers in the query.
 /// </para>
 /// <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>
 /// </summary>
 public SimpleStatement Bind(params object[] values)
 {
     if (values != null && values.Length == 1 && Utils.IsAnonymousType(values[0]))
     {
         var keyValues = Utils.GetValues(values[0]);
         //Force named values to lowercase as identifiers are lowercased in Cassandra
         QueryValueNames = keyValues.Keys.Select(k => k.ToLowerInvariant()).ToList();
         values          = keyValues.Values.ToArray();
     }
     SetValues(values);
     return(this);
 }
Ejemplo n.º 6
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);

            if (values != null && values.Length == 1 && Utils.IsAnonymousType(values[0]))
            {
                //Using named params
                //Reorder the params according the position in the query
                values = Utils.GetValues(Metadata.Columns.Select(c => c.Name), values[0]).ToArray();
            }
            bs.SetValues(values);
            return(bs);
        }