/// <summary> /// 根据CommandSchema创建命令,并将Shema中的参数设置到命令 /// </summary> /// <param name="cmdSchema">命令配置</param> /// <returns></returns> public DbCommand getCommand(CommandSchema cmdSchema) { if (cmdSchema == null || string.IsNullOrEmpty(cmdSchema.CommandText)) { throw new XException(Lang.NoUpLoadCommand); } DbCommand cmd = dbAdmin.getSqlCommand(cmdSchema.CommandText, cmdSchema.CommandType); SqlParse sqlp = new SqlParse(cmdSchema.CommandText); string[] parameters = sqlp.GetParamNames(); foreach (string pName in parameters) { string fName = pName.Remove(0, 1); string val = null; DbType pType = DbType.String; ParameterDirection pDir = ParameterDirection.Input; ParameterSchema ps = cmdSchema.QueryParams == null ? null : cmdSchema.QueryParams.FindItem(pName); FieldSchema flds = schema.Fields == null ? null : schema.Fields.FindItem(fName); if (pName.StartsWith(XSqlBuilder.OLD_VERSION_PIX)) { flds = schema.Fields.FindItem(fName.Remove(0, XSqlBuilder.OLD_VERSION_PIX.Length)); } //获取字典定义中的参数类型,参数方向默认为input if (flds != null) { pType = flds.DataType; } //获取参数定义中的参数类型,及参数方向; if (ps != null) { pType = ps.DataType; val = ps.DefaultValue; pDir = ps.Direction; } //if (row.ContainsKey(fName)) // val = row[fName]; //if (realParams.ContainsKey(pName)) // val = realParams[pName]; switch (pDir) { case ParameterDirection.Input: dbAdmin.addInParameter(cmd, pName, pType, val); break; case ParameterDirection.InputOutput: break; case ParameterDirection.Output: dbAdmin.AddOutParameter(cmd, pName, pType, int.MaxValue); break; } } return(cmd); }