public void ExecuteReader() { using (var conn = DbConnectionManager.Clone()) { conn.Open(); QueryStart(); IDataReader reader = conn.ExecuteReader(Command) as IDataReader; for (int rowNr = 0; rowNr < ReadTopX; rowNr++) { if (reader.Read()) { InternalBeforeRowReadAction?.Invoke(); BeforeRowReadAction?.Invoke(); for (int i = 0; i < Actions?.Count; i++) { if (!reader.IsDBNull(i)) { Actions?[i]?.Invoke(reader.GetValue(i)); } else { Actions?[i]?.Invoke(null); } } AfterRowReadAction?.Invoke(); InternalAfterRowReadAction?.Invoke(); } else { break; } } reader.Close(); QueryFinish(); } }
public void ExecuteReader() { using (var conn = DbConnectionManager.Clone()) { conn.Open(); QueryStart(); IDataReader reader = conn.ExecuteReader(Command, _Parameter) as IDataReader; //for (int rowNr = 0; rowNr < ReadTopX; rowNr++) //{ while (reader.Read()) { InternalBeforeRowReadAction?.Invoke(); BeforeRowReadAction?.Invoke(); for (int i = 0; i < Actions?.Count; i++) { //if (!reader.IsDBNull(i)) //{ //string value = reader.GetValue(i).ToString(); //for (int j = 0; j < reader.FieldCount; j++) //{ // if (String.IsNullOrEmpty(value)) // { // value = reader.GetValue(j).ToString(); // } // else // { // value += "," + reader.GetValue(j).ToString(); // } //} Actions?[i]?.Invoke(reader); //} //else //{ // Actions?[i]?.Invoke(null); //} } AfterRowReadAction?.Invoke(); InternalAfterRowReadAction?.Invoke(); } //else //{ // break; //} //} reader.Close(); QueryFinish(); } }
public void ExecuteReader() { var conn = DbConnectionManager.Clone(); try { conn.Open(); if (!DisableLogging) { LoggingStart(); } IDataReader reader = conn.ExecuteReader(Command, Parameter) as IDataReader; for (int rowNr = 0; rowNr < Limit; rowNr++) { if (reader.Read()) { BeforeRowReadAction?.Invoke(); for (int i = 0; i < Actions?.Count; i++) { if (!reader.IsDBNull(i)) { Actions?[i]?.Invoke(reader.GetValue(i)); } else { Actions?[i]?.Invoke(null); } } AfterRowReadAction?.Invoke(); } else { break; } } reader.Close(); if (!DisableLogging) { LoggingEnd(); } } finally { if (!conn.LeaveOpen) { conn.Close(); } } }
public void ExecuteReader() { var conn = DbConnectionManager.CloneIfNotLeaveOpen(); try { conn.Open(); if (!DisableLogging) { LoggingStart(); } using (var reader = conn.ExecuteReader(Command, Parameter)) { object value; for (int rowIndex = 0; rowIndex < Limit; rowIndex++) { if (reader.Read()) { BeforeRowReadAction?.Invoke(); for (int columnIndex = 0; columnIndex < Actions?.Count; columnIndex++) { value = reader.IsDBNull(columnIndex) ? null : reader.GetValue(columnIndex); Actions?[columnIndex]?.Invoke(value); } AfterRowReadAction?.Invoke(); } else { break; } } } if (!DisableLogging) { LoggingEnd(); } } finally { if (!conn.LeaveOpen) { conn.Close(); } } }
public void ExecuteReader() { LogErrorsAndClose(conn => { try { using (IDataReader reader = conn.ExecuteReader(Sql, Parameter) as IDataReader) { LogInfo("{action}: Executing sql.", "START"); LogTrace("{sql}", Sql); for (int rowNr = 0; rowNr < Limit; rowNr++) { if (reader.Read()) { BeforeRowReadAction?.Invoke(); for (int i = 0; i < Actions?.Count; i++) { if (!reader.IsDBNull(i)) { Actions?[i]?.Invoke(reader.GetValue(i)); } else { Actions?[i]?.Invoke(null); } } AfterRowReadAction?.Invoke(); } else { break; } } LogInfo("{action}: Sql execution completed.", "END"); } } catch (IndexOutOfRangeException ir) { int count = Actions?.Count ?? 0; var ex = new ETLBoxException($"Error when executing a read action - all columns in the source sql statement were already read by the previous actions. Please define only as many actions as columns returned in your sql statement. You defined {count} actions, which exceeded the number of returned columns in the sql. See Data[\"Sql\"] for the used sql statement.", ir); ex.Data.Add("Sql", Sql); throw ex; } }); }