Beispiel #1
0
        public override object VisitJoin_right([NotNull] SqlParser.Join_rightContext context)
        {
            var joinTable = new JoinTable();

            if (context.join_operator().K_CROSS() != null)
            {
                joinTable.JoinType = JoinType.Cross;
            }
            else if (context.join_operator().K_INNER() != null)
            {
                joinTable.JoinType = JoinType.Inner;
            }
            else if (context.join_operator().K_LEFT() != null && context.join_operator().K_OUTER() != null)
            {
                joinTable.JoinType = JoinType.LeftOuter;
            }
            else if (context.join_operator().K_LEFT() != null)
            {
                joinTable.JoinType = JoinType.Left;
            }
            else
            {
                joinTable.JoinType = JoinType.Inner;
            }

            joinTable.Table          = (TableName)VisitTable_or_subquery(context.table_or_subquery());
            joinTable.JoinContraints = (IExpression)VisitJoin_constraint(context.join_constraint());

            return(joinTable);
        }
Beispiel #2
0
        public void ToString_WithJoinTable()
        {
            var schema    = "fromSchema";
            var name      = "fromTable";
            var tableName = new EntityName(schema, name);

            var fromColumn1 = "fromCol1";
            var fromColumn2 = "fromCol2";
            var fromAlias2  = "fromAlias2";
            var columns     = new IItemName[]  {
                new ItemName(fromColumn1),
                new ColumnName(fromColumn2, fromAlias2)
            };
            var fromTable = new FromTable(tableName, columns);

            IEntityName joinTableName = new EntityName("joinTable");

            IItemName[] selectColumns = new IItemName[2] {
                new ItemName("joinTblCol1"), new ItemName("joinTblCol2")
            };
            var joinTable = new JoinTable(joinTableName, selectColumns);

            fromTable.Join(joinTable);

            var selectClause = fromTable.GetSelectClause();
            var testString   = $"[{schema}].[{name}].[{fromColumn1}], [{schema}].[{name}].[{fromColumn2}] as [{fromAlias2}], {joinTableName}.{selectColumns[0]}, {joinTableName}.{selectColumns[1]}";

            Assert.AreEqual(testString, selectClause);
        }
Beispiel #3
0
        public void ToString_WithJoinTable_NoJTSelectColumns()
        {
            var schema    = "fromSchema";
            var name      = "fromTable";
            var tableName = new EntityName(schema, name);

            var fromColumn1 = "fromCol1";
            var fromColumn2 = "fromCol2";
            var fromAlias2  = "fromAlias2";
            var columns     = new IColumnName[]  {
                new ColumnName(fromColumn1),
                new ColumnName(fromColumn2, fromAlias2)
            };
            IFromTable fromTable = new FromTable(tableName, columns);

            IEntityName joinTableName = new EntityName("joinTable");
            var         joinTable     = new JoinTable(joinTableName);

            fromTable.Join(joinTable);

            var selectClause = fromTable.ToString();
            var testString   = $"select [{schema}].[{name}].[{fromColumn1}], [{schema}].[{name}].[{fromColumn2}] as [{fromAlias2}]\r\nfrom [{schema}].[{name}]\r\n";

            Assert.AreEqual(testString.TrimEnd(), selectClause.TrimEnd());
        }
 public void Constructor_NullTableNameArgument()
 {
     IItemName[] selectColumns = new IItemName[1] {
         new ItemName("joinColumn")
     };
     var table = new JoinTable(null, selectColumns);
 }
Beispiel #5
0
        private static void ListOrders()
        {
            JoinTable table = Order.employeeID.InnerJoin(Employee.employeeID)
                              .InnerJoin(Order.customerID, Customer.customerID)
                              .Select(Order.orderID.At(), Customer.companyName, Employee.firstName, Employee.lastName);

            IList <OrderView> orders = new Expression().List <OrderView>(table);
        }
        public void Constructor_NullColumnsArgument()
        {
            IEntityName tableName = new EntityName("joinTable");
            var         table     = new JoinTable(tableName, null);

            Assert.AreEqual(tableName, table.TableName);
            Assert.IsNull(table.Columns);
        }
Beispiel #7
0
        public IList <OrderDetail> GetOrderDetail(ISession session, GetDetail e)
        {
            Expression exp = Models.OrderDetails.orderID == e.OrderID;
            JoinTable  jt  = Models.OrderDetails.productID.InnerJoin(Models.Products.productID);

            jt.Select("OrderDetails.*", Models.Products.productName.Name);
            return(exp.List <OrderDetail>(jt));
        }
        public void Constructor_EmptyColumnsArgument()
        {
            IEntityName tableName = new EntityName("joinTable");

            IItemName[] selectColumns = new IItemName[0];
            var         table         = new JoinTable(tableName, selectColumns);

            Assert.AreEqual(0, table.Columns.Length);
        }
        public void Constructor_OneNullColumnArgument()
        {
            IEntityName tableName = new EntityName("joinTable");

            IItemName[] selectColumns = new IItemName[2] {
                new ItemName("joinColumn"), null
            };
            var table = new JoinTable(tableName, selectColumns);
        }
        public void ToString_NoJoinColumns()
        {
            IEntityName tableName = new EntityName("joinTable");

            IItemName[] selectColumns = new IItemName[1] {
                new ItemName("selectColumn")
            };
            var table = new JoinTable(tableName, selectColumns);

            Assert.AreEqual(string.Empty, table.ToString());
        }
        public void Constructor_WithColumns()
        {
            IEntityName tableName = new EntityName("joinTable");

            IItemName[] selectColumns = new IItemName[1] {
                new ItemName("joinColumn")
            };
            var table = new JoinTable(tableName, selectColumns);

            Assert.AreEqual(tableName, table.TableName);
            Assert.AreEqual(selectColumns, table.Columns);
        }
Beispiel #12
0
 private void ConvertTableRelation(QueryModel queryModel, StringBuilder sb)
 {
     sb.AppendFormat("{0} ", queryModel.TableRelation.PrimeTable);
     if (queryModel.TableRelation.JoinTables.IsNotEmpty())
     {
         JoinTable joinTable = null;
         for (int idx = 0; idx < queryModel.TableRelation.JoinTables.Count; idx++)
         {
             joinTable = queryModel.TableRelation.JoinTables[idx];
             ConvertJoinTable(joinTable, sb);
         }
     }
 }
        public void AddJoinColumn()
        {
            IEntityName tableName = new EntityName("joinTable");

            IItemName[] selectColumns = new IItemName[1] {
                new ItemName("joinColumn")
            };
            var        table         = new JoinTable(tableName, selectColumns);
            EntityName fromTableName = "fromTable";
            ItemName   leftColumn    = "leftJoinColumn";
            ItemName   rightColumn   = "rightJoinColumn";

            table.AddJoinColumn(fromTableName, leftColumn, rightColumn);
        }
Beispiel #14
0
    //Loads the incoming Join Requests
    private void loadJoinRequestsTable()
    {
        UsersTable         userTable = new UsersTable(new DatabaseConnection());
        List <JoinRequest> requests  = userTable.getJoinRequests(game.GameID);

        if (requests.Count == 0)
        {
            return;
        }

        JoinTable joinTable = new JoinTable(requests);

        JoinRequestsPlaceholder.Controls.Add(joinTable);
    }
Beispiel #15
0
        private static void ListOrders()
        {
            TimeWatch.________________________________________________________("list order");
            TimeWatch.________________________________________________________("create table");
            JoinTable table = Order.employeeID.InnerJoin(Employee.employeeID)
                              .InnerJoin(Order.customerID, Customer.customerID)
                              .Select(Order.orderID.At(), Customer.companyName, Employee.firstName, Employee.lastName);

            TimeWatch.________________________________________________________();
            TimeWatch.________________________________________________________("List");
            IList <OrderView> orders = new Expression().List <OrderView>(table);

            TimeWatch.________________________________________________________();
            TimeWatch.________________________________________________________();
        }
Beispiel #16
0
        public ActionResult Join(string tableId)
        {
            var table = _tables.GetById(tableId);

            if (table.Players.Any(x => x.UserId == UserId))
            {
                return(Json(new { Joined = true }));
            }
            var cmd = new JoinTable
            {
                Id     = tableId,
                Cash   = 1000,
                UserId = UserId
            };

            Send(cmd);
            return(Json(cmd));
        }
Beispiel #17
0
    private void generateTableScrollItem(TableView tableView)
    {
        Button tableScrollItemObj = Instantiate(tablesScrollItemPrefab);

        tableScrollItemObj.transform.SetParent(tablesScrollContent.transform, false);
        tableScrollItemObj.transform.Find("Table_Name").gameObject.GetComponent <TextMeshProUGUI>().text    = tableView.firstPlayerNick;
        tableScrollItemObj.transform.Find("Clients_Count").gameObject.GetComponent <TextMeshProUGUI>().text = tableView.playersIds.Count + "/" + tableView.maxPlayersCount;
        tableScrollItemObj.onClick.AddListener(() => {
            loadingDisplayer.showLoading();
            string clientIdValue = PlayerPrefs.GetString("Id");
            ClientId clientId    = new ClientId(clientIdValue);
            TableId tableId      = new TableId(tableView.tableViewId);
            JoinTable joinTable  = new JoinTable(clientId, tableId);
            Debug.Log("Joining to table:s" + joinTable.tableId + " by client: " + joinTable.clientId);
            string joinTableJson = JsonUtility.ToJson(joinTable) ?? "";
            StartCoroutine(this.joinTable(joinTableJson));
        });
    }
        public void ToString_OneJoinColumn()
        {
            IEntityName tableName = new EntityName("joinTable");

            IItemName[] selectColumns = new IItemName[1] {
                new ItemName("selectColumn")
            };
            var        table         = new JoinTable(tableName, selectColumns);
            EntityName fromTableName = "fromTable";
            ItemName   leftColumn1   = "leftJoinColumn";
            ItemName   rightColumn1  = "rightJoinColumn";

            table.AddJoinColumn(fromTableName, leftColumn1, rightColumn1);

            var testString = $"join {tableName} on {fromTableName}.{leftColumn1}{RelationalOperators.Equal.ToSqlString()}{table.TableName}.{rightColumn1}";

            Assert.AreEqual(testString, table.ToString());
        }
Beispiel #19
0
        private void ConvertJoinTable(JoinTable joinTable, StringBuilder sbTarget)
        {
            if (joinTable == null || joinTable.RelFields.IsEmpty())
            {
                throw new Exception("关联表信息不完整!");
            }

            //关联表sql模板: join base_dict_type bdt on bd.dict_type=bdt.type_code
            StringBuilder sbInner = new StringBuilder();

            sbInner.AppendFormat("{0} join {1} on ", joinTable.JoinType, joinTable.Table);
            RelationField relField = null;

            for (int idx = 0; idx < joinTable.RelFields.Count; idx++)
            {
                relField = joinTable.RelFields[idx];
                sbInner.AppendFormat("{0} = {1} {2} ", relField.Field1, relField.Field2, idx == joinTable.RelFields.Count - 1 ? "" : "and");
            }
            sbTarget.Append(sbInner.ToString());
        }
Beispiel #20
0
        public IActionResult Table(JoinTable newPlayer)
        {
            Console.WriteLine($"HanError: " + newPlayer.userID);

            Table tableOne = DataTemp.readData();

            if (tableOne == null)
            {
                tableOne = new Table();
                tableOne.LoadTable();
                tableOne.nextTurn = 0;
                Console.WriteLine("HanError: from Action Table 1");
            }

            if (tableOne.NumOfActivePlayers() >= 6)
            {
                // room is full
                return(View("Index"));
            }
            newPlayer.LoadUser();

            Console.Write("HanError: First");
            Console.WriteLine(newPlayer.user.FirstName);

            if (tableOne.table.Seats.FirstOrDefault(o => o.Player.UserId == newPlayer.userID) == null)
            {
                tableOne.JoinGame(newPlayer.user);

                if (tableOne.NumOfActivePlayers() == 2)
                {
                    tableOne.StartGame();
                    tableOne.StartRound();
                }
            }

            DataTemp.writeData(tableOne);

            return(View("Table", tableOne));
        }
Beispiel #21
0
        /// <summary>Concatena la estructura de tablas para la clausula from</summary>
        private string ConcatJoin(UnionSelect union)
        {
            StringBuilder sqlQuery     = new StringBuilder();
            bool          isFirstTable = true;
            bool          joinFound;
            string        onWhere = "";

            foreach (Table tbl in union.lstFrom)
            {
                //Si no es la primera tabla del from, agrega el tipo de union con la previa
                if (!isFirstTable)
                {
                    joinFound = false;
                    List <JoinTable> lstJoin = union.lstJoin.Select(j => j).ToList(); //Clonar lista
                    for (int iAls = 0; iAls < lstJoin.Count; iAls++)
                    {
                        if (tbl.tableAlias == lstJoin[iAls].tableAlias)
                        {
                            sqlQuery.Append(" " + lstJoin[iAls].type.ToString().ToUpper() + " JOIN");
                            lstJoin.RemoveAt(iAls);
                            joinFound = true;
                            break;
                        }
                    }
                    if (!joinFound)
                    {
                        sqlQuery.Append(",");
                    }
                }
                //Agrega la tabla y su alias en caso de tener
                sqlQuery.Append(" " + (tbl.database == "" ? "" : tbl.database + ".") + (tbl.schema == "" ? "" : tbl.schema + ".") + tbl.table + (tbl.tableAlias == "" ? "" : " AS " + tbl.tableAlias));
                //Si no es la primera tabla del from, agrega las condiciones de union con las previas
                if (!isFirstTable)
                {
                    onWhere = "";
                    List <Comparison> lstJoinOn       = new List <Comparison>(union.lstJoinOn);
                    string[]          condicionesJoin = lstJoinOn
                                                        .Where(j => j.owner == tbl.tableAlias)
                                                        .Select(j => EvalComparison(j)).ToArray();
                    JoinTable currentJoin = union.lstJoin.First(j => j.tableAlias == tbl.tableAlias);
                    if (currentJoin.type != dbJoi.Cross)
                    {
                        onWhere += " ON " + string.Join(" AND ", condicionesJoin);
                    }

                    //onWhere = "";
                    ////Se revisan todas las anteriores tablas agregadas hasta llegar a la actual
                    //foreach (Table prevTbl in union.lstFrom)
                    //{
                    //    if (prevTbl.tableAlias == tbl.tableAlias)
                    //    {
                    //        break;
                    //    }
                    //    iCnd = 0;
                    //    //Ciclo para control de condicion de repeticion
                    //    while (iCnd <= union.lstJoinOn.Count - 1)
                    //    {
                    //        //Si ambas partes de la condicion son campos
                    //        if (union.lstJoinOn[iCnd].expr == null && (Regex.IsMatch(union.lstJoinOn[iCnd].comparator, ".+[.].+") && Regex.IsMatch(union.lstJoinOn[iCnd].values[0], ".+[.].+")))
                    //        {
                    //            Regex rgxCurTable = new Regex("^" + tbl.tableAlias + "[.].+");
                    //            Regex rgxPreTable = new Regex("^" + prevTbl.tableAlias + "[.].+");
                    //            //Si la condicion esta relacionada a esta tabla y la otra condicion a la tabla anterior
                    //            if ((rgxCurTable.IsMatch(union.lstJoinOn[iCnd].comparator) || rgxCurTable.IsMatch(union.lstJoinOn[iCnd].values[0])) && (rgxPreTable.IsMatch(union.lstJoinOn[iCnd].comparator) || rgxPreTable.IsMatch(union.lstJoinOn[iCnd].values[0])))
                    //            {
                    //                //Agregar condicion al where
                    //                onWhere += (onWhere == "") ? " ON" : " AND";
                    //                onWhere += " " + union.lstJoinOn[iCnd].comparator + " " + dbComToString(union.lstJoinOn[iCnd].type) + " " + union.lstJoinOn[iCnd].values[0];
                    //                //Remover condicion para que ya no aparezca en el where y ajustar el control de ciclo
                    //                union.lstJoinOn.RemoveAt(iCnd);
                    //                iCnd--;
                    //            }
                    //        }
                    //        iCnd++;
                    //    }
                    //}
                }
                sqlQuery.Append(onWhere);
                isFirstTable = false;
            }
            return(sqlQuery.ToString());
        }
 public void Handle(JoinTable c)
 {
     _repository.Perform(c.Id, table => table.JoinTable(c.UserId, c.Cash));
 }