Ejemplo n.º 1
0
        public void AddAndPredicate(string predicate)
        {
            var visitor = new AddWherePredicateVisitor(predicate, _dbmsType, _forSqlAccessor);

            this.GetStmt().Accept(visitor);
        }
Ejemplo n.º 2
0
        public void AddAndPredicate(SqlPredicate predicate)
        {
            var visitor = new AddWherePredicateVisitor(predicate.Predicate);

            this.GetStmt().Accept(visitor);
        }
Ejemplo n.º 3
0
        // 結合条件を作成し付加する
        // 付加できた場合はtrueを返す
        private bool AddCorrelatedCondition(IQueryClause subQueryClause
                                            , IResultInfo subResultInfo
                                            , string tableAliasNameOfSub
                                            , IResultInfo mainResultInfo
                                            , string tableAliasNameOfMain)
        {
            if (subResultInfo.Type == ResultInfoType.Query)
            {
                var subQueryInfo = (QueryResultInfo)subResultInfo;
                //// SELECT句の抽出元テーブル情報を取得する
                // 結合条件を作成する
                string condition;
                string subTableAliasName    = subQueryInfo.SourceInfo.TableAliasName;
                string primaryKeyOfSubTable = subQueryInfo.SourceInfo.ColumnAliasName;
                if (mainResultInfo == null)
                {
                    var primaryKey = this.GetSourceTableResultInfo(subQueryInfo).ColumnAliasName;
                    condition = tableAliasNameOfSub + "." + primaryKeyOfSubTable
                                + " = " +
                                tableAliasNameOfMain + "." + primaryKey;
                }
                else
                {
                    string primaryKeyOfMainTable = mainResultInfo.ColumnAliasName;
                    condition = tableAliasNameOfSub + "." + primaryKeyOfSubTable
                                + " = " +
                                tableAliasNameOfMain + "." + primaryKeyOfMainTable;
                }

                // 結合条件を追加する
                var visitor = new AddWherePredicateVisitor(condition, _dbmsType, _forSqlAccessor);
                subQueryClause.Accept(visitor);
                return(true);
            }
            else if (subResultInfo.Type == ResultInfoType.Compound)
            {
                var compoundQueryInfo = (CompoundQueryResultInfo)subResultInfo;

                if (subQueryClause.Type != QueryType.Compound)
                {
                    return(false);
                }

                // 集合演算での抽出元の走査は左演算子を優先する
                var ret = this.AddCorrelatedCondition(((CompoundQuery)subQueryClause).Left
                                                      , compoundQueryInfo.LeftResultInfo
                                                      , tableAliasNameOfSub
                                                      , mainResultInfo
                                                      , tableAliasNameOfMain);
                if (!ret)
                {
                    ret = this.AddCorrelatedCondition(((CompoundQuery)subQueryClause).Right
                                                      , compoundQueryInfo.RightResultInfo
                                                      , tableAliasNameOfSub
                                                      , mainResultInfo
                                                      , tableAliasNameOfMain);
                }
                return(ret);
            }
            else if (subResultInfo.Type == ResultInfoType.Count)
            {
                return(false);
            }
            else if (subResultInfo.Type == ResultInfoType.Table)
            {
                // selectItemがTableResultInfoの場合はない
                throw new ArgumentException(
                          "GetCorrelatedCondition()にTableResultInfoは指定できません", "selectItem");
            }
            else
            {
                throw new InvalidEnumArgumentException("Undefined ResultInfoType is used"
                                                       , (int)subResultInfo.Type
                                                       , typeof(ResultInfoType));
            }
        }