Example #1
0
        /**
         * Method declaration
         *
         *
         * @return
         *
         * @throws Exception
         */
        public object getValue()
        {
            switch (iType)
            {
            case VALUE:
                return(oData);

            case COLUMN:
                try
                {
                    return(tFilter.oCurrentData[iColumn]);
                }
                catch (Exception e)
                {
                    throw Trace.error(Trace.COLUMN_NOT_FOUND, sColumn);
                }

            /*				case FUNCTION:
             *                                      return fFunction.getValue();
             */
            case QUERY:
                return(sSelect.getValue(iDataType));

            case NEGATE:
                return(Column.negate(eArg.getValue(iDataType), iDataType));

            case COUNT:

                // count(*): sum(1); count(col): sum(col<>null)
                if (eArg.iType == ASTERIX || eArg.getValue() != null)
                {
                    return(1);
                }

                return(0);

            case MAX:

            case MIN:

            case SUM:

            case AVG:
                return(eArg.getValue());

            case EXISTS:
                return(test());

            case CONVERT:
                return(eArg.getValue(iDataType));

            case CASEWHEN:
                if (eArg.test())
                {
                    return(eArg2.eArg.getValue());
                }
                else
                {
                    return(eArg2.eArg2.getValue());
                }
            }

            // todo: simplify this
            object a = null, b = null;

            if (eArg != null)
            {
                a = eArg.getValue(iDataType);
            }

            if (eArg2 != null)
            {
                b = eArg2.getValue(iDataType);
            }

            switch (iType)
            {
            case ADD:
                return(Column.add(a, b, iDataType));

            case SUBTRACT:
                return(Column.subtract(a, b, iDataType));

            case MULTIPLY:
                return(Column.multiply(a, b, iDataType));

            case DIVIDE:
                return(Column.divide(a, b, iDataType));

            case CONCAT:
                return(Column.concat(a, b));

            case IFNULL:
                return(a == null ? b : a);

            default:

                // must be comparisation
                // todo: make sure it is
                return(test());
            }
        }