예제 #1
0
        public object GetFunctionValue(HqlRecord record)
        {
            switch (FieldType)
            {
            case HqlFieldType.FIELDNUM:
            case HqlFieldType.FIXEDWIDTH:
            case HqlFieldType.LITERAL_STRING:
            case HqlFieldType.STAR:
            case HqlFieldType.FUNCTION:
            case HqlFieldType.LITERAL_INT:
            case HqlFieldType.LITERAL_FLOAT:
                return(GetValue(record));

            case HqlFieldType.SCALAR:
            {
                // This works because this function is only called when HasFunction is true.
                // If I'm in here and it goes to scalar, it REALLY wants the function value
                // this is for the groupby
#if DEBUG
                if (Func == null)
                {
                    throw new Exception("Unexpected null function");
                }
#endif
                //return Func.GetFunctionValue(record);
                return(Func.GetValue(record));
            }

            default:
                throw new Exception("Unknown HqlField type");
            }
        }
예제 #2
0
        ///////////////////////
        // Private

        private bool?EvaluateSingle(HqlRecord record)
        {
            object v1 = record.GetValue(Token1);
            object v2 = record.GetValue(Token2);

            return(Evaluate(v1, v2, Compare));
        }
예제 #3
0
        public object GetValue(HqlRecord record)
        {
            switch (FieldType)
            {
            case HqlFieldType.FIELDNUM:
            case HqlFieldType.FIXEDWIDTH:
            case HqlFieldType.STAR:
            case HqlFieldType.ROWNUM:
            case HqlFieldType.FILENAME:
                return(record.GetValue(this));

            case HqlFieldType.SCALAR:
                return(Scalar.Evaluate(record));

            case HqlFieldType.FUNCTION:
                return(Func.GetValue(record));

            case HqlFieldType.LITERAL_STRING:
                return(Name);

            case HqlFieldType.LITERAL_INT:
                return(IntValue);

            case HqlFieldType.LITERAL_FLOAT:
                return(DecimalValue);

            default:
                throw new Exception("Unknown HqlField type");
            }
        }
예제 #4
0
        public new string Evaluate(HqlRecord record)
        {
            StringBuilder sb = new StringBuilder(_filename);

            for (int i = 0; i < _fieldgroup.Count; ++i)
            {
                string result = _fieldgroup[i].GetValue(record).ToString();
                sb.Replace("{" + _fieldgroup[i].FieldRename + "}", result);
            }

            return(sb.ToString());
        }
예제 #5
0
        public bool Evaluate(HqlRecord record)
        {
            int counter = 0;

            if (_q == null || _q.Count == 0)
            {
                return(true);
            }

            bool?res = HqlEvaluator.Evaluate(record, _q, ref counter);

            return(HqlEvaluator.EvalNullableBool(res, false));
        }
예제 #6
0
        /// <summary>
        /// Same as GetValues() except it erases the values of the functions
        /// because the Key in the array cannot have the value since it constantly changes.
        /// I need a place holder in the final answer though due to sorting though
        /// </summary>
        /// <param name="record"></param>
        /// <returns></returns>
        public object[] GetKeyValues(HqlRecord record)
        {
            object[] o = _fieldgroup.GetValues(record);
            for (int i = 0; i < _fieldgroup.Count; ++i)
            {
                if (_fieldgroup[i].HasFunction)
                {
                    o[i] = null;
                }
            }

            return(o);
        }
예제 #7
0
        public object[] GetValues(HqlRecord record)
        {
            if (_fields == null || _fields.Length == 0)
            {
                return(new object[0]);
            }

            object[] arr = new object[_fields.Length];
            for (int i = 0; i < _fields.Length; ++i)
            {
                arr[i] = _fields[i].GetValue(record);
            }
            return(arr);
        }
예제 #8
0
        public bool Evaluate(HqlRecord record)
        {
            switch (_type)
            {
            case HqlCompareTokenType.SINGLE:
                return(HqlEvaluator.EvalNullableBool(EvaluateSingle(record), false));

            case HqlCompareTokenType.IN:
                return(HqlEvaluator.EvalNullableBool(EvaluateInValues(record), false));

            case HqlCompareTokenType.NOT_IN:
                bool b = HqlEvaluator.EvalNullableBool(EvaluateInValues(record), false);     // TODO, should this be true?
                return(!b);

            default:
                throw new NotSupportedException("Unknown type of COMPARETOKEN");
            }
        }
예제 #9
0
 public void AddToResultRow(int start, HqlRecord record, HqlResultRow row)
 {
     for (int i = 0; i < _fieldgroup.Count; ++i)
     {
         if (_fieldgroup[i].HasFunction)
         {
             object value = _fieldgroup[i].GetFunctionValue(record);
             row[start + i] = value; // this is an overloaded function that "adds" to this function or assigns if the first time
         }
         else
         {
             if (!row.ValuesSet)
             {
                 // save these!
                 object value = _fieldgroup[i].GetValue(record);
                 row[start + i] = value;
             }
         }
     }
 }
예제 #10
0
        private void CreateKeyAndValue(HqlRecord record)
        {
            HqlKey KEY = null;

            object[] keys = CreateRecordKey(record, _orderby, _groupby, _settings.Output, _linenum);
            KEY = new HqlKey(keys);

            HqlResultRow row = _groupby.FindResultRow(KEY);

            if (row == null)
            {
                row = CreateObjectArrayValue(_orderby, _select, _settings.Output);
            }
#if DEBUG
            else
            {
                int stop = 0;
            }
#endif

            // set the values on the row
            int counter = 0;

            _orderby.AddToResultRow(counter, record, row);
            counter += _orderby.Count;

            _select.AddToResultRow(counter, record, row);
            counter += _select.Count;

            if (_settings.PrintCategorizeFilename)
            {
                _settings.Output.AddToResultRow(counter, record, row);
                //counter += _output.Count;
            }

            if (!row.ValuesSet)
            {
                row.ValuesSet = true;
                _groupby.SetResultRow(KEY, row);
            }
        }
예제 #11
0
        ///////////////////////
        // Static Functions

        private static object[] CreateRecordKey(HqlRecord record, HqlOrderBy order, HqlClause group, HqlClause output, int linenum)
        {
            int orderlength  = order.Count;
            int grouplength  = (group.Count == 0) ? 1: group.Count;
            int outputlength = ((output == null) ? 0 : output.Count);

            int length = orderlength + grouplength + outputlength;

            object[] keys = new object[length];

            object[] orderarray = order.GetKeyValues(record);
            object[] grouparray;
            if (group.Count > 0)
            {
                grouparray = group.GetValues(record);
            }
            else
            {
                grouparray = new object[1] {
                    linenum
                }
            };
            object[] outputarray = ((output == null) ? null : output.GetValues(record));

            int counter = 0;

            orderarray.CopyTo(keys, counter);
            counter += orderarray.Length;

            grouparray.CopyTo(keys, counter);
            counter += grouparray.Length;

            if (outputarray != null)
            {
                outputarray.CopyTo(keys, counter);
                //counter += outputarray.Length;
            }

            return(keys);
        }
예제 #12
0
        public string Evaluate(HqlRecord record)
        {
            StringBuilder sb      = new StringBuilder();
            bool          printed = false;

            for (int i = 0; i < _fieldgroup.Count; ++i)
            {
                if (!_fieldgroup[i].PrintResult)
                {
                    continue;
                }
                object result = _fieldgroup[i].GetValue(record);
                if (printed)
                {
                    sb.Append(_settings.OutDelimiter);
                }
                sb.Append(result.ToString());
                printed = true;
            }
            sb.Append(_settings.FinalDelimiter);

            return(sb.ToString());
        }
예제 #13
0
        private bool?EvaluateInValues(HqlRecord record)
        {
            object v1 = record.GetValue(Token1);

            for (int i = 0; i < _values.Count; ++i)
            {
                try
                {
                    HqlToken t  = (HqlToken)_values[i];
                    object   v2 = record.GetValue(t);

                    if (Evaluate(v1, v2, Compare))
                    {
                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    int stop = 0;
                    throw;
                }
            }
            return(false);
        }
예제 #14
0
        static internal bool?Evaluate(HqlRecord record, ArrayList q, ref int counter)
        {
            if (counter > q.Count)
            {
                throw new Exception("Unexpected end of WHERE evaluation");
            }

            bool?result = null;

            for (; ;)
            {
                if (counter >= q.Count)
                {
                    break;
                }

                Object o = q[counter];
                counter++;
                if (o is HqlToken)
                {
                    // open paren := token.Type == HqlWordType.KEYWORD && token.Keyword == HqlKeyword.OPENPAREN
                    // closed paren := token.Type == HqlWordType.KEYWORD && token.Keyword == HqlKeyword.CLOSEDPAREN
                    // and_or := token.Type == HqlWordType.KEYWORD && token.Keyword == HqlKeyword.AND_OR
                    //
                    HqlToken token = (HqlToken)o;
                    if (token.WordType == HqlWordType.KEYWORD && token.Keyword == HqlKeyword.OPENPAREN)
                    {
#if DEBUG
                        if (result.HasValue)
                        {
                            throw new Exception("How did it get a value?");
                        }
#endif
                        result = Evaluate(record, q, ref counter);
                        continue;
                    }
                    else if (token.WordType == HqlWordType.KEYWORD && token.Keyword == HqlKeyword.CLOSEDPAREN)
                    {
                        return(result);
                    }
                    else if (token.WordType == HqlWordType.KEYWORD && token.Keyword == HqlKeyword.OR)
                    {
                        bool b2 = MustContainValue(result, "left OR");
                        bool b1 = MustContainValue(Evaluate(record, q, ref counter), "right OR");
                        result = b1 || b2;
                        continue;
                    }
                    else if (token.WordType == HqlWordType.KEYWORD && token.Keyword == HqlKeyword.AND)
                    {
                        bool b2 = MustContainValue(result, "left AND");
                        bool b1 = MustContainValue(Evaluate(record, q, ref counter), "right AND");
                        result = b1 && b2;
                        continue;
                    }
                    else
                    {
                        throw new Exception("Unknown type of HqlToken in WHERE clause");
                    }
                }
                else if (o is HqlCompareToken)
                {
                    HqlCompareToken c = (HqlCompareToken)o;
#if DEBUG
                    if (result.HasValue)
                    {
                        throw new Exception("How did it get a value?");
                    }
#endif
                    result = c.Evaluate(record);

                    continue;
                }
                else
                {
                    throw new Exception("Unknown type of object in WHERE evaluation.");
                }
            }

            return(MustContainValue(result, "whole thing"));
        }
예제 #15
0
 public HqlValues(HqlFieldGroup fieldsImpacted, HqlRecord record)
 {
     _fieldsImpacted = fieldsImpacted;
     _values1        = _fieldsImpacted.GetValues(record);
 }
예제 #16
0
 public object[] GetValues(HqlRecord record)
 {
     return(_fieldgroup.GetValues(record));
 }
예제 #17
0
        //public object GetFunctionValue(HqlRecord record)
        //{
        //    return Field.GetValue(record);
        //}

        public object GetValue(HqlRecord record)
        {
            return(Field.GetValue(record));
        }