/// <summary> 设置存储过程名称和参数,得到执行器 /// </summary> /// <param name="procedureName">存储过程名称</param> /// <param name="args">参数</param> public DbExecuter Proc(string procedureName, params object[] args) { if (args == null) { return(new DbExecuter(_DBHelper, CommandType.StoredProcedure, procedureName, new DbParameter[0], null)); } var length = args.Length; DbParameter[] parameters = new DbParameter[length]; for (int i = 0; i < length; i++) { var p = args[i] as DbParameter; parameters[i] = (p == null) ? _FQLProvider.CreateDbParameter(args[i]) : p; } return(new DbExecuter(_DBHelper, CommandType.StoredProcedure, procedureName, parameters, null)); }
/// <summary> 追加一个值到参数 /// </summary> private DbParameter AppendValues(object value) { var dp = value as DbParameter; #region DbParameter if (dp != null) { AppendValues(dp); return(null); } #endregion string pname = GetParameterName(); if (Values.ContainsKey(pname)) { SqlBuffer.Append(Provider.ParameterPrefix); SqlBuffer.Append(Values[pname].ParameterName); return(null); } var t = value as Type; #region Type if (t != null) { if (!_isOut) { throw new FormatException(GetErrorMessage("当参数是 Type 类型时,必须使用关键字out或ref")); } if (t == typeof(object)) { throw new FormatException(GetErrorMessage("无法从 typeof(object) 推断返回值的类型")); } var p = Provider.CreateDbParameter(Convert2.TypeToDbType(t), t); p.ParameterName = pname; AddParameter(pname, p); p.Direction = (_isIn) ? ParameterDirection.InputOutput : ParameterDirection.Output; return(p); } #endregion var em = value as IEnumerable; #region IEnumerable if (em != null && value is string == false) //string实现接口IEnumerable { if (_isOut) { throw new FormatException(GetErrorMessage("当参数是 IEnumerable 类型时,不能使用关键字out/ref")); } var ee = em.GetEnumerator(); if (ee.MoveNext()) { _enumerIndex++; AppendValues(ee.Current); while (ee.MoveNext()) { _enumerIndex++; SqlBuffer.Append(','); AppendValues(ee.Current); } } else { throw new FormatException(GetErrorMessage("当参数是 IEnumerable 类型时,元素个数不能为0")); } return(null); } #endregion { var p = Provider.CreateDbParameter(value); if (p == null) { SqlBuffer.Append("NULL"); return(null); } p.ParameterName = pname; AddParameter(pname, p); if (_isIn) { p.Direction = _isOut ? ParameterDirection.InputOutput : ParameterDirection.Input; } else { p.Direction = ParameterDirection.Output; } return(p); } }