public override object calculate() { object obj3; try { if (base.paramList.Count < 2) { throw new ReportError("dbsql函数参数列表至少有2个"); } IDbConnection connection = null; string dsn = null; string sql = null; string encoding = null; ExpParse parse3 = (ExpParse)base.paramList[0]; if (parse3 != null) { object obj7 = ConvertTool.getValue(parse3.calculate()); if (!(obj7 is string)) { throw new ReportError("dbsql函数参数个数为1时参数应为数据库逻辑名"); } dsn = (string)obj7; } connection = (dsn != null) ? base.env.getConnection(dsn) : base.env.getConnection(); if ((connection == null) || (connection.State == null)) { throw new ReportError("dbsql函数执行异常,无有效数据库连接"); } encoding = (dsn != null) ? base.env.getDBCharset(dsn) : base.env.getDBCharset(); object obj6 = ConvertTool.getValue(((ExpParse)base.paramList[1]).calculate()); if (!(obj6 is string)) { throw new ReportError("dbsql函数参数2应为sql串"); } sql = (string)obj6; IDbCommand pst = SupportClass.TransactionManager.manager.PrepareStatement(connection, sql); for (int i = 2; i < base.paramList.Count; i++) { ExpParse parse = (ExpParse)base.paramList[i]; if (parse == null) { throw new ReportError("数据库查询函数出现无效参数"); } object o = ConvertTool.getValue(parse.calculate()); SQLTool.setObject(pst, i - 1, o, 12, ""); } if (pst.ExecuteNonQuery() > 0) { pst.Dispose(); return(null); } ArrayList list = new ArrayList(); IDataReader rs = pst.ExecuteReader(); while (rs.Read()) { list.Add(SQLTool.getObject(rs, 0, encoding)); } rs.Close(); pst.Dispose(); if (list.Count != 1) { return(list); } obj3 = list[0]; } catch (IOException exception) { throw new ReportError("dbsql函数sql异常:" + exception.Message.ToString().ToString(), exception); } catch (OleDbException exception2) { throw new ReportError("dbsql函数sql异常:" + exception2.Message.ToString().ToString(), exception2); } return(obj3); }
public override object calculate() { object obj2; try { if (base.paramList.Count < 2) { throw new ReportError("dbcall函数参数列表至少有2个"); } IDbConnection connection = null; string dsn = null; string sql = null; string encoding = null; ExpParse parse4 = (ExpParse)base.paramList[0]; if (parse4 != null) { object obj8 = ConvertTool.getValue(parse4.calculate()); if (!(obj8 is string)) { throw new ReportError("dbcall函数参数个数为1时参数应为数据库逻辑名"); } dsn = (string)obj8; } connection = (dsn == null) ? base.env.getConnection() : base.env.getConnection(dsn); if ((connection == null) || (connection.State == null)) { throw new ReportError("过程调用函数执行异常,无有效数据库连接"); } encoding = (dsn != null) ? base.env.getDBCharset(dsn) : base.env.getDBCharset(); object obj7 = ConvertTool.getValue(((ExpParse)base.paramList[1]).calculate()); if (!(obj7 is string)) { throw new ReportError("过程调用函数参数1应为字符串"); } sql = (string)obj7; IDbCommand pst = SupportClass.TransactionManager.manager.PrepareCall(connection, sql); string[] strArray = null; int num3 = 2; if ((pst is OracleCommand) || (pst is SqlCommand)) { num3 = 3; if (base.paramList.Count > 2) { object obj6 = ConvertTool.getValue(((ExpParse)base.paramList[2]).calculate()); if (!(obj6 is string)) { throw new ReportError("过程调用函数参数3应为字符串"); } strArray = ((string)obj6).Split(new char[] { ',' }); if (strArray.Length != (base.paramList.Count - num3)) { throw new ReportError("dbcall函数中的参数名称个数与参数值个数不一致!"); } } } OracleParameter parameter2 = null; SqlParameter parameter3 = null; OleDbParameter parameter = null; int num4 = 0; int num2 = num3; Label_01BC: if (num2 < base.paramList.Count) { ExpParse parse = (ExpParse)base.paramList[num2]; if (parse == null) { throw new ReportError("过程调用函数出现无效参数"); } string argName = ""; if (num3 == 2) { argName = strArray[num2 - num3]; } object obj5 = ConvertTool.getValue(parse.calculate()); if ((obj5 == null) || !obj5.ToString().ToUpper().Equals("@@result".ToUpper())) { //goto Label_0318; //Label_0318: SQLTool.setObject(pst, (num2 - num3) + 1, obj5, encoding, argName); //Label_032C: num2++; goto Label_01BC; } if (pst is OracleCommand) { try { parameter2 = new OracleParameter(); parameter2.ParameterName = (argName); parameter2.OracleType = (OracleType)(22); parameter2.Size = (4000); parameter2.Direction = (ParameterDirection)(6); pst.Parameters.Add(parameter2); } catch (Exception) { } } while (pst is SqlCommand) { try { parameter3 = new SqlParameter(); parameter3.ParameterName = (argName); parameter3.Size = (4000); parameter3.SqlDbType = (SqlDbType)(22); parameter3.Direction = (ParameterDirection)(2); pst.Parameters.Add(parameter3); } catch (Exception) { } Label_02CA: if (pst is OleDbCommand) { try { parameter = new OleDbParameter(); parameter.Size = (4000); parameter.OleDbType = (OleDbType)(200); parameter.Direction = (ParameterDirection)(2); pst.Parameters.Add(parameter); } catch (Exception) { } } if (num4 == 0) { num4 = num2; } goto Label_032C; Label_0318: SQLTool.setObject(pst, (num2 - num3) + 1, obj5, encoding, argName); Label_032C: num2++; goto Label_01BC; } // TODO: 错误,暂时注释 // goto Label_02CA; } if (((parameter2 != null) || (parameter3 != null)) || (parameter != null)) { pst.ExecuteNonQuery(); pst.Dispose(); } if (parameter2 == null) { if (parameter3 != null) { return(parameter3.Value.ToString()); } if (parameter != null) { return(parameter.Value.ToString()); } IDataReader rs = null; rs = pst.ExecuteReader(); if (rs != null) { ArrayList list = new ArrayList(); while (rs.Read()) { list.Add(SQLTool.getObject(rs, 0, encoding)); } rs.Close(); pst.Dispose(); if (list.Count == 1) { return(list[0]); } return(list); } pst.Dispose(); return(null); } obj2 = parameter2.Value.ToString(); } catch (Exception exception) { throw new ReportError("过程调用函数sql异常:" + exception.Message.ToString().ToString(), exception); } return(obj2); }