A parameter to a BigQueryCommand.
Inheritance: System.Data.Common.DbParameter, ICloneable
Ejemplo n.º 1
0
        static string ConvertToStringForLegacySql(BigQueryParameter parameter) {
            if(parameter?.Value == null)
                return null;
            
            if(parameter.BigQueryDbType == BigQueryDbType.String) {
                var invariantString = parameter.Value.ToInvariantString();
                var trimmedString = invariantString.Substring(0, parameter.Size);
                var escapedString = EscapeString(trimmedString);
                return $"'{escapedString}'";
            }

            string format = "{0}";

            switch(parameter.BigQueryDbType) {
                case BigQueryDbType.DateTime:
                    format = "cast('{0}' as DATETIME)";
                    break;
                case BigQueryDbType.Date:
                    format = "cast('{0}' as DATE)";
                    break;
                case BigQueryDbType.Time:
                    format = "cast('{0}' as TIME)";
                    break;
                case BigQueryDbType.Timestamp:
                    format = "cast('{0}' as TIMESTAMP)";
                    break;
            } 
            
            return ConvertToString(parameter).ToInvariantString(format);
        }
        static string ConvertToString(BigQueryParameter parameter)
        {
            if (parameter?.Value == null)
            {
                return(null);
            }

            string format = "{0}";

            switch (parameter.BigQueryDbType)
            {
            case BigQueryDbType.DateTime:
                format = "{0:yyyy-MM-dd HH:mm:ss.ffffff}";
                break;

            case BigQueryDbType.Date:
                format = "{0:yyyy-MM-dd}";
                break;

            case BigQueryDbType.Time:
                format = "{0:HH:mm:ss.ffffff}";
                break;

            case BigQueryDbType.Timestamp:
                format = "{0:u}";
                break;
            }

            return(parameter.Value.ToInvariantString(format));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// returns the index of the specified parameter.
        /// </summary>
        /// <param name="parameterName">The name of a BigQueryParameter.</param>
        /// <returns>the index of the specified BigQueryParameter.</returns>
        public override int IndexOf(string parameterName)
        {
            BigQueryParameter value = innerList.FirstOrDefault(p => p.ParameterName == parameterName);

            return(IndexOf(value));
        }
 /// <summary>
 ///  Creates a shallow copy of the current BigQueryParameter.
 /// </summary>
 /// <returns>a shallow copy of the current BigQueryParameter.</returns>
 public BigQueryParameter Clone()
 {
     BigQueryParameter parameter = new BigQueryParameter(ParameterName, Value) {
         Direction = Direction,
         IsNullable = IsNullable,
         DbType = DbType,
         BigQueryDbType = BigQueryDbType,
         Size = Size,
     };
     return parameter;
 }