Esempio n. 1
0
 public WhereUnion(List <Where.Builder> builders, ViewSchema vs, ViewTable vTable, SelectSet selectSet, Select select, Schema baseSchema, Table table, Operation.ExpressionParsingContext expressionParsingContext)
 {
     foreach (var b in builders)
     {
         Add(b.Build(vs, vTable, selectSet, select, baseSchema, table, expressionParsingContext));
     }
 }
Esempio n. 2
0
        // [Figure.1] Example structure of nodes, SelectSets and ExpressionParsingContext (EPC)
        //=============================================================================================================================================================
        // Node                 | SelectSet                  | Node 0     | Node 0_0      | Node 0_0_0    | Node 0_0_1    | Node 0_1      | Node 0_1_0    | Node 0_1_1
        //-------------------------------------------------------------------------------------------------------------------------------------------------------------
        //   + Node 0
        //   |                    localSelectSet               EPC.row=-1   EPC.row=-1      EPC.row=-1      EPC.row-1       EPC.row=-1      EPC.row=-1      EPC.row=-1
        //   |                                                  /|\          /|\             /|\             /|\             /|\             /|\             /|\
        //   |                                                   |            |               |               |               |               |               |
        //   |                    dataSelectSet                EPC.row=-1   EPC.row=0       EPC.row=0       EPC.row=0       EPC.row=1       EPC.row=1       EPC.row=1
        //   |                                                               /|\             /|\             /|\             /|\             /|\             /|\
        //   |-+ Node 0_0                                                     |               |               |               |               |               |
        //   | |                  localSelectSet                            EPC.row=-1      EPC.row=-1      EPC.row=-1        |               |               |
        //   | |                                                             /|\             /|\             /|\              |               |               |
        //   | |                                                              |               |               |               |               |               |
        //   | |                  dataSelectSet                             EPC.row=-1      EPC.row=0       EPC.row=1         |               |               |
        //   | |                                                                             /|\             /|\              |               |               |
        //   | |- Node 0_0_0                                                                  |               |               |               |               |
        //   | |                  localSelectSet                                            EPC.row=-1        |               |               |               |
        //   | |                                                                             /|\              |               |               |               |
        //   | |                                                                              |               |               |               |               |
        //   | |                  dataSelectSet                                             EPC.row=-1        |               |               |               |
        //   | |                                                                                              |               |               |               |
        //   | |- Node 0_0_1                                                                                  |               |               |               |
        //   |                                                                                                |               |               |               |
        //   |                    localSelectSet                                                            EPC.row=-1        |               |               |
        //   |                                                                                               /|\              |               |               |
        //   |                                                                                                |               |               |               |
        //   |                    dataSelectSet                                                             EPC.row=-1        |               |               |
        //   |                                                                                                                |               |               |
        //   |-+ Node 0_1                                                                                                     |               |               |
        //     |                  localSelectSet                                                                            EPC.row=-1      EPC.row=-1      EPC.row=-1
        //     |                                                                                                             /|\             /|\             /|\
        //     |                                                                                                              |               |               |
        //     |                  dataSelectSet                                                                             EPC.row=-1      EPC.row=0       EPC.row=1
        //     |                                                                                                                             /|\             /|\
        //     |- Node 0_1_0                                                                                                                  |               |
        //     |                  localSelectSet                                                                                              |               |
        //     |                                                                                                                            EPC.row=-1        |
        //     |                                                                                                                             /|\              |
        //     |                  dataSelectSet                                                                                               |               |
        //     |                                                                                                                            EPC.row=-1        |
        //     |- Node 0_1_1                                                                                                                                  |
        //                        localSelectSet                                                                                                              |
        //                                                                                                                                                  EPC.row=-1
        //                                                                                                                                                   /|\
        //                        dataSelectSet                                                                                                               |
        //                                                                                                                                                  EPC.row=-1
        //=============================================================================================================================================================
        //
        //  Using this structure, name look-up are prioritized in this order:
        //==========================================================================
        //    Node         |  Select Set               |  Data used from select set
        //--------------------------------------------------------------------------
        //    Node 0
        //                    Node0.dataSelectSet         all
        //                    Node0.localSelectSet        all
        //    Node 0_0
        //                    Node0_0.dataSelectSet       all
        //                    Node0_0.localSelectSet      all
        //                    Node0.dataSelectSet         row 0
        //                    Node0.localSelectSet        all
        //    Node 0_1:
        //                    Node0_1.dataSelectSet       all
        //                    Node0_1.localSelectSet      all
        //                    Node0.dataSelectSet         row 1
        //                    Node0.localSelectSet        all
        //    Node 0_0_0
        //                    Node0_0_0.dataSelectSet     all
        //                    Node0_0_0.localSelectSet    all
        //                    Node0_0.dataSelectSet       row 0
        //                    Node0_0.localSelectSet      all
        //                    Node0.dataSelectSet         row 0
        //                    Node0.localSelectSet        all
        //    Node 0_0_1
        //                    Node0_0_1.dataSelectSet     all
        //                    Node0_0_1.localSelectSet    all
        //                    Node0_0.dataSelectSet       row 1
        //                    Node0_0.localSelectSet      all
        //                    Node0.dataSelectSet         row 0
        //                    Node0.localSelectSet        all
        //    Node 0_1_0
        //                    Node0_1_0.dataSelectSet     all
        //                    Node0_1_0.localSelectSet    all
        //                    Node0_1.dataSelectSet       row 0
        //                    Node0_1.localSelectSet      all
        //                    Node0.dataSelectSet         row 1
        //                    Node0.localSelectSet        all
        //    Node 0_1_1
        //                    Node0_1_1.dataSelectSet     all
        //                    Node0_1_1.localSelectSet    all
        //                    Node0_1.dataSelectSet       row 1
        //                    Node0_1.localSelectSet      all
        //                    Node0.dataSelectSet         row 1
        //                    Node0.localSelectSet        all
        //==========================================================================


        public ViewTable(ViewSchema viewSchema, Schema baseSchema, Builder.Node node, ExpressionParsingContext parentExpressionParsingContext)
            : base(viewSchema)
        {
            this.ViewSchema                = viewSchema;
            this.BaseSchema                = baseSchema;
            this.node                      = node;
            ExpressionParsingContext       = parentExpressionParsingContext;
            ParentExpressionParsingContext = parentExpressionParsingContext;
        }
Esempio n. 3
0
            public Where Build(ViewSchema vs, ViewTable vTable, SelectSet selectSet, Select select, Schema baseSchema, Table table, Operation.ExpressionParsingContext expressionParsingContext)
            {
                Where w      = new Where();
                var   option = new Operation.Expression.ParseIdentifierOption(vs, table, true, false, null, expressionParsingContext);

                option.formatError = (msg, y) =>
                {
                    return(FormatErrorContextInfo(vs, vTable, select) + msg);
                };
                option.BypassSelectSetCondition = selectSet;
                w.m_Comparison = comparison.Build(option);
                return(w);
            }
Esempio n. 4
0
            private string FormatErrorContextInfo(ViewSchema vs, ViewTable vTable)
            {
                string str = "Error while building view column '" + name + "'";

                if (vs != null)
                {
                    str += " schema '" + vs.name + "'";
                }
                if (vTable != null)
                {
                    str += " view table '" + vTable.GetName() + "'";
                }
                return(str);
            }
Esempio n. 5
0
 public void Build(ViewSchema vs, ViewTable vTable, SelectSet selectSet, Select sel, Database.Schema baseSchema, Operation.ExpressionParsingContext expressionParsingContext)
 {
     if (where.Count > 0)
     {
         sel.where = new WhereUnion();
         foreach (var w in where)
         {
             var w2 = w.Build(vs, vTable, selectSet, sel, baseSchema, sel.sourceTable, expressionParsingContext);
             if (w2.Comparison.IsManyToMany())
             {
                 sel.isManyToMany = true;
             }
             sel.where.Add(w2);
         }
     }
 }
Esempio n. 6
0
            public SelectSet Build(ViewTable viewTable, ViewSchema viewSchema, Database.Schema baseSchema)
            {
                if (select.Count == 0)
                {
                    return(null);
                }

                SelectSet selectSet = new SelectSet();

                // Create select statements (first pass)
                foreach (var iSelect in select)
                {
                    Select s = iSelect.Create(viewTable.ViewSchema, baseSchema, viewTable);
                    if (s != null)
                    {
                        selectSet.Add(s);
                    }
                    else
                    {
                        Debug.LogError("Could not create Select named '" + iSelect.name + "'");
                    }
                }

                // add current set to the expression parsing hierarchy
                var expressionParsingContext = new Operation.ExpressionParsingContext(viewTable.ExpressionParsingContext, selectSet);

                // Build select statements (second pass)
                var eSelBuilder = select.GetEnumerator();
                var eSelList    = selectSet.select.GetEnumerator();

                while (eSelBuilder.MoveNext())
                {
                    eSelList.MoveNext();
                    eSelBuilder.Current.Build(viewSchema, viewTable, selectSet, eSelList.Current, baseSchema, expressionParsingContext);
                }

                if (Condition != null)
                {
                    Operation.Expression.ParseIdentifierOption parseOpt = new Operation.Expression.ParseIdentifierOption(viewSchema, viewTable, true, false, null, expressionParsingContext);
                    parseOpt.BypassSelectSetCondition = selectSet;
                    selectSet.Condition = Condition.Build(parseOpt);
                }

                return(selectSet);
            }
Esempio n. 7
0
            public Select Create(ViewSchema vs, Database.Schema baseSchema, Table table)
            {
                Select sel = new Select();

                sel.name = name;
                if (baseSchema != null)
                {
                    sel.sourceTable = baseSchema.GetTableByName(sourceTableName);
                }
                sel.MaxRow = MaxRow;
                if (sel.sourceTable == null)
                {
                    Debug.LogError("No table named '" + (sourceTableName == null ? "null" : sourceTableName) + "'");
                    return(null);
                }

                return(sel);
            }
Esempio n. 8
0
            public ViewSchema Build(Database.Schema baseSchema)
            {
                ViewSchema vs = new ViewSchema();

                vs.baseSchema = baseSchema;
                vs.tables     = new ViewTable[viewTable.Count];
                vs.name       = name;
                int i = 0;

                foreach (var tBuilder in viewTable)
                {
                    var table = tBuilder.Build(vs, baseSchema);
                    vs.tables[i] = table;
                    vs.tablesByName.Add(table.GetName(), table);
                    ++i;
                }
                return(vs);
            }
Esempio n. 9
0
            private string FormatErrorContextInfo(ViewSchema vs, ViewTable vTable, Select select)
            {
                string str = "";

                if (vs != null && vTable != null)
                {
                    str += "Error while building view '" + vs.name + "' table '" + vTable.GetName() + "'";
                }
                if (select != null)
                {
                    str += " select '" + select.name + "'";
                }
                if (str != "")
                {
                    str += ". ";
                }
                return(str);
            }
Esempio n. 10
0
                public ViewTable Build(BuildingData buildingData, ViewTable parent, long row, ViewSchema vs, Database.Schema baseSchema, Operation.ExpressionParsingContext parentExpressionParsingContext)
                {
                    // Check for usage error from data.
                    if (parent == null && String.IsNullOrEmpty(name))
                    {
                        Debug.LogError("Table need a name");
                        return(null);
                    }

                    // Check for usage error from code.
                    if (!(parent == null || parent.node == this.parent))
                    {
                        Debug.LogError("Parent ViewTable must points to the node's parent while building child node's ViewTable.");
                    }

                    ViewTable vTable = new ViewTable(vs, baseSchema, this, parentExpressionParsingContext);


                    // If has local select set, create it and add it to the expression parsing context hierarchy. see [Figure.1]
                    vTable.SetupLocalSelectSet(localSelectSet.Build(vTable, vs, baseSchema));

                    MetaTable metaTable = BuildOrGetMetaTable(parent, vTable);

                    if (buildingData.MetaTable == null)
                    {
                        buildingData.MetaTable = metaTable;
                    }

                    //declare columns
                    foreach (var colb in column)
                    {
                        MetaColumn metaColumn = metaTable.GetColumnByName(colb.name);

                        colb.BuildOrUpdateDeclaration(buildingData, vTable, ref metaColumn, vTable.ExpressionParsingContext);
                    }

                    if (data != null)
                    {
                        data.Build(buildingData, this, vTable, parent, parentExpressionParsingContext);
                    }

                    // Fix meta columns (that does not have a data type set) to their fallback value
                    foreach (var fb in buildingData.FallbackColumnType)
                    {
                        if (fb.Key.Type == null)
                        {
                            fb.Key.Type = fb.Value;
                        }
                    }

                    //Build missing column with default behavior
                    for (int i = 0; i != metaTable.GetColumnCount(); ++i)
                    {
                        var metaColumn = metaTable.GetColumnByIndex(i);
                        var column     = vTable.GetColumnByIndex(i);

                        if (column == null)
                        {
                            if (metaColumn.DefaultMergeAlgorithm != null)
                            {
                                //when we have a merge algorithm, set the entries as the result of each group's merge value.
                                column = ViewColumn.Builder.BuildColumnNodeMerge(vTable, metaColumn, parentExpressionParsingContext);
                            }

                            vTable.SetColumn(metaColumn, column);
                        }
                    }

                    if (data != null && data.type == Data.DataType.Select && vTable.dataSelectSet.IsManyToMany())
                    {
                        Debug.LogError("Cannot build a view using a many-to-many select statement. Specify a row value for your select statement where condition(s).");
                        MemoryProfilerAnalytics.AddMetaDatatoEvent <MemoryProfilerAnalytics.LoadViewXMLEvent>(7);
                    }

                    return(vTable);
                }
Esempio n. 11
0
 public BuildingData(ViewSchema schema, Schema baseSchema)
 {
     Schema     = schema;
     BaseSchema = baseSchema;
 }