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); }
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 virtual DataSet getDataSet(Env env) { DataSet set3; DataSetConfig config = (DataSetConfig)this.hashtable_0["dsc"]; CellExt1 cs = (CellExt1)this.hashtable_0["ecs"]; string name = config.Name; IDbCommand pst = null; IDataReader rs = null; IDbConnection connection = null; try { bool flag; bool flag2; string dataSourceName = config.DataSourceName; if (dataSourceName != null) { connection = env.getConnection(dataSourceName); if (connection == null) { connection = env.getConnection(); } } else { connection = env.getConnection(); dataSourceName = ""; } if ((connection == null) || (connection.State == null)) { return(null); } if ((dataSourceName != null) && (dataSourceName.Trim().Length != 0)) { flag = env.getIsEncoding(dataSourceName); } else { flag = env.getIsEncoding(); } string dbCharset = env.getDBCharset(dataSourceName); if ((dbCharset == null) || (dbCharset.Trim().Length == 0)) { dbCharset = env.getDBCharset(); } string str = MacroCalc.replaceMacros(config.SQL, env.MacrosMap); if ((dataSourceName != null) && (dataSourceName.Trim().Length != 0)) { flag2 = env.getNeedTransSQLcode(dataSourceName); } else { flag2 = env.getNeedTransSQLcode(); } if (flag2) { str = Encoding.GetEncoding(dbCharset).GetString(Encoding.Default.GetBytes(str)); } string[] sqlArguments = config.SqlArguments; string[] sqlArgumentsName = config.SqlArgumentsName; int[] argumentTypes = config.ArgumentTypes; object[] objArray = null; if (sqlArguments != null) { objArray = new object[sqlArguments.Length]; int num7 = 0; for (int i = 0; i < sqlArguments.Length; i++) { num7 = ExpString.indexOf(str, "?", num7 + 1, 18); if ((sqlArguments[i] != null) && sqlArguments[i].ToLower().Equals("@@result")) { objArray[i] = "@@result"; } else { objArray[i] = ConvertTool.getValue(new ExpParse(cs, sqlArguments[i]).calculate()); if ((objArray[i] != null) && (objArray[i] is ArrayList)) { objArray[i] = ((ArrayList)objArray[i]).ToArray(); if (((((object[])objArray[i]).Length > 0) && (((object[])objArray[i])[0] is string)) && flag2) { for (int j = 0; j < ((object[])objArray[i]).Length; j++) { ((object[])objArray[i])[j] = Convert.ToString(Encoding.GetEncoding(dbCharset).GetBytes((string)((object[])objArray[i])[0])); } } } else if ((objArray[i] is string) && flag2) { objArray[i] = Convert.ToString(Encoding.GetEncoding(dbCharset).GetBytes((string)objArray[i])); } if ((objArray[i] != null) && objArray[i].GetType().IsArray) { int length = ((object[])objArray[i]).Length; StringBuilder builder = new StringBuilder(2 * length); for (int k = 0; k < length; k++) { builder.Append("?,"); } if ((builder.Length > 0) && (builder[builder.Length - 1] == ',')) { builder.Remove(builder.Length - 1, 1); } if (builder.Length > 1) { str = new StringBuilder(str.Substring(0, num7).ToString().ToString()).Append(builder.ToString()).Append(str.Substring(num7 + 1)).ToString().ToString(); } num7 += builder.Length; } } } } Logger.debug("下面开始打出sql"); int num6 = 0; if ((3 != config.SQLType) || (connection is OleDbConnection)) { try { Logger.debug(new StringBuilder(name.ToString().ToString()).Append("=").Append(str).ToString().ToString()); pst = SupportClass.TransactionManager.manager.PrepareStatement(connection, str); goto Label_0472; } catch (Exception exception3) { throw new ReportError(new StringBuilder("数据集").Append(name).Append(" sql异常:").Append(exception3.Message).ToString().ToString(), exception3); } } try { pst = SupportClass.TransactionManager.manager.PrepareCall(connection, str); } catch (Exception exception4) { throw new ReportError(new StringBuilder("数据集").Append(name).Append(" sql异常:").Append(exception4.Message).ToString().ToString(), exception4); } Label_0472: if ((objArray == null) || (objArray.Length <= 0)) { goto Label_06A2; } int index = 0; int num3 = 0; Label_048F: if (num3 >= objArray.Length) { goto Label_06A2; } index++; if ((sqlArguments[num3] == null) || !sqlArguments[num3].ToLower().Equals("@@result")) { goto Label_050E; } if (!(pst is OracleCommand)) { goto Label_0698; } try { OracleParameter parameter = new OracleParameter(); parameter.ParameterName = (sqlArgumentsName[num3]); parameter.OracleType = (OracleType)(5); parameter.Direction = (ParameterDirection)(2); pst.Parameters.Add(parameter); goto Label_0698; } catch (Exception) { goto Label_0698; } Label_0504: num6 = index; goto Label_068D; Label_050E: try { if ((objArray[num3] != null) && objArray[num3].GetType().IsArray) { string msg = new StringBuilder("第").Append(num3).Append("个参数组: ").ToString().ToString(); for (int m = 0; m < ((object[])objArray[num3]).Length; m++) { msg = (msg.ToString() + ((object[])objArray[num3])[m].ToString()).ToString().ToString() + ","; SQLTool.setObject(pst, index, ((object[])objArray[num3])[m], argumentTypes[num3], sqlArgumentsName[num3]); index++; } Logger.debug(msg); index--; } else { Logger.debug(new StringBuilder("第").Append(num3).Append("个参数: ").Append(objArray[num3]).ToString().ToString()); if ((6 == argumentTypes[num3]) && (objArray[num3] == null)) { objArray[num3] = ""; } SQLTool.setObject(pst, index, objArray[num3], argumentTypes[num3], sqlArgumentsName[num3]); } } catch (Exception exception2) { throw new ReportError(new StringBuilder("数据集").Append(name).Append("的sql第").Append(num3 + 1).Append("个参数异常:").Append(exception2.Message).ToString().ToString(), exception2); } Label_068D: num3++; goto Label_048F; Label_0698: if (num6 == 0) { goto Label_0504; } goto Label_068D; Label_06A2: try { rs = pst.ExecuteReader(); } catch (Exception exception) { throw new ReportError(new StringBuilder("数据集").Append(name).Append("的 sql异常:").Append(exception.Message).ToString().ToString(), exception); } string beginRow = config.BeginRow; string endRow = config.EndRow; if (((beginRow == null) || (beginRow.Trim().Length == 0)) || beginRow.Trim().ToUpper().Equals("null".ToUpper())) { beginRow = "0"; } if (((endRow == null) || (endRow.Trim().Length == 0)) || endRow.Trim().ToUpper().Equals("null".ToUpper())) { endRow = "0"; } beginRow = MacroCalc.replaceMacros(beginRow, env.MacrosMap); endRow = MacroCalc.replaceMacros(endRow, env.MacrosMap); int num = 0; int num2 = 0; try { object obj2 = ConvertTool.getValue(new ExpParse(env, beginRow).calculate()); object obj3 = ConvertTool.getValue(new ExpParse(env, endRow).calculate()); if ((obj2 is int) && (obj3 is int)) { num = (int)obj2; num2 = (int)obj3; } } catch (Exception) { throw new ReportError("数据集的起始行或者结束行设置有误。"); } ArrayList fieldText = config.getFieldTextList(); RecordCheck oRecordCheck = new RecordCheck(new ConnectionConfig().getDBOperator(), env.Request, env.Session); DataSet set = DataSetTool.populate(null, rs, num, num2, dbCharset, fieldText, false, flag, oRecordCheck); if ((config.IndexCols != null) && (config.IndexCols.Length > 0)) { set.createIndex(config.IndexCols, config.IndexSorted); } set3 = set; } catch (ReportError error) { throw error; } catch (Exception exception5) { throw new ReportError(exception5.Message, exception5); } finally { try { if (rs != null) { rs.Close(); } if (pst != null) { pst.Dispose(); } } catch (Exception exception6) { throw new ReportError(exception6.Message, exception6); } } return(set3); }