示例#1
0
 static byte[] ToBinary(ExpressionBlock expr)
 {
     using (var writer = PersistWriter.Create()) {
         writer.Write(expr);
         return(writer.ToArray());
     }
 }
示例#2
0
        // read an expression block
        public ExpressionBlock ReadExpr()
        {
            ExpressionBlock eb;
            var             name   = ReadString();
            var             kind   = (ExpressionKinds)ReadByte();
            var             serial = ReadInteger();

            switch (kind)
            {
            case ExpressionKinds.Project:
                eb = ExpressionBlock.Create(name, name, ReadDataType());
                break;

            case ExpressionKinds.Rename:
                eb = ExpressionBlock.Create(name, ReadString(), ReadDataType());
                break;

            case ExpressionKinds.IsOrder:
                eb = ExpressionBlock.Create(name, ReadDataType(), _reader.ReadBoolean(), _reader.ReadBoolean());
                break;

            case ExpressionKinds.Value:
                eb = ExpressionBlock.Create(name, ReadValue());
                break;

            default:
                eb = ExpressionBlock.Create(name, kind, ReadByteCode(), ReadDataType(), ReadArgType(), ReadInteger(), serial);
                break;
            }
            return(eb);
        }
示例#3
0
        // write a code value
        public void Write(ExpressionBlock eblock)
        {
            Write(eblock.Name);
            Write((byte)eblock.Kind);
            Write(eblock.Serial);
            switch (eblock.Kind)
            {
            case ExpressionKinds.Project:
                Write(eblock.ReturnType);
                break;

            case ExpressionKinds.Rename:
                Write(eblock.OldName);
                Write(eblock.ReturnType);
                break;

            case ExpressionKinds.IsOrder:
                Write(eblock.ReturnType);
                Write(eblock.IsGrouped);
                Write(eblock.IsDesc);
                break;

            case ExpressionKinds.Value:
                WriteValue(eblock.Value);
                break;

            default:

                Write(eblock.Code);
                Write(eblock.ReturnType);
                WriteArgType(eblock.Lookup);
                Write(eblock.AccumCount);
                break;
            }
        }
示例#4
0
        public string Having(ExpressionBlock expr)
        {
            var dict = new Dictionary <string, SubstituteDelegate> {
                { "expr", (x) => EvalFunc(expr) }, // FIX: predicate
            };

            return(_templater.Process("Having", dict));
        }
示例#5
0
 DataRow MakeOperator(string name, DataType datatype, ExpressionBlock value)
 {
     return(DataRow.Create(Table.Heading, new TypedValue[]
                           { TextValue.Create(name),
                             TextValue.Create(value.ReturnType.BaseType.Name),
                             TextValue.Create(value.ReturnType.GetUniqueName ?? ""),
                             TextValue.Create(value.NumArgs == 0 ? "" : value.SubtypeName) })); // suppress empty arg list
 }
示例#6
0
        // Sql to insert rows of data into named table as literals (not currently used)
        //public string InsertValues(string tablename, DataTable other) {
        //  var namelist = NameList(other.Heading);
        //  var tmpl = _templater.Create("InsertValues");
        //  var rowno = 0;
        //  foreach (var row in other.GetRows()) {
        //    var values = row.Values;
        //    var valuelist = ValueList(other.Heading.Degree, x => ColumnValue(values[x]));
        //    var dict = new Dictionary<string, SubstituteDelegate> {
        //      { "table", (x) => tablename },
        //      { "namelist", (x) => namelist },
        //      { "valuelist", (x) => valuelist },
        //    };
        //    if (rowno > 0) tmpl.Append("\n");
        //    tmpl.Process(dict);
        //  }
        //  return tmpl.ToString();
        //}

        // Sql to delete according to predicate
        public string Delete(string tablename, ExpressionBlock pred)
        {
            var dict = new Dictionary <string, SubstituteDelegate> {
                { "table", (x) => tablename },
                { "pred", (x) => EvalFunc(pred) },
            };

            return(_templater.Process("Delete", dict));
        }
示例#7
0
        static public CodeValue Create(ExpressionBlock expr)
        {
            var ret = new CodeValue {
                Value     = expr,
                _datatype = expr.FullDataType,
            };

            return(ret);
        }
示例#8
0
        string EvalFunc(ExpressionBlock expr)
        {
            var lookups = (expr.NumArgs == 0) ? "" : NameList(expr.Lookup.Columns.Select(c => c.Name).ToArray());
            var dict    = new Dictionary <string, SubstituteDelegate> {
                { "func", (x) => FuncName(expr) },
                { "lookups", (x) => lookups },
            };

            return(_templater.Process("EvalFunc", dict));
        }
示例#9
0
        // Sql to udpate according to predicate and expressions
        public string Update(string tablename, ExpressionBlock pred, ExpressionBlock[] exprs)
        {
            var exps = exprs.Where(e => e.IsOpen).ToArray();
            var dict = new Dictionary <string, SubstituteDelegate> {
                { "table", (x) => tablename },
                { "pred", (x) => EvalFunc(pred) },
                { "namesetlist", (x) => NameSetList(exps) },
            };

            return(_templater.Process("Update", dict));
        }
示例#10
0
        //public static string BinaryLiteral(ExpressionBlock expr) {
        //  return BinaryLiteral(ToBinary(expr));
        //}

        public static string FuncName(ExpressionBlock expr)
        {
            if (expr.IsOpen)
            {
                return("EVAL" + expr.Serial.ToString());
            }
            if (expr.HasFold)
            {
                return("EVALA" + expr.Serial.ToString());
            }
            return(null);
        }
示例#11
0
 public static ExpressionEval Create(Evaluator evaluator, ExpressionBlock expr)
 {
     return(new ExpressionEval {
         Evaluator = evaluator,
         Name = expr.Name,
         Kind = expr.Kind,
         ReturnType = expr.ReturnType,
         InternalLookup = expr.InternalLookup,
         OldName = expr.OldName,
         Code = expr.Code,
         AccumCount = expr.AccumCount,
         IsGrouped = expr.IsGrouped,
         IsDesc = expr.IsDesc,
         Serial = expr.Serial,
     });
 }
示例#12
0
 static string ExprShort(ExpressionBlock expr)
 {
     return(string.Format("{0}:{1}[{2}]", expr.Name, expr.Kind, expr.Serial));
 }