/// <summary> /// Constructs a parameter with the given name, type and value. /// </summary> /// <param name="name">The initial name of the parameter.</param> /// <param name="type">The initial type of the parameter.</param> /// <param name="value">The initial value of the parameter.</param> public BigQueryParameter(string name, BigQueryDbType?type, object value) { Name = name; if (type != null) { Type = GaxPreconditions.CheckEnumValue(type.Value, nameof(type)); } ValidateValue(value, nameof(value)); // Proof against refactoring of parameter name... Value = value; }
public void ToQueryParameter_Invalid(string name, BigQueryDbType?type, object value) { var parameter = new BigQueryParameter(type, value); Assert.Throws <InvalidOperationException>(() => parameter.ToQueryParameter()); }
private static QueryParameter PopulateArrayParameter(QueryParameter parameter, object value, BigQueryDbType?arrayType) { if (value == null) { throw new InvalidOperationException("The value of an array parameter cannot be null"); } if (!IsArrayValue(value)) { throw new InvalidOperationException($"Invalid value for array parameter: {value.GetType()}"); } List <object> values = ((IEnumerable)value).Cast <object>().ToList(); if (values.Any(v => v == null)) { throw new InvalidOperationException("Array parameter values cannot contain null elements"); } BigQueryDbType actualArrayType = arrayType ?? s_typeMapping[GetArrayElementType(value)]; parameter.ParameterType = new QueryParameterType { Type = BigQueryDbType.Array.ToParameterApiType(), ArrayType = new QueryParameterType { Type = actualArrayType.ToParameterApiType() } }; var parameterValues = values .Select(p => new BigQueryParameter(actualArrayType, p).ToQueryParameter().ParameterValue) .ToList(); parameter.ParameterValue = new QueryParameterValue { ArrayValues = parameterValues }; return(parameter); }
/// <summary> /// Constructs a parameter with the given name and type, but no initial value. /// </summary> /// <param name="name">The initial name of the parameter.</param> /// <param name="type">The initial type of the parameter.</param> public BigQueryParameter(string name, BigQueryDbType?type) : this(name, type, null) { }
/// <summary> /// Constructs a parameter with no name, and the specified type and value. /// </summary> /// <param name="type">The initial type of the parameter.</param> /// <param name="value">The initial value of the parameter.</param> public BigQueryParameter(BigQueryDbType?type, object value) : this(null, type, value) { }
/// <summary> /// Adds a new parameter to the collection with the given type and value, but no name. /// </summary> /// <param name="type">The initial type of the parameter.</param> /// <param name="value">The initial value of the parameter.</param> public BigQueryParameter Add(BigQueryDbType?type, object value) => Add(new BigQueryParameter(type, value));
/// <summary> /// Adds a new parameter to the collection with the given name, type and value. /// </summary> /// <param name="name">The initial name of the parameter.</param> /// <param name="type">The initial type of the parameter.</param> /// <param name="value">The initial value of the parameter.</param> /// <returns>The parameter added.</returns> public BigQueryParameter Add(string name, BigQueryDbType?type, object value) => Add(new BigQueryParameter(name, type, value));
/// <summary> /// Adds a new parameter to the collection with the given name and type, but no initial value. /// </summary> /// <param name="name">The initial name of the parameter.</param> /// <param name="type">The initial type of the parameter.</param> /// <returns>The parameter added.</returns> public BigQueryParameter Add(string name, BigQueryDbType?type) => Add(new BigQueryParameter(name, type));