IIndexedDict[] ReadGroupedRows(DbDataReader rdr) { int n = rdr.FieldCount; var key2ndx = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase); for (int i = 0; i < n; i++) { var key = rdr.GetName(i); key2ndx.Add(key, i); } var lst = new OPs.ListOf <IIndexedDict>(); object currKey = null; var currValues = new List <object> [n - 1]; for (int i = 1; i < n; i++) { currValues[i - 1] = new List <object>(); } var values = new object[n]; while (rdr.Read()) { rdr.GetValues(values); bool keyChanged = currKey == null || W.Common.Cmp.CmpKeys(currKey, values[0]) != 0; if (keyChanged) { if (currKey != null) { // store akkumulated values lists var vals = new object[n]; vals[0] = currKey; for (int i = 1; i < n; i++) { vals[i] = currValues[i - 1].ToArray(); currValues[i - 1].Clear(); } lst.Add(ValuesDictionary.New(vals, key2ndx)); } currKey = values[0]; } for (int i = 1; i < n; i++) { currValues[i - 1].Add(values[i]); // akkumulate values in lists } } if (currKey != null) { // store akkumulated values lists var vals = new object[n]; vals[0] = currKey; for (int i = 1; i < n; i++) { vals[i] = currValues[i - 1].ToArray(); currValues[i - 1].Clear(); } lst.Add(ValuesDictionary.New(vals, key2ndx)); } return(lst.ToArray()); }
private static object ReadRows(DbDataReader rdr) { int nFields = rdr.FieldCount; var key2ndx = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase); var lstUsedFields = new List <int>(nFields); int iStartTimeField = -1; int iEndTimeField = -1; for (int i = 0; i < nFields; i++) { var key = rdr.GetName(i); if (string.Compare(key, nameof(START_TIME), StringComparison.InvariantCultureIgnoreCase) == 0) { iStartTimeField = i; continue; } else if (iStartTimeField >= 0 && ( string.Compare(key, "end_time__dt", StringComparison.InvariantCultureIgnoreCase) == 0 || string.Compare(key, nameof(END_TIME), StringComparison.InvariantCultureIgnoreCase) == 0 )) { iEndTimeField = i; continue; } key2ndx.Add(key, lstUsedFields.Count); lstUsedFields.Add(i); } var usedFields = lstUsedFields.ToArray(); int nUsedFields = usedFields.Length; var lst = new OPs.ListOf <IIndexedDict>(); if (iEndTimeField >= 0) { var values = new object[nFields]; while (rdr.Read()) { rdr.GetValues(values); var endTime = values[iEndTimeField]; var vals = new object[nUsedFields]; var dtBeg = (DateTime)values[iStartTimeField]; var dtEnd = (endTime == DBNull.Value) ? DateTime.MaxValue : (DateTime)endTime; if (dtBeg == dtEnd) { dtBeg = dtEnd; } //vals[0] = TimedObject.Timed(dtBeg, dtEnd, values[0]); for (int i = 0; i < nUsedFields; i++) { vals[i] = TimedObject.Timed(dtBeg, dtEnd, values[usedFields[i]]); } lst.Add(new ValuesDictionary(vals, key2ndx, dtBeg, dtEnd)); } } else if (iStartTimeField >= 0) { var values = new object[nFields]; object[] prevs = null; var prevTime = DateTime.MinValue; while (rdr.Read()) { rdr.GetValues(values); var time = (DateTime)values[iStartTimeField]; if (prevs != null) { var dtBeg = prevTime; var dtEnd = (Cmp.CmpKeys(prevs[0], values[0]) == 0) ? time : DateTime.MaxValue; if (dtBeg == dtEnd) { continue; } for (int i = 0; i < nUsedFields; i++) { prevs[i] = TimedObject.Timed(dtBeg, dtEnd, prevs[i]); } lst.Add(new ValuesDictionary(prevs, key2ndx, dtBeg, dtEnd)); } prevTime = time; var vals = new object[nUsedFields]; for (int i = 0; i < nUsedFields; i++) { vals[i] = values[usedFields[i]]; } prevs = vals; } if (prevs != null) { for (int i = 0; i < nUsedFields; i++) { prevs[i] = TimedObject.Timed(prevTime, DateTime.MaxValue, prevs[i]); } lst.Add(new ValuesDictionary(prevs, key2ndx, prevTime, DateTime.MaxValue)); } } else { System.Diagnostics.Trace.Assert(nFields == nUsedFields); while (rdr.Read()) { var values = new object[nFields]; rdr.GetValues(values); for (int i = values.Length - 1; i >= 0; i--) { values[i] = Minimize(values[i]); } lst.Add(ValuesDictionary.New(values, key2ndx)); } } #if OCP_LOG using (var writer = System.IO.File.AppendText("OraConnPool.log")) { writer.WriteLine(string.Join("\t", key2ndx.Keys)); foreach (var vals in lst) { writer.WriteLine(string.Join("\t", vals.ValuesList)); } writer.Flush(); } #endif return(lst.ToArray()); }