📄 result.java
字号:
order[i] = i; way[i] = 1; } sortResult(order, way); Record n = rRoot; for (;;) { Record next = n.next; if (next == null) { break; } if (compareRecord(n.data, next.data, len) == 0) { n.next = next.next; iSize--; } else { n = next; } } rTail = n; Trace.doAssert(rTail.next == null, "rTail not correct in Result.removeDuplicates iSise =" + iSize); } /** * Method declaration * * @param minus * @throws SQLException */ void removeSecond(Result minus) throws SQLException { removeDuplicates(); minus.removeDuplicates(); int len = getColumnCount(); Record n = rRoot; Record last = rRoot; boolean rootr = true; // checking rootrecord Record n2 = minus.rRoot; int i = 0; while (n != null && n2 != null) { i = compareRecord(n.data, n2.data, len); if (i == 0) { if (rootr) { rRoot = last = n.next; } else { last.next = n.next; } n = n.next; iSize--; } else if (i > 0) { // r > minus n2 = n2.next; } else { // r < minus last = n; rootr = false; n = n.next; } } for (; n != null; ) { last = n; n = n.next; } rTail = last; Trace.doAssert( (rRoot == null && rTail == null) || rTail.next == null, "rTail not correct in Result.removeSecond iSise =" + iSize); } /** * Method declaration * * @param r2 * @throws SQLException */ void removeDifferent(Result r2) throws SQLException { removeDuplicates(); r2.removeDuplicates(); int len = getColumnCount(); Record n = rRoot; Record last = rRoot; boolean rootr = true; // checking rootrecord Record n2 = r2.rRoot; int i = 0; iSize = 0; while (n != null && n2 != null) { i = compareRecord(n.data, n2.data, len); if (i == 0) { // same rows if (rootr) { rRoot = n; // make this the first record } else { last.next = n; // this is next record in resultset } rootr = false; last = n; // this is last record in resultset n = n.next; n2 = n2.next; iSize++; } else if (i > 0) { // r > r2 n2 = n2.next; } else { // r < r2 n = n.next; } } if (rootr) { // if no lines in resultset rRoot = null; // then return null last = null; } else { last.next = null; // else end resultset } rTail = last; Trace.doAssert( (rRoot == null && rTail == null) || rTail.next == null, "rTail not correct in Result.removeDifference iSise =" + iSize); } /** * Method declaration * * @param order * @param way * @throws SQLException */ void sortResult(int order[], int way[]) throws SQLException { if (rRoot == null || rRoot.next == null) { return; } Record source0, source1; Record target[] = new Record[2]; Record targetlast[] = new Record[2]; int dest = 0; Record n = rRoot; while (n != null) { Record next = n.next; n.next = target[dest]; target[dest] = n; n = next; dest ^= 1; } for (int blocksize = 1; target[1] != null; blocksize <<= 1) { source0 = target[0]; source1 = target[1]; target[0] = target[1] = targetlast[0] = targetlast[1] = null; for (dest = 0; source0 != null; dest ^= 1) { int n0 = blocksize, n1 = blocksize; while (true) { if (n0 == 0 || source0 == null) { if (n1 == 0 || source1 == null) { break; } n = source1; source1 = source1.next; n1--; } else if (n1 == 0 || source1 == null) { n = source0; source0 = source0.next; n0--; } else if (compareRecord( source0.data, source1.data, order, way) > 0) { n = source1; source1 = source1.next; n1--; } else { n = source0; source0 = source0.next; n0--; } if (target[dest] == null) { target[dest] = n; } else { targetlast[dest].next = n; } targetlast[dest] = n; n.next = null; } } } rRoot = target[0]; rTail = targetlast[0]; Trace.doAssert(rTail.next == null, "rTail not correct in Result.sortResult iSise =" + iSize); } /** * Method declaration * * @param a * @param b * @param order * @param way * @return * @throws SQLException */ private int compareRecord(Object a[], Object b[], int order[], int way[]) throws SQLException { int i = Column.compare(a[order[0]], b[order[0]], colType[order[0]]); if (i == 0) { for (int j = 1; j < order.length; j++) { i = Column.compare(a[order[j]], b[order[j]], colType[order[j]]); if (i != 0) { return i * way[j]; } } } return i * way[0]; } /** * Method declaration * * @param a * @param b * @param len * @return * @throws SQLException */ private int compareRecord(Object a[], Object b[], int len) throws SQLException { for (int j = 0; j < len; j++) { int i = Column.compare(a[j], b[j], colType[j]); if (i != 0) { return i; } } return 0; }// fredt@users 20020221 - patch 513005 by sqlbob@users (RMP) /** * Method declaration * * @return * @throws SQLException */ byte[] getBytes() throws SQLException { try { DatabaseRowOutputInterface out = new BinaryServerRowOutput(); out.writeIntData(iMode); if (iMode == UPDATECOUNT) { out.writeIntData(iUpdateCount); } else if (iMode == ERROR) { out.writeIntData(errorCode); out.writeString(sError); } else { int l = iColumnCount; out.writeIntData(l); Record n = rRoot; for (int i = 0; i < l; i++) { out.writeType(colType[i]); out.writeString(sLabel[i]); out.writeString(sTable[i]); out.writeString(sName[i]); } while (n != null) { out.writeData(l, colType, n.data); n = n.next; } } return out.toByteArray(); } catch (IOException e) { throw Trace.error(Trace.TRANSFER_CORRUPTED); } } /** * Method declaration * * @param columns */ private void prepareData(int columns) { iMode = DATA; sLabel = new String[columns]; sTable = new String[columns]; sName = new String[columns]; isLabelQuoted = new boolean[columns]; colType = new int[columns]; colSize = new int[columns]; colScale = new int[columns]; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -