/// <summary> /// Build a set of rows from data in the buffer /// </summary> public override void BuildDataFromOtherRetrievedData( QueryEngine qe, int ti, List <object[]> results, int firstResult, int resultCount) { // This routine takes a set of results in the buffer, computes the calculated field value // and stores the results back in the buffer. For a calc field derived from a single column // the process is simple; however, for two column calculations there are two cases to consider. // 1. If no values then nothing to compute. // 2. If both values are present in the buffer row then just use them. // 3. If a single value is present then pick up the most recent other value that // exists for the same key. // Note that if the query only retrieves one of the two fields the the other field // will be retrieved into the calc field buffer. QueryColumn qc; MetaColumn mc; CalcFieldColumn cfc, cfc2; int voiCfKey, voiCf, voi; object v, v1, v2, vn; object[] vo, mergedVo; const int keyOffset = 1; throw new NotImplementedException(); #if false Query q = qe.Query; CalcFieldMetaTable cfMt = GetCalcFieldMetaTable(q.Tables[ti].MetaTable); CalcField cf = cfMt.CalcField; // Setup if (resultCount <= 0) { return; } if (SelectList.Count <= 1) { return; // just return if only key selected } voiCfKey = Qt.KeyQueryColumn.VoPosition; // calc field key value buffer index voiCf = Qt.GetQueryColumnByNameWithException("CALC_FIELD").VoPosition; // calculated value buffer index mergedVo = new object[results[0].Length]; // merged vo containing latest values for each column // Process each result row for (int ri = firstResult; ri < firstResult + resultCount; ri++) // result loop { vo = results[ri]; if (vo[0] == null) { continue; } if (mergedVo[0] == null || Lex.Ne(vo[0].ToString(), mergedVo[0].ToString())) { // if new key init voVals Array.Clear(mergedVo, 0, mergedVo.Length); mergedVo[0] = vo[0]; } int nonNullCount = 0; int nullCount = 0; QueryColumn[] colMap = _dataMap.InputColMap; for (int mi = 0; mi < colMap.Length; mi++) { if (colMap[mi] == null) { continue; // } voi = colMap[mi].VoPosition; v = vo[voi]; if (!NullValue.IsNull(v)) { mergedVo[voi] = v; nonNullCount++; } else { nullCount++; } } if (nonNullCount == 0) { continue; // if all inputs are null then all done (assume all outputs are null also) } vo[voiCfKey] = vo[0]; // copy key value QueryTableData qtd = qe.Qtd[ti]; // Pick up each retrieved value in the from other data fields for (int cfci = 0; cfci < qtd.SelectedColumns.Count; cfci++) // columns to retrieve/calculate loop { qc = qtd.SelectedColumns[cfci]; mc = qc.MetaColumn; voi = qc.VoPosition; bool calcFieldCol = Lex.Eq(mc.Name, "CALC_FIELD"); bool selectedCol = !calcFieldCol; // Input value column if (selectedCol) // retrieved input value { QueryColumn cmi = _dataMap.SelectedColMap[cfci]; if (cmi != null && cmi.VoPosition > 0) { v = mergedVo[cmi.VoPosition]; if (mc.DataType == MetaColumnType.Image) // convert to proper image reference { MetaTable sourceMt = cmi.QueryTable.MetaTable; GenericMetaBroker gmb = QueryEngine.GetGlobalBroker(cmi.QueryTable.MetaTable); v = gmb.ConvertValueToImageReference(v); } vo[voi] = v; } } // Calculate the CF value else { cfc = cf.CfCols[0]; vn = vo[voiCf]; // get possible single retrieved value vo[voiCf] = null; // clear calc value (may hold one of two values) v = mergedVo[colMap[0].VoPosition]; // get first value if (NullValue.IsNull(v)) { continue; // if null then result must be null } v = ApplyFunction(cfc, v); for (int mi = 1; mi < colMap.Length; mi++) // combine with { v1 = v; // reference previous value if (colMap[mi] == null) { continue; } cfc2 = cf.CfCols[mi]; voi = colMap[mi].VoPosition; v2 = mergedVo[voi]; v2 = ApplyFunction(cfc2, v2); v = CalculateValue(cf, v1, cfc2, v2); if (v == null) { break; } } v = ApplyClassification(cf, v); vo[voiCf] = v; // store calculated value } } // column loop vo = vo; // debug to check row loop at end } // row loop return; #endif }