/** * Method declaration * * * @param o * @param datatype * * @return * * @throws Exception */ private bool testValueList(object o, int datatype) { if (iType == VALUELIST) { if (datatype != iDataType) { o = Column.convertobject(o, iDataType); } return(hList.ContainsKey(o)); } else if (iType == QUERY) { // todo: convert to valuelist before if everything is resolvable Result r = sSelect.getResult(0); Record n = r.rRoot; int type = r.iType[0]; if (datatype != type) { o = Column.convertobject(o, type); } while (n != null) { object o2 = n.data[0]; if (o2 != null && o2.Equals(o)) { return(true); } n = n.next; } return(false); } throw Trace.error(Trace.WRONG_DATA_TYPE); }
// [email protected] end changes from 1.50 // [email protected] begin changes from 1.50 public Result getResult(int start, int cnt) { int maxrows = start + cnt; //<-new, cut definitly // [email protected] begin changes from 1.50 resolve(); checkResolved(); if (sUnion != null && sUnion.iResultLen != iResultLen) { throw Trace.error(Trace.COLUMN_COUNT_DOES_NOT_MATCH); } int len = eColumn.Length; Result r = new Result(len); bool aggregated = false; bool grouped = false; for (int i = 0; i < len; i++) { Expression e = eColumn[i]; r.iType[i] = e.getDataType(); if (e.isAggregate()) { aggregated = true; } } object[] agg = null; if (aggregated) { agg = new object[len]; } if (iGroupLen > 0) { // has been set in Parser grouped = true; } bool simple_maxrows = false; if (maxrows != 0 && grouped == false && sUnion == null && iOrderLen == 0) { simple_maxrows = true; } else { simple_maxrows = false; } int count = 0; int filter = tFilter.Length; bool[] first = new bool[filter]; int level = 0; while (level >= 0) { TableFilter t = tFilter[level]; bool found; if (!first[level]) { found = t.findFirst(); first[level] = found; } else { found = t.next(); first[level] = found; } if (!found) { level--; continue; } if (level < filter - 1) { level++; continue; } if (eCondition == null || eCondition.test()) { object[] row = new object[len]; for (int i = 0; i < len; i++) { row[i] = eColumn[i].getValue(); } count++; if (aggregated) { updateAggregateRow(agg, row, len); } else { r.add(row); if (simple_maxrows && count >= maxrows) { break; } } } } if (aggregated && !grouped) { addAggregateRow(r, agg, len, count); } else if (grouped) { int[] order = new int[iGroupLen]; int[] way = new int[iGroupLen]; for (int i = iResultLen, j = 0; j < iGroupLen; i++, j++) { order[j] = i; way[j] = 1; } r = sortResult(r, order, way); Record n = r.rRoot; Result x = new Result(len); for (int i = 0; i < len; i++) { x.iType[i] = r.iType[i]; } do { object[] row = new object[len]; count = 0; bool newgroup = false; while (n != null && newgroup == false) { count++; for (int i = 0; i < iGroupLen; i++) { if (n.next == null) { newgroup = true; } else if (Column.compare(n.data[i], n.next.data[i], r.iType[i]) != 0) { // can't use .Equals because 'null' is also one group newgroup = true; } } updateAggregateRow(row, n.data, len); n = n.next; } addAggregateRow(x, row, len, count); } while (n != null); r = x; } if (iOrderLen != 0) { int[] order = new int[iOrderLen]; int[] way = new int[iOrderLen]; for (int i = iResultLen, j = 0; j < iOrderLen; i++, j++) { order[j] = i; way[j] = eColumn[i].isDescending() ? -1 : 1; } r = sortResult(r, order, way); } // the result is maybe bigger (due to group and order by) // but don't tell this anybody else r.setColumnCount(iResultLen); if (bDistinct) { r = removeDuplicates(r); } for (int i = 0; i < iResultLen; i++) { Expression e = eColumn[i]; r.sLabel[i] = e.getAlias(); r.sTable[i] = e.getTableName(); r.sName[i] = e.getColumnName(); } if (sUnion != null) { Result x = sUnion.getResult(0); if (iUnionType == UNION) { r.append(x); r = removeDuplicates(r); } else if (iUnionType == UNIONALL) { r.append(x); } else if (iUnionType == INTERSECT) { r = removeDuplicates(r); x = removeDuplicates(x); r = removeDifferent(r, x); } else if (iUnionType == EXCEPT) { r = removeDuplicates(r); x = removeDuplicates(x); r = removeSecond(r, x); } } if (maxrows > 0 && !simple_maxrows) { trimResult(r, maxrows); } // [email protected] begin changes from 1.50 if (start > 0) { //then cut the first 'start' elements trimResultFront(r, start); } // [email protected] end changes from 1.50 return(r); }