Ejemplo n.º 1
0
        /**
         * Method declaration
         *
         *
         * @param a
         * @param b
         * @param r
         * @param len
         *
         * @return
         *
         * @throws Exception
         */
        private static int compareRecord(object[] a, object[] b, Result r,
                                         int len)
        {
            for (int j = 0; j < len; j++)
            {
                int i = Column.compare(a[j], b[j], r.iType[j]);

                if (i != 0)
                {
                    return(i);
                }
            }

            return(0);
        }
Ejemplo n.º 2
0
        /**
         * Method declaration
         *
         *
         * @param a
         * @param b
         *
         * @return
         *
         * @throws Exception
         */
        private int compareRow(object[] a, object[] b)
        {
            int i = Column.compare(a[iColumn_0], b[iColumn_0], iType_0);

            if (i != 0)
            {
                return(i);
            }

            for (int j = 1; j < iFields; j++)
            {
                i = Column.compare(a[iColumn[j]], b[iColumn[j]], iType[j]);

                if (i != 0)
                {
                    return(i);
                }
            }

            return(0);
        }
Ejemplo n.º 3
0
        /**
         * Method declaration
         *
         *
         * @param a
         * @param b
         * @param r
         * @param order
         * @param way
         *
         * @return
         *
         * @throws Exception
         */
        private static int compareRecord(object[] a, object[] b, Result r,
                                         int[] order,
                                         int[] way)
        {
            int i = Column.compare(a[order[0]], b[order[0]], r.iType[order[0]]);

            if (i == 0)
            {
                for (int j = 1; j < order.Length; j++)
                {
                    i = Column.compare(a[order[j]], b[order[j]],
                                       r.iType[order[j]]);

                    if (i != 0)
                    {
                        return(i * way[j]);
                    }
                }
            }

            return(i * way[0]);
        }
Ejemplo n.º 4
0
 /**
  * Method declaration
  *
  *
  * @param a
  * @param b
  *
  * @return
  *
  * @throws Exception
  */
 private int compareValue(object a, object b)
 {
     return(Column.compare(a, b, iType_0));
 }
Ejemplo n.º 5
0
        /**
         * Method declaration
         *
         *
         * @return
         *
         * @throws Exception
         */
        public bool test()
        {
            switch (iType)
            {
            case TRUE:
                return(true);

            case NOT:
                Trace.assert(eArg2 == null, "Expression.test");

                return(!eArg.test());

            case AND:
                return(eArg.test() && eArg2.test());

            case OR:
                return(eArg.test() || eArg2.test());

            case LIKE:

                // todo: now for all tests a new 'like' object required!
                string s    = (string)eArg2.getValue(Column.VARCHAR);
                int    type = eArg.iDataType;
                Like   l    = new Like(s, cLikeEscape, type == Column.VARCHAR_IGNORECASE);
                string c    = (string)eArg.getValue(Column.VARCHAR);

                return(l.compare(c));

            case IN:
                return(eArg2.testValueList(eArg.getValue(), eArg.iDataType));

            case EXISTS:
                Result r = eArg.sSelect.getResult(1);                            // 1 is already enough

                return(r.rRoot != null);
            }

            Trace.check(eArg != null, Trace.GENERAL_ERROR);

            object o     = eArg.getValue();
            int    dtype = eArg.iDataType;

            Trace.check(eArg2 != null, Trace.GENERAL_ERROR);

            object o2     = eArg2.getValue(dtype);
            int    result = Column.compare(o, o2, dtype);

            switch (iType)
            {
            case EQUAL:
                return(result == 0);

            case BIGGER:
                return(result > 0);

            case BIGGER_EQUAL:
                return(result >= 0);

            case SMALLER_EQUAL:
                return(result <= 0);

            case SMALLER:
                return(result < 0);

            case NOT_EQUAL:
                return(result != 0);
            }

            Trace.assert(false, "Expression.test2");

            return(false);
        }
Ejemplo n.º 6
0
        // [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);
        }