private void AddParameters(Report rpt, IDbConnection cn, IDbCommand cmSQL, bool bValue) { // any parameters to substitute if (this._QueryParameters == null || this._QueryParameters.Items == null || this._QueryParameters.Items.Count == 0 || this._QueryParameters.ContainsArray) // arrays get handled by AddParametersAsLiterals { return; } // AddParametersAsLiterals handles it when there is replacement if (RdlEngineConfig.DoParameterReplacement(Provider, cn)) { return; } foreach (QueryParameter qp in this._QueryParameters.Items) { string paramName; // force the name to start with @ if (qp.Name.Nm[0] == '@') { paramName = qp.Name.Nm; } else { paramName = "@" + qp.Name.Nm; } object pvalue = bValue? qp.Value.Evaluate(rpt, null): null; IDbDataParameter dp = cmSQL.CreateParameter(); dp.ParameterName = paramName; if (pvalue is ArrayList) // Probably a MultiValue Report parameter result { ArrayList ar = (ArrayList)pvalue; dp.Value = ar.ToArray(ar[0].GetType()); } else { dp.Value = pvalue; } cmSQL.Parameters.Add(dp); } }
private string AddParametersAsLiterals(Report rpt, IDbConnection cn, string sql, bool bValue) { // No parameters means nothing to do if (this._QueryParameters == null || this._QueryParameters.Items == null || this._QueryParameters.Items.Count == 0) { return(sql); } // Only do this for ODBC datasources - AddParameters handles it in other cases if (!RdlEngineConfig.DoParameterReplacement(Provider, cn)) { if (!_QueryParameters.ContainsArray) // when array we do substitution { return(sql); } } StringBuilder sb = new StringBuilder(sql); List <QueryParameter> qlist; if (_QueryParameters.Items.Count <= 1) { qlist = _QueryParameters.Items; } else { // need to sort the list so that longer items are first in the list // otherwise substitution could be done incorrectly qlist = new List <QueryParameter>(_QueryParameters.Items); qlist.Sort(); } foreach (QueryParameter qp in qlist) { string paramName; // force the name to start with @ if (qp.Name.Nm[0] == '@') { paramName = qp.Name.Nm; } else { paramName = "@" + qp.Name.Nm; } // build the replacement value string svalue; if (bValue) { // use the value provided svalue = this.ParameterValue(rpt, qp); } else { // just need a place holder value that will pass parsing switch (qp.Value.Expr.GetTypeCode()) { case TypeCode.Char: svalue = "' '"; break; case TypeCode.DateTime: svalue = "'1900-01-01 00:00:00'"; break; case TypeCode.Decimal: case TypeCode.Double: case TypeCode.Int32: case TypeCode.Int64: svalue = "0"; break; case TypeCode.Boolean: svalue = "'false'"; break; case TypeCode.String: default: svalue = "' '"; break; } } sb.Replace(paramName, svalue); } return(sb.ToString()); }